parse 3.4.2 → 3.4.3-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/parse.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Parse JavaScript SDK v3.4.2
2
+ * Parse JavaScript SDK v3.4.3-alpha.1
3
3
  *
4
4
  * The source tree of this library can be found at
5
5
  * https://github.com/ParsePlatform/Parse-SDK-JS
@@ -699,7 +699,7 @@ var config
699
699
  SERVER_AUTH_TOKEN: null,
700
700
  LIVEQUERY_SERVER_URL: null,
701
701
  ENCRYPTED_KEY: null,
702
- VERSION: 'js' + "3.4.2",
702
+ VERSION: 'js' + "3.4.3-alpha.1",
703
703
  APPLICATION_ID: null,
704
704
  JAVASCRIPT_KEY: null,
705
705
  MASTER_KEY: null,
@@ -8390,6 +8390,8 @@ _Object$defineProperty(exports, "__esModule", {
8390
8390
 
8391
8391
  exports.default = void 0;
8392
8392
 
8393
+ var _indexOf = _interopRequireDefault(_dereq_("@babel/runtime-corejs3/core-js-stable/instance/index-of"));
8394
+
8393
8395
  var _slicedToArray2 = _interopRequireDefault(_dereq_("@babel/runtime-corejs3/helpers/slicedToArray"));
8394
8396
 
8395
8397
  var _promise = _interopRequireDefault(_dereq_("@babel/runtime-corejs3/core-js-stable/promise"));
@@ -8406,8 +8408,6 @@ var _asyncToGenerator2 = _interopRequireDefault(_dereq_("@babel/runtime-corejs3/
8406
8408
 
8407
8409
  var _slice = _interopRequireDefault(_dereq_("@babel/runtime-corejs3/core-js-stable/instance/slice"));
8408
8410
 
8409
- var _indexOf = _interopRequireDefault(_dereq_("@babel/runtime-corejs3/core-js-stable/instance/index-of"));
8410
-
8411
8411
  var _isArray = _interopRequireDefault(_dereq_("@babel/runtime-corejs3/core-js-stable/array/is-array"));
8412
8412
 
8413
8413
  var _classCallCheck2 = _interopRequireDefault(_dereq_("@babel/runtime-corejs3/helpers/classCallCheck"));
@@ -8434,12 +8434,12 @@ function ownKeys(object, enumerableOnly) {
8434
8434
 
8435
8435
  function _objectSpread(target) {
8436
8436
  for (var i = 1; i < arguments.length; i++) {
8437
- var _context5, _context6;
8437
+ var _context8, _context9;
8438
8438
 
8439
8439
  var source = null != arguments[i] ? arguments[i] : {};
8440
- i % 2 ? _forEachInstanceProperty2(_context5 = ownKeys(Object(source), !0)).call(_context5, function (key) {
8440
+ i % 2 ? _forEachInstanceProperty2(_context8 = ownKeys(Object(source), !0)).call(_context8, function (key) {
8441
8441
  (0, _defineProperty2.default)(target, key, source[key]);
8442
- }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty2(_context6 = ownKeys(Object(source))).call(_context6, function (key) {
8442
+ }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty2(_context9 = ownKeys(Object(source))).call(_context9, function (key) {
8443
8443
  _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key));
8444
8444
  });
8445
8445
  }
@@ -8477,7 +8477,8 @@ if (typeof XMLHttpRequest !== 'undefined') {
8477
8477
  uri: string,
8478
8478
  type: string,
8479
8479
  };*/
8480
- var dataUriRegexp = /^data:([a-zA-Z]+\/[-a-zA-Z0-9+.]+)(;charset=[a-zA-Z0-9\-\/]*)?;base64,/;
8480
+ var base64Regex = new RegExp('([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))', 'i');
8481
+ var dataUriRegex = new RegExp("^data:([a-zA-Z]+\\/[-a-zA-Z0-9+.]+(;[a-z-]+=[a-zA-Z0-9+.-]+)?)?(;base64)?,(".concat(base64Regex.source, ")*$"), 'i');
8481
8482
 
8482
8483
  function b64Digit(number
8483
8484
  /*: number*/
@@ -8591,26 +8592,31 @@ var ParseFile = /*#__PURE__*/function () {
8591
8592
  type: specifiedType
8592
8593
  };
8593
8594
  } else if (data && typeof data.base64 === 'string') {
8594
- var base64 = data.base64;
8595
- var commaIndex = (0, _indexOf.default)(base64).call(base64, ',');
8595
+ var _context, _context2, _context3; // Check if data URI or base64 string is valid
8596
8596
 
8597
- if (commaIndex !== -1) {
8598
- var matches = dataUriRegexp.exec((0, _slice.default)(base64).call(base64, 0, commaIndex + 1)); // if data URI with type and charset, there will be 4 matches.
8599
8597
 
8600
- this._data = (0, _slice.default)(base64).call(base64, commaIndex + 1);
8601
- this._source = {
8602
- format: 'base64',
8603
- base64: this._data,
8604
- type: matches[1]
8605
- };
8606
- } else {
8607
- this._data = base64;
8608
- this._source = {
8609
- format: 'base64',
8610
- base64: base64,
8611
- type: specifiedType
8612
- };
8598
+ var validationRegex = new RegExp(base64Regex.source + '|' + dataUriRegex.source, 'i');
8599
+
8600
+ if (!validationRegex.test(data.base64)) {
8601
+ throw new Error('Cannot create a Parse.File without valid data URIs or base64 encoded data.');
8613
8602
  }
8603
+
8604
+ var base64 = (0, _slice.default)(_context = data.base64.split(',')).call(_context, -1)[0];
8605
+
8606
+ var _type = specifiedType || (0, _slice.default)(_context2 = (0, _slice.default)(_context3 = data.base64.split(';')).call(_context3, 0, 1)[0].split(':')).call(_context2, 1, 2)[0] || ''; // https://tools.ietf.org/html/rfc2397
8607
+ // If <mediatype> is omitted, it defaults to text/plain;charset=US-ASCII.
8608
+ // As a shorthand, "text/plain" can be omitted but the charset parameter supplied.
8609
+
8610
+
8611
+ if (dataUriRegex.test(data.base64)) {
8612
+ _type = _type || 'text/plain';
8613
+ }
8614
+
8615
+ this._source = {
8616
+ format: 'base64',
8617
+ base64: base64,
8618
+ type: _type
8619
+ };
8614
8620
  } else {
8615
8621
  throw new TypeError('Cannot create a Parse.File with that data.');
8616
8622
  }
@@ -8632,20 +8638,20 @@ var ParseFile = /*#__PURE__*/function () {
8632
8638
  var _this = this;
8633
8639
 
8634
8640
  var options, controller, result;
8635
- return _regenerator.default.wrap(function (_context) {
8641
+ return _regenerator.default.wrap(function (_context4) {
8636
8642
  while (1) {
8637
- switch (_context.prev = _context.next) {
8643
+ switch (_context4.prev = _context4.next) {
8638
8644
  case 0:
8639
8645
  if (!this._data) {
8640
- _context.next = 2;
8646
+ _context4.next = 2;
8641
8647
  break;
8642
8648
  }
8643
8649
 
8644
- return _context.abrupt("return", this._data);
8650
+ return _context4.abrupt("return", this._data);
8645
8651
 
8646
8652
  case 2:
8647
8653
  if (this._url) {
8648
- _context.next = 4;
8654
+ _context4.next = 4;
8649
8655
  break;
8650
8656
  }
8651
8657
 
@@ -8658,17 +8664,17 @@ var ParseFile = /*#__PURE__*/function () {
8658
8664
  }
8659
8665
  };
8660
8666
  controller = _CoreManager.default.getFileController();
8661
- _context.next = 8;
8667
+ _context4.next = 8;
8662
8668
  return controller.download(this._url, options);
8663
8669
 
8664
8670
  case 8:
8665
- result = _context.sent;
8671
+ result = _context4.sent;
8666
8672
  this._data = result.base64;
8667
- return _context.abrupt("return", this._data);
8673
+ return _context4.abrupt("return", this._data);
8668
8674
 
8669
8675
  case 11:
8670
8676
  case "end":
8671
- return _context.stop();
8677
+ return _context4.stop();
8672
8678
  }
8673
8679
  }
8674
8680
  }, _callee, this);
@@ -8924,9 +8930,9 @@ var ParseFile = /*#__PURE__*/function () {
8924
8930
  var _this4 = this;
8925
8931
 
8926
8932
  if (metadata && (0, _typeof2.default)(metadata) === 'object') {
8927
- var _context2;
8933
+ var _context5;
8928
8934
 
8929
- (0, _forEach.default)(_context2 = (0, _keys.default)(metadata)).call(_context2, function (key) {
8935
+ (0, _forEach.default)(_context5 = (0, _keys.default)(metadata)).call(_context5, function (key) {
8930
8936
  _this4.addMetadata(key, metadata[key]);
8931
8937
  });
8932
8938
  }
@@ -8963,9 +8969,9 @@ var ParseFile = /*#__PURE__*/function () {
8963
8969
  var _this5 = this;
8964
8970
 
8965
8971
  if (tags && (0, _typeof2.default)(tags) === 'object') {
8966
- var _context3;
8972
+ var _context6;
8967
8973
 
8968
- (0, _forEach.default)(_context3 = (0, _keys.default)(tags)).call(_context3, function (key) {
8974
+ (0, _forEach.default)(_context6 = (0, _keys.default)(tags)).call(_context6, function (key) {
8969
8975
  _this5.addTag(key, tags[key]);
8970
8976
  });
8971
8977
  }
@@ -9037,19 +9043,19 @@ var DefaultController = {
9037
9043
  ) {
9038
9044
  var base64Data, _base64Data$split, _base64Data$split2, first, second, data, newSource;
9039
9045
 
9040
- return _regenerator.default.wrap(function (_context4) {
9046
+ return _regenerator.default.wrap(function (_context7) {
9041
9047
  while (1) {
9042
- switch (_context4.prev = _context4.next) {
9048
+ switch (_context7.prev = _context7.next) {
9043
9049
  case 0:
9044
9050
  if (!(source.format !== 'file')) {
9045
- _context4.next = 2;
9051
+ _context7.next = 2;
9046
9052
  break;
9047
9053
  }
9048
9054
 
9049
9055
  throw new Error('saveFile can only be used with File-type sources.');
9050
9056
 
9051
9057
  case 2:
9052
- _context4.next = 4;
9058
+ _context7.next = 4;
9053
9059
  return new _promise.default(function (res, rej) {
9054
9060
  // eslint-disable-next-line no-undef
9055
9061
  var reader = new FileReader();
@@ -9066,7 +9072,7 @@ var DefaultController = {
9066
9072
  });
9067
9073
 
9068
9074
  case 4:
9069
- base64Data = _context4.sent; // we only want the data after the comma
9075
+ base64Data = _context7.sent; // we only want the data after the comma
9070
9076
  // For example: "data:application/pdf;base64,JVBERi0xLjQKJ..." we would only want "JVBERi0xLjQKJ..."
9071
9077
 
9072
9078
  _base64Data$split = base64Data.split(','), _base64Data$split2 = (0, _slicedToArray2.default)(_base64Data$split, 2), first = _base64Data$split2[0], second = _base64Data$split2[1]; // in the event there is no 'data:application/pdf;base64,' at the beginning of the base64 string
@@ -9078,15 +9084,15 @@ var DefaultController = {
9078
9084
  base64: data,
9079
9085
  type: source.type || (source.file ? source.file.type : null)
9080
9086
  };
9081
- _context4.next = 10;
9087
+ _context7.next = 10;
9082
9088
  return DefaultController.saveBase64(name, newSource, options);
9083
9089
 
9084
9090
  case 10:
9085
- return _context4.abrupt("return", _context4.sent);
9091
+ return _context7.abrupt("return", _context7.sent);
9086
9092
 
9087
9093
  case 11:
9088
9094
  case "end":
9089
- return _context4.stop();
9095
+ return _context7.stop();
9090
9096
  }
9091
9097
  }
9092
9098
  }, _callee2);