parse 3.4.2-alpha.1 → 3.4.3-alpha.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.
@@ -224,7 +224,7 @@ var config
224
224
  SERVER_AUTH_TOKEN: null,
225
225
  LIVEQUERY_SERVER_URL: null,
226
226
  ENCRYPTED_KEY: null,
227
- VERSION: 'js' + "3.4.2-alpha.1",
227
+ VERSION: 'js' + "3.4.3-alpha.2",
228
228
  APPLICATION_ID: null,
229
229
  JAVASCRIPT_KEY: null,
230
230
  MASTER_KEY: null,
@@ -24,6 +24,8 @@ _Object$defineProperty(exports, "__esModule", {
24
24
 
25
25
  exports.default = void 0;
26
26
 
27
+ var _indexOf = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/index-of"));
28
+
27
29
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/slicedToArray"));
28
30
 
29
31
  var _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/promise"));
@@ -40,8 +42,6 @@ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs3/
40
42
 
41
43
  var _slice = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/slice"));
42
44
 
43
- var _indexOf = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/index-of"));
44
-
45
45
  var _isArray = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/is-array"));
46
46
 
47
47
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/classCallCheck"));
@@ -68,12 +68,12 @@ function ownKeys(object, enumerableOnly) {
68
68
 
69
69
  function _objectSpread(target) {
70
70
  for (var i = 1; i < arguments.length; i++) {
71
- var _context5, _context6;
71
+ var _context8, _context9;
72
72
 
73
73
  var source = null != arguments[i] ? arguments[i] : {};
74
- i % 2 ? _forEachInstanceProperty2(_context5 = ownKeys(Object(source), !0)).call(_context5, function (key) {
74
+ i % 2 ? _forEachInstanceProperty2(_context8 = ownKeys(Object(source), !0)).call(_context8, function (key) {
75
75
  (0, _defineProperty2.default)(target, key, source[key]);
76
- }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty2(_context6 = ownKeys(Object(source))).call(_context6, function (key) {
76
+ }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty2(_context9 = ownKeys(Object(source))).call(_context9, function (key) {
77
77
  _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key));
78
78
  });
79
79
  }
@@ -111,7 +111,8 @@ if (typeof XMLHttpRequest !== 'undefined') {
111
111
  uri: string,
112
112
  type: string,
113
113
  };*/
114
- var dataUriRegexp = /^data:([a-zA-Z]+\/[-a-zA-Z0-9+.]+)(;charset=[a-zA-Z0-9\-\/]*)?;base64,/;
114
+ var base64Regex = new RegExp('([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))', 'i');
115
+ var dataUriRegex = new RegExp("^data:([a-zA-Z]+\\/[-a-zA-Z0-9+.]+(;[a-z-]+=[a-zA-Z0-9+.-]+)?)?(;base64)?,(".concat(base64Regex.source, ")*$"), 'i');
115
116
 
116
117
  function b64Digit(number
117
118
  /*: number*/
@@ -225,26 +226,31 @@ var ParseFile = /*#__PURE__*/function () {
225
226
  type: specifiedType
226
227
  };
227
228
  } else if (data && typeof data.base64 === 'string') {
228
- var base64 = data.base64;
229
- var commaIndex = (0, _indexOf.default)(base64).call(base64, ',');
230
-
231
- if (commaIndex !== -1) {
232
- 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.
233
-
234
- this._data = (0, _slice.default)(base64).call(base64, commaIndex + 1);
235
- this._source = {
236
- format: 'base64',
237
- base64: this._data,
238
- type: matches[1]
239
- };
240
- } else {
241
- this._data = base64;
242
- this._source = {
243
- format: 'base64',
244
- base64: base64,
245
- type: specifiedType
246
- };
229
+ var _context, _context2, _context3; // Check if data URI or base64 string is valid
230
+
231
+
232
+ var validationRegex = new RegExp(base64Regex.source + '|' + dataUriRegex.source, 'i');
233
+
234
+ if (!validationRegex.test(data.base64)) {
235
+ throw new Error('Cannot create a Parse.File without valid data URIs or base64 encoded data.');
247
236
  }
237
+
238
+ var base64 = (0, _slice.default)(_context = data.base64.split(',')).call(_context, -1)[0];
239
+
240
+ 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
241
+ // If <mediatype> is omitted, it defaults to text/plain;charset=US-ASCII.
242
+ // As a shorthand, "text/plain" can be omitted but the charset parameter supplied.
243
+
244
+
245
+ if (dataUriRegex.test(data.base64)) {
246
+ _type = _type || 'text/plain';
247
+ }
248
+
249
+ this._source = {
250
+ format: 'base64',
251
+ base64: base64,
252
+ type: _type
253
+ };
248
254
  } else {
249
255
  throw new TypeError('Cannot create a Parse.File with that data.');
250
256
  }
@@ -266,20 +272,20 @@ var ParseFile = /*#__PURE__*/function () {
266
272
  var _this = this;
267
273
 
268
274
  var options, controller, result;
269
- return _regenerator.default.wrap(function (_context) {
275
+ return _regenerator.default.wrap(function (_context4) {
270
276
  while (1) {
271
- switch (_context.prev = _context.next) {
277
+ switch (_context4.prev = _context4.next) {
272
278
  case 0:
273
279
  if (!this._data) {
274
- _context.next = 2;
280
+ _context4.next = 2;
275
281
  break;
276
282
  }
277
283
 
278
- return _context.abrupt("return", this._data);
284
+ return _context4.abrupt("return", this._data);
279
285
 
280
286
  case 2:
281
287
  if (this._url) {
282
- _context.next = 4;
288
+ _context4.next = 4;
283
289
  break;
284
290
  }
285
291
 
@@ -292,17 +298,17 @@ var ParseFile = /*#__PURE__*/function () {
292
298
  }
293
299
  };
294
300
  controller = _CoreManager.default.getFileController();
295
- _context.next = 8;
301
+ _context4.next = 8;
296
302
  return controller.download(this._url, options);
297
303
 
298
304
  case 8:
299
- result = _context.sent;
305
+ result = _context4.sent;
300
306
  this._data = result.base64;
301
- return _context.abrupt("return", this._data);
307
+ return _context4.abrupt("return", this._data);
302
308
 
303
309
  case 11:
304
310
  case "end":
305
- return _context.stop();
311
+ return _context4.stop();
306
312
  }
307
313
  }
308
314
  }, _callee, this);
@@ -558,9 +564,9 @@ var ParseFile = /*#__PURE__*/function () {
558
564
  var _this4 = this;
559
565
 
560
566
  if (metadata && (0, _typeof2.default)(metadata) === 'object') {
561
- var _context2;
567
+ var _context5;
562
568
 
563
- (0, _forEach.default)(_context2 = (0, _keys.default)(metadata)).call(_context2, function (key) {
569
+ (0, _forEach.default)(_context5 = (0, _keys.default)(metadata)).call(_context5, function (key) {
564
570
  _this4.addMetadata(key, metadata[key]);
565
571
  });
566
572
  }
@@ -597,9 +603,9 @@ var ParseFile = /*#__PURE__*/function () {
597
603
  var _this5 = this;
598
604
 
599
605
  if (tags && (0, _typeof2.default)(tags) === 'object') {
600
- var _context3;
606
+ var _context6;
601
607
 
602
- (0, _forEach.default)(_context3 = (0, _keys.default)(tags)).call(_context3, function (key) {
608
+ (0, _forEach.default)(_context6 = (0, _keys.default)(tags)).call(_context6, function (key) {
603
609
  _this5.addTag(key, tags[key]);
604
610
  });
605
611
  }
@@ -671,19 +677,19 @@ var DefaultController = {
671
677
  ) {
672
678
  var base64Data, _base64Data$split, _base64Data$split2, first, second, data, newSource;
673
679
 
674
- return _regenerator.default.wrap(function (_context4) {
680
+ return _regenerator.default.wrap(function (_context7) {
675
681
  while (1) {
676
- switch (_context4.prev = _context4.next) {
682
+ switch (_context7.prev = _context7.next) {
677
683
  case 0:
678
684
  if (!(source.format !== 'file')) {
679
- _context4.next = 2;
685
+ _context7.next = 2;
680
686
  break;
681
687
  }
682
688
 
683
689
  throw new Error('saveFile can only be used with File-type sources.');
684
690
 
685
691
  case 2:
686
- _context4.next = 4;
692
+ _context7.next = 4;
687
693
  return new _promise.default(function (res, rej) {
688
694
  // eslint-disable-next-line no-undef
689
695
  var reader = new FileReader();
@@ -700,7 +706,7 @@ var DefaultController = {
700
706
  });
701
707
 
702
708
  case 4:
703
- base64Data = _context4.sent; // we only want the data after the comma
709
+ base64Data = _context7.sent; // we only want the data after the comma
704
710
  // For example: "data:application/pdf;base64,JVBERi0xLjQKJ..." we would only want "JVBERi0xLjQKJ..."
705
711
 
706
712
  _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
@@ -712,15 +718,15 @@ var DefaultController = {
712
718
  base64: data,
713
719
  type: source.type || (source.file ? source.file.type : null)
714
720
  };
715
- _context4.next = 10;
721
+ _context7.next = 10;
716
722
  return DefaultController.saveBase64(name, newSource, options);
717
723
 
718
724
  case 10:
719
- return _context4.abrupt("return", _context4.sent);
725
+ return _context7.abrupt("return", _context7.sent);
720
726
 
721
727
  case 11:
722
728
  case "end":
723
- return _context4.stop();
729
+ return _context7.stop();
724
730
  }
725
731
  }
726
732
  }, _callee2);
@@ -152,6 +152,8 @@ var ParseRole = /*#__PURE__*/function (_ParseObject) {
152
152
  )
153
153
  /*: ParseObject | boolean*/
154
154
  {
155
+ this._validateName(name);
156
+
155
157
  return this.set('name', name, options);
156
158
  }
157
159
  /**
@@ -192,6 +194,17 @@ var ParseRole = /*#__PURE__*/function (_ParseObject) {
192
194
  {
193
195
  return this.relation('roles');
194
196
  }
197
+ }, {
198
+ key: "_validateName",
199
+ value: function (newName) {
200
+ if (typeof newName !== 'string') {
201
+ throw new _ParseError.default(_ParseError.default.OTHER_CAUSE, "A role's name must be a String.");
202
+ }
203
+
204
+ if (!/^[0-9a-zA-Z\-_ ]+$/.test(newName)) {
205
+ throw new _ParseError.default(_ParseError.default.OTHER_CAUSE, "A role's name can be only contain alphanumeric characters, _, " + '-, and spaces.');
206
+ }
207
+ }
195
208
  }, {
196
209
  key: "validate",
197
210
  value: function (attrs
@@ -217,12 +230,10 @@ var ParseRole = /*#__PURE__*/function (_ParseObject) {
217
230
  return new _ParseError.default(_ParseError.default.OTHER_CAUSE, "A role's name can only be set before it has been saved.");
218
231
  }
219
232
 
220
- if (typeof newName !== 'string') {
221
- return new _ParseError.default(_ParseError.default.OTHER_CAUSE, "A role's name must be a String.");
222
- }
223
-
224
- if (!/^[0-9a-zA-Z\-_ ]+$/.test(newName)) {
225
- return new _ParseError.default(_ParseError.default.OTHER_CAUSE, "A role's name can be only contain alphanumeric characters, _, " + '-, and spaces.');
233
+ try {
234
+ this._validateName(newName);
235
+ } catch (e) {
236
+ return e;
226
237
  }
227
238
  }
228
239
 
@@ -1280,7 +1280,7 @@ var ParseUser = /*#__PURE__*/function (_ParseObject) {
1280
1280
  * Request an email verification.
1281
1281
  *
1282
1282
  * @param {string} email The email address associated with the user that
1283
- * forgot their password.
1283
+ * needs to verify their email.
1284
1284
  * @param {object} options
1285
1285
  * @static
1286
1286
  * @returns {Promise}
@@ -217,7 +217,7 @@ const config
217
217
  SERVER_AUTH_TOKEN: null,
218
218
  LIVEQUERY_SERVER_URL: null,
219
219
  ENCRYPTED_KEY: null,
220
- VERSION: 'js' + "3.4.2-alpha.1",
220
+ VERSION: 'js' + "3.4.3-alpha.2",
221
221
  APPLICATION_ID: null,
222
222
  JAVASCRIPT_KEY: null,
223
223
  MASTER_KEY: null,
@@ -84,7 +84,8 @@ if (typeof XMLHttpRequest !== 'undefined') {
84
84
  uri: string,
85
85
  type: string,
86
86
  };*/
87
- const dataUriRegexp = /^data:([a-zA-Z]+\/[-a-zA-Z0-9+.]+)(;charset=[a-zA-Z0-9\-\/]*)?;base64,/;
87
+ const base64Regex = new RegExp('([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))', 'i');
88
+ const dataUriRegex = new RegExp(`^data:([a-zA-Z]+\\/[-a-zA-Z0-9+.]+(;[a-z-]+=[a-zA-Z0-9+.-]+)?)?(;base64)?,(${base64Regex.source})*$`, 'i');
88
89
 
89
90
  function b64Digit(number
90
91
  /*: number*/
@@ -205,26 +206,27 @@ class ParseFile {
205
206
  type: specifiedType
206
207
  };
207
208
  } else if (data && typeof data.base64 === 'string') {
208
- const base64 = data.base64;
209
- const commaIndex = base64.indexOf(',');
209
+ // Check if data URI or base64 string is valid
210
+ const validationRegex = new RegExp(base64Regex.source + '|' + dataUriRegex.source, 'i');
210
211
 
211
- if (commaIndex !== -1) {
212
- const matches = dataUriRegexp.exec(base64.slice(0, commaIndex + 1)); // if data URI with type and charset, there will be 4 matches.
212
+ if (!validationRegex.test(data.base64)) {
213
+ throw new Error('Cannot create a Parse.File without valid data URIs or base64 encoded data.');
214
+ }
213
215
 
214
- this._data = base64.slice(commaIndex + 1);
215
- this._source = {
216
- format: 'base64',
217
- base64: this._data,
218
- type: matches[1]
219
- };
220
- } else {
221
- this._data = base64;
222
- this._source = {
223
- format: 'base64',
224
- base64: base64,
225
- type: specifiedType
226
- };
216
+ const base64 = data.base64.split(',').slice(-1)[0];
217
+ let type = specifiedType || data.base64.split(';').slice(0, 1)[0].split(':').slice(1, 2)[0] || ''; // https://tools.ietf.org/html/rfc2397
218
+ // If <mediatype> is omitted, it defaults to text/plain;charset=US-ASCII.
219
+ // As a shorthand, "text/plain" can be omitted but the charset parameter supplied.
220
+
221
+ if (dataUriRegex.test(data.base64)) {
222
+ type = type || 'text/plain';
227
223
  }
224
+
225
+ this._source = {
226
+ format: 'base64',
227
+ base64,
228
+ type
229
+ };
228
230
  } else {
229
231
  throw new TypeError('Cannot create a Parse.File with that data.');
230
232
  }
@@ -105,6 +105,8 @@ class ParseRole extends _ParseObject.default {
105
105
  )
106
106
  /*: ParseObject | boolean*/
107
107
  {
108
+ this._validateName(name);
109
+
108
110
  return this.set('name', name, options);
109
111
  }
110
112
  /**
@@ -144,6 +146,16 @@ class ParseRole extends _ParseObject.default {
144
146
  return this.relation('roles');
145
147
  }
146
148
 
149
+ _validateName(newName) {
150
+ if (typeof newName !== 'string') {
151
+ throw new _ParseError.default(_ParseError.default.OTHER_CAUSE, "A role's name must be a String.");
152
+ }
153
+
154
+ if (!/^[0-9a-zA-Z\-_ ]+$/.test(newName)) {
155
+ throw new _ParseError.default(_ParseError.default.OTHER_CAUSE, "A role's name can be only contain alphanumeric characters, _, " + '-, and spaces.');
156
+ }
157
+ }
158
+
147
159
  validate(attrs
148
160
  /*: AttributeMap*/
149
161
  , options
@@ -167,12 +179,10 @@ class ParseRole extends _ParseObject.default {
167
179
  return new _ParseError.default(_ParseError.default.OTHER_CAUSE, "A role's name can only be set before it has been saved.");
168
180
  }
169
181
 
170
- if (typeof newName !== 'string') {
171
- return new _ParseError.default(_ParseError.default.OTHER_CAUSE, "A role's name must be a String.");
172
- }
173
-
174
- if (!/^[0-9a-zA-Z\-_ ]+$/.test(newName)) {
175
- return new _ParseError.default(_ParseError.default.OTHER_CAUSE, "A role's name can be only contain alphanumeric characters, _, " + '-, and spaces.');
182
+ try {
183
+ this._validateName(newName);
184
+ } catch (e) {
185
+ return e;
176
186
  }
177
187
  }
178
188
 
@@ -1012,7 +1012,7 @@ class ParseUser extends _ParseObject.default {
1012
1012
  * Request an email verification.
1013
1013
  *
1014
1014
  * @param {string} email The email address associated with the user that
1015
- * forgot their password.
1015
+ * needs to verify their email.
1016
1016
  * @param {object} options
1017
1017
  * @static
1018
1018
  * @returns {Promise}
@@ -8,7 +8,7 @@ var config = {
8
8
  SERVER_AUTH_TOKEN: null,
9
9
  LIVEQUERY_SERVER_URL: null,
10
10
  ENCRYPTED_KEY: null,
11
- VERSION: 'js' + "3.4.2-alpha.1",
11
+ VERSION: 'js' + "3.4.3-alpha.2",
12
12
  APPLICATION_ID: null,
13
13
  JAVASCRIPT_KEY: null,
14
14
  MASTER_KEY: null,
@@ -51,7 +51,8 @@ if (typeof XMLHttpRequest !== 'undefined') {
51
51
  XHR = XMLHttpRequest;
52
52
  }
53
53
 
54
- var dataUriRegexp = /^data:([a-zA-Z]+\/[-a-zA-Z0-9+.]+)(;charset=[a-zA-Z0-9\-\/]*)?;base64,/;
54
+ var base64Regex = new RegExp('([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))', 'i');
55
+ var dataUriRegex = new RegExp("^data:([a-zA-Z]+\\/[-a-zA-Z0-9+.]+(;[a-z-]+=[a-zA-Z0-9+.-]+)?)?(;base64)?,(" + base64Regex.source + ")*$", 'i');
55
56
 
56
57
  function b64Digit(number) {
57
58
  if (number < 26) {
@@ -106,25 +107,25 @@ var ParseFile = function () {
106
107
  type: specifiedType
107
108
  };
108
109
  } else if (data && typeof data.base64 === 'string') {
109
- var base64 = data.base64;
110
- var commaIndex = base64.indexOf(',');
111
-
112
- if (commaIndex !== -1) {
113
- var matches = dataUriRegexp.exec(base64.slice(0, commaIndex + 1));
114
- this._data = base64.slice(commaIndex + 1);
115
- this._source = {
116
- format: 'base64',
117
- base64: this._data,
118
- type: matches[1]
119
- };
120
- } else {
121
- this._data = base64;
122
- this._source = {
123
- format: 'base64',
124
- base64: base64,
125
- type: specifiedType
126
- };
110
+ var validationRegex = new RegExp(base64Regex.source + '|' + dataUriRegex.source, 'i');
111
+
112
+ if (!validationRegex.test(data.base64)) {
113
+ throw new Error('Cannot create a Parse.File without valid data URIs or base64 encoded data.');
114
+ }
115
+
116
+ var base64 = data.base64.split(',').slice(-1)[0];
117
+
118
+ var _type = specifiedType || data.base64.split(';').slice(0, 1)[0].split(':').slice(1, 2)[0] || '';
119
+
120
+ if (dataUriRegex.test(data.base64)) {
121
+ _type = _type || 'text/plain';
127
122
  }
123
+
124
+ this._source = {
125
+ format: 'base64',
126
+ base64: base64,
127
+ type: _type
128
+ };
128
129
  } else {
129
130
  throw new TypeError('Cannot create a Parse.File with that data.');
130
131
  }
@@ -88,6 +88,8 @@ var ParseRole = function (_ParseObject) {
88
88
  }, {
89
89
  key: "setName",
90
90
  value: function (name, options) {
91
+ this._validateName(name);
92
+
91
93
  return this.set('name', name, options);
92
94
  }
93
95
  }, {
@@ -100,6 +102,17 @@ var ParseRole = function (_ParseObject) {
100
102
  value: function () {
101
103
  return this.relation('roles');
102
104
  }
105
+ }, {
106
+ key: "_validateName",
107
+ value: function (newName) {
108
+ if (typeof newName !== 'string') {
109
+ throw new _ParseError.default(_ParseError.default.OTHER_CAUSE, "A role's name must be a String.");
110
+ }
111
+
112
+ if (!/^[0-9a-zA-Z\-_ ]+$/.test(newName)) {
113
+ throw new _ParseError.default(_ParseError.default.OTHER_CAUSE, "A role's name can be only contain alphanumeric characters, _, " + '-, and spaces.');
114
+ }
115
+ }
103
116
  }, {
104
117
  key: "validate",
105
118
  value: function (attrs, options) {
@@ -116,12 +129,10 @@ var ParseRole = function (_ParseObject) {
116
129
  return new _ParseError.default(_ParseError.default.OTHER_CAUSE, "A role's name can only be set before it has been saved.");
117
130
  }
118
131
 
119
- if (typeof newName !== 'string') {
120
- return new _ParseError.default(_ParseError.default.OTHER_CAUSE, "A role's name must be a String.");
121
- }
122
-
123
- if (!/^[0-9a-zA-Z\-_ ]+$/.test(newName)) {
124
- return new _ParseError.default(_ParseError.default.OTHER_CAUSE, "A role's name can be only contain alphanumeric characters, _, " + '-, and spaces.');
132
+ try {
133
+ this._validateName(newName);
134
+ } catch (e) {
135
+ return e;
125
136
  }
126
137
  }
127
138
 
@@ -224,7 +224,7 @@ var config
224
224
  SERVER_AUTH_TOKEN: null,
225
225
  LIVEQUERY_SERVER_URL: null,
226
226
  ENCRYPTED_KEY: null,
227
- VERSION: 'js' + "3.4.2-alpha.1",
227
+ VERSION: 'js' + "3.4.3-alpha.2",
228
228
  APPLICATION_ID: null,
229
229
  JAVASCRIPT_KEY: null,
230
230
  MASTER_KEY: null,