jscrambler
Advanced tools
Comparing version 6.4.21 to 6.4.23
#!/usr/bin/env node | ||
"use strict"; | ||
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } | ||
require("core-js/modules/es.symbol.description.js"); | ||
require("core-js/modules/es.regexp.exec.js"); | ||
require("core-js/modules/web.dom-collections.iterator.js"); | ||
var _commander = _interopRequireDefault(require("commander")); | ||
@@ -9,24 +11,21 @@ var _lodash = _interopRequireDefault(require("lodash.defaults")); | ||
var _filesizeParser = _interopRequireDefault(require("filesize-parser")); | ||
var _config3 = _interopRequireDefault(require("../config")); | ||
var _config2 = _interopRequireDefault(require("../config")); | ||
var _ = _interopRequireDefault(require("../")); | ||
var _utils = require("../utils"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
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; } | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } | ||
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } | ||
var debug = !!process.env.DEBUG; | ||
var validateBool = function validateBool(option) { | ||
return function (val) { | ||
if (!/^(true|false)$/i.test(val)) { | ||
console.error("*".concat(option, "* requires a <bool> value.")); | ||
process.exit(1); | ||
} | ||
return val.toLowerCase(); | ||
}; | ||
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; } | ||
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; } | ||
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; } | ||
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); } | ||
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); } | ||
const debug = !!process.env.DEBUG; | ||
const validateBool = option => val => { | ||
if (!/^(true|false)$/i.test(val)) { | ||
console.error("*".concat(option, "* requires a <bool> value.")); | ||
process.exit(1); | ||
} | ||
return val.toLowerCase(); | ||
}; | ||
var validateCodeHardeningThreshold = function validateCodeHardeningThreshold(val) { | ||
var inBytes; | ||
const validateCodeHardeningThreshold = val => { | ||
let inBytes; | ||
try { | ||
@@ -40,5 +39,5 @@ inBytes = (0, _filesizeParser.default)(val); | ||
}; | ||
var validateProfilingDataMode = function validateProfilingDataMode(mode) { | ||
var availableModes = ['automatic', 'annotations', 'off']; | ||
var normalizedMode = mode.toLowerCase(); | ||
const validateProfilingDataMode = mode => { | ||
const availableModes = ['automatic', 'annotations', 'off']; | ||
const normalizedMode = mode.toLowerCase(); | ||
if (!availableModes.includes(normalizedMode)) { | ||
@@ -50,5 +49,5 @@ console.error("*profiling-data-mode* requires one of the following modes: {".concat(availableModes.toString(), "}. Example: --profiling-data-mode ").concat(availableModes[0])); | ||
}; | ||
var availableEnvironments = ['node', 'browser', 'isomorphic', 'automatic']; | ||
var validateForceAppEnvironment = function validateForceAppEnvironment(env) { | ||
var normalizeEnvironment = env.toLowerCase(); | ||
const availableEnvironments = ['node', 'browser', 'isomorphic', 'automatic']; | ||
const validateForceAppEnvironment = env => { | ||
const normalizeEnvironment = env.toLowerCase(); | ||
if (!availableEnvironments.includes(normalizeEnvironment)) { | ||
@@ -61,3 +60,3 @@ console.error("*force-app-environment* requires one of the following values: {".concat(availableEnvironments.toString(), "}. Example: --force-app-environment ").concat(availableEnvironments[0])); | ||
_commander.default.version(require('../../package.json').version).usage('[options] <file ...>').option('-a, --access-key <accessKey>', 'Access key').option('-c, --config <config>', 'Jscrambler configuration options').option('-H, --host <host>', 'Hostname').option('-i, --application-id <id>', 'Application ID').option('-o, --output-dir <dir>', 'Output directory').option('-p, --port <port>', 'Port').option('--base-path <path>', 'Base Path').option('--protocol <protocol>', 'Protocol (http or https)').option('--cafile <path>', 'Internal certificate authority').option('-C, --cwd <dir>', 'Current Working Directory').option('-s, --secret-key <secretKey>', 'Secret key').option('-m, --source-maps <id>', 'Download source maps').option('-R, --randomization-seed <seed>', 'Set randomization seed').option('--instrument', 'Instrument file(s) before start profiling. ATTENTION: previous profiling information will be deleted').option('--start-profiling', 'Starts profiling (assumes an already instrumented application)').option('--stop-profiling', 'Stops profiling').option('--code-hardening-threshold <threshold>', 'Set code hardening file size threshold. Format: {value}{unit="b,kb,mb"}. Example: 200kb', validateCodeHardeningThreshold).option('--recommended-order <bool>', 'Use recommended order', validateBool('recommended-order')).option('-W, --werror <bool>', 'Set werror flag value (default: true)', validateBool('werror')).option('--utc <bool>', 'Set UTC as the request time zone. Otherwise it uses the local time zone (default: true)', validateBool('utc')).option('--tolerate-minification <bool>', "Don't detect minification as malicious tampering (default: true)", validateBool('tolerate-minification')).option('--use-profiling-data <bool>', "(version 6.2 only) Protection should use the existing profiling data (default: true)", validateBool('use-profiling-data')).option('--profiling-data-mode <mode>', "(version 6.3 and above) Select profiling mode (default: automatic)", validateProfilingDataMode).option('--remove-profiling-data', "Removes the current application profiling information").option('--use-app-classification <bool>', '(version 6.3 and above) Protection should use Application Classification metadata when protecting (default: true)', validateBool('--use-app-classification')).option('--input-symbol-table <file>', '(version 6.3 and above) Protection should use symbol table when protecting. (default: no file)').option('--output-symbol-table <id>', '(version 6.3 and above) Download output symbol table (json)').option('--jscramblerVersion <version>', 'Use a specific Jscrambler version').option('--debugMode', 'Protect in debug mode').option('--skip-sources', 'Prevent source files from being updated').option('--force-app-environment <environment>', "(version 7.1 and above) Override application's environment detected automatically. Possible values: ".concat(availableEnvironments.toString()), validateForceAppEnvironment).option('--ensure-code-annotation <bool>', "(version 7.3 and above) Fail protection if no annotations are found on the source code (default: false)", validateBool('ensure-code-annotation')).option('-n <number>', "(version 7.2 and above) Create multiple protections at once.").parse(process.argv); | ||
var globSrc, filesSrc, config; | ||
let globSrc, filesSrc, config; | ||
@@ -125,3 +124,3 @@ // If -c, --config file was provided | ||
} | ||
config = (0, _lodash.default)(config, _config3.default); | ||
config = (0, _lodash.default)(config, _config2.default); | ||
config.numberOfProtections = (0, _utils.validateNProtections)(_commander.default.N); | ||
@@ -142,5 +141,5 @@ if (config.codeHardeningThreshold) { | ||
filesSrc = globSrc; | ||
var nSources = 0; | ||
let nSources = 0; | ||
// Iterate `globSrc` to build a list of source files into `filesSrc` | ||
for (var i = 0, l = globSrc.length; i < l; i += 1) { | ||
for (let i = 0, l = globSrc.length; i < l; i += 1) { | ||
// Calling sync `glob` because async is pointless for the CLI use case | ||
@@ -154,3 +153,3 @@ // (as of now at least) | ||
} | ||
var tmpGlob = (0, _utils.getMatchedFiles)(globSrc[i]); | ||
const tmpGlob = (0, _utils.getMatchedFiles)(globSrc[i]); | ||
if (config.werror && tmpGlob.length === 0) { | ||
@@ -165,3 +164,3 @@ console.error("Pattern \"".concat(globSrc[i], "\" doesn't match any files.")); | ||
console.log("Pattern \"".concat(globSrc[i], "\" matched the following files:")); | ||
tmpGlob.forEach(function (file) { | ||
tmpGlob.forEach(file => { | ||
console.log(" ".concat(file)); | ||
@@ -180,44 +179,43 @@ }); | ||
} | ||
var _config2 = config, | ||
applicationId = _config2.applicationId, | ||
accessKey = _config2.accessKey, | ||
secretKey = _config2.secretKey, | ||
filesDest = _config2.filesDest, | ||
host = _config2.host, | ||
port = _config2.port, | ||
basePath = _config2.basePath, | ||
protocol = _config2.protocol, | ||
cafile = _config2.cafile, | ||
applicationTypes = _config2.applicationTypes, | ||
languageSpecifications = _config2.languageSpecifications, | ||
areSubscribersOrdered = _config2.areSubscribersOrdered, | ||
cwd = _config2.cwd, | ||
randomizationSeed = _config2.randomizationSeed, | ||
_config2$sourceMaps = _config2.sourceMaps, | ||
sourceMaps = _config2$sourceMaps === void 0 ? false : _config2$sourceMaps, | ||
useRecommendedOrder = _config2.useRecommendedOrder, | ||
werror = _config2.werror, | ||
tolerateMinification = _config2.tolerateMinification, | ||
jscramblerVersion = _config2.jscramblerVersion, | ||
debugMode = _config2.debugMode, | ||
proxy = _config2.proxy, | ||
codeHardeningThreshold = _config2.codeHardeningThreshold, | ||
useProfilingData = _config2.useProfilingData, | ||
profilingDataMode = _config2.profilingDataMode, | ||
browsers = _config2.browsers, | ||
useAppClassification = _config2.useAppClassification, | ||
removeProfilingData = _config2.removeProfilingData, | ||
skipSources = _config2.skipSources, | ||
inputSymbolTable = _config2.inputSymbolTable, | ||
utc = _config2.utc, | ||
entryPoint = _config2.entryPoint, | ||
excludeList = _config2.excludeList, | ||
numberOfProtections = _config2.numberOfProtections, | ||
ensureCodeAnnotation = _config2.ensureCodeAnnotation, | ||
forceAppEnvironment = _config2.forceAppEnvironment; | ||
var params = config.params; | ||
var incompatibleOptions = ['sourceMaps', 'instrument', 'startProfiling', 'stopProfiling']; | ||
var usedIncompatibleOptions = []; | ||
for (var _i = 0, _incompatibleOptions = incompatibleOptions; _i < _incompatibleOptions.length; _i++) { | ||
var incompatibleOption = _incompatibleOptions[_i]; | ||
const { | ||
applicationId, | ||
accessKey, | ||
secretKey, | ||
filesDest, | ||
host, | ||
port, | ||
basePath, | ||
protocol, | ||
cafile, | ||
applicationTypes, | ||
languageSpecifications, | ||
areSubscribersOrdered, | ||
cwd, | ||
randomizationSeed, | ||
sourceMaps = false, | ||
useRecommendedOrder, | ||
werror, | ||
tolerateMinification, | ||
jscramblerVersion, | ||
debugMode, | ||
proxy, | ||
codeHardeningThreshold, | ||
useProfilingData, | ||
profilingDataMode, | ||
browsers, | ||
useAppClassification, | ||
removeProfilingData, | ||
skipSources, | ||
inputSymbolTable, | ||
utc, | ||
entryPoint, | ||
excludeList, | ||
numberOfProtections, | ||
ensureCodeAnnotation, | ||
forceAppEnvironment | ||
} = config; | ||
const params = config.params; | ||
const incompatibleOptions = ['sourceMaps', 'instrument', 'startProfiling', 'stopProfiling']; | ||
const usedIncompatibleOptions = []; | ||
for (const incompatibleOption of incompatibleOptions) { | ||
if (_commander.default[incompatibleOption]) { | ||
@@ -231,82 +229,52 @@ usedIncompatibleOptions.push(incompatibleOption); | ||
} | ||
var clientSettings = { | ||
const clientSettings = { | ||
keys: { | ||
accessKey: accessKey, | ||
secretKey: secretKey | ||
accessKey, | ||
secretKey | ||
}, | ||
host: host, | ||
port: port, | ||
basePath: basePath, | ||
protocol: protocol, | ||
cafile: cafile, | ||
proxy: proxy, | ||
utc: utc, | ||
jscramblerVersion: jscramblerVersion | ||
host, | ||
port, | ||
basePath, | ||
protocol, | ||
cafile, | ||
proxy, | ||
utc, | ||
jscramblerVersion | ||
}; | ||
if (_commander.default.sourceMaps) { | ||
// Go, go, go download | ||
_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() { | ||
return _regeneratorRuntime().wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
_context.prev = 0; | ||
_context.next = 3; | ||
return _.default.downloadSourceMaps(_objectSpread(_objectSpread({}, clientSettings), {}, { | ||
filesDest: filesDest, | ||
filesSrc: filesSrc, | ||
protectionId: _commander.default.sourceMaps | ||
})); | ||
case 3: | ||
_context.next = 9; | ||
break; | ||
case 5: | ||
_context.prev = 5; | ||
_context.t0 = _context["catch"](0); | ||
console.error(debug ? _context.t0 : _context.t0.message || _context.t0); | ||
process.exit(1); | ||
case 9: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, null, [[0, 5]]); | ||
}))(); | ||
(async () => { | ||
try { | ||
await _.default.downloadSourceMaps(_objectSpread(_objectSpread({}, clientSettings), {}, { | ||
filesDest, | ||
filesSrc, | ||
protectionId: _commander.default.sourceMaps | ||
})); | ||
} catch (error) { | ||
console.error(debug ? error : error.message || error); | ||
process.exit(1); | ||
} | ||
})(); | ||
} else if (_commander.default.outputSymbolTable) { | ||
// Go, go, go download | ||
_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() { | ||
return _regeneratorRuntime().wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
_context2.prev = 0; | ||
_context2.next = 3; | ||
return _.default.downloadSymbolTable(_objectSpread(_objectSpread({}, clientSettings), {}, { | ||
filesDest: filesDest, | ||
filesSrc: filesSrc, | ||
protectionId: _commander.default.outputSymbolTable | ||
})); | ||
case 3: | ||
_context2.next = 9; | ||
break; | ||
case 5: | ||
_context2.prev = 5; | ||
_context2.t0 = _context2["catch"](0); | ||
console.error(debug ? _context2.t0 : _context2.t0.message || _context2.t0); | ||
process.exit(1); | ||
case 9: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
} | ||
}, _callee2, null, [[0, 5]]); | ||
}))(); | ||
(async () => { | ||
try { | ||
await _.default.downloadSymbolTable(_objectSpread(_objectSpread({}, clientSettings), {}, { | ||
filesDest, | ||
filesSrc, | ||
protectionId: _commander.default.outputSymbolTable | ||
})); | ||
} catch (error) { | ||
console.error(debug ? error : error.message || error); | ||
process.exit(1); | ||
} | ||
})(); | ||
} else if (_commander.default.instrument) { | ||
_.default.instrumentAndDownload(_objectSpread(_objectSpread({}, clientSettings), {}, { | ||
applicationId: applicationId, | ||
filesSrc: filesSrc, | ||
filesDest: filesDest, | ||
skipSources: skipSources, | ||
cwd: cwd | ||
})).catch(function (error) { | ||
applicationId, | ||
filesSrc, | ||
filesDest, | ||
skipSources, | ||
cwd | ||
})).catch(error => { | ||
console.error(debug ? error : error.message || error); | ||
@@ -317,4 +285,4 @@ process.exit(1); | ||
_.default.setProfilingState(_objectSpread(_objectSpread({}, clientSettings), {}, { | ||
applicationId: applicationId | ||
}), 'RUNNING', 'STARTED', "Exercise your application and when you're finished run *--stop-profiling* command").catch(function (error) { | ||
applicationId | ||
}), 'RUNNING', 'STARTED', "Exercise your application and when you're finished run *--stop-profiling* command").catch(error => { | ||
console.error(debug ? error : error.message || error); | ||
@@ -325,4 +293,4 @@ process.exit(1); | ||
_.default.setProfilingState(_objectSpread(_objectSpread({}, clientSettings), {}, { | ||
applicationId: applicationId | ||
}), 'READY', 'STOPPED', 'Protect your application with 2 extra arguments: *--profiling-data-mode automatic* and *--skip-sources*').catch(function (error) { | ||
applicationId | ||
}), 'READY', 'STOPPED', 'Protect your application with 2 extra arguments: *--profiling-data-mode automatic* and *--skip-sources*').catch(error => { | ||
console.error(debug ? error : error.message || error); | ||
@@ -333,57 +301,41 @@ process.exit(1); | ||
// Go, go, go | ||
_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() { | ||
var protectAndDownloadOptions; | ||
return _regeneratorRuntime().wrap(function _callee3$(_context3) { | ||
while (1) { | ||
switch (_context3.prev = _context3.next) { | ||
case 0: | ||
protectAndDownloadOptions = _objectSpread(_objectSpread({}, clientSettings), {}, { | ||
applicationId: applicationId, | ||
filesSrc: filesSrc, | ||
filesDest: filesDest, | ||
params: params, | ||
applicationTypes: applicationTypes, | ||
languageSpecifications: languageSpecifications, | ||
areSubscribersOrdered: areSubscribersOrdered, | ||
cwd: cwd, | ||
sourceMaps: sourceMaps, | ||
randomizationSeed: randomizationSeed, | ||
useRecommendedOrder: useRecommendedOrder, | ||
tolerateMinification: tolerateMinification, | ||
debugMode: debugMode, | ||
codeHardeningThreshold: codeHardeningThreshold, | ||
useProfilingData: useProfilingData, | ||
profilingDataMode: profilingDataMode, | ||
browsers: browsers, | ||
useAppClassification: useAppClassification, | ||
skipSources: skipSources, | ||
removeProfilingData: removeProfilingData, | ||
inputSymbolTable: inputSymbolTable, | ||
entryPoint: entryPoint, | ||
excludeList: excludeList, | ||
ensureCodeAnnotation: ensureCodeAnnotation, | ||
numberOfProtections: numberOfProtections, | ||
forceAppEnvironment: forceAppEnvironment | ||
}); | ||
_context3.prev = 1; | ||
if (typeof werror !== 'undefined') { | ||
protectAndDownloadOptions.bail = werror; | ||
} | ||
_context3.next = 5; | ||
return _.default.protectAndDownload(protectAndDownloadOptions); | ||
case 5: | ||
_context3.next = 11; | ||
break; | ||
case 7: | ||
_context3.prev = 7; | ||
_context3.t0 = _context3["catch"](1); | ||
console.error(debug ? _context3.t0 : _context3.t0.message || _context3.t0); | ||
process.exit(1); | ||
case 11: | ||
case "end": | ||
return _context3.stop(); | ||
} | ||
(async () => { | ||
const protectAndDownloadOptions = _objectSpread(_objectSpread({}, clientSettings), {}, { | ||
applicationId, | ||
filesSrc, | ||
filesDest, | ||
params, | ||
applicationTypes, | ||
languageSpecifications, | ||
areSubscribersOrdered, | ||
cwd, | ||
sourceMaps, | ||
randomizationSeed, | ||
useRecommendedOrder, | ||
tolerateMinification, | ||
debugMode, | ||
codeHardeningThreshold, | ||
useProfilingData, | ||
profilingDataMode, | ||
browsers, | ||
useAppClassification, | ||
skipSources, | ||
removeProfilingData, | ||
inputSymbolTable, | ||
entryPoint, | ||
excludeList, | ||
ensureCodeAnnotation, | ||
numberOfProtections, | ||
forceAppEnvironment | ||
}); | ||
try { | ||
if (typeof werror !== 'undefined') { | ||
protectAndDownloadOptions.bail = werror; | ||
} | ||
}, _callee3, null, [[1, 7]]); | ||
}))(); | ||
await _.default.protectAndDownload(protectAndDownloadOptions); | ||
} catch (error) { | ||
console.error(debug ? error : error.message || error); | ||
process.exit(1); | ||
} | ||
})(); | ||
} |
@@ -7,12 +7,11 @@ "use strict"; | ||
exports.default = cleanupInputFields; | ||
require("core-js/modules/es.regexp.exec.js"); | ||
require("core-js/modules/es.string.replace.js"); | ||
require("core-js/modules/es.regexp.constructor.js"); | ||
function cleanupInputFields(args, fragments) { | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
var cleanedUpFragments = fragments; | ||
var dataArg = args.find(function (arg) { | ||
return arg.name === 'data'; | ||
}); | ||
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
let cleanedUpFragments = fragments; | ||
const dataArg = args.find(arg => arg.name === 'data'); | ||
function fieldCleanUp(field) { | ||
var hasFieldArg = dataArg && dataArg.type.inputFields.some(function (e) { | ||
return e.name === field; | ||
}); | ||
const hasFieldArg = dataArg && dataArg.type.inputFields.some(e => e.name === field); | ||
if (!hasFieldArg && typeof options[field] !== 'undefined') { | ||
@@ -19,0 +18,0 @@ options[field] = undefined; |
"use strict"; | ||
require("core-js/modules/es.symbol.description.js"); | ||
require("core-js/modules/web.dom-collections.iterator.js"); | ||
require("core-js/modules/es.regexp.exec.js"); | ||
require("core-js/modules/es.string.replace.js"); | ||
require("core-js/modules/es.string.trim.js"); | ||
var _lodash = _interopRequireDefault(require("lodash.defaults")); | ||
@@ -18,34 +23,17 @@ var _fs = _interopRequireDefault(require("fs")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); } | ||
function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct.bind(); } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); } | ||
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } | ||
function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
var debug = !!process.env.DEBUG; | ||
var metrics = !!process.env.METRICS; | ||
var noCompression = !!process.env.NO_COMPRESSION; | ||
var ClientError = /*#__PURE__*/function (_Error) { | ||
_inherits(ClientError, _Error); | ||
var _super = _createSuper(ClientError); | ||
function ClientError(message, statusCode) { | ||
var _this; | ||
_classCallCheck(this, ClientError); | ||
_this = _super.call(this, message); | ||
_this.statusCode = statusCode; | ||
return _this; | ||
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; } | ||
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; } | ||
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; } | ||
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); } | ||
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); } | ||
const debug = !!process.env.DEBUG; | ||
const metrics = !!process.env.METRICS; | ||
const noCompression = !!process.env.NO_COMPRESSION; | ||
class ClientError extends Error { | ||
constructor(message, statusCode) { | ||
super(message); | ||
this.statusCode = statusCode; | ||
} | ||
return _createClass(ClientError); | ||
}( /*#__PURE__*/_wrapNativeSuper(Error)); | ||
} | ||
/** | ||
@@ -63,2 +51,3 @@ * @class JScramblerClient | ||
*/ | ||
function JScramblerClient(options) { | ||
@@ -77,9 +66,10 @@ // Sluggish hack for backwards compatibility | ||
this.options = (0, _lodash.default)(options || {}, _config.default); | ||
var _this$options = this.options, | ||
jscramblerVersion = _this$options.jscramblerVersion, | ||
clientId = _this$options.clientId; | ||
const { | ||
jscramblerVersion, | ||
clientId | ||
} = this.options; | ||
this.axiosInstance = _axios.default.create({ | ||
headers: { | ||
jscramblerVersion: jscramblerVersion, | ||
clientId: clientId | ||
jscramblerVersion, | ||
clientId | ||
}, | ||
@@ -116,3 +106,3 @@ transformRequest: _axios.default.defaults.transformRequest.concat(function (data, headers) { | ||
JScramblerClient.prototype.get = function (path, params) { | ||
var isJSON = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true; | ||
let isJSON = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true; | ||
return this.request('GET', path, params, isJSON); | ||
@@ -128,6 +118,5 @@ }; | ||
JScramblerClient.prototype.request = function (method, path) { | ||
var _this2 = this; | ||
var params = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
var isJSON = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true; | ||
var signedData; | ||
let params = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
let isJSON = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true; | ||
let signedData; | ||
if (this.options.useHeaderAuth) { | ||
@@ -149,4 +138,4 @@ if (!this.token) { | ||
} | ||
var _keys = (0, _lodash2.default)(params); | ||
for (var i = 0, l = _keys.length; i < l; i++) { | ||
const _keys = (0, _lodash2.default)(params); | ||
for (let i = 0, l = _keys.length; i < l; i++) { | ||
if (params[_keys[i]] instanceof Array) { | ||
@@ -163,6 +152,7 @@ params[_keys[i]] = params[_keys[i]].join(','); | ||
} | ||
var _this$options2 = this.options, | ||
protocol = _this$options2.protocol, | ||
port = _this$options2.port, | ||
proxy = _this$options2.proxy; | ||
let { | ||
protocol, | ||
port, | ||
proxy | ||
} = this.options; | ||
if (!port && !protocol) { | ||
@@ -178,13 +168,13 @@ port = 443; | ||
} | ||
var formattedUrl = _url.default.format({ | ||
const formattedUrl = _url.default.format({ | ||
hostname: this.options.host, | ||
port: port, | ||
port, | ||
pathname: this.options.basePath + path, | ||
protocol: protocol | ||
protocol | ||
}); | ||
var data; | ||
var settings = {}; | ||
let data; | ||
const settings = {}; | ||
// Internal CA | ||
var agentOptions = {}; | ||
let agentOptions = {}; | ||
if (this.options.cafile) { | ||
@@ -195,14 +185,17 @@ agentOptions = { | ||
} | ||
if (proxy || _typeof(proxy) === 'object') { | ||
var host = proxy.host, | ||
_proxy$port = proxy.port, | ||
_port = _proxy$port === void 0 ? 8080 : _proxy$port, | ||
auth = proxy.auth; | ||
if (proxy || typeof proxy === 'object') { | ||
const { | ||
host, | ||
port = 8080, | ||
auth | ||
} = proxy; | ||
if (!host) { | ||
throw new Error('Required *proxy.host* not provided'); | ||
} | ||
var formattedAuth = undefined; | ||
let formattedAuth = undefined; | ||
if (auth) { | ||
var username = auth.username, | ||
password = auth.password; | ||
const { | ||
username, | ||
password | ||
} = auth; | ||
if (!username || !password) { | ||
@@ -219,3 +212,3 @@ throw new Error('Required *proxy.auth* username or/and password not provided'); | ||
if (agentOptions.ca) { | ||
var oriCallback = _httpsProxyAgent.default.prototype.callback; | ||
const oriCallback = _httpsProxyAgent.default.prototype.callback; | ||
_httpsProxyAgent.default.prototype.callback = function (req, opts) { | ||
@@ -226,5 +219,5 @@ return oriCallback.call(this, req, _objectSpread(_objectSpread({}, opts), agentOptions)); | ||
settings.proxy = false; | ||
var proxyConfig = _objectSpread({ | ||
host: host, | ||
port: _port, | ||
const proxyConfig = _objectSpread({ | ||
host, | ||
port, | ||
auth: formattedAuth | ||
@@ -241,3 +234,3 @@ }, agentOptions); | ||
} | ||
var promise; | ||
let promise; | ||
if (method === 'GET' || method === 'DELETE') { | ||
@@ -250,4 +243,4 @@ settings.params = signedData; | ||
} | ||
var start = Date.now(); | ||
return promise.then(function (res) { | ||
const start = Date.now(); | ||
return promise.then(res => { | ||
if (metrics || debug) { | ||
@@ -257,5 +250,5 @@ console.log("".concat(method, " ").concat(path, " ").concat(((data || settings.params).query || '').split('(')[0].trim().replace(' ', '-'), " ").concat(JSON.stringify(data || settings.params).length, "B ").concat(Date.now() - start, "ms")); | ||
return res.data; | ||
}).catch(function (err) { | ||
var errorMessage = 'Unexpected Response: '; | ||
var statusCode = 500; | ||
}).catch(err => { | ||
let errorMessage = 'Unexpected Response: '; | ||
let statusCode = 500; | ||
if (err.response) { | ||
@@ -267,3 +260,3 @@ if (debug) { | ||
statusCode = err.response.status; | ||
var incompatibleApi = false; | ||
let incompatibleApi = false; | ||
if (statusCode === _constants.HTTP_STATUS_CODES.UNAUTHORIZED && /Invalid Signature/i.test(err.response.data.message)) { | ||
@@ -273,3 +266,3 @@ incompatibleApi = err.response.data.errorCode !== _constants.JSCRAMBLER_ERROR_CODES.INVALID_SIGNATURE; | ||
if (incompatibleApi) { | ||
errorMessage = "Incompatible jscrambler CLI version (".concat(_package.version, "). Please downgrade to: \n\t$ npm install ").concat(_constants.CLIENT_PACKAGES[_this2.options.clientId], "@5"); | ||
errorMessage = "Incompatible jscrambler CLI version (".concat(_package.version, "). Please downgrade to: \n\t$ npm install ").concat(_constants.CLIENT_PACKAGES[this.options.clientId], "@5"); | ||
} else if ( | ||
@@ -305,8 +298,8 @@ // For when we have API error messages | ||
}; | ||
var _token; | ||
let _token; | ||
Object.defineProperty(JScramblerClient.prototype, 'token', { | ||
get: function get() { | ||
get() { | ||
return _token; | ||
}, | ||
set: function set(value) { | ||
set(value) { | ||
_token = value; | ||
@@ -313,0 +306,0 @@ if (value) { |
@@ -12,3 +12,3 @@ "use strict"; | ||
// getting variables from `argv`. | ||
var config = (0, _rc.default)('jscrambler', { | ||
const config = (0, _rc.default)('jscrambler', { | ||
keys: {}, | ||
@@ -23,3 +23,2 @@ host: 'api4.jscrambler.com', | ||
}, []); | ||
var _default = config; | ||
exports.default = _default; | ||
var _default = exports.default = config; |
@@ -7,5 +7,3 @@ "use strict"; | ||
exports.JSCRAMBLER_ERROR_CODES = exports.HTTP_STATUS_CODES = exports.CLIENT_PACKAGES = exports.CLIENT_IDS = void 0; | ||
var _Object$freeze; | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
var HTTP_STATUS_CODES = Object.freeze({ | ||
const HTTP_STATUS_CODES = exports.HTTP_STATUS_CODES = Object.freeze({ | ||
UNAUTHORIZED: 401, | ||
@@ -17,8 +15,6 @@ FORBIDDEN: 403, | ||
}); | ||
exports.HTTP_STATUS_CODES = HTTP_STATUS_CODES; | ||
var JSCRAMBLER_ERROR_CODES = Object.freeze({ | ||
const JSCRAMBLER_ERROR_CODES = exports.JSCRAMBLER_ERROR_CODES = Object.freeze({ | ||
INVALID_SIGNATURE: '254' | ||
}); | ||
exports.JSCRAMBLER_ERROR_CODES = JSCRAMBLER_ERROR_CODES; | ||
var CLIENT_IDS = Object.freeze({ | ||
const CLIENT_IDS = exports.CLIENT_IDS = Object.freeze({ | ||
CLI: 0, | ||
@@ -32,4 +28,10 @@ APP: 1, | ||
}); | ||
exports.CLIENT_IDS = CLIENT_IDS; | ||
var CLIENT_PACKAGES = Object.freeze((_Object$freeze = {}, _defineProperty(_Object$freeze, CLIENT_IDS.CLI, 'jscrambler'), _defineProperty(_Object$freeze, CLIENT_IDS.APP, 'app'), _defineProperty(_Object$freeze, CLIENT_IDS.WEBPACK, 'jscrambler-webpack-plugin'), _defineProperty(_Object$freeze, CLIENT_IDS.GULP, 'gulp-jscrambler'), _defineProperty(_Object$freeze, CLIENT_IDS.GRUNT, 'grunt-jscrambler'), _defineProperty(_Object$freeze, CLIENT_IDS.EMBER, 'ember-cli-jscrambler'), _defineProperty(_Object$freeze, CLIENT_IDS.METRO, 'jscrambler-metro-plugin'), _Object$freeze)); | ||
exports.CLIENT_PACKAGES = CLIENT_PACKAGES; | ||
const CLIENT_PACKAGES = exports.CLIENT_PACKAGES = Object.freeze({ | ||
[CLIENT_IDS.CLI]: 'jscrambler', | ||
[CLIENT_IDS.APP]: 'app', | ||
[CLIENT_IDS.WEBPACK]: 'jscrambler-webpack-plugin', | ||
[CLIENT_IDS.GULP]: 'gulp-jscrambler', | ||
[CLIENT_IDS.GRUNT]: 'grunt-jscrambler', | ||
[CLIENT_IDS.EMBER]: 'ember-cli-jscrambler', | ||
[CLIENT_IDS.METRO]: 'jscrambler-metro-plugin' | ||
}); |
@@ -7,2 +7,5 @@ "use strict"; | ||
exports.default = signedParams; | ||
require("core-js/modules/es.array.sort.js"); | ||
require("core-js/modules/es.regexp.exec.js"); | ||
require("core-js/modules/es.string.replace.js"); | ||
var _lodash = _interopRequireDefault(require("lodash.clone")); | ||
@@ -13,7 +16,6 @@ var _crypto = _interopRequireDefault(require("crypto")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } | ||
var debug = !!process.env.DEBUG; | ||
const debug = !!process.env.DEBUG; | ||
function signedParams(method, path, host, keys) { | ||
var params = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {}; | ||
var utc = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : true; | ||
let params = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {}; | ||
let utc = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : true; | ||
params = (0, _lodash2.default)((0, _lodash.default)(params), { | ||
@@ -27,6 +29,6 @@ access_key: keys.accessKey, | ||
function generateHmacSignature(method, path, host, keys, params) { | ||
var paramsCopy = (0, _lodash.default)(params); | ||
var signatureData = "".concat(method.toUpperCase(), ";").concat(host.toLowerCase(), ";").concat(path, ";").concat(buildSortedQuery(paramsCopy)); | ||
const paramsCopy = (0, _lodash.default)(params); | ||
const signatureData = "".concat(method.toUpperCase(), ";").concat(host.toLowerCase(), ";").concat(path, ";").concat(buildSortedQuery(paramsCopy)); | ||
debug && console.log("Signature data: ".concat(signatureData)); | ||
var hmac = _crypto.default.createHmac('sha256', keys.secretKey.toUpperCase()); | ||
const hmac = _crypto.default.createHmac('sha256', keys.secretKey.toUpperCase()); | ||
hmac.update(signatureData); | ||
@@ -37,6 +39,6 @@ return hmac.digest('base64'); | ||
// Sorted keys | ||
var _keys = (0, _lodash3.default)(params).sort(); | ||
var query = ''; | ||
for (var i = 0, l = _keys.length; i < l; i++) { | ||
var value = _typeof(params[_keys[i]]) === 'object' ? JSON.stringify(params[_keys[i]]) : params[_keys[i]]; | ||
const _keys = (0, _lodash3.default)(params).sort(); | ||
let query = ''; | ||
for (let i = 0, l = _keys.length; i < l; i++) { | ||
const value = typeof params[_keys[i]] === 'object' ? JSON.stringify(params[_keys[i]]) : params[_keys[i]]; | ||
query += "".concat(encodeURIComponent(_keys[i]), "=").concat(encodeURIComponent(value), "&"); | ||
@@ -43,0 +45,0 @@ } |
"use strict"; | ||
require("core-js/modules/web.dom-collections.iterator.js"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -8,45 +9,17 @@ value: true | ||
var introspection = _interopRequireWildcard(require("./introspection")); | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
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; } | ||
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } | ||
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } | ||
function getIntrospection(_x, _x2) { | ||
return _getIntrospection.apply(this, arguments); | ||
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); } | ||
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; } | ||
async function getIntrospection(client, typeName) { | ||
let _introspection; | ||
try { | ||
_introspection = await introspection.type(client, typeName); | ||
} catch (e) {} | ||
return _introspection; | ||
} | ||
function _getIntrospection() { | ||
_getIntrospection = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(client, typeName) { | ||
var _introspection; | ||
return _regeneratorRuntime().wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
_context.prev = 0; | ||
_context.next = 3; | ||
return introspection.type(client, typeName); | ||
case 3: | ||
_introspection = _context.sent; | ||
_context.next = 8; | ||
break; | ||
case 6: | ||
_context.prev = 6; | ||
_context.t0 = _context["catch"](0); | ||
case 8: | ||
return _context.abrupt("return", _introspection); | ||
case 9: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, null, [[0, 6]]); | ||
})); | ||
return _getIntrospection.apply(this, arguments); | ||
} | ||
function fragmentToQL(fragment) { | ||
var iterate = function iterate(i) { | ||
return Object.keys(i).map(function (key) { | ||
const iterate = i => { | ||
return Object.keys(i).map(key => { | ||
var result; | ||
var value = i[key]; | ||
if (_typeof(value) === 'object') { | ||
const value = i[key]; | ||
if (typeof value === 'object') { | ||
result = "".concat(key, " { ").concat(iterate(value), " }"); | ||
@@ -62,9 +35,7 @@ } else { | ||
function getAvaliableFragments(a, b) { | ||
var fragment = {}; | ||
Object.keys(b).forEach(function (field) { | ||
var _field = a.find(function (f) { | ||
return f.name === field; | ||
}); | ||
const fragment = {}; | ||
Object.keys(b).forEach(field => { | ||
const _field = a.find(f => f.name === field); | ||
if (_field) { | ||
if (_typeof(b[field]) === 'object' && _field.type.ofType.kind === 'OBJECT') { | ||
if (typeof b[field] === 'object' && _field.type.ofType.kind === 'OBJECT') { | ||
fragment[field] = b[field]; | ||
@@ -78,3 +49,3 @@ } else { | ||
} | ||
var protectionFields = { | ||
const protectionFields = { | ||
_id: 1, | ||
@@ -92,11 +63,11 @@ state: 1, | ||
}; | ||
var deprecationFields = { | ||
const deprecationFields = { | ||
type: 1, | ||
entity: 1 | ||
}; | ||
var sourceFields = { | ||
const sourceFields = { | ||
filename: 1, | ||
isSource: 1 | ||
}; | ||
var errorMessageFields = { | ||
const errorMessageFields = { | ||
message: 1, | ||
@@ -107,50 +78,21 @@ line: 1, | ||
}; | ||
function _default(_x3) { | ||
return _ref.apply(this, arguments); | ||
} | ||
function _ref() { | ||
_ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(client) { | ||
var appProtection, deprecation, source, errorMessage, fragments; | ||
return _regeneratorRuntime().wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
_context2.next = 2; | ||
return getIntrospection(client, 'ApplicationProtection'); | ||
case 2: | ||
appProtection = _context2.sent; | ||
_context2.next = 5; | ||
return getIntrospection(client, 'Deprecation'); | ||
case 5: | ||
deprecation = _context2.sent; | ||
_context2.next = 8; | ||
return getIntrospection(client, 'ApplicationSource'); | ||
case 8: | ||
source = _context2.sent; | ||
_context2.next = 11; | ||
return getIntrospection(client, 'ErrorMessages'); | ||
case 11: | ||
errorMessage = _context2.sent; | ||
fragments = { | ||
application: { | ||
name: 1 | ||
}, | ||
applicationProtection: {} | ||
}; | ||
fragments.applicationProtection = appProtection && getAvaliableFragments(appProtection.fields, protectionFields); | ||
fragments.applicationProtection.deprecations = deprecation && getAvaliableFragments(deprecation.fields, deprecationFields); | ||
fragments.applicationProtection.sources = source && getAvaliableFragments(source.fields, sourceFields); | ||
fragments.applicationProtection.sources.errorMessages = errorMessage && getAvaliableFragments(errorMessage.fields, errorMessageFields); | ||
return _context2.abrupt("return", { | ||
application: fragmentToQL(fragments.application), | ||
applicationProtection: fragmentToQL(fragments.applicationProtection) | ||
}); | ||
case 18: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
} | ||
}, _callee2); | ||
})); | ||
return _ref.apply(this, arguments); | ||
async function _default(client) { | ||
const appProtection = await getIntrospection(client, 'ApplicationProtection'); | ||
const deprecation = await getIntrospection(client, 'Deprecation'); | ||
const source = await getIntrospection(client, 'ApplicationSource'); | ||
const errorMessage = await getIntrospection(client, 'ErrorMessages'); | ||
const fragments = { | ||
application: { | ||
name: 1 | ||
}, | ||
applicationProtection: {} | ||
}; | ||
fragments.applicationProtection = appProtection && getAvaliableFragments(appProtection.fields, protectionFields); | ||
fragments.applicationProtection.deprecations = deprecation && getAvaliableFragments(deprecation.fields, deprecationFields); | ||
fragments.applicationProtection.sources = source && getAvaliableFragments(source.fields, sourceFields); | ||
fragments.applicationProtection.sources.errorMessages = errorMessage && getAvaliableFragments(errorMessage.fields, errorMessageFields); | ||
return { | ||
application: fragmentToQL(fragments.application), | ||
applicationProtection: fragmentToQL(fragments.applicationProtection) | ||
}; | ||
} |
@@ -10,183 +10,61 @@ "use strict"; | ||
exports.type = type; | ||
require("core-js/modules/web.dom-collections.iterator.js"); | ||
var _lodash = _interopRequireDefault(require("lodash.clonedeep")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } | ||
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; } | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } | ||
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } | ||
var typeCache = {}; | ||
function type(_x, _x2) { | ||
return _type.apply(this, arguments); | ||
const typeCache = {}; | ||
async function type(client, name) { | ||
const { | ||
jscramblerVersion | ||
} = client.options; | ||
if (!typeCache[jscramblerVersion]) { | ||
typeCache[jscramblerVersion] = {}; | ||
} | ||
if (typeCache[jscramblerVersion][name]) { | ||
return typeCache[jscramblerVersion][name]; | ||
} | ||
const query = { | ||
query: "\nquery getType($name: String!) {\n __type(name: $name) {\n kind\n name\n description\n fields(includeDeprecated: true) {\n name\n description\n args {\n ...InputValue\n }\n type {\n ...TypeRef\n }\n isDeprecated\n deprecationReason\n }\n inputFields {\n ...InputValue\n }\n interfaces {\n ...TypeRef\n }\n enumValues(includeDeprecated: true) {\n name\n description\n isDeprecated\n deprecationReason\n }\n possibleTypes {\n ...TypeRef\n }\n }\n}\n\nfragment InputValue on __InputValue {\n name\n description\n type { ...TypeRef }\n defaultValue\n}\n\nfragment TypeRef on __Type {\n kind\n name\n inputFields {\n name\n type {\n name\n kind\n }\n }\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n }\n }\n }\n}", | ||
params: JSON.stringify({ | ||
name | ||
}) | ||
}; | ||
const res = await client.get('/application', query); | ||
const __type = res.data.__type; | ||
typeCache[jscramblerVersion][__type.name] = __type; | ||
return __type; | ||
} | ||
function _type() { | ||
_type = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(client, name) { | ||
var jscramblerVersion, query, res, __type; | ||
return _regeneratorRuntime().wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
jscramblerVersion = client.options.jscramblerVersion; | ||
if (!typeCache[jscramblerVersion]) { | ||
typeCache[jscramblerVersion] = {}; | ||
} | ||
if (!typeCache[jscramblerVersion][name]) { | ||
_context.next = 4; | ||
break; | ||
} | ||
return _context.abrupt("return", typeCache[jscramblerVersion][name]); | ||
case 4: | ||
query = { | ||
query: "\nquery getType($name: String!) {\n __type(name: $name) {\n kind\n name\n description\n fields(includeDeprecated: true) {\n name\n description\n args {\n ...InputValue\n }\n type {\n ...TypeRef\n }\n isDeprecated\n deprecationReason\n }\n inputFields {\n ...InputValue\n }\n interfaces {\n ...TypeRef\n }\n enumValues(includeDeprecated: true) {\n name\n description\n isDeprecated\n deprecationReason\n }\n possibleTypes {\n ...TypeRef\n }\n }\n}\n\nfragment InputValue on __InputValue {\n name\n description\n type { ...TypeRef }\n defaultValue\n}\n\nfragment TypeRef on __Type {\n kind\n name\n inputFields {\n name\n type {\n name\n kind\n }\n }\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n }\n }\n }\n}", | ||
params: JSON.stringify({ | ||
name: name | ||
}) | ||
}; | ||
_context.next = 7; | ||
return client.get('/application', query); | ||
case 7: | ||
res = _context.sent; | ||
__type = res.data.__type; | ||
typeCache[jscramblerVersion][__type.name] = __type; | ||
return _context.abrupt("return", __type); | ||
case 11: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee); | ||
})); | ||
return _type.apply(this, arguments); | ||
async function mutation(client, name) { | ||
const rootMutation = await type(client, 'RootMutation'); | ||
const mutationType = rootMutation.fields.find(f => f.name === name); | ||
return mutationType; | ||
} | ||
function mutation(_x3, _x4) { | ||
return _mutation.apply(this, arguments); | ||
async function query(client, name) { | ||
const rootQuery = await type(client, 'RootQuery'); | ||
const queryType = rootQuery.fields.find(f => f.name === name); | ||
return queryType; | ||
} | ||
function _mutation() { | ||
_mutation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(client, name) { | ||
var rootMutation, mutationType; | ||
return _regeneratorRuntime().wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
_context2.next = 2; | ||
return type(client, 'RootMutation'); | ||
case 2: | ||
rootMutation = _context2.sent; | ||
mutationType = rootMutation.fields.find(function (f) { | ||
return f.name === name; | ||
}); | ||
return _context2.abrupt("return", mutationType); | ||
case 5: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
async function intoObjectType(client, obj, name) { | ||
var _resultType$fields; | ||
const resultType = await type(client, name); | ||
const fields = (_resultType$fields = resultType.fields) !== null && _resultType$fields !== void 0 ? _resultType$fields : resultType.inputFields; | ||
const finalObj = {}; | ||
const keys = Object.keys(obj); | ||
await Promise.all(keys.map(async k => { | ||
const field = fields.find(f => f.name === k); | ||
if (field && field.type) { | ||
finalObj[k] = (0, _lodash.default)(obj[k]); | ||
if (field.type.kind === 'OBJECT' && !!field.type.name) { | ||
finalObj[k] = await intoObjectType(client, finalObj[k], field.type.name); | ||
return; | ||
} | ||
}, _callee2); | ||
})); | ||
return _mutation.apply(this, arguments); | ||
} | ||
function query(_x5, _x6) { | ||
return _query.apply(this, arguments); | ||
} | ||
function _query() { | ||
_query = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(client, name) { | ||
var rootQuery, queryType; | ||
return _regeneratorRuntime().wrap(function _callee3$(_context3) { | ||
while (1) { | ||
switch (_context3.prev = _context3.next) { | ||
case 0: | ||
_context3.next = 2; | ||
return type(client, 'RootQuery'); | ||
case 2: | ||
rootQuery = _context3.sent; | ||
queryType = rootQuery.fields.find(function (f) { | ||
return f.name === name; | ||
}); | ||
return _context3.abrupt("return", queryType); | ||
case 5: | ||
case "end": | ||
return _context3.stop(); | ||
} | ||
if ((field.type.kind === 'NON_NULL' || field.type.kind === 'LIST') && field.type.ofType.kind === 'OBJECT') { | ||
finalObj[k] = await intoObjectType(client, finalObj[k], field.type.ofType.name); | ||
return; | ||
} | ||
}, _callee3); | ||
})); | ||
return _query.apply(this, arguments); | ||
} | ||
function intoObjectType(_x7, _x8, _x9) { | ||
return _intoObjectType.apply(this, arguments); | ||
} | ||
function _intoObjectType() { | ||
_intoObjectType = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(client, obj, name) { | ||
var _resultType$fields; | ||
var resultType, fields, finalObj, keys; | ||
return _regeneratorRuntime().wrap(function _callee5$(_context5) { | ||
while (1) { | ||
switch (_context5.prev = _context5.next) { | ||
case 0: | ||
_context5.next = 2; | ||
return type(client, name); | ||
case 2: | ||
resultType = _context5.sent; | ||
fields = (_resultType$fields = resultType.fields) !== null && _resultType$fields !== void 0 ? _resultType$fields : resultType.inputFields; | ||
finalObj = {}; | ||
keys = Object.keys(obj); | ||
_context5.next = 8; | ||
return Promise.all(keys.map( /*#__PURE__*/function () { | ||
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(k) { | ||
var field; | ||
return _regeneratorRuntime().wrap(function _callee4$(_context4) { | ||
while (1) { | ||
switch (_context4.prev = _context4.next) { | ||
case 0: | ||
field = fields.find(function (f) { | ||
return f.name === k; | ||
}); | ||
if (!(field && field.type)) { | ||
_context4.next = 14; | ||
break; | ||
} | ||
finalObj[k] = (0, _lodash.default)(obj[k]); | ||
if (!(field.type.kind === 'OBJECT' && !!field.type.name)) { | ||
_context4.next = 8; | ||
break; | ||
} | ||
_context4.next = 6; | ||
return intoObjectType(client, finalObj[k], field.type.name); | ||
case 6: | ||
finalObj[k] = _context4.sent; | ||
return _context4.abrupt("return"); | ||
case 8: | ||
if (!((field.type.kind === 'NON_NULL' || field.type.kind === 'LIST') && field.type.ofType.kind === 'OBJECT')) { | ||
_context4.next = 13; | ||
break; | ||
} | ||
_context4.next = 11; | ||
return intoObjectType(client, finalObj[k], field.type.ofType.name); | ||
case 11: | ||
finalObj[k] = _context4.sent; | ||
return _context4.abrupt("return"); | ||
case 13: | ||
if (field.type.name === 'String' && typeof finalObj[k] !== 'string') { | ||
finalObj[k] = JSON.stringify(finalObj[k]); | ||
} | ||
case 14: | ||
case "end": | ||
return _context4.stop(); | ||
} | ||
} | ||
}, _callee4); | ||
})); | ||
return function (_x10) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}())); | ||
case 8: | ||
return _context5.abrupt("return", finalObj); | ||
case 9: | ||
case "end": | ||
return _context5.stop(); | ||
} | ||
if (field.type.name === 'String' && typeof finalObj[k] !== 'string') { | ||
finalObj[k] = JSON.stringify(finalObj[k]); | ||
} | ||
}, _callee5); | ||
} | ||
})); | ||
return _intoObjectType.apply(this, arguments); | ||
return finalObj; | ||
} |
@@ -22,23 +22,18 @@ "use strict"; | ||
exports.updateTemplate = updateTemplate; | ||
var _cleanupInputFields3 = _interopRequireDefault(require("./cleanup-input-fields")); | ||
require("core-js/modules/web.dom-collections.iterator.js"); | ||
var _cleanupInputFields = _interopRequireDefault(require("./cleanup-input-fields")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
var createApplicationDefaultFragments = "\n _id,\n createdAt,\n name\n"; | ||
const createApplicationDefaultFragments = "\n _id,\n createdAt,\n name\n"; | ||
function createApplication(data) { | ||
var fragments = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : createApplicationDefaultFragments; | ||
let fragments = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : createApplicationDefaultFragments; | ||
return { | ||
query: "\n mutation createApplication ($data: ApplicationCreate!) {\n createApplication(data: $data) {\n ".concat(fragments, "\n }\n }\n "), | ||
params: { | ||
data: data | ||
data | ||
} | ||
}; | ||
} | ||
var duplicateApplicationDefaultFragments = "\n _id\n"; | ||
const duplicateApplicationDefaultFragments = "\n _id\n"; | ||
function duplicateApplication(id) { | ||
var fragments = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : duplicateApplicationDefaultFragments; | ||
let fragments = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : duplicateApplicationDefaultFragments; | ||
return { | ||
@@ -51,5 +46,5 @@ query: "\n mutation duplicateApplication ($_id: String!) {\n duplicateApplication (_id: $_id) {\n ".concat(fragments, "\n }\n }\n "), | ||
} | ||
var removeApplicationDefaultFragments = "\n _id\n"; | ||
const removeApplicationDefaultFragments = "\n _id\n"; | ||
function removeApplication(id) { | ||
var fragments = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : removeApplicationDefaultFragments; | ||
let fragments = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : removeApplicationDefaultFragments; | ||
return { | ||
@@ -62,5 +57,5 @@ query: "\n mutation removeApplication ($_id: String!) {\n removeApplication (_id: $_id) {\n ".concat(fragments, "\n }\n }\n "), | ||
} | ||
var removeProtectionDefaultFragments = "\n _id\n"; | ||
const removeProtectionDefaultFragments = "\n _id\n"; | ||
function removeProtection(id, appId) { | ||
var fragments = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : removeProtectionDefaultFragments; | ||
let fragments = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : removeProtectionDefaultFragments; | ||
return { | ||
@@ -74,5 +69,5 @@ query: "\n mutation removeProtection ($_id: String!, $applicationId: String!) {\n removeProtection (_id: $_id, applicationId: $applicationId) {\n ".concat(fragments, "\n }\n }\n "), | ||
} | ||
var cancelProtectionDefaultFragments = "\n _id\n"; | ||
const cancelProtectionDefaultFragments = "\n _id\n"; | ||
function cancelProtection(id, appId) { | ||
var fragments = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : cancelProtectionDefaultFragments; | ||
let fragments = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : cancelProtectionDefaultFragments; | ||
return { | ||
@@ -86,7 +81,7 @@ query: "\n mutation cancelProtection ($_id: String!, $applicationId: String!) {\n cancelProtection (_id: $_id, applicationId: $applicationId) {\n ".concat(fragments, "\n }\n }\n "), | ||
} | ||
var updateApplicationDefaultFragments = "\n _id,\n createdAt,\n name\n"; | ||
const updateApplicationDefaultFragments = "\n _id,\n createdAt,\n name\n"; | ||
function updateApplication(applicationData) { | ||
var fragments = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : updateApplicationDefaultFragments; | ||
var applicationId = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined; | ||
var appId = applicationId !== null && applicationId !== void 0 ? applicationId : applicationData._id; | ||
let fragments = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : updateApplicationDefaultFragments; | ||
let applicationId = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined; | ||
const appId = applicationId !== null && applicationId !== void 0 ? applicationId : applicationData._id; | ||
delete applicationData._id; | ||
@@ -101,5 +96,5 @@ return { | ||
} | ||
var unlockApplicationDefaultFragments = "\n _id,\n createdAt,\n name\n"; | ||
const unlockApplicationDefaultFragments = "\n _id,\n createdAt,\n name\n"; | ||
function unlockApplication(application) { | ||
var fragments = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : unlockApplicationDefaultFragments; | ||
let fragments = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : unlockApplicationDefaultFragments; | ||
return { | ||
@@ -112,17 +107,17 @@ query: "\n mutation unlockApplication ($applicationId: String!) {\n unlockApplication (_id: $applicationId) {\n ".concat(fragments, "\n }\n }\n "), | ||
} | ||
var addApplicationSourceDefaultFragments = "\n _id,\n filename,\n extension\n"; | ||
const addApplicationSourceDefaultFragments = "\n _id,\n filename,\n extension\n"; | ||
function addApplicationSource(applicationId, data) { | ||
var fragments = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : addApplicationSourceDefaultFragments; | ||
let fragments = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : addApplicationSourceDefaultFragments; | ||
return { | ||
query: "\n mutation addSourceToApplication ($applicationId: String!, $data: ApplicationSourceCreate!) {\n addSourceToApplication(applicationId: $applicationId, data: $data) {\n ".concat(fragments, "\n }\n }\n "), | ||
params: { | ||
applicationId: applicationId, | ||
data: data | ||
applicationId, | ||
data | ||
} | ||
}; | ||
} | ||
var updateApplicationSourceDefaultFragments = "\n _id,\n filename,\n extension\n"; | ||
const updateApplicationSourceDefaultFragments = "\n _id,\n filename,\n extension\n"; | ||
function updateApplicationSource(applicationSource) { | ||
var fragments = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : updateApplicationSourceDefaultFragments; | ||
var sourceId = applicationSource._id; | ||
let fragments = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : updateApplicationSourceDefaultFragments; | ||
const sourceId = applicationSource._id; | ||
delete applicationSource._id; | ||
@@ -132,3 +127,3 @@ return { | ||
params: { | ||
sourceId: sourceId, | ||
sourceId, | ||
data: applicationSource | ||
@@ -138,16 +133,16 @@ } | ||
} | ||
var removeSourceFromApplicationDefaultFragments = "\n _id,\n sources {\n filename\n }\n"; | ||
const removeSourceFromApplicationDefaultFragments = "\n _id,\n sources {\n filename\n }\n"; | ||
function removeSourceFromApplication(filename, applicationId) { | ||
var fragments = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : removeSourceFromApplicationDefaultFragments; | ||
let fragments = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : removeSourceFromApplicationDefaultFragments; | ||
return { | ||
query: "\n mutation removeSource ($filename: String!, $applicationId: String!) {\n removeSource (filename: $filename, applicationId: $applicationId) {\n ".concat(fragments, "\n }\n }\n "), | ||
params: { | ||
filename: filename, | ||
applicationId: applicationId | ||
filename, | ||
applicationId | ||
} | ||
}; | ||
} | ||
var createTemplateDefaultFragments = "\n _id,\n name,\n description,\n parameters\n"; | ||
const createTemplateDefaultFragments = "\n _id,\n name,\n description,\n parameters\n"; | ||
function createTemplate(template) { | ||
var fragments = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : createTemplateDefaultFragments; | ||
let fragments = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : createTemplateDefaultFragments; | ||
return { | ||
@@ -160,5 +155,5 @@ query: "\n mutation createTemplate ($data: TemplateInput!) {\n createTemplate (data: $data) {\n ".concat(fragments, "\n }\n }\n "), | ||
} | ||
var removeTemplateDefaultFragments = "\n _id\n"; | ||
const removeTemplateDefaultFragments = "\n _id\n"; | ||
function removeTemplate(id) { | ||
var fragments = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : removeTemplateDefaultFragments; | ||
let fragments = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : removeTemplateDefaultFragments; | ||
return { | ||
@@ -171,6 +166,6 @@ query: "\n mutation removeTemplate ($_id: String!) {\n removeTemplate (_id: $_id) {\n ".concat(fragments, "\n }\n }\n "), | ||
} | ||
var updateTemplateDefaultFragments = "\n _id,\n parameters\n"; | ||
const updateTemplateDefaultFragments = "\n _id,\n parameters\n"; | ||
function updateTemplate(template) { | ||
var fragments = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : updateTemplateDefaultFragments; | ||
var templateId = template._id; | ||
let fragments = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : updateTemplateDefaultFragments; | ||
const templateId = template._id; | ||
delete template._id; | ||
@@ -180,3 +175,3 @@ return { | ||
params: { | ||
templateId: templateId, | ||
templateId, | ||
data: template | ||
@@ -186,30 +181,25 @@ } | ||
} | ||
var createProtectionDefaultFragments = "\n _id,\n state\n"; | ||
const createProtectionDefaultFragments = "\n _id,\n state\n"; | ||
function createApplicationProtection(applicationId) { | ||
var _fragments = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : createProtectionDefaultFragments; | ||
var _options = arguments.length > 2 ? arguments[2] : undefined; | ||
var args = arguments.length > 3 ? arguments[3] : undefined; | ||
var _ref = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {}, | ||
_ref$mutationName = _ref.mutationName, | ||
mutationName = _ref$mutationName === void 0 ? 'createApplicationProtection' : _ref$mutationName, | ||
_ref$mutationInputTyp = _ref.mutationInputType, | ||
mutationInputType = _ref$mutationInputTyp === void 0 ? 'ApplicationProtectionCreate' : _ref$mutationInputTyp; | ||
var fragments = _fragments; | ||
var options = _options; | ||
var _cleanupInputFields = (0, _cleanupInputFields3.default)(args, fragments, options); | ||
var _cleanupInputFields2 = _slicedToArray(_cleanupInputFields, 2); | ||
options = _cleanupInputFields2[0]; | ||
fragments = _cleanupInputFields2[1]; | ||
if (!args.some(function (f) { | ||
return f.name === 'options'; | ||
})) { | ||
var _options2 = options, | ||
bail = _options2.bail, | ||
randomizationSeed = _options2.randomizationSeed; | ||
let _fragments = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : createProtectionDefaultFragments; | ||
let _options = arguments.length > 2 ? arguments[2] : undefined; | ||
let args = arguments.length > 3 ? arguments[3] : undefined; | ||
let { | ||
mutationName = 'createApplicationProtection', | ||
mutationInputType = 'ApplicationProtectionCreate' | ||
} = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {}; | ||
let fragments = _fragments; | ||
let options = _options; | ||
[options, fragments] = (0, _cleanupInputFields.default)(args, fragments, options); | ||
if (!args.some(f => f.name === 'options')) { | ||
const { | ||
bail, | ||
randomizationSeed | ||
} = options; | ||
return { | ||
query: "\n mutation ".concat(mutationName, " ($applicationId: String!, $bail: Boolean, $randomizationSeed: String) {\n ").concat(mutationName, " (applicationId: $applicationId, bail: $bail, randomizationSeed: $randomizationSeed) {\n ").concat(fragments, "\n }\n }\n "), | ||
params: { | ||
applicationId: applicationId, | ||
bail: bail, | ||
randomizationSeed: randomizationSeed | ||
applicationId, | ||
bail, | ||
randomizationSeed | ||
} | ||
@@ -220,9 +210,7 @@ }; | ||
// Check if createApplicationProtection supports "data" argument | ||
if (args.some(function (arg) { | ||
return arg.name === 'data'; | ||
})) { | ||
if (args.some(arg => arg.name === 'data')) { | ||
return { | ||
query: "\n mutation ".concat(mutationName, " ($applicationId: String!, $data: ").concat(mutationInputType, ") {\n ").concat(mutationName, " (applicationId: $applicationId, data: $data) {\n ").concat(fragments, "\n }\n }\n "), | ||
params: { | ||
applicationId: applicationId, | ||
applicationId, | ||
data: options | ||
@@ -235,12 +223,12 @@ } | ||
params: { | ||
applicationId: applicationId, | ||
options: options | ||
applicationId, | ||
options | ||
} | ||
}; | ||
} | ||
var createProtectionsDefaultFragments = "\n protections {\n ".concat(createProtectionDefaultFragments, "\n }\n"); | ||
const createProtectionsDefaultFragments = "\n protections {\n ".concat(createProtectionDefaultFragments, "\n }\n"); | ||
function createApplicationProtections(applicationId) { | ||
var _fragments = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : createProtectionsDefaultFragments; | ||
var _options = arguments.length > 2 ? arguments[2] : undefined; | ||
var args = arguments.length > 3 ? arguments[3] : undefined; | ||
let _fragments = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : createProtectionsDefaultFragments; | ||
let _options = arguments.length > 2 ? arguments[2] : undefined; | ||
let args = arguments.length > 3 ? arguments[3] : undefined; | ||
return createApplicationProtection(applicationId, _fragments, _options, args, { | ||
@@ -251,12 +239,12 @@ mutationName: 'createApplicationProtections', | ||
} | ||
var applyTemplateDefaultFragments = "\n _id,\n parameters\n"; | ||
const applyTemplateDefaultFragments = "\n _id,\n parameters\n"; | ||
function applyTemplate(templateId, appId) { | ||
var fragments = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : applyTemplateDefaultFragments; | ||
let fragments = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : applyTemplateDefaultFragments; | ||
return { | ||
query: "\n mutation applyTemplate ($templateId: String!, $appId: String!) {\n applyTemplate (templateId: $templateId, appId: $appId) {\n ".concat(fragments, "\n }\n }\n "), | ||
params: { | ||
templateId: templateId, | ||
appId: appId | ||
templateId, | ||
appId | ||
} | ||
}; | ||
} |
@@ -13,6 +13,11 @@ "use strict"; | ||
exports.getTemplates = getTemplates; | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
var getApplicationDefaultFragments = "\n _id,\n name,\n createdAt,\n sources {\n _id,\n filename,\n extension\n }\n"; | ||
require("core-js/modules/es.regexp.exec.js"); | ||
require("core-js/modules/es.string.replace.js"); | ||
require("core-js/modules/es.symbol.description.js"); | ||
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; } | ||
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; } | ||
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; } | ||
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); } | ||
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); } | ||
const getApplicationDefaultFragments = "\n _id,\n name,\n createdAt,\n sources {\n _id,\n filename,\n extension\n }\n"; | ||
/** | ||
@@ -26,50 +31,46 @@ * Return one application by id. | ||
function getApplication(applicationId) { | ||
var fragments = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : getApplicationDefaultFragments; | ||
var params = arguments.length > 2 ? arguments[2] : undefined; | ||
let fragments = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : getApplicationDefaultFragments; | ||
let params = arguments.length > 2 ? arguments[2] : undefined; | ||
return { | ||
query: "\n query getApplication ($applicationId: String!, $protectionsVersion: String, $protectionsLimit: Int) {\n application(_id: $applicationId, protectionsVersion: $protectionsVersion, protectionsLimit: $protectionsLimit) {\n ".concat(fragments, "\n }\n }\n "), | ||
params: JSON.stringify(_objectSpread({ | ||
applicationId: applicationId | ||
applicationId | ||
}, params)) | ||
}; | ||
} | ||
var getApplicationSourceDefaultFragments = "\n _id,\n filename,\n extension\n"; | ||
const getApplicationSourceDefaultFragments = "\n _id,\n filename,\n extension\n"; | ||
function getApplicationSource(sourceId) { | ||
var fragments = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : getApplicationSourceDefaultFragments; | ||
var limits = arguments.length > 2 ? arguments[2] : undefined; | ||
let fragments = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : getApplicationSourceDefaultFragments; | ||
let limits = arguments.length > 2 ? arguments[2] : undefined; | ||
return { | ||
query: "\n query getApplicationSource ($sourceId: String!, $contentLimit: Int, $transformedLimit: Int) {\n applicationSource(_id: $sourceId, contentLimit: $contentLimit, transformedLimit: $transformedLimit) {\n ".concat(fragments, "\n }\n }\n "), | ||
params: JSON.stringify(_objectSpread({ | ||
sourceId: sourceId | ||
sourceId | ||
}, limits)) | ||
}; | ||
} | ||
var getApplicationProtectionsDefaultFragments = "\n _id,\n sources,\n parameters,\n finishedAt,\n randomizationSeed\n"; | ||
const getApplicationProtectionsDefaultFragments = "\n _id,\n sources,\n parameters,\n finishedAt,\n randomizationSeed\n"; | ||
function getApplicationProtections(applicationId, params) { | ||
var fragments = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : getApplicationProtectionsDefaultFragments; | ||
var queryArgs = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : []; | ||
let fragments = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : getApplicationProtectionsDefaultFragments; | ||
let queryArgs = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : []; | ||
return { | ||
query: "\n query getApplicationProtections ($applicationId: String!, $sort: String, $order: String, $limit: Int, $page: Int".concat(queryArgs.map(function (v) { | ||
return ",".concat(v); | ||
}), ") {\n applicationProtections(_id: $applicationId, sort: $sort, order: $order, limit: $limit, page: $page").concat(queryArgs.map(function (v) { | ||
return ", ".concat(v.split(':')[0].replace('$', ''), ": ").concat(v.split(':')[0]); | ||
}), ") {\n ").concat(fragments, "\n }\n }\n "), | ||
query: "\n query getApplicationProtections ($applicationId: String!, $sort: String, $order: String, $limit: Int, $page: Int".concat(queryArgs.map(v => ",".concat(v)), ") {\n applicationProtections(_id: $applicationId, sort: $sort, order: $order, limit: $limit, page: $page").concat(queryArgs.map(v => ", ".concat(v.split(':')[0].replace('$', ''), ": ").concat(v.split(':')[0])), ") {\n ").concat(fragments, "\n }\n }\n "), | ||
params: JSON.stringify(_objectSpread({ | ||
applicationId: applicationId | ||
applicationId | ||
}, params)) | ||
}; | ||
} | ||
var getApplicationProtectionsCountDefaultFragments = "\n count\n"; | ||
const getApplicationProtectionsCountDefaultFragments = "\n count\n"; | ||
function getApplicationProtectionsCount(applicationId) { | ||
var fragments = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : getApplicationProtectionsCountDefaultFragments; | ||
let fragments = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : getApplicationProtectionsCountDefaultFragments; | ||
return { | ||
query: "\n query getApplicationProtectionsCount ($applicationId: String!) {\n applicationProtectionsCount(_id: $applicationId) {\n ".concat(fragments, "\n }\n }\n "), | ||
params: JSON.stringify({ | ||
applicationId: applicationId | ||
applicationId | ||
}) | ||
}; | ||
} | ||
var getTemplatesDefaultFragments = "\n _id,\n parameters\n"; | ||
const getTemplatesDefaultFragments = "\n _id,\n parameters\n"; | ||
function getTemplates() { | ||
var fragments = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getTemplatesDefaultFragments; | ||
let fragments = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getTemplatesDefaultFragments; | ||
return { | ||
@@ -80,3 +81,3 @@ query: "\n query getTemplates {\n templates {\n ".concat(fragments, "\n }\n }\n "), | ||
} | ||
var getApplicationsDefaultFragments = "\n _id,\n name,\n protections,\n parameters\n"; | ||
const getApplicationsDefaultFragments = "\n _id,\n name,\n protections,\n parameters\n"; | ||
/** | ||
@@ -89,4 +90,4 @@ * Return all applications. | ||
function getApplications() { | ||
var fragments = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getApplicationsDefaultFragments; | ||
var params = arguments.length > 1 ? arguments[1] : undefined; | ||
let fragments = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getApplicationsDefaultFragments; | ||
let params = arguments.length > 1 ? arguments[1] : undefined; | ||
return { | ||
@@ -97,3 +98,3 @@ query: "\n query getApplications($protectionsVersion:String, $protectionsLimit: Int) {\n applications(protectionsVersion: $protectionsVersion, protectionsLimit: $protectionsLimit) {\n ".concat(fragments, "\n }\n }\n "), | ||
} | ||
var getProtectionDefaultFragments = { | ||
const getProtectionDefaultFragments = { | ||
application: "\n name\n ", | ||
@@ -103,10 +104,10 @@ applicationProtection: "\n _id,\n state,\n bail,\n deprecations {\n type,\n entity\n },\n errorMessage,\n sources {\n filename,\n errorMessages {\n message,\n line,\n column,\n fatal\n }\n }\n " | ||
function getProtection(applicationId, protectionId) { | ||
var fragments = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : getProtectionDefaultFragments; | ||
let fragments = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : getProtectionDefaultFragments; | ||
return { | ||
query: "\n query getProtection ($applicationId: String!, $protectionId: String!) {\n application (_id: $applicationId) {\n ".concat(fragments.application, "\n }\n applicationProtection (_id: $protectionId) {\n ").concat(fragments.applicationProtection, "\n }\n }\n "), | ||
params: JSON.stringify({ | ||
applicationId: applicationId, | ||
protectionId: protectionId | ||
applicationId, | ||
protectionId | ||
}) | ||
}; | ||
} |
@@ -17,3 +17,3 @@ "use strict"; | ||
function getMatchedFiles(pattern) { | ||
var matchedFiles = _glob.default.sync(pattern, { | ||
let matchedFiles = _glob.default.sync(pattern, { | ||
dot: true | ||
@@ -32,3 +32,3 @@ }); | ||
} | ||
var nProtections = parseInt(n, 10); | ||
const nProtections = parseInt(n, 10); | ||
if (Number.isNaN(nProtections) || nProtections.toString() !== n.toString() || nProtections < 1) { | ||
@@ -35,0 +35,0 @@ console.error("*protections* requires an integer greater than 0."); |
307
dist/zip.js
"use strict"; | ||
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -9,3 +8,3 @@ value: true | ||
enumerable: true, | ||
get: function get() { | ||
get: function () { | ||
return _fsExtra.outputFileSync; | ||
@@ -17,2 +16,4 @@ } | ||
exports.zipSources = zipSources; | ||
require("core-js/modules/es.regexp.exec.js"); | ||
require("core-js/modules/web.dom-collections.iterator.js"); | ||
var _lodash = _interopRequireDefault(require("lodash.size")); | ||
@@ -26,120 +27,76 @@ var _temp = _interopRequireDefault(require("temp")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
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; } | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } | ||
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } | ||
var debug = !!process.env.DEBUG; | ||
// TODO Replace `sync` functions with async versions | ||
const debug = !!process.env.DEBUG; | ||
// ./zip.js module is excluded from browser-like environments. We take advantage of that here. | ||
function zip(_x, _x2) { | ||
return _zip.apply(this, arguments); | ||
} | ||
function _zip() { | ||
_zip = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(files, cwd) { | ||
var deferred, hasFiles, _zip2, zipFile, _zip3, i, l, buffer, name, sPath; | ||
return _regeneratorRuntime().wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
debug && console.log('Zipping files', (0, _util.inspect)(files)); | ||
deferred = (0, _q.defer)(); // Flag to detect if any file was added to the zip archive | ||
hasFiles = false; // Sanitize `cwd` | ||
if (cwd) { | ||
cwd = (0, _path2.normalize)(cwd); | ||
} | ||
// If it's already a zip file | ||
if (!(files.length === 1 && /^.*\.zip$/.test(files[0]))) { | ||
_context.next = 14; | ||
break; | ||
} | ||
hasFiles = true; | ||
_zip2 = new _jszip.default(); | ||
zipFile = (0, _fsExtra.readFileSync)(files[0]); | ||
_context.next = 10; | ||
return _zip2.loadAsync(zipFile); | ||
case 10: | ||
zipFile = _context.sent; | ||
deferred.resolve(zipFile); | ||
_context.next = 31; | ||
break; | ||
case 14: | ||
_zip3 = new _jszip.default(); | ||
i = 0, l = files.length; | ||
case 16: | ||
if (!(i < l)) { | ||
_context.next = 28; | ||
break; | ||
} | ||
// Sanitise path | ||
if (typeof files[i] === 'string') { | ||
files[i] = (0, _path2.normalize)(files[i]); | ||
if (files[i].indexOf('../') === 0) { | ||
files[i] = (0, _path2.resolve)(files[i]); | ||
} | ||
} | ||
// Bypass unwanted patterns from `files` | ||
if (!/.*\.(git|hg)(\/.*|$)/.test(files[i].path || files[i])) { | ||
_context.next = 20; | ||
break; | ||
} | ||
return _context.abrupt("continue", 25); | ||
case 20: | ||
buffer = void 0, name = void 0; | ||
sPath = void 0; | ||
if (cwd && files[i].indexOf && files[i].indexOf(cwd) !== 0) { | ||
sPath = (0, _path2.join)(cwd, files[i]); | ||
} else { | ||
sPath = files[i]; | ||
} | ||
// If buffer | ||
if (files[i].contents) { | ||
name = (0, _path2.relative)(files[i].cwd, files[i].path); | ||
buffer = files[i].contents; | ||
} else if (!(0, _fsExtra.statSync)(sPath).isDirectory()) { | ||
// Else if it's a path and not a directory | ||
if (cwd && files[i].indexOf && files[i].indexOf(cwd) === 0) { | ||
name = files[i].substring(cwd.length); | ||
} else { | ||
name = files[i]; | ||
} | ||
buffer = (0, _fsExtra.readFileSync)(sPath); | ||
} else { | ||
// Else if it's a directory path | ||
_zip3.folder(sPath); | ||
} | ||
if (name) { | ||
hasFiles = true; | ||
_zip3.file(name, buffer); | ||
} | ||
case 25: | ||
++i; | ||
_context.next = 16; | ||
break; | ||
case 28: | ||
if (hasFiles) { | ||
_context.next = 30; | ||
break; | ||
} | ||
throw new Error('No source files found. If you intend to send a whole directory sufix your path with "**" (e.g. ./my-directory/**)'); | ||
case 30: | ||
deferred.resolve(_zip3); | ||
case 31: | ||
return _context.abrupt("return", deferred.promise); | ||
case 32: | ||
case "end": | ||
return _context.stop(); | ||
async function zip(files, cwd) { | ||
debug && console.log('Zipping files', (0, _util.inspect)(files)); | ||
const deferred = (0, _q.defer)(); | ||
// Flag to detect if any file was added to the zip archive | ||
let hasFiles = false; | ||
// Sanitize `cwd` | ||
if (cwd) { | ||
cwd = (0, _path2.normalize)(cwd); | ||
} | ||
// If it's already a zip file | ||
if (files.length === 1 && /^.*\.zip$/.test(files[0])) { | ||
hasFiles = true; | ||
const zip = new _jszip.default(); | ||
let zipFile = (0, _fsExtra.readFileSync)(files[0]); | ||
zipFile = await zip.loadAsync(zipFile); | ||
deferred.resolve(zipFile); | ||
} else { | ||
const zip = new _jszip.default(); | ||
for (let i = 0, l = files.length; i < l; ++i) { | ||
// Sanitise path | ||
if (typeof files[i] === 'string') { | ||
files[i] = (0, _path2.normalize)(files[i]); | ||
if (files[i].indexOf('../') === 0) { | ||
files[i] = (0, _path2.resolve)(files[i]); | ||
} | ||
} | ||
}, _callee); | ||
})); | ||
return _zip.apply(this, arguments); | ||
// Bypass unwanted patterns from `files` | ||
if (/.*\.(git|hg)(\/.*|$)/.test(files[i].path || files[i])) { | ||
continue; | ||
} | ||
let buffer, name; | ||
let sPath; | ||
if (cwd && files[i].indexOf && files[i].indexOf(cwd) !== 0) { | ||
sPath = (0, _path2.join)(cwd, files[i]); | ||
} else { | ||
sPath = files[i]; | ||
} | ||
// If buffer | ||
if (files[i].contents) { | ||
name = (0, _path2.relative)(files[i].cwd, files[i].path); | ||
buffer = files[i].contents; | ||
} else if (!(0, _fsExtra.statSync)(sPath).isDirectory()) { | ||
// Else if it's a path and not a directory | ||
if (cwd && files[i].indexOf && files[i].indexOf(cwd) === 0) { | ||
name = files[i].substring(cwd.length); | ||
} else { | ||
name = files[i]; | ||
} | ||
buffer = (0, _fsExtra.readFileSync)(sPath); | ||
} else { | ||
// Else if it's a directory path | ||
zip.folder(sPath); | ||
} | ||
if (name) { | ||
hasFiles = true; | ||
zip.file(name, buffer); | ||
} | ||
} | ||
if (!hasFiles) { | ||
throw new Error('No source files found. If you intend to send a whole directory sufix your path with "**" (e.g. ./my-directory/**)'); | ||
} | ||
deferred.resolve(zip); | ||
} | ||
return deferred.promise; | ||
} | ||
function zipSources(sources) { | ||
var zipFile = new _jszip.default(); | ||
var fileNames = sources.map(function (source) { | ||
const zipFile = new _jszip.default(); | ||
const fileNames = sources.map(source => { | ||
zipFile.file(source.filename, source.content); | ||
@@ -157,90 +114,46 @@ return source.filename; | ||
function parseWinAbsolutePath(_path) { | ||
var _path$match = _path.match(/^([a-z]:)(.*)/i), | ||
_path$match2 = _slicedToArray(_path$match, 3), | ||
full = _path$match2[0], | ||
drv = _path$match2[1], | ||
path = _path$match2[2]; | ||
const [full, drv, path] = _path.match(/^([a-z]:)(.*)/i); | ||
return { | ||
drv: drv, | ||
path: path | ||
drv, | ||
path | ||
}; | ||
} | ||
function unzip(_x3, _x4) { | ||
return _unzip.apply(this, arguments); | ||
} | ||
function _unzip() { | ||
_unzip = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(zipFile, dest) { | ||
var stream, | ||
zip, | ||
_size, | ||
results, | ||
file, | ||
buffer, | ||
destPath, | ||
lastDestChar, | ||
_file, | ||
_args2 = arguments; | ||
return _regeneratorRuntime().wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
stream = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : true; | ||
zip = new _jszip.default(); | ||
_context2.next = 4; | ||
return zip.loadAsync(zipFile); | ||
case 4: | ||
_size = (0, _lodash.default)(zip.files); | ||
results = []; | ||
_context2.t0 = _regeneratorRuntime().keys(zip.files); | ||
case 7: | ||
if ((_context2.t1 = _context2.t0()).done) { | ||
_context2.next = 16; | ||
break; | ||
} | ||
file = _context2.t1.value; | ||
if (zip.files[file].dir) { | ||
_context2.next = 14; | ||
break; | ||
} | ||
_context2.next = 12; | ||
return zip.file(file).async('nodebuffer'); | ||
case 12: | ||
buffer = _context2.sent; | ||
if (typeof dest === 'function') { | ||
if (stream) { | ||
dest(buffer, file); | ||
} else { | ||
results.push({ | ||
filename: file, | ||
content: buffer.toString() | ||
}); | ||
} | ||
} else if (dest && typeof dest === 'string') { | ||
lastDestChar = dest[dest.length - 1]; | ||
if (_size === 1 && lastDestChar !== '/' && lastDestChar !== '\\') { | ||
destPath = dest; | ||
} else { | ||
_file = file; // Deal with win path join c:\dest\:c\src | ||
if (isWinAbsolutePath(_file)) { | ||
_file = parseWinAbsolutePath(_file).path; | ||
} | ||
destPath = (0, _path2.join)(dest, _file); | ||
} | ||
(0, _fsExtra.outputFileSync)(destPath, buffer); | ||
} | ||
case 14: | ||
_context2.next = 7; | ||
break; | ||
case 16: | ||
if (!stream) { | ||
dest(results); | ||
} | ||
case 17: | ||
case "end": | ||
return _context2.stop(); | ||
async function unzip(zipFile, dest) { | ||
let stream = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true; | ||
const zip = new _jszip.default(); | ||
await zip.loadAsync(zipFile); | ||
const _size = (0, _lodash.default)(zip.files); | ||
const results = []; | ||
for (const file in zip.files) { | ||
if (!zip.files[file].dir) { | ||
const buffer = await zip.file(file).async('nodebuffer'); | ||
if (typeof dest === 'function') { | ||
if (stream) { | ||
dest(buffer, file); | ||
} else { | ||
results.push({ | ||
filename: file, | ||
content: buffer.toString() | ||
}); | ||
} | ||
} else if (dest && typeof dest === 'string') { | ||
var destPath; | ||
const lastDestChar = dest[dest.length - 1]; | ||
if (_size === 1 && lastDestChar !== '/' && lastDestChar !== '\\') { | ||
destPath = dest; | ||
} else { | ||
let _file = file; | ||
// Deal with win path join c:\dest\:c\src | ||
if (isWinAbsolutePath(_file)) { | ||
_file = parseWinAbsolutePath(_file).path; | ||
} | ||
destPath = (0, _path2.join)(dest, _file); | ||
} | ||
(0, _fsExtra.outputFileSync)(destPath, buffer); | ||
} | ||
}, _callee2); | ||
})); | ||
return _unzip.apply(this, arguments); | ||
} | ||
} | ||
if (!stream) { | ||
dest(results); | ||
} | ||
} |
{ | ||
"name": "jscrambler", | ||
"description": "Jscrambler API client.", | ||
"version": "6.4.21", | ||
"version": "6.4.23", | ||
"homepage": "https://github.com/jscrambler/jscrambler", | ||
"author": "Jscrambler <code@jscrambler.com>", | ||
"author": "Jscrambler <support@jscrambler.com>", | ||
"repository": { | ||
@@ -14,13 +14,6 @@ "type": "git", | ||
}, | ||
"licenses": [ | ||
{ | ||
"type": "MIT", | ||
"url": "https://github.com/jscrambler/javascript-jscrambler/blob/master/LICENSE-MIT" | ||
} | ||
], | ||
"scripts": { | ||
"clean": "rm -rf ./dist", | ||
"build": "babel src --out-dir dist", | ||
"watch": "grunt watch", | ||
"prepublish": "npm run build" | ||
"license": "MIT", | ||
"publishConfig": { | ||
"access": "public", | ||
"registry": "https://registry.npmjs.org/" | ||
}, | ||
@@ -47,3 +40,2 @@ "engines": { | ||
"rc": "^1.1.0", | ||
"regenerator-runtime": "^0.13.9", | ||
"snake-case": "^2.1.0", | ||
@@ -53,15 +45,9 @@ "temp": "^0.8.3" | ||
"devDependencies": { | ||
"@babel/cli": "^7.14.8", | ||
"@babel/core": "^7.15.0", | ||
"@babel/plugin-proposal-object-rest-spread": "^7.14.7", | ||
"@babel/preset-env": "^7.15.0", | ||
"grunt": "^1.0.2", | ||
"grunt-cli": "^1.2.0", | ||
"grunt-contrib-clean": "^1.0.0", | ||
"grunt-contrib-copy": "^1.0.0", | ||
"grunt-contrib-watch": "^1.0.0" | ||
"@babel/cli": "^7.23.4", | ||
"@babel/core": "^7.23.7", | ||
"@babel/preset-env": "^7.23.8" | ||
}, | ||
"files": [ | ||
"dist", | ||
"LICENSE-MIT" | ||
"CHANGELOG.md" | ||
], | ||
@@ -71,3 +57,19 @@ "main": "dist/index.js", | ||
"jscrambler": "dist/bin/jscrambler.js" | ||
}, | ||
"keywords": [ | ||
"cli", | ||
"jscrambler", | ||
"obfuscate", | ||
"protect", | ||
"js", | ||
"javascript" | ||
], | ||
"scripts": { | ||
"clean": "rm -rf ./dist", | ||
"build": "babel src --out-dir dist", | ||
"watch": "babel -w src --out-dir dist", | ||
"prepublish": "npm run build", | ||
"eslint": "eslint src/", | ||
"eslint:fix": "eslint src/ --fix" | ||
} | ||
} | ||
} |
Sorry, the diff of this file is too big to display
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
18
3
17
122245
2518
- Removedregenerator-runtime@^0.13.9
- Removedregenerator-runtime@0.13.11(transitive)