jscrambler 6.0.4 → 6.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/client.js CHANGED
@@ -1,80 +1,86 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
- var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
3
+ var _lodash = _interopRequireDefault(require("lodash.defaults"));
4
4
 
5
- var _lodash = require('lodash.defaults');
5
+ var _fs = _interopRequireDefault(require("fs"));
6
6
 
7
- var _lodash2 = _interopRequireDefault(_lodash);
7
+ var _lodash2 = _interopRequireDefault(require("lodash.keys"));
8
8
 
9
- var _fs = require('fs');
9
+ var _axios = _interopRequireDefault(require("axios"));
10
10
 
11
- var _fs2 = _interopRequireDefault(_fs);
11
+ var _url = _interopRequireDefault(require("url"));
12
12
 
13
- var _lodash3 = require('lodash.keys');
13
+ var _https = _interopRequireDefault(require("https"));
14
14
 
15
- var _lodash4 = _interopRequireDefault(_lodash3);
15
+ var _http = _interopRequireDefault(require("http"));
16
16
 
17
- var _axios = require('axios');
17
+ var _httpsProxyAgent = _interopRequireDefault(require("@jscrambler/https-proxy-agent"));
18
18
 
19
- var _axios2 = _interopRequireDefault(_axios);
19
+ var _httpProxyAgent = _interopRequireDefault(require("http-proxy-agent"));
20
20
 
21
- var _url = require('url');
21
+ var _config = _interopRequireDefault(require("./config"));
22
22
 
23
- var _url2 = _interopRequireDefault(_url);
23
+ var _generateSignedParams = _interopRequireDefault(require("./generate-signed-params"));
24
24
 
25
- var _https = require('https');
25
+ var _constants = require("./constants");
26
26
 
27
- var _https2 = _interopRequireDefault(_https);
27
+ var _package = require("../package.json");
28
28
 
29
- var _http = require('http');
29
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
30
30
 
31
- var _http2 = _interopRequireDefault(_http);
31
+ 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; }
32
32
 
33
- var _httpsProxyAgent = require('@jscrambler/https-proxy-agent');
33
+ 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; }
34
34
 
35
- var _httpsProxyAgent2 = _interopRequireDefault(_httpsProxyAgent);
35
+ 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; }
36
36
 
37
- var _httpProxyAgent = require('http-proxy-agent');
37
+ 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); }
38
38
 
39
- var _httpProxyAgent2 = _interopRequireDefault(_httpProxyAgent);
39
+ 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); } }
40
40
 
41
- var _config = require('./config');
41
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
42
42
 
43
- var _config2 = _interopRequireDefault(_config);
43
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
44
44
 
45
- var _generateSignedParams = require('./generate-signed-params');
45
+ 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); }
46
46
 
47
- var _generateSignedParams2 = _interopRequireDefault(_generateSignedParams);
47
+ 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); }; }
48
48
 
49
- var _constants = require('./constants');
49
+ 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); }
50
50
 
51
- var _package = require('../package.json');
51
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
52
52
 
53
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
53
+ 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); }
54
54
 
55
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
55
+ function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct; } 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); }
56
+
57
+ 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; } }
58
+
59
+ function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
56
60
 
57
- function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
61
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
58
62
 
59
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
63
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
60
64
 
61
65
  var debug = !!process.env.DEBUG;
62
66
 
63
- var ClientError = function (_Error) {
67
+ var ClientError = /*#__PURE__*/function (_Error) {
64
68
  _inherits(ClientError, _Error);
65
69
 
70
+ var _super = _createSuper(ClientError);
71
+
66
72
  function ClientError(message, statusCode) {
67
- _classCallCheck(this, ClientError);
73
+ var _this;
68
74
 
69
- var _this = _possibleConstructorReturn(this, (ClientError.__proto__ || Object.getPrototypeOf(ClientError)).call(this, message));
75
+ _classCallCheck(this, ClientError);
70
76
 
77
+ _this = _super.call(this, message);
71
78
  _this.statusCode = statusCode;
72
79
  return _this;
73
80
  }
74
81
 
75
- return ClientError;
76
- }(Error);
77
-
82
+ return _createClass(ClientError);
83
+ }( /*#__PURE__*/_wrapNativeSuper(Error));
78
84
  /**
79
85
  * @class JScramblerClient
80
86
  * @param {Object} options
@@ -84,10 +90,11 @@ var ClientError = function (_Error) {
84
90
  * @param {String} [options.port=443]
85
91
  * @param {String} [options.basePath]
86
92
  * @param {String} [options.clientId=0]
87
- * @author José Magalhães (magalhas@gmail.com)
93
+ * @author Jscrambler
88
94
  * @license MIT <http://opensource.org/licenses/MIT>
89
95
  */
90
96
 
97
+
91
98
  function JScramblerClient(options) {
92
99
  // Sluggish hack for backwards compatibility
93
100
  if (options && !options.keys && (options.accessKey || options.secretKey)) {
@@ -96,24 +103,22 @@ function JScramblerClient(options) {
96
103
  options.keys.secretKey = options.secretKey;
97
104
  }
98
105
 
99
- options.keys = (0, _lodash2.default)(options.keys || {}, _config2.default.keys);
100
-
106
+ options.keys = (0, _lodash.default)(options.keys || {}, _config.default.keys);
101
107
  /**
102
108
  * @member
103
109
  */
104
- this.options = (0, _lodash2.default)(options || {}, _config2.default);
105
-
106
- var _options = this.options,
107
- jscramblerVersion = _options.jscramblerVersion,
108
- clientId = _options.clientId;
109
-
110
110
 
111
- this.axiosInstance = _axios2.default.create({
111
+ this.options = (0, _lodash.default)(options || {}, _config.default);
112
+ var _this$options = this.options,
113
+ jscramblerVersion = _this$options.jscramblerVersion,
114
+ clientId = _this$options.clientId;
115
+ this.axiosInstance = _axios.default.create({
112
116
  headers: {
113
117
  jscramblerVersion: jscramblerVersion,
114
118
  clientId: clientId
115
119
  },
116
120
  maxBodyLength: 100 * 1000 * 1000 // 100 MB
121
+
117
122
  });
118
123
  }
119
124
  /**
@@ -122,6 +127,8 @@ function JScramblerClient(options) {
122
127
  * @param {Object} params
123
128
  * @param {Callback} callback
124
129
  */
130
+
131
+
125
132
  JScramblerClient.prototype.delete = function (path, params) {
126
133
  return this.request('DELETE', path, params);
127
134
  };
@@ -131,9 +138,10 @@ JScramblerClient.prototype.delete = function (path, params) {
131
138
  * @param {Object} params
132
139
  * @param {Callback} callback
133
140
  */
141
+
142
+
134
143
  JScramblerClient.prototype.get = function (path, params) {
135
144
  var isJSON = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
136
-
137
145
  return this.request('GET', path, params, isJSON);
138
146
  };
139
147
  /**
@@ -143,13 +151,15 @@ JScramblerClient.prototype.get = function (path, params) {
143
151
  * @param {Object} params
144
152
  * @param {Callback} callback
145
153
  */
154
+
155
+
146
156
  JScramblerClient.prototype.request = function (method, path) {
147
157
  var _this2 = this;
148
158
 
149
159
  var params = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
150
160
  var isJSON = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
161
+ var signedData;
151
162
 
152
- var signedData = void 0;
153
163
  if (this.options.useHeaderAuth) {
154
164
  if (!this.token) {
155
165
  throw new Error('Generating auth token when useHeaderAuth === true is not yet supported. You need to set the jscramblerClient token property explicitly.');
@@ -168,25 +178,25 @@ JScramblerClient.prototype.request = function (method, path) {
168
178
  }
169
179
  }
170
180
 
171
- var _keys = (0, _lodash4.default)(params);
181
+ var _keys = (0, _lodash2.default)(params);
182
+
172
183
  for (var i = 0, l = _keys.length; i < l; i++) {
173
184
  if (params[_keys[i]] instanceof Array) {
174
185
  params[_keys[i]] = params[_keys[i]].join(',');
175
186
  }
176
- }
187
+ } // If post sign data and set the request as multipart
188
+
177
189
 
178
- // If post sign data and set the request as multipart
179
190
  if (this.options.keys.accessKey && this.options.keys.secretKey) {
180
- signedData = (0, _generateSignedParams2.default)(method, path, this.options.host, this.options.keys, params, this.options.utc);
191
+ signedData = (0, _generateSignedParams.default)(method, path, this.options.host, this.options.keys, params, this.options.utc);
181
192
  } else {
182
193
  signedData = params;
183
194
  }
184
195
 
185
- var _options2 = this.options,
186
- protocol = _options2.protocol,
187
- port = _options2.port,
188
- proxy = _options2.proxy;
189
-
196
+ var _this$options2 = this.options,
197
+ protocol = _this$options2.protocol,
198
+ port = _this$options2.port,
199
+ proxy = _this$options2.proxy;
190
200
 
191
201
  if (!port && !protocol) {
192
202
  port = 443;
@@ -201,28 +211,28 @@ JScramblerClient.prototype.request = function (method, path) {
201
211
  protocol = port === 443 ? 'https' : 'http';
202
212
  }
203
213
 
204
- var formattedUrl = _url2.default.format({
214
+ var formattedUrl = _url.default.format({
205
215
  hostname: this.options.host,
206
216
  port: port,
207
217
  pathname: this.options.basePath + path,
208
218
  protocol: protocol
209
219
  });
210
220
 
211
- var data = void 0;
212
- var settings = {};
221
+ var data;
222
+ var settings = {}; // Internal CA
213
223
 
214
- // Internal CA
215
224
  var agentOptions = {};
225
+
216
226
  if (this.options.cafile) {
217
227
  agentOptions = {
218
- ca: _fs2.default.readFileSync(this.options.cafile)
228
+ ca: _fs.default.readFileSync(this.options.cafile)
219
229
  };
220
230
  }
221
231
 
222
- if (proxy || (typeof proxy === 'undefined' ? 'undefined' : _typeof(proxy)) === 'object') {
232
+ if (proxy || _typeof(proxy) === 'object') {
223
233
  var host = proxy.host,
224
234
  _proxy$port = proxy.port,
225
- _port = _proxy$port === undefined ? 8080 : _proxy$port,
235
+ _port = _proxy$port === void 0 ? 8080 : _proxy$port,
226
236
  auth = proxy.auth;
227
237
 
228
238
  if (!host) {
@@ -230,43 +240,51 @@ JScramblerClient.prototype.request = function (method, path) {
230
240
  }
231
241
 
232
242
  var formattedAuth = undefined;
243
+
233
244
  if (auth) {
234
245
  var username = auth.username,
235
246
  password = auth.password;
236
247
 
237
-
238
248
  if (!username || !password) {
239
249
  throw new Error('Required *proxy.auth* username or/and password not provided');
240
250
  }
241
251
 
242
- formattedAuth = username + ':' + password;
252
+ formattedAuth = "".concat(username, ":").concat(password);
243
253
  }
244
-
245
254
  /**
246
255
  * Monkey-patch to inject a custom Cert CA into TLS.connect
247
256
  * options.
248
257
  */
258
+
259
+
249
260
  if (agentOptions.ca) {
250
- var oriCallback = _httpsProxyAgent2.default.prototype.callback;
251
- _httpsProxyAgent2.default.prototype.callback = function (req, opts) {
252
- return oriCallback.call(this, req, Object.assign({}, opts, agentOptions));
261
+ var oriCallback = _httpsProxyAgent.default.prototype.callback;
262
+
263
+ _httpsProxyAgent.default.prototype.callback = function (req, opts) {
264
+ return oriCallback.call(this, req, _objectSpread(_objectSpread({}, opts), agentOptions));
253
265
  };
254
266
  }
255
267
 
256
268
  settings.proxy = false;
257
- var proxyConfig = Object.assign({ host: host, port: _port, auth: formattedAuth }, agentOptions);
258
- settings.httpsAgent = new _httpsProxyAgent2.default(proxyConfig);
259
- settings.httpAgent = new _httpProxyAgent2.default(proxyConfig);
269
+
270
+ var proxyConfig = _objectSpread({
271
+ host: host,
272
+ port: _port,
273
+ auth: formattedAuth
274
+ }, agentOptions);
275
+
276
+ settings.httpsAgent = new _httpsProxyAgent.default(proxyConfig);
277
+ settings.httpAgent = new _httpProxyAgent.default(proxyConfig);
260
278
  } else if (agentOptions) {
261
- settings.httpsAgent = new _https2.default.Agent(agentOptions);
262
- settings.httpAgent = new _http2.default.Agent(agentOptions);
279
+ settings.httpsAgent = new _https.default.Agent(agentOptions);
280
+ settings.httpAgent = new _http.default.Agent(agentOptions);
263
281
  }
264
282
 
265
283
  if (!isJSON) {
266
284
  settings.responseType = 'arraybuffer';
267
285
  }
268
286
 
269
- var promise = void 0;
287
+ var promise;
270
288
 
271
289
  if (method === 'GET' || method === 'DELETE') {
272
290
  settings.params = signedData;
@@ -287,22 +305,21 @@ JScramblerClient.prototype.request = function (method, path) {
287
305
  console.error(err.response);
288
306
  }
289
307
 
290
- errorMessage += err.response.status + ' ' + err.response.statusText;
308
+ errorMessage += "".concat(err.response.status, " ").concat(err.response.statusText);
291
309
  statusCode = err.response.status;
292
-
293
310
  var incompatibleApi = false;
311
+
294
312
  if (statusCode === _constants.HTTP_STATUS_CODES.UNAUTHORIZED) {
295
313
  incompatibleApi = err.response.data.errorCode !== _constants.JSCRAMBLER_ERROR_CODES.INVALID_SIGNATURE;
296
314
  }
297
315
 
298
316
  if (incompatibleApi) {
299
- errorMessage = 'Incompatible jscrambler CLI version (' + _package.version + '). Please downgrade to: \n\t$ npm install ' + _constants.CLIENT_PACKAGES[_this2.options.clientId] + '@5';
300
- } else if (
301
- // For when we have API error messages
317
+ errorMessage = "Incompatible jscrambler CLI version (".concat(_package.version, "). Please downgrade to: \n\t$ npm install ").concat(_constants.CLIENT_PACKAGES[_this2.options.clientId], "@5");
318
+ } else if ( // For when we have API error messages
302
319
  err.response.data && err.response.data.error && err.response.data.message) {
303
- errorMessage += ' - ' + err.response.data.message;
320
+ errorMessage += " - ".concat(err.response.data.message);
304
321
  } else if (err.response.data && err.response.data.errors && err.response.data.errors.length > 0) {
305
- errorMessage += ' - ' + err.response.data.errors;
322
+ errorMessage += " - ".concat(err.response.data.errors);
306
323
  }
307
324
  } else {
308
325
  errorMessage += err.message;
@@ -317,6 +334,8 @@ JScramblerClient.prototype.request = function (method, path) {
317
334
  * @param {Object} params
318
335
  * @param {Callback} callback
319
336
  */
337
+
338
+
320
339
  JScramblerClient.prototype.post = function (path, params) {
321
340
  return this.request('POST', path, params);
322
341
  };
@@ -325,11 +344,13 @@ JScramblerClient.prototype.post = function (path, params) {
325
344
  * @param {string} path
326
345
  * @param {object} params
327
346
  */
347
+
348
+
328
349
  JScramblerClient.prototype.patch = function (path, params) {
329
350
  return this.request('PATCH', path, params);
330
351
  };
331
352
 
332
- var _token = void 0;
353
+ var _token;
333
354
 
334
355
  Object.defineProperty(JScramblerClient.prototype, 'token', {
335
356
  get: function get() {
@@ -337,6 +358,7 @@ Object.defineProperty(JScramblerClient.prototype, 'token', {
337
358
  },
338
359
  set: function set(value) {
339
360
  _token = value;
361
+
340
362
  if (value) {
341
363
  if (this.options.useHeaderAuth) {
342
364
  this.axiosInstance.defaults.headers['x-user-authentication'] = _token;
@@ -346,5 +368,4 @@ Object.defineProperty(JScramblerClient.prototype, 'token', {
346
368
  }
347
369
  }
348
370
  });
349
-
350
371
  exports = module.exports = JScramblerClient;
package/dist/config.js CHANGED
@@ -1,20 +1,19 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.default = void 0;
6
7
 
7
- var _rc = require('rc');
8
+ var _rc = _interopRequireDefault(require("rc"));
8
9
 
9
- var _rc2 = _interopRequireDefault(_rc);
10
-
11
- var _constants = require('./constants');
10
+ var _constants = require("./constants");
12
11
 
13
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
13
 
15
14
  // Load RC configuration if present. Pass `[]` as last argument to avoid
16
15
  // getting variables from `argv`.
17
- var config = (0, _rc2.default)('jscrambler', {
16
+ var config = (0, _rc.default)('jscrambler', {
18
17
  keys: {},
19
18
  host: 'api4.jscrambler.com',
20
19
  basePath: '',
@@ -24,5 +23,5 @@ var config = (0, _rc2.default)('jscrambler', {
24
23
  utc: true,
25
24
  maxRetries: 5
26
25
  }, []);
27
-
28
- exports.default = config;
26
+ var _default = config;
27
+ exports.default = _default;
package/dist/constants.js CHANGED
@@ -1,26 +1,27 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.JSCRAMBLER_ERROR_CODES = exports.HTTP_STATUS_CODES = exports.CLIENT_PACKAGES = exports.CLIENT_IDS = void 0;
6
7
 
7
8
  var _Object$freeze;
8
9
 
9
10
  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; }
10
11
 
11
- var HTTP_STATUS_CODES = exports.HTTP_STATUS_CODES = Object.freeze({
12
+ var HTTP_STATUS_CODES = Object.freeze({
12
13
  UNAUTHORIZED: 401,
13
14
  FORBIDDEN: 403,
14
15
  NOT_FOUND: 404,
15
16
  SERVICE_UNAVAILABLE: 503,
16
17
  GATEWAY_TIMEOUT: 504
17
18
  });
18
-
19
- var JSCRAMBLER_ERROR_CODES = exports.JSCRAMBLER_ERROR_CODES = Object.freeze({
19
+ exports.HTTP_STATUS_CODES = HTTP_STATUS_CODES;
20
+ var JSCRAMBLER_ERROR_CODES = Object.freeze({
20
21
  INVALID_SIGNATURE: '254'
21
22
  });
22
-
23
- var CLIENT_IDS = exports.CLIENT_IDS = Object.freeze({
23
+ exports.JSCRAMBLER_ERROR_CODES = JSCRAMBLER_ERROR_CODES;
24
+ var CLIENT_IDS = Object.freeze({
24
25
  CLI: 0,
25
26
  APP: 1,
26
27
  WEBPACK: 2,
@@ -29,5 +30,6 @@ var CLIENT_IDS = exports.CLIENT_IDS = Object.freeze({
29
30
  EMBER: 5,
30
31
  METRO: 6
31
32
  });
32
-
33
- var CLIENT_PACKAGES = exports.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));
33
+ exports.CLIENT_IDS = CLIENT_IDS;
34
+ 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));
35
+ exports.CLIENT_PACKAGES = CLIENT_PACKAGES;
@@ -1,38 +1,28 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
-
7
- var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
8
-
9
6
  exports.default = signedParams;
10
7
 
11
- var _lodash = require('lodash.clone');
12
-
13
- var _lodash2 = _interopRequireDefault(_lodash);
14
-
15
- var _crypto = require('crypto');
8
+ var _lodash = _interopRequireDefault(require("lodash.clone"));
16
9
 
17
- var _crypto2 = _interopRequireDefault(_crypto);
10
+ var _crypto = _interopRequireDefault(require("crypto"));
18
11
 
19
- var _lodash3 = require('lodash.defaults');
12
+ var _lodash2 = _interopRequireDefault(require("lodash.defaults"));
20
13
 
21
- var _lodash4 = _interopRequireDefault(_lodash3);
22
-
23
- var _lodash5 = require('lodash.keys');
24
-
25
- var _lodash6 = _interopRequireDefault(_lodash5);
14
+ var _lodash3 = _interopRequireDefault(require("lodash.keys"));
26
15
 
27
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
28
17
 
18
+ 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); }
19
+
29
20
  var debug = !!process.env.DEBUG;
30
21
 
31
22
  function signedParams(method, path, host, keys) {
32
23
  var params = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
33
24
  var utc = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : true;
34
-
35
- params = (0, _lodash4.default)((0, _lodash2.default)(params), {
25
+ params = (0, _lodash2.default)((0, _lodash.default)(params), {
36
26
  access_key: keys.accessKey,
37
27
  timestamp: utc.toString() !== 'false' ? new Date().toISOString() : new Date().toLocaleString()
38
28
  });
@@ -41,23 +31,28 @@ function signedParams(method, path, host, keys) {
41
31
  }
42
32
 
43
33
  function generateHmacSignature(method, path, host, keys, params) {
44
- var paramsCopy = (0, _lodash2.default)(params);
45
- var signatureData = method.toUpperCase() + ';' + host.toLowerCase() + ';' + path + ';' + buildSortedQuery(paramsCopy);
46
- debug && console.log('Signature data: ' + signatureData);
47
- var hmac = _crypto2.default.createHmac('sha256', keys.secretKey.toUpperCase());
34
+ var paramsCopy = (0, _lodash.default)(params);
35
+ var signatureData = "".concat(method.toUpperCase(), ";").concat(host.toLowerCase(), ";").concat(path, ";").concat(buildSortedQuery(paramsCopy));
36
+ debug && console.log("Signature data: ".concat(signatureData));
37
+
38
+ var hmac = _crypto.default.createHmac('sha256', keys.secretKey.toUpperCase());
39
+
48
40
  hmac.update(signatureData);
49
41
  return hmac.digest('base64');
50
42
  }
51
43
 
52
44
  function buildSortedQuery(params) {
53
45
  // Sorted keys
54
- var _keys = (0, _lodash6.default)(params).sort();
46
+ var _keys = (0, _lodash3.default)(params).sort();
47
+
55
48
  var query = '';
49
+
56
50
  for (var i = 0, l = _keys.length; i < l; i++) {
57
51
  var value = _typeof(params[_keys[i]]) === 'object' ? JSON.stringify(params[_keys[i]]) : params[_keys[i]];
58
- query += encodeURIComponent(_keys[i]) + '=' + encodeURIComponent(value) + '&';
52
+ query += "".concat(encodeURIComponent(_keys[i]), "=").concat(encodeURIComponent(value), "&");
59
53
  }
60
- query = query.replace(/\*/g, '%2A').replace(/[!'()]/g, escape).replace(/%7E/g, '~').replace(/\+/g, '%20');
61
- // Strip the last separator and return
54
+
55
+ query = query.replace(/\*/g, '%2A').replace(/[!'()]/g, escape).replace(/%7E/g, '~').replace(/\+/g, '%20'); // Strip the last separator and return
56
+
62
57
  return query.substring(0, query.length - 1);
63
58
  }