parse 5.2.0-alpha.1 → 5.2.0-alpha.3

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.
Files changed (247) hide show
  1. package/dist/parse.js +10519 -15246
  2. package/dist/parse.min.js +2 -2
  3. package/dist/parse.weapp.js +10499 -15371
  4. package/dist/parse.weapp.min.js +2 -2
  5. package/lib/browser/Analytics.js +7 -11
  6. package/lib/browser/AnonymousUtils.js +17 -22
  7. package/lib/browser/Cloud.js +23 -41
  8. package/lib/browser/CoreManager.js +71 -79
  9. package/lib/browser/CryptoController.js +14 -9
  10. package/lib/browser/EventEmitter.js +9 -2
  11. package/lib/browser/EventuallyQueue.js +156 -357
  12. package/lib/browser/FacebookUtils.js +23 -28
  13. package/lib/browser/IndexedDBStorageController.js +18 -14
  14. package/lib/browser/InstallationController.js +55 -121
  15. package/lib/browser/LiveQueryClient.js +312 -485
  16. package/lib/browser/LiveQuerySubscription.js +25 -28
  17. package/lib/browser/LocalDatastore.js +258 -624
  18. package/lib/browser/LocalDatastoreController.default.js +42 -226
  19. package/lib/browser/LocalDatastoreController.js +11 -1
  20. package/lib/browser/LocalDatastoreController.react-native.js +66 -160
  21. package/lib/browser/LocalDatastoreUtils.js +4 -7
  22. package/lib/browser/ObjectStateMutations.js +54 -96
  23. package/lib/browser/OfflineQuery.js +106 -198
  24. package/lib/browser/Parse.js +44 -60
  25. package/lib/browser/ParseACL.js +242 -288
  26. package/lib/browser/ParseCLP.js +372 -572
  27. package/lib/browser/ParseConfig.js +115 -138
  28. package/lib/browser/ParseError.js +85 -182
  29. package/lib/browser/ParseFile.js +294 -438
  30. package/lib/browser/ParseGeoPoint.js +121 -146
  31. package/lib/browser/ParseHooks.js +23 -25
  32. package/lib/browser/ParseInstallation.js +225 -367
  33. package/lib/browser/ParseLiveQuery.js +74 -148
  34. package/lib/browser/ParseObject.js +2014 -2621
  35. package/lib/browser/ParseOp.js +343 -484
  36. package/lib/browser/ParsePolygon.js +101 -120
  37. package/lib/browser/ParseQuery.js +1708 -2052
  38. package/lib/browser/ParseRelation.js +99 -118
  39. package/lib/browser/ParseRole.js +88 -140
  40. package/lib/browser/ParseSchema.js +372 -434
  41. package/lib/browser/ParseSession.js +62 -110
  42. package/lib/browser/ParseUser.js +941 -1284
  43. package/lib/browser/Push.js +15 -38
  44. package/lib/browser/RESTController.js +85 -124
  45. package/lib/browser/SingleInstanceStateController.js +57 -86
  46. package/lib/browser/Socket.weapp.js +50 -33
  47. package/lib/browser/Storage.js +23 -28
  48. package/lib/browser/StorageController.browser.js +16 -13
  49. package/lib/browser/StorageController.default.js +15 -14
  50. package/lib/browser/StorageController.js +14 -1
  51. package/lib/browser/StorageController.react-native.js +31 -30
  52. package/lib/browser/StorageController.weapp.js +19 -13
  53. package/lib/browser/TaskQueue.js +31 -43
  54. package/lib/browser/UniqueInstanceStateController.js +65 -86
  55. package/lib/browser/WebSocketController.js +11 -4
  56. package/lib/browser/Xhr.weapp.js +90 -78
  57. package/lib/browser/arrayContainsObject.js +3 -3
  58. package/lib/browser/canBeSerialized.js +10 -11
  59. package/lib/browser/decode.js +11 -11
  60. package/lib/browser/encode.js +11 -11
  61. package/lib/browser/equals.js +9 -10
  62. package/lib/browser/escape.js +2 -2
  63. package/lib/browser/isRevocableSession.js +1 -1
  64. package/lib/browser/parseDate.js +10 -10
  65. package/lib/browser/promiseUtils.js +19 -19
  66. package/lib/browser/unique.js +4 -4
  67. package/lib/browser/unsavedChildren.js +20 -21
  68. package/lib/browser/uuid.js +2 -4
  69. package/lib/node/Analytics.js +5 -9
  70. package/lib/node/AnonymousUtils.js +10 -15
  71. package/lib/node/Cloud.js +11 -11
  72. package/lib/node/CoreManager.js +59 -67
  73. package/lib/node/CryptoController.js +8 -3
  74. package/lib/node/EventEmitter.js +7 -1
  75. package/lib/node/EventuallyQueue.js +20 -39
  76. package/lib/node/FacebookUtils.js +4 -8
  77. package/lib/node/IndexedDBStorageController.js +14 -10
  78. package/lib/node/InstallationController.js +12 -13
  79. package/lib/node/LiveQueryClient.js +23 -21
  80. package/lib/node/LiveQuerySubscription.js +6 -7
  81. package/lib/node/LocalDatastore.js +23 -23
  82. package/lib/node/LocalDatastoreController.default.js +11 -12
  83. package/lib/node/LocalDatastoreController.js +14 -1
  84. package/lib/node/LocalDatastoreController.react-native.js +25 -21
  85. package/lib/node/LocalDatastoreUtils.js +4 -7
  86. package/lib/node/ObjectStateMutations.js +12 -22
  87. package/lib/node/OfflineQuery.js +37 -23
  88. package/lib/node/Parse.js +36 -50
  89. package/lib/node/ParseACL.js +21 -30
  90. package/lib/node/ParseCLP.js +38 -40
  91. package/lib/node/ParseConfig.js +10 -17
  92. package/lib/node/ParseError.js +460 -461
  93. package/lib/node/ParseFile.js +27 -47
  94. package/lib/node/ParseGeoPoint.js +16 -17
  95. package/lib/node/ParseHooks.js +16 -18
  96. package/lib/node/ParseInstallation.js +10 -11
  97. package/lib/node/ParseLiveQuery.js +9 -14
  98. package/lib/node/ParseObject.js +142 -173
  99. package/lib/node/ParseOp.js +35 -47
  100. package/lib/node/ParsePolygon.js +14 -20
  101. package/lib/node/ParseQuery.js +100 -123
  102. package/lib/node/ParseRelation.js +10 -19
  103. package/lib/node/ParseRole.js +10 -11
  104. package/lib/node/ParseSchema.js +29 -42
  105. package/lib/node/ParseSession.js +10 -11
  106. package/lib/node/ParseUser.js +76 -87
  107. package/lib/node/Push.js +7 -12
  108. package/lib/node/RESTController.js +24 -36
  109. package/lib/node/SingleInstanceStateController.js +41 -69
  110. package/lib/node/Socket.weapp.js +23 -2
  111. package/lib/node/Storage.js +14 -19
  112. package/lib/node/StorageController.browser.js +10 -8
  113. package/lib/node/StorageController.default.js +9 -9
  114. package/lib/node/StorageController.js +16 -1
  115. package/lib/node/StorageController.react-native.js +20 -20
  116. package/lib/node/StorageController.weapp.js +14 -8
  117. package/lib/node/TaskQueue.js +2 -3
  118. package/lib/node/UniqueInstanceStateController.js +43 -63
  119. package/lib/node/WebSocketController.js +15 -2
  120. package/lib/node/Xhr.weapp.js +11 -2
  121. package/lib/node/arrayContainsObject.js +4 -4
  122. package/lib/node/canBeSerialized.js +5 -5
  123. package/lib/node/decode.js +4 -4
  124. package/lib/node/encode.js +5 -5
  125. package/lib/node/equals.js +4 -4
  126. package/lib/node/escape.js +1 -1
  127. package/lib/node/isRevocableSession.js +1 -1
  128. package/lib/node/parseDate.js +1 -1
  129. package/lib/node/promiseUtils.js +7 -7
  130. package/lib/node/unique.js +5 -5
  131. package/lib/node/unsavedChildren.js +5 -5
  132. package/lib/node/uuid.js +2 -4
  133. package/lib/react-native/Analytics.js +2 -2
  134. package/lib/react-native/AnonymousUtils.js +3 -4
  135. package/lib/react-native/CoreManager.js +2 -3
  136. package/lib/react-native/CryptoController.js +6 -1
  137. package/lib/react-native/EventEmitter.js +6 -1
  138. package/lib/react-native/EventuallyQueue.js +1 -2
  139. package/lib/react-native/FacebookUtils.js +1 -2
  140. package/lib/react-native/IndexedDBStorageController.js +11 -5
  141. package/lib/react-native/InstallationController.js +1 -2
  142. package/lib/react-native/LiveQueryClient.js +8 -7
  143. package/lib/react-native/LiveQuerySubscription.js +2 -4
  144. package/lib/react-native/LocalDatastore.js +3 -3
  145. package/lib/react-native/LocalDatastoreController.default.js +1 -2
  146. package/lib/react-native/LocalDatastoreController.js +11 -1
  147. package/lib/react-native/LocalDatastoreController.react-native.js +11 -12
  148. package/lib/react-native/LocalDatastoreUtils.js +3 -6
  149. package/lib/react-native/OfflineQuery.js +25 -20
  150. package/lib/react-native/Parse.js +24 -38
  151. package/lib/react-native/ParseACL.js +4 -6
  152. package/lib/react-native/ParseCLP.js +2 -4
  153. package/lib/react-native/ParseConfig.js +4 -6
  154. package/lib/react-native/ParseError.js +13 -31
  155. package/lib/react-native/ParseFile.js +3 -4
  156. package/lib/react-native/ParseGeoPoint.js +2 -4
  157. package/lib/react-native/ParseInstallation.js +13 -30
  158. package/lib/react-native/ParseLiveQuery.js +2 -4
  159. package/lib/react-native/ParseObject.js +77 -87
  160. package/lib/react-native/ParseOp.js +41 -79
  161. package/lib/react-native/ParsePolygon.js +2 -4
  162. package/lib/react-native/ParseQuery.js +43 -45
  163. package/lib/react-native/ParseRelation.js +2 -4
  164. package/lib/react-native/ParseRole.js +13 -30
  165. package/lib/react-native/ParseSchema.js +3 -5
  166. package/lib/react-native/ParseSession.js +12 -29
  167. package/lib/react-native/ParseUser.js +24 -49
  168. package/lib/react-native/RESTController.js +10 -4
  169. package/lib/react-native/SingleInstanceStateController.js +23 -37
  170. package/lib/react-native/Socket.weapp.js +9 -4
  171. package/lib/react-native/Storage.js +1 -2
  172. package/lib/react-native/StorageController.browser.js +6 -1
  173. package/lib/react-native/StorageController.default.js +6 -1
  174. package/lib/react-native/StorageController.js +13 -1
  175. package/lib/react-native/StorageController.react-native.js +11 -6
  176. package/lib/react-native/StorageController.weapp.js +6 -1
  177. package/lib/react-native/TaskQueue.js +2 -4
  178. package/lib/react-native/UniqueInstanceStateController.js +23 -37
  179. package/lib/react-native/WebSocketController.js +9 -1
  180. package/lib/react-native/Xhr.weapp.js +9 -4
  181. package/lib/react-native/unsavedChildren.js +3 -3
  182. package/lib/react-native/uuid.js +1 -2
  183. package/lib/weapp/Analytics.js +7 -11
  184. package/lib/weapp/AnonymousUtils.js +17 -22
  185. package/lib/weapp/Cloud.js +23 -41
  186. package/lib/weapp/CoreManager.js +71 -79
  187. package/lib/weapp/CryptoController.js +14 -9
  188. package/lib/weapp/EventEmitter.js +9 -2
  189. package/lib/weapp/EventuallyQueue.js +156 -357
  190. package/lib/weapp/FacebookUtils.js +23 -28
  191. package/lib/weapp/IndexedDBStorageController.js +18 -14
  192. package/lib/weapp/InstallationController.js +55 -121
  193. package/lib/weapp/LiveQueryClient.js +312 -485
  194. package/lib/weapp/LiveQuerySubscription.js +25 -28
  195. package/lib/weapp/LocalDatastore.js +258 -624
  196. package/lib/weapp/LocalDatastoreController.default.js +42 -226
  197. package/lib/weapp/LocalDatastoreController.js +11 -1
  198. package/lib/weapp/LocalDatastoreController.react-native.js +66 -160
  199. package/lib/weapp/LocalDatastoreUtils.js +4 -7
  200. package/lib/weapp/ObjectStateMutations.js +54 -96
  201. package/lib/weapp/OfflineQuery.js +106 -198
  202. package/lib/weapp/Parse.js +44 -59
  203. package/lib/weapp/ParseACL.js +242 -288
  204. package/lib/weapp/ParseCLP.js +372 -572
  205. package/lib/weapp/ParseConfig.js +115 -138
  206. package/lib/weapp/ParseError.js +85 -182
  207. package/lib/weapp/ParseFile.js +295 -440
  208. package/lib/weapp/ParseGeoPoint.js +121 -146
  209. package/lib/weapp/ParseHooks.js +23 -25
  210. package/lib/weapp/ParseInstallation.js +225 -367
  211. package/lib/weapp/ParseLiveQuery.js +74 -148
  212. package/lib/weapp/ParseObject.js +2014 -2621
  213. package/lib/weapp/ParseOp.js +343 -484
  214. package/lib/weapp/ParsePolygon.js +101 -120
  215. package/lib/weapp/ParseQuery.js +1708 -2052
  216. package/lib/weapp/ParseRelation.js +99 -118
  217. package/lib/weapp/ParseRole.js +88 -140
  218. package/lib/weapp/ParseSchema.js +372 -434
  219. package/lib/weapp/ParseSession.js +62 -110
  220. package/lib/weapp/ParseUser.js +941 -1284
  221. package/lib/weapp/Push.js +15 -38
  222. package/lib/weapp/RESTController.js +86 -125
  223. package/lib/weapp/SingleInstanceStateController.js +57 -86
  224. package/lib/weapp/Socket.weapp.js +50 -33
  225. package/lib/weapp/Storage.js +23 -28
  226. package/lib/weapp/StorageController.browser.js +16 -13
  227. package/lib/weapp/StorageController.default.js +15 -14
  228. package/lib/weapp/StorageController.js +14 -1
  229. package/lib/weapp/StorageController.react-native.js +31 -30
  230. package/lib/weapp/StorageController.weapp.js +19 -13
  231. package/lib/weapp/TaskQueue.js +31 -43
  232. package/lib/weapp/UniqueInstanceStateController.js +65 -86
  233. package/lib/weapp/WebSocketController.js +11 -4
  234. package/lib/weapp/Xhr.weapp.js +90 -78
  235. package/lib/weapp/arrayContainsObject.js +3 -3
  236. package/lib/weapp/canBeSerialized.js +10 -11
  237. package/lib/weapp/decode.js +11 -11
  238. package/lib/weapp/encode.js +11 -11
  239. package/lib/weapp/equals.js +9 -10
  240. package/lib/weapp/escape.js +2 -2
  241. package/lib/weapp/isRevocableSession.js +1 -1
  242. package/lib/weapp/parseDate.js +10 -10
  243. package/lib/weapp/promiseUtils.js +19 -19
  244. package/lib/weapp/unique.js +4 -4
  245. package/lib/weapp/unsavedChildren.js +20 -21
  246. package/lib/weapp/uuid.js +6 -8
  247. package/package.json +24 -30
@@ -1,99 +1,24 @@
1
1
  "use strict";
2
2
 
3
- var _Reflect$construct = require("@babel/runtime-corejs3/core-js-stable/reflect/construct");
4
- var _Object$keys = require("@babel/runtime-corejs3/core-js-stable/object/keys");
5
- var _Object$getOwnPropertySymbols = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols");
6
- var _filterInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/filter");
7
- var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor");
8
- var _forEachInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/for-each");
9
- var _Object$getOwnPropertyDescriptors = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors");
10
- var _Object$defineProperties = require("@babel/runtime-corejs3/core-js-stable/object/define-properties");
11
3
  var _Object$defineProperty2 = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
12
4
  var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
13
5
  _Object$defineProperty2(exports, "__esModule", {
14
6
  value: true
15
7
  });
16
8
  exports.default = void 0;
17
- var _regenerator = _interopRequireDefault(require("@babel/runtime-corejs3/regenerator"));
18
9
  var _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/promise"));
19
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/define-property"));
10
+ var _defineProperty = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/define-property"));
20
11
  var _stringify = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/json/stringify"));
21
- var _defineProperty3 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
22
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/asyncToGenerator"));
23
- var _typeof2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/typeof"));
24
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/classCallCheck"));
25
- var _createClass2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/createClass"));
26
- var _get2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/get"));
27
- var _inherits2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/inherits"));
28
- var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/possibleConstructorReturn"));
29
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/getPrototypeOf"));
30
12
  var _CoreManager = _interopRequireDefault(require("./CoreManager"));
31
13
  var _isRevocableSession = _interopRequireDefault(require("./isRevocableSession"));
32
14
  var _ParseError = _interopRequireDefault(require("./ParseError"));
33
- var _ParseObject2 = _interopRequireDefault(require("./ParseObject"));
15
+ var _ParseObject = _interopRequireDefault(require("./ParseObject"));
34
16
  var _Storage = _interopRequireDefault(require("./Storage"));
35
- function ownKeys(object, enumerableOnly) {
36
- var keys = _Object$keys(object);
37
- if (_Object$getOwnPropertySymbols) {
38
- var symbols = _Object$getOwnPropertySymbols(object);
39
- enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) {
40
- return _Object$getOwnPropertyDescriptor(object, sym).enumerable;
41
- })), keys.push.apply(keys, symbols);
42
- }
43
- return keys;
44
- }
45
- function _objectSpread(target) {
46
- for (var i = 1; i < arguments.length; i++) {
47
- var _context7, _context8;
48
- var source = null != arguments[i] ? arguments[i] : {};
49
- i % 2 ? _forEachInstanceProperty(_context7 = ownKeys(Object(source), !0)).call(_context7, function (key) {
50
- (0, _defineProperty3.default)(target, key, source[key]);
51
- }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context8 = ownKeys(Object(source))).call(_context8, function (key) {
52
- _Object$defineProperty2(target, key, _Object$getOwnPropertyDescriptor(source, key));
53
- });
54
- }
55
- return target;
56
- }
57
- function _createSuper(Derived) {
58
- var hasNativeReflectConstruct = _isNativeReflectConstruct();
59
- return function () {
60
- var Super = (0, _getPrototypeOf2.default)(Derived),
61
- result;
62
- if (hasNativeReflectConstruct) {
63
- var NewTarget = (0, _getPrototypeOf2.default)(this).constructor;
64
- result = _Reflect$construct(Super, arguments, NewTarget);
65
- } else {
66
- result = Super.apply(this, arguments);
67
- }
68
- return (0, _possibleConstructorReturn2.default)(this, result);
69
- };
70
- }
71
- function _isNativeReflectConstruct() {
72
- if (typeof Reflect === "undefined" || !_Reflect$construct) return false;
73
- if (_Reflect$construct.sham) return false;
74
- if (typeof Proxy === "function") return true;
75
- try {
76
- Boolean.prototype.valueOf.call(_Reflect$construct(Boolean, [], function () {}));
77
- return true;
78
- } catch (e) {
79
- return false;
80
- }
81
- }
82
- /*:: export type AuthData = { [key: string]: any };*/
83
- /*:: export type AuthProviderType = {
84
- authenticate?(options: {
85
- error?: (provider: AuthProviderType, error: string | any) => void,
86
- success?: (provider: AuthProviderType, result: AuthData) => void,
87
- }): void,
88
- restoreAuthentication(authData: any): boolean;
89
- getAuthType(): string;
90
- deauthenticate?(): void;
91
- };*/
92
- var CURRENT_USER_KEY = 'currentUser';
93
- var canUseCurrentUser = !_CoreManager.default.get('IS_NODE');
94
- var currentUserCacheMatchesDisk = false;
95
- var currentUserCache /*: ParseUser | null*/ = null;
96
- var authProviders /*: { [key: string]: AuthProviderType }*/ = {};
17
+ const CURRENT_USER_KEY = 'currentUser';
18
+ let canUseCurrentUser = !_CoreManager.default.get('IS_NODE');
19
+ let currentUserCacheMatchesDisk = false;
20
+ let currentUserCache = null;
21
+ const authProviders = {};
97
22
 
98
23
  /**
99
24
  * <p>A Parse.User object is a local representation of a user persisted to the
@@ -105,22 +30,17 @@ var authProviders /*: { [key: string]: AuthProviderType }*/ = {};
105
30
  * @alias Parse.User
106
31
  * @augments Parse.Object
107
32
  */
108
- var ParseUser = /*#__PURE__*/function (_ParseObject) {
109
- (0, _inherits2.default)(ParseUser, _ParseObject);
110
- var _super = _createSuper(ParseUser);
33
+ class ParseUser extends _ParseObject.default {
111
34
  /**
112
35
  * @param {object} attributes The initial set of data to store in the user.
113
36
  */
114
- function ParseUser(attributes /*:: ?: AttributeMap*/) {
115
- var _this;
116
- (0, _classCallCheck2.default)(this, ParseUser);
117
- _this = _super.call(this, '_User');
118
- if (attributes && (0, _typeof2.default)(attributes) === 'object') {
119
- if (!_this.set(attributes || {})) {
37
+ constructor(attributes) {
38
+ super('_User');
39
+ if (attributes && typeof attributes === 'object') {
40
+ if (!this.set(attributes || {})) {
120
41
  throw new Error("Can't create an invalid Parse User");
121
42
  }
122
43
  }
123
- return _this;
124
44
  }
125
45
 
126
46
  /**
@@ -130,1203 +50,963 @@ var ParseUser = /*#__PURE__*/function (_ParseObject) {
130
50
  * @returns {Promise} A promise that is resolved when the replacement
131
51
  * token has been fetched.
132
52
  */
133
- (0, _createClass2.default)(ParseUser, [{
134
- key: "_upgradeToRevocableSession",
135
- value: function (options /*: RequestOptions*/) /*: Promise<void>*/{
136
- options = options || {};
137
- var upgradeOptions /*: RequestOptions*/ = {};
138
- if (options.hasOwnProperty('useMasterKey')) {
139
- upgradeOptions.useMasterKey = options.useMasterKey;
140
- }
141
- var controller = _CoreManager.default.getUserController();
142
- return controller.upgradeToRevocableSession(this, upgradeOptions);
143
- }
53
+ _upgradeToRevocableSession(options) {
54
+ options = options || {};
55
+ const upgradeOptions = {};
56
+ if (options.hasOwnProperty('useMasterKey')) {
57
+ upgradeOptions.useMasterKey = options.useMasterKey;
58
+ }
59
+ const controller = _CoreManager.default.getUserController();
60
+ return controller.upgradeToRevocableSession(this, upgradeOptions);
61
+ }
144
62
 
145
- /**
146
- * Parse allows you to link your users with {@link https://docs.parseplatform.org/parse-server/guide/#oauth-and-3rd-party-authentication 3rd party authentication}, enabling
147
- * your users to sign up or log into your application using their existing identities.
148
- * Since 2.9.0
149
- *
150
- * @see {@link https://docs.parseplatform.org/js/guide/#linking-users Linking Users}
151
- * @param {string | AuthProvider} provider Name of auth provider or {@link https://parseplatform.org/Parse-SDK-JS/api/master/AuthProvider.html AuthProvider}
152
- * @param {object} options
153
- * @param {object} [options.authData] AuthData to link with
154
- * <ul>
155
- * <li>If provider is string, options is {@link http://docs.parseplatform.org/parse-server/guide/#supported-3rd-party-authentications authData}
156
- * <li>If provider is AuthProvider, options is saveOpts
157
- * </ul>
158
- * @param {object} saveOpts useMasterKey / sessionToken
159
- * @returns {Promise} A promise that is fulfilled with the user is linked
160
- */
161
- }, {
162
- key: "linkWith",
163
- value: function (provider /*: AuthProviderType*/, options /*: { authData?: AuthData }*/) /*: Promise<ParseUser>*/{
164
- var _this2 = this;
165
- var saveOpts /*: FullOptions*/ = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
166
- saveOpts.sessionToken = saveOpts.sessionToken || this.getSessionToken() || '';
167
- var authType;
168
- if (typeof provider === 'string') {
169
- authType = provider;
170
- if (authProviders[provider]) {
171
- provider = authProviders[provider];
172
- } else {
173
- var authProvider = {
174
- restoreAuthentication: function () {
175
- return true;
176
- },
177
- getAuthType: function () {
178
- return authType;
179
- }
180
- };
181
- authProviders[authProvider.getAuthType()] = authProvider;
182
- provider = authProvider;
183
- }
63
+ /**
64
+ * Parse allows you to link your users with {@link https://docs.parseplatform.org/parse-server/guide/#oauth-and-3rd-party-authentication 3rd party authentication}, enabling
65
+ * your users to sign up or log into your application using their existing identities.
66
+ * Since 2.9.0
67
+ *
68
+ * @see {@link https://docs.parseplatform.org/js/guide/#linking-users Linking Users}
69
+ * @param {string | AuthProvider} provider Name of auth provider or {@link https://parseplatform.org/Parse-SDK-JS/api/master/AuthProvider.html AuthProvider}
70
+ * @param {object} options
71
+ * @param {object} [options.authData] AuthData to link with
72
+ * <ul>
73
+ * <li>If provider is string, options is {@link http://docs.parseplatform.org/parse-server/guide/#supported-3rd-party-authentications authData}
74
+ * <li>If provider is AuthProvider, options is saveOpts
75
+ * </ul>
76
+ * @param {object} saveOpts useMasterKey / sessionToken
77
+ * @returns {Promise} A promise that is fulfilled with the user is linked
78
+ */
79
+ linkWith(provider, options) {
80
+ let saveOpts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
81
+ saveOpts.sessionToken = saveOpts.sessionToken || this.getSessionToken() || '';
82
+ let authType;
83
+ if (typeof provider === 'string') {
84
+ authType = provider;
85
+ if (authProviders[provider]) {
86
+ provider = authProviders[provider];
184
87
  } else {
185
- authType = provider.getAuthType();
88
+ const authProvider = {
89
+ restoreAuthentication() {
90
+ return true;
91
+ },
92
+ getAuthType() {
93
+ return authType;
94
+ }
95
+ };
96
+ authProviders[authProvider.getAuthType()] = authProvider;
97
+ provider = authProvider;
186
98
  }
187
- if (options && options.hasOwnProperty('authData')) {
188
- var _authData = this.get('authData') || {};
189
- if ((0, _typeof2.default)(_authData) !== 'object') {
190
- throw new Error('Invalid type: authData field should be an object');
191
- }
192
- _authData[authType] = options.authData;
193
- var oldAnonymousData = _authData.anonymous;
194
- this.stripAnonymity();
195
- var controller = _CoreManager.default.getUserController();
196
- return controller.linkWith(this, _authData, saveOpts).catch(function (e) {
197
- delete _authData[authType];
198
- _this2.restoreAnonimity(oldAnonymousData);
199
- throw e;
200
- });
201
- } else {
202
- return new _promise.default(function (resolve, reject) {
203
- provider.authenticate({
204
- success: function (provider, result) {
205
- var opts /*: { authData?: AuthData }*/ = {};
206
- opts.authData = result;
207
- _this2.linkWith(provider, opts, saveOpts).then(function () {
208
- resolve(_this2);
209
- }, function (error) {
210
- reject(error);
211
- });
212
- },
213
- error: function (_error) {
214
- function error() {
215
- return _error.apply(this, arguments);
216
- }
217
- error.toString = function () {
218
- return _error.toString();
219
- };
220
- return error;
221
- }(function (provider, error) {
99
+ } else {
100
+ authType = provider.getAuthType();
101
+ }
102
+ if (options && options.hasOwnProperty('authData')) {
103
+ const authData = this.get('authData') || {};
104
+ if (typeof authData !== 'object') {
105
+ throw new Error('Invalid type: authData field should be an object');
106
+ }
107
+ authData[authType] = options.authData;
108
+ const oldAnonymousData = authData.anonymous;
109
+ this.stripAnonymity();
110
+ const controller = _CoreManager.default.getUserController();
111
+ return controller.linkWith(this, authData, saveOpts).catch(e => {
112
+ delete authData[authType];
113
+ this.restoreAnonimity(oldAnonymousData);
114
+ throw e;
115
+ });
116
+ } else {
117
+ return new _promise.default((resolve, reject) => {
118
+ provider.authenticate({
119
+ success: (provider, result) => {
120
+ const opts = {};
121
+ opts.authData = result;
122
+ this.linkWith(provider, opts, saveOpts).then(() => {
123
+ resolve(this);
124
+ }, error => {
222
125
  reject(error);
223
- })
224
- });
126
+ });
127
+ },
128
+ error: (provider, error) => {
129
+ reject(error);
130
+ }
225
131
  });
226
- }
132
+ });
227
133
  }
134
+ }
228
135
 
229
- /**
230
- * @param provider
231
- * @param options
232
- * @param {object} [options.authData]
233
- * @param saveOpts
234
- * @deprecated since 2.9.0 see {@link https://parseplatform.org/Parse-SDK-JS/api/master/Parse.User.html#linkWith linkWith}
235
- * @returns {Promise}
236
- */
237
- }, {
238
- key: "_linkWith",
239
- value: function (provider /*: any*/, options /*: { authData?: AuthData }*/) /*: Promise<ParseUser>*/{
240
- var saveOpts /*: FullOptions*/ = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
241
- return this.linkWith(provider, options, saveOpts);
242
- }
136
+ /**
137
+ * @param provider
138
+ * @param options
139
+ * @param {object} [options.authData]
140
+ * @param saveOpts
141
+ * @deprecated since 2.9.0 see {@link https://parseplatform.org/Parse-SDK-JS/api/master/Parse.User.html#linkWith linkWith}
142
+ * @returns {Promise}
143
+ */
144
+ _linkWith(provider, options) {
145
+ let saveOpts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
146
+ return this.linkWith(provider, options, saveOpts);
147
+ }
243
148
 
244
- /**
245
- * Synchronizes auth data for a provider (e.g. puts the access token in the
246
- * right place to be used by the Facebook SDK).
247
- *
248
- * @param provider
249
- */
250
- }, {
251
- key: "_synchronizeAuthData",
252
- value: function (provider /*: string | AuthProviderType*/) {
253
- if (!this.isCurrent() || !provider) {
254
- return;
255
- }
256
- var authType;
257
- if (typeof provider === 'string') {
258
- authType = provider;
259
- provider = authProviders[authType];
260
- } else {
261
- authType = provider.getAuthType();
262
- }
263
- var authData = this.get('authData');
264
- if (!provider || !authData || (0, _typeof2.default)(authData) !== 'object') {
265
- return;
266
- }
267
- var success = provider.restoreAuthentication(authData[authType]);
268
- if (!success) {
269
- this._unlinkFrom(provider);
270
- }
149
+ /**
150
+ * Synchronizes auth data for a provider (e.g. puts the access token in the
151
+ * right place to be used by the Facebook SDK).
152
+ *
153
+ * @param provider
154
+ */
155
+ _synchronizeAuthData(provider) {
156
+ if (!this.isCurrent() || !provider) {
157
+ return;
158
+ }
159
+ let authType;
160
+ if (typeof provider === 'string') {
161
+ authType = provider;
162
+ provider = authProviders[authType];
163
+ } else {
164
+ authType = provider.getAuthType();
271
165
  }
272
-
273
- /**
274
- * Synchronizes authData for all providers.
275
- */
276
- }, {
277
- key: "_synchronizeAllAuthData",
278
- value: function () {
279
- var authData = this.get('authData');
280
- if ((0, _typeof2.default)(authData) !== 'object') {
281
- return;
282
- }
283
- for (var _key in authData) {
284
- this._synchronizeAuthData(_key);
285
- }
166
+ const authData = this.get('authData');
167
+ if (!provider || !authData || typeof authData !== 'object') {
168
+ return;
286
169
  }
287
-
288
- /**
289
- * Removes null values from authData (which exist temporarily for unlinking)
290
- */
291
- }, {
292
- key: "_cleanupAuthData",
293
- value: function () {
294
- if (!this.isCurrent()) {
295
- return;
296
- }
297
- var authData = this.get('authData');
298
- if ((0, _typeof2.default)(authData) !== 'object') {
299
- return;
300
- }
301
- for (var _key2 in authData) {
302
- if (!authData[_key2]) {
303
- delete authData[_key2];
304
- }
305
- }
170
+ const success = provider.restoreAuthentication(authData[authType]);
171
+ if (!success) {
172
+ this._unlinkFrom(provider);
306
173
  }
174
+ }
307
175
 
308
- /**
309
- * Unlinks a user from a service.
310
- *
311
- * @param {string | AuthProvider} provider Name of auth provider or {@link https://parseplatform.org/Parse-SDK-JS/api/master/AuthProvider.html AuthProvider}
312
- * @param {object} options MasterKey / SessionToken
313
- * @returns {Promise} A promise that is fulfilled when the unlinking
314
- * finishes.
315
- */
316
- }, {
317
- key: "_unlinkFrom",
318
- value: function (provider /*: any*/, options /*:: ?: FullOptions*/) /*: Promise<ParseUser>*/{
319
- var _this3 = this;
320
- return this.linkWith(provider, {
321
- authData: null
322
- }, options).then(function () {
323
- _this3._synchronizeAuthData(provider);
324
- return _promise.default.resolve(_this3);
325
- });
176
+ /**
177
+ * Synchronizes authData for all providers.
178
+ */
179
+ _synchronizeAllAuthData() {
180
+ const authData = this.get('authData');
181
+ if (typeof authData !== 'object') {
182
+ return;
326
183
  }
327
-
328
- /**
329
- * Checks whether a user is linked to a service.
330
- *
331
- * @param {object} provider service to link to
332
- * @returns {boolean} true if link was successful
333
- */
334
- }, {
335
- key: "_isLinked",
336
- value: function (provider /*: any*/) /*: boolean*/{
337
- var authType;
338
- if (typeof provider === 'string') {
339
- authType = provider;
340
- } else {
341
- authType = provider.getAuthType();
342
- }
343
- var authData = this.get('authData') || {};
344
- if ((0, _typeof2.default)(authData) !== 'object') {
345
- return false;
346
- }
347
- return !!authData[authType];
184
+ for (const key in authData) {
185
+ this._synchronizeAuthData(key);
348
186
  }
187
+ }
349
188
 
350
- /**
351
- * Deauthenticates all providers.
352
- */
353
- }, {
354
- key: "_logOutWithAll",
355
- value: function () {
356
- var authData = this.get('authData');
357
- if ((0, _typeof2.default)(authData) !== 'object') {
358
- return;
359
- }
360
- for (var _key3 in authData) {
361
- this._logOutWith(_key3);
362
- }
189
+ /**
190
+ * Removes null values from authData (which exist temporarily for unlinking)
191
+ */
192
+ _cleanupAuthData() {
193
+ if (!this.isCurrent()) {
194
+ return;
363
195
  }
364
-
365
- /**
366
- * Deauthenticates a single provider (e.g. removing access tokens from the
367
- * Facebook SDK).
368
- *
369
- * @param {object} provider service to logout of
370
- */
371
- }, {
372
- key: "_logOutWith",
373
- value: function (provider /*: any*/) {
374
- if (!this.isCurrent()) {
375
- return;
376
- }
377
- if (typeof provider === 'string') {
378
- provider = authProviders[provider];
379
- }
380
- if (provider && provider.deauthenticate) {
381
- provider.deauthenticate();
196
+ const authData = this.get('authData');
197
+ if (typeof authData !== 'object') {
198
+ return;
199
+ }
200
+ for (const key in authData) {
201
+ if (!authData[key]) {
202
+ delete authData[key];
382
203
  }
383
204
  }
205
+ }
206
+
207
+ /**
208
+ * Unlinks a user from a service.
209
+ *
210
+ * @param {string | AuthProvider} provider Name of auth provider or {@link https://parseplatform.org/Parse-SDK-JS/api/master/AuthProvider.html AuthProvider}
211
+ * @param {object} options MasterKey / SessionToken
212
+ * @returns {Promise} A promise that is fulfilled when the unlinking
213
+ * finishes.
214
+ */
215
+ _unlinkFrom(provider, options) {
216
+ return this.linkWith(provider, {
217
+ authData: null
218
+ }, options).then(() => {
219
+ this._synchronizeAuthData(provider);
220
+ return _promise.default.resolve(this);
221
+ });
222
+ }
384
223
 
385
- /**
386
- * Class instance method used to maintain specific keys when a fetch occurs.
387
- * Used to ensure that the session token is not lost.
388
- *
389
- * @returns {object} sessionToken
390
- */
391
- }, {
392
- key: "_preserveFieldsOnFetch",
393
- value: function () /*: AttributeMap*/{
394
- return {
395
- sessionToken: this.get('sessionToken')
396
- };
224
+ /**
225
+ * Checks whether a user is linked to a service.
226
+ *
227
+ * @param {object} provider service to link to
228
+ * @returns {boolean} true if link was successful
229
+ */
230
+ _isLinked(provider) {
231
+ let authType;
232
+ if (typeof provider === 'string') {
233
+ authType = provider;
234
+ } else {
235
+ authType = provider.getAuthType();
236
+ }
237
+ const authData = this.get('authData') || {};
238
+ if (typeof authData !== 'object') {
239
+ return false;
397
240
  }
241
+ return !!authData[authType];
242
+ }
398
243
 
399
- /**
400
- * Returns true if <code>current</code> would return this user.
401
- *
402
- * @returns {boolean} true if user is cached on disk
403
- */
404
- }, {
405
- key: "isCurrent",
406
- value: function () /*: boolean*/{
407
- var current = ParseUser.current();
408
- return !!current && current.id === this.id;
244
+ /**
245
+ * Deauthenticates all providers.
246
+ */
247
+ _logOutWithAll() {
248
+ const authData = this.get('authData');
249
+ if (typeof authData !== 'object') {
250
+ return;
251
+ }
252
+ for (const key in authData) {
253
+ this._logOutWith(key);
409
254
  }
255
+ }
410
256
 
411
- /**
412
- * Returns true if <code>current</code> would return this user.
413
- *
414
- * @returns {Promise<boolean>} true if user is cached on disk
415
- */
416
- }, {
417
- key: "isCurrentAsync",
418
- value: function () {
419
- var _isCurrentAsync = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
420
- var current;
421
- return _regenerator.default.wrap(function (_context) {
422
- while (1) switch (_context.prev = _context.next) {
423
- case 0:
424
- _context.next = 2;
425
- return ParseUser.currentAsync();
426
- case 2:
427
- current = _context.sent;
428
- return _context.abrupt("return", !!current && current.id === this.id);
429
- case 4:
430
- case "end":
431
- return _context.stop();
432
- }
433
- }, _callee, this);
434
- }));
435
- function isCurrentAsync() {
436
- return _isCurrentAsync.apply(this, arguments);
437
- }
438
- return isCurrentAsync;
439
- }()
440
- }, {
441
- key: "stripAnonymity",
442
- value: function () {
443
- var authData = this.get('authData');
444
- if (authData && (0, _typeof2.default)(authData) === 'object' && authData.hasOwnProperty('anonymous')) {
445
- // We need to set anonymous to null instead of deleting it in order to remove it from Parse.
446
- authData.anonymous = null;
447
- }
257
+ /**
258
+ * Deauthenticates a single provider (e.g. removing access tokens from the
259
+ * Facebook SDK).
260
+ *
261
+ * @param {object} provider service to logout of
262
+ */
263
+ _logOutWith(provider) {
264
+ if (!this.isCurrent()) {
265
+ return;
448
266
  }
449
- }, {
450
- key: "restoreAnonimity",
451
- value: function (anonymousData /*: any*/) {
452
- if (anonymousData) {
453
- var _authData2 = this.get('authData');
454
- _authData2.anonymous = anonymousData;
455
- }
267
+ if (typeof provider === 'string') {
268
+ provider = authProviders[provider];
456
269
  }
270
+ if (provider && provider.deauthenticate) {
271
+ provider.deauthenticate();
272
+ }
273
+ }
457
274
 
458
- /**
459
- * Returns get("username").
460
- *
461
- * @returns {string}
462
- */
463
- }, {
464
- key: "getUsername",
465
- value: function () /*: string | null*/{
466
- var username = this.get('username');
467
- if (username == null || typeof username === 'string') {
468
- return username;
469
- }
470
- return '';
275
+ /**
276
+ * Class instance method used to maintain specific keys when a fetch occurs.
277
+ * Used to ensure that the session token is not lost.
278
+ *
279
+ * @returns {object} sessionToken
280
+ */
281
+ _preserveFieldsOnFetch() {
282
+ return {
283
+ sessionToken: this.get('sessionToken')
284
+ };
285
+ }
286
+
287
+ /**
288
+ * Returns true if <code>current</code> would return this user.
289
+ *
290
+ * @returns {boolean} true if user is cached on disk
291
+ */
292
+ isCurrent() {
293
+ const current = ParseUser.current();
294
+ return !!current && current.id === this.id;
295
+ }
296
+
297
+ /**
298
+ * Returns true if <code>current</code> would return this user.
299
+ *
300
+ * @returns {Promise<boolean>} true if user is cached on disk
301
+ */
302
+ async isCurrentAsync() {
303
+ const current = await ParseUser.currentAsync();
304
+ return !!current && current.id === this.id;
305
+ }
306
+ stripAnonymity() {
307
+ const authData = this.get('authData');
308
+ if (authData && typeof authData === 'object' && authData.hasOwnProperty('anonymous')) {
309
+ // We need to set anonymous to null instead of deleting it in order to remove it from Parse.
310
+ authData.anonymous = null;
471
311
  }
312
+ }
313
+ restoreAnonimity(anonymousData) {
314
+ if (anonymousData) {
315
+ const authData = this.get('authData');
316
+ authData.anonymous = anonymousData;
317
+ }
318
+ }
472
319
 
473
- /**
474
- * Calls set("username", username, options) and returns the result.
475
- *
476
- * @param {string} username
477
- */
478
- }, {
479
- key: "setUsername",
480
- value: function (username /*: string*/) {
481
- this.stripAnonymity();
482
- this.set('username', username);
320
+ /**
321
+ * Returns get("username").
322
+ *
323
+ * @returns {string}
324
+ */
325
+ getUsername() {
326
+ const username = this.get('username');
327
+ if (username == null || typeof username === 'string') {
328
+ return username;
483
329
  }
330
+ return '';
331
+ }
332
+
333
+ /**
334
+ * Calls set("username", username, options) and returns the result.
335
+ *
336
+ * @param {string} username
337
+ */
338
+ setUsername(username) {
339
+ this.stripAnonymity();
340
+ this.set('username', username);
341
+ }
342
+
343
+ /**
344
+ * Calls set("password", password, options) and returns the result.
345
+ *
346
+ * @param {string} password User's Password
347
+ */
348
+ setPassword(password) {
349
+ this.set('password', password);
350
+ }
484
351
 
485
- /**
486
- * Calls set("password", password, options) and returns the result.
487
- *
488
- * @param {string} password User's Password
489
- */
490
- }, {
491
- key: "setPassword",
492
- value: function (password /*: string*/) {
493
- this.set('password', password);
352
+ /**
353
+ * Returns get("email").
354
+ *
355
+ * @returns {string} User's Email
356
+ */
357
+ getEmail() {
358
+ const email = this.get('email');
359
+ if (email == null || typeof email === 'string') {
360
+ return email;
494
361
  }
362
+ return '';
363
+ }
495
364
 
496
- /**
497
- * Returns get("email").
498
- *
499
- * @returns {string} User's Email
500
- */
501
- }, {
502
- key: "getEmail",
503
- value: function () /*: string | null*/{
504
- var email = this.get('email');
505
- if (email == null || typeof email === 'string') {
506
- return email;
507
- }
508
- return '';
365
+ /**
366
+ * Calls set("email", email) and returns the result.
367
+ *
368
+ * @param {string} email
369
+ * @returns {boolean}
370
+ */
371
+ setEmail(email) {
372
+ return this.set('email', email);
373
+ }
374
+
375
+ /**
376
+ * Returns the session token for this user, if the user has been logged in,
377
+ * or if it is the result of a query with the master key. Otherwise, returns
378
+ * undefined.
379
+ *
380
+ * @returns {string} the session token, or undefined
381
+ */
382
+ getSessionToken() {
383
+ const token = this.get('sessionToken');
384
+ if (token == null || typeof token === 'string') {
385
+ return token;
509
386
  }
387
+ return '';
388
+ }
389
+
390
+ /**
391
+ * Checks whether this user is the current user and has been authenticated.
392
+ *
393
+ * @returns {boolean} whether this user is the current user and is logged in.
394
+ */
395
+ authenticated() {
396
+ const current = ParseUser.current();
397
+ return !!this.get('sessionToken') && !!current && current.id === this.id;
398
+ }
510
399
 
511
- /**
512
- * Calls set("email", email) and returns the result.
513
- *
514
- * @param {string} email
515
- * @returns {boolean}
516
- */
517
- }, {
518
- key: "setEmail",
519
- value: function (email /*: string*/) {
520
- return this.set('email', email);
400
+ /**
401
+ * Signs up a new user. You should call this instead of save for
402
+ * new Parse.Users. This will create a new Parse.User on the server, and
403
+ * also persist the session on disk so that you can access the user using
404
+ * <code>current</code>.
405
+ *
406
+ * <p>A username and password must be set before calling signUp.</p>
407
+ *
408
+ * @param {object} attrs Extra fields to set on the new user, or null.
409
+ * @param {object} options
410
+ * @returns {Promise} A promise that is fulfilled when the signup
411
+ * finishes.
412
+ */
413
+ signUp(attrs, options) {
414
+ options = options || {};
415
+ const signupOptions = {};
416
+ if (options.hasOwnProperty('useMasterKey')) {
417
+ signupOptions.useMasterKey = options.useMasterKey;
521
418
  }
419
+ if (options.hasOwnProperty('installationId')) {
420
+ signupOptions.installationId = options.installationId;
421
+ }
422
+ if (options.hasOwnProperty('context') && Object.prototype.toString.call(options.context) === '[object Object]') {
423
+ signupOptions.context = options.context;
424
+ }
425
+ const controller = _CoreManager.default.getUserController();
426
+ return controller.signUp(this, attrs, signupOptions);
427
+ }
522
428
 
523
- /**
524
- * Returns the session token for this user, if the user has been logged in,
525
- * or if it is the result of a query with the master key. Otherwise, returns
526
- * undefined.
527
- *
528
- * @returns {string} the session token, or undefined
529
- */
530
- }, {
531
- key: "getSessionToken",
532
- value: function () /*: string | null*/{
533
- var token = this.get('sessionToken');
534
- if (token == null || typeof token === 'string') {
535
- return token;
536
- }
537
- return '';
429
+ /**
430
+ * Logs in a Parse.User. On success, this saves the session to disk,
431
+ * so you can retrieve the currently logged in user using
432
+ * <code>current</code>.
433
+ *
434
+ * <p>A username and password must be set before calling logIn.</p>
435
+ *
436
+ * @param {object} options
437
+ * @returns {Promise} A promise that is fulfilled with the user when
438
+ * the login is complete.
439
+ */
440
+ logIn() {
441
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
442
+ options = options || {};
443
+ const loginOptions = {
444
+ usePost: true
445
+ };
446
+ if (options.hasOwnProperty('useMasterKey')) {
447
+ loginOptions.useMasterKey = options.useMasterKey;
448
+ }
449
+ if (options.hasOwnProperty('installationId')) {
450
+ loginOptions.installationId = options.installationId;
451
+ }
452
+ if (options.hasOwnProperty('usePost')) {
453
+ loginOptions.usePost = options.usePost;
538
454
  }
455
+ if (options.hasOwnProperty('context') && Object.prototype.toString.call(options.context) === '[object Object]') {
456
+ loginOptions.context = options.context;
457
+ }
458
+ const controller = _CoreManager.default.getUserController();
459
+ return controller.logIn(this, loginOptions);
460
+ }
539
461
 
540
- /**
541
- * Checks whether this user is the current user and has been authenticated.
542
- *
543
- * @returns {boolean} whether this user is the current user and is logged in.
544
- */
545
- }, {
546
- key: "authenticated",
547
- value: function () /*: boolean*/{
548
- var current = ParseUser.current();
549
- return !!this.get('sessionToken') && !!current && current.id === this.id;
462
+ /**
463
+ * Wrap the default save behavior with functionality to save to local
464
+ * storage if this is current user.
465
+ *
466
+ * @param {...any} args
467
+ * @returns {Promise}
468
+ */
469
+ async save() {
470
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
471
+ args[_key] = arguments[_key];
472
+ }
473
+ await super.save.apply(this, args);
474
+ const current = await this.isCurrentAsync();
475
+ if (current) {
476
+ return _CoreManager.default.getUserController().updateUserOnDisk(this);
550
477
  }
478
+ return this;
479
+ }
551
480
 
552
- /**
553
- * Signs up a new user. You should call this instead of save for
554
- * new Parse.Users. This will create a new Parse.User on the server, and
555
- * also persist the session on disk so that you can access the user using
556
- * <code>current</code>.
557
- *
558
- * <p>A username and password must be set before calling signUp.</p>
559
- *
560
- * @param {object} attrs Extra fields to set on the new user, or null.
561
- * @param {object} options
562
- * @returns {Promise} A promise that is fulfilled when the signup
563
- * finishes.
564
- */
565
- }, {
566
- key: "signUp",
567
- value: function (attrs /*: AttributeMap*/, options /*:: ?: FullOptions & { context?: AttributeMap }*/) /*: Promise<ParseUser>*/{
568
- options = options || {};
569
- var signupOptions /*: FullOptions & { context?: AttributeMap }*/ = {};
570
- if (options.hasOwnProperty('useMasterKey')) {
571
- signupOptions.useMasterKey = options.useMasterKey;
572
- }
573
- if (options.hasOwnProperty('installationId')) {
574
- signupOptions.installationId = options.installationId;
575
- }
576
- if (options.hasOwnProperty('context') && Object.prototype.toString.call(options.context) === '[object Object]') {
577
- signupOptions.context = options.context;
578
- }
579
- var controller = _CoreManager.default.getUserController();
580
- return controller.signUp(this, attrs, signupOptions);
481
+ /**
482
+ * Wrap the default destroy behavior with functionality that logs out
483
+ * the current user when it is destroyed
484
+ *
485
+ * @param {...any} args
486
+ * @returns {Parse.User}
487
+ */
488
+ async destroy() {
489
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
490
+ args[_key2] = arguments[_key2];
491
+ }
492
+ await super.destroy.apply(this, args);
493
+ const current = await this.isCurrentAsync();
494
+ if (current) {
495
+ return _CoreManager.default.getUserController().removeUserFromDisk();
581
496
  }
497
+ return this;
498
+ }
582
499
 
583
- /**
584
- * Logs in a Parse.User. On success, this saves the session to disk,
585
- * so you can retrieve the currently logged in user using
586
- * <code>current</code>.
587
- *
588
- * <p>A username and password must be set before calling logIn.</p>
589
- *
590
- * @param {object} options
591
- * @returns {Promise} A promise that is fulfilled with the user when
592
- * the login is complete.
593
- */
594
- }, {
595
- key: "logIn",
596
- value: function () /*: Promise<ParseUser>*/{
597
- var options /*: FullOptions & { context?: AttributeMap }*/ = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
598
- options = options || {};
599
- var loginOptions /*: FullOptions & { context?: AttributeMap }*/ = {
600
- usePost: true
601
- };
602
- if (options.hasOwnProperty('useMasterKey')) {
603
- loginOptions.useMasterKey = options.useMasterKey;
604
- }
605
- if (options.hasOwnProperty('installationId')) {
606
- loginOptions.installationId = options.installationId;
607
- }
608
- if (options.hasOwnProperty('usePost')) {
609
- loginOptions.usePost = options.usePost;
610
- }
611
- if (options.hasOwnProperty('context') && Object.prototype.toString.call(options.context) === '[object Object]') {
612
- loginOptions.context = options.context;
613
- }
614
- var controller = _CoreManager.default.getUserController();
615
- return controller.logIn(this, loginOptions);
500
+ /**
501
+ * Wrap the default fetch behavior with functionality to save to local
502
+ * storage if this is current user.
503
+ *
504
+ * @param {...any} args
505
+ * @returns {Parse.User}
506
+ */
507
+ async fetch() {
508
+ for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
509
+ args[_key3] = arguments[_key3];
510
+ }
511
+ await super.fetch.apply(this, args);
512
+ const current = await this.isCurrentAsync();
513
+ if (current) {
514
+ return _CoreManager.default.getUserController().updateUserOnDisk(this);
616
515
  }
516
+ return this;
517
+ }
617
518
 
618
- /**
619
- * Wrap the default save behavior with functionality to save to local
620
- * storage if this is current user.
621
- *
622
- * @param {...any} args
623
- * @returns {Promise}
624
- */
625
- }, {
626
- key: "save",
627
- value: function () {
628
- var _save = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() {
629
- var _len,
630
- args,
631
- _key4,
632
- current,
633
- _args2 = arguments;
634
- return _regenerator.default.wrap(function (_context2) {
635
- while (1) switch (_context2.prev = _context2.next) {
636
- case 0:
637
- for (_len = _args2.length, args = new Array(_len), _key4 = 0; _key4 < _len; _key4++) {
638
- args[_key4] = _args2[_key4];
639
- }
640
- _context2.next = 3;
641
- return (0, _get2.default)((0, _getPrototypeOf2.default)(ParseUser.prototype), "save", this).apply(this, args);
642
- case 3:
643
- _context2.next = 5;
644
- return this.isCurrentAsync();
645
- case 5:
646
- current = _context2.sent;
647
- if (!current) {
648
- _context2.next = 8;
649
- break;
650
- }
651
- return _context2.abrupt("return", _CoreManager.default.getUserController().updateUserOnDisk(this));
652
- case 8:
653
- return _context2.abrupt("return", this);
654
- case 9:
655
- case "end":
656
- return _context2.stop();
657
- }
658
- }, _callee2, this);
659
- }));
660
- function save() {
661
- return _save.apply(this, arguments);
662
- }
663
- return save;
664
- }()
665
- /**
666
- * Wrap the default destroy behavior with functionality that logs out
667
- * the current user when it is destroyed
668
- *
669
- * @param {...any} args
670
- * @returns {Parse.User}
671
- */
672
- }, {
673
- key: "destroy",
674
- value: function () {
675
- var _destroy = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3() {
676
- var _len2,
677
- args,
678
- _key5,
679
- current,
680
- _args3 = arguments;
681
- return _regenerator.default.wrap(function (_context3) {
682
- while (1) switch (_context3.prev = _context3.next) {
683
- case 0:
684
- for (_len2 = _args3.length, args = new Array(_len2), _key5 = 0; _key5 < _len2; _key5++) {
685
- args[_key5] = _args3[_key5];
686
- }
687
- _context3.next = 3;
688
- return (0, _get2.default)((0, _getPrototypeOf2.default)(ParseUser.prototype), "destroy", this).apply(this, args);
689
- case 3:
690
- _context3.next = 5;
691
- return this.isCurrentAsync();
692
- case 5:
693
- current = _context3.sent;
694
- if (!current) {
695
- _context3.next = 8;
696
- break;
697
- }
698
- return _context3.abrupt("return", _CoreManager.default.getUserController().removeUserFromDisk());
699
- case 8:
700
- return _context3.abrupt("return", this);
701
- case 9:
702
- case "end":
703
- return _context3.stop();
704
- }
705
- }, _callee3, this);
706
- }));
707
- function destroy() {
708
- return _destroy.apply(this, arguments);
709
- }
710
- return destroy;
711
- }()
712
- /**
713
- * Wrap the default fetch behavior with functionality to save to local
714
- * storage if this is current user.
715
- *
716
- * @param {...any} args
717
- * @returns {Parse.User}
718
- */
719
- }, {
720
- key: "fetch",
721
- value: function () {
722
- var _fetch = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4() {
723
- var _len3,
724
- args,
725
- _key6,
726
- current,
727
- _args4 = arguments;
728
- return _regenerator.default.wrap(function (_context4) {
729
- while (1) switch (_context4.prev = _context4.next) {
730
- case 0:
731
- for (_len3 = _args4.length, args = new Array(_len3), _key6 = 0; _key6 < _len3; _key6++) {
732
- args[_key6] = _args4[_key6];
733
- }
734
- _context4.next = 3;
735
- return (0, _get2.default)((0, _getPrototypeOf2.default)(ParseUser.prototype), "fetch", this).apply(this, args);
736
- case 3:
737
- _context4.next = 5;
738
- return this.isCurrentAsync();
739
- case 5:
740
- current = _context4.sent;
741
- if (!current) {
742
- _context4.next = 8;
743
- break;
744
- }
745
- return _context4.abrupt("return", _CoreManager.default.getUserController().updateUserOnDisk(this));
746
- case 8:
747
- return _context4.abrupt("return", this);
748
- case 9:
749
- case "end":
750
- return _context4.stop();
751
- }
752
- }, _callee4, this);
753
- }));
754
- function fetch() {
755
- return _fetch.apply(this, arguments);
756
- }
757
- return fetch;
758
- }()
759
- /**
760
- * Wrap the default fetchWithInclude behavior with functionality to save to local
761
- * storage if this is current user.
762
- *
763
- * @param {...any} args
764
- * @returns {Parse.User}
765
- */
766
- }, {
767
- key: "fetchWithInclude",
768
- value: function () {
769
- var _fetchWithInclude = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5() {
770
- var _len4,
771
- args,
772
- _key7,
773
- current,
774
- _args5 = arguments;
775
- return _regenerator.default.wrap(function (_context5) {
776
- while (1) switch (_context5.prev = _context5.next) {
777
- case 0:
778
- for (_len4 = _args5.length, args = new Array(_len4), _key7 = 0; _key7 < _len4; _key7++) {
779
- args[_key7] = _args5[_key7];
780
- }
781
- _context5.next = 3;
782
- return (0, _get2.default)((0, _getPrototypeOf2.default)(ParseUser.prototype), "fetchWithInclude", this).apply(this, args);
783
- case 3:
784
- _context5.next = 5;
785
- return this.isCurrentAsync();
786
- case 5:
787
- current = _context5.sent;
788
- if (!current) {
789
- _context5.next = 8;
790
- break;
791
- }
792
- return _context5.abrupt("return", _CoreManager.default.getUserController().updateUserOnDisk(this));
793
- case 8:
794
- return _context5.abrupt("return", this);
795
- case 9:
796
- case "end":
797
- return _context5.stop();
798
- }
799
- }, _callee5, this);
800
- }));
801
- function fetchWithInclude() {
802
- return _fetchWithInclude.apply(this, arguments);
803
- }
804
- return fetchWithInclude;
805
- }()
806
- /**
807
- * Verify whether a given password is the password of the current user.
808
- *
809
- * @param {string} password The password to be verified.
810
- * @param {object} options The options.
811
- * @param {boolean} [options.ignoreEmailVerification=false] Set to `true` to bypass email verification and verify
812
- * the password regardless of whether the email has been verified. This requires the master key.
813
- * @returns {Promise} A promise that is fulfilled with a user when the password is correct.
814
- */
815
- }, {
816
- key: "verifyPassword",
817
- value: function (password /*: string*/, options /*:: ?: RequestOptions*/) /*: Promise<ParseUser>*/{
818
- var username = this.getUsername() || '';
819
- return ParseUser.verifyPassword(username, password, options);
820
- }
821
- }], [{
822
- key: "readOnlyAttributes",
823
- value: function () {
824
- return ['sessionToken'];
519
+ /**
520
+ * Wrap the default fetchWithInclude behavior with functionality to save to local
521
+ * storage if this is current user.
522
+ *
523
+ * @param {...any} args
524
+ * @returns {Parse.User}
525
+ */
526
+ async fetchWithInclude() {
527
+ for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
528
+ args[_key4] = arguments[_key4];
825
529
  }
530
+ await super.fetchWithInclude.apply(this, args);
531
+ const current = await this.isCurrentAsync();
532
+ if (current) {
533
+ return _CoreManager.default.getUserController().updateUserOnDisk(this);
534
+ }
535
+ return this;
536
+ }
826
537
 
827
- /**
828
- * Adds functionality to the existing Parse.User class.
829
- *
830
- * @param {object} protoProps A set of properties to add to the prototype
831
- * @param {object} classProps A set of static properties to add to the class
832
- * @static
833
- * @returns {Parse.User} The newly extended Parse.User class
834
- */
835
- }, {
836
- key: "extend",
837
- value: function (protoProps /*: { [prop: string]: any }*/, classProps /*: { [prop: string]: any }*/) {
838
- if (protoProps) {
839
- for (var _prop in protoProps) {
840
- if (_prop !== 'className') {
841
- (0, _defineProperty2.default)(ParseUser.prototype, _prop, {
842
- value: protoProps[_prop],
843
- enumerable: false,
844
- writable: true,
845
- configurable: true
846
- });
847
- }
538
+ /**
539
+ * Verify whether a given password is the password of the current user.
540
+ *
541
+ * @param {string} password The password to be verified.
542
+ * @param {object} options The options.
543
+ * @param {boolean} [options.ignoreEmailVerification] Set to `true` to bypass email verification and verify
544
+ * the password regardless of whether the email has been verified. This requires the master key.
545
+ * @returns {Promise} A promise that is fulfilled with a user when the password is correct.
546
+ */
547
+ verifyPassword(password, options) {
548
+ const username = this.getUsername() || '';
549
+ return ParseUser.verifyPassword(username, password, options);
550
+ }
551
+ static readOnlyAttributes() {
552
+ return ['sessionToken'];
553
+ }
554
+
555
+ /**
556
+ * Adds functionality to the existing Parse.User class.
557
+ *
558
+ * @param {object} protoProps A set of properties to add to the prototype
559
+ * @param {object} classProps A set of static properties to add to the class
560
+ * @static
561
+ * @returns {Parse.User} The newly extended Parse.User class
562
+ */
563
+ static extend(protoProps, classProps) {
564
+ if (protoProps) {
565
+ for (const prop in protoProps) {
566
+ if (prop !== 'className') {
567
+ (0, _defineProperty.default)(ParseUser.prototype, prop, {
568
+ value: protoProps[prop],
569
+ enumerable: false,
570
+ writable: true,
571
+ configurable: true
572
+ });
848
573
  }
849
574
  }
850
- if (classProps) {
851
- for (var _prop2 in classProps) {
852
- if (_prop2 !== 'className') {
853
- (0, _defineProperty2.default)(ParseUser, _prop2, {
854
- value: classProps[_prop2],
855
- enumerable: false,
856
- writable: true,
857
- configurable: true
858
- });
859
- }
575
+ }
576
+ if (classProps) {
577
+ for (const prop in classProps) {
578
+ if (prop !== 'className') {
579
+ (0, _defineProperty.default)(ParseUser, prop, {
580
+ value: classProps[prop],
581
+ enumerable: false,
582
+ writable: true,
583
+ configurable: true
584
+ });
860
585
  }
861
586
  }
862
- return ParseUser;
863
587
  }
588
+ return ParseUser;
589
+ }
864
590
 
865
- /**
866
- * Retrieves the currently logged in ParseUser with a valid session,
867
- * either from memory or localStorage, if necessary.
868
- *
869
- * @static
870
- * @returns {Parse.Object} The currently logged in Parse.User.
871
- */
872
- }, {
873
- key: "current",
874
- value: function () /*: ParseUser | null*/{
875
- if (!canUseCurrentUser) {
876
- return null;
877
- }
878
- var controller = _CoreManager.default.getUserController();
879
- return controller.currentUser();
591
+ /**
592
+ * Retrieves the currently logged in ParseUser with a valid session,
593
+ * either from memory or localStorage, if necessary.
594
+ *
595
+ * @static
596
+ * @returns {Parse.Object} The currently logged in Parse.User.
597
+ */
598
+ static current() {
599
+ if (!canUseCurrentUser) {
600
+ return null;
880
601
  }
602
+ const controller = _CoreManager.default.getUserController();
603
+ return controller.currentUser();
604
+ }
881
605
 
882
- /**
883
- * Retrieves the currently logged in ParseUser from asynchronous Storage.
884
- *
885
- * @static
886
- * @returns {Promise} A Promise that is resolved with the currently
887
- * logged in Parse User
888
- */
889
- }, {
890
- key: "currentAsync",
891
- value: function () /*: Promise<ParseUser | null>*/{
892
- if (!canUseCurrentUser) {
893
- return _promise.default.resolve(null);
894
- }
895
- var controller = _CoreManager.default.getUserController();
896
- return controller.currentUserAsync();
606
+ /**
607
+ * Retrieves the currently logged in ParseUser from asynchronous Storage.
608
+ *
609
+ * @static
610
+ * @returns {Promise} A Promise that is resolved with the currently
611
+ * logged in Parse User
612
+ */
613
+ static currentAsync() {
614
+ if (!canUseCurrentUser) {
615
+ return _promise.default.resolve(null);
897
616
  }
617
+ const controller = _CoreManager.default.getUserController();
618
+ return controller.currentUserAsync();
619
+ }
898
620
 
899
- /**
900
- * Signs up a new user with a username (or email) and password.
901
- * This will create a new Parse.User on the server, and also persist the
902
- * session in localStorage so that you can access the user using
903
- * {@link #current}.
904
- *
905
- * @param {string} username The username (or email) to sign up with.
906
- * @param {string} password The password to sign up with.
907
- * @param {object} attrs Extra fields to set on the new user.
908
- * @param {object} options
909
- * @static
910
- * @returns {Promise} A promise that is fulfilled with the user when
911
- * the signup completes.
912
- */
913
- }, {
914
- key: "signUp",
915
- value: function (username /*: string*/, password /*: string*/, attrs /*: AttributeMap*/, options /*:: ?: FullOptions*/) {
916
- attrs = attrs || {};
917
- attrs.username = username;
918
- attrs.password = password;
919
- var user = new this(attrs);
920
- return user.signUp({}, options);
921
- }
621
+ /**
622
+ * Signs up a new user with a username (or email) and password.
623
+ * This will create a new Parse.User on the server, and also persist the
624
+ * session in localStorage so that you can access the user using
625
+ * {@link #current}.
626
+ *
627
+ * @param {string} username The username (or email) to sign up with.
628
+ * @param {string} password The password to sign up with.
629
+ * @param {object} attrs Extra fields to set on the new user.
630
+ * @param {object} options
631
+ * @static
632
+ * @returns {Promise} A promise that is fulfilled with the user when
633
+ * the signup completes.
634
+ */
635
+ static signUp(username, password, attrs, options) {
636
+ attrs = attrs || {};
637
+ attrs.username = username;
638
+ attrs.password = password;
639
+ const user = new this(attrs);
640
+ return user.signUp({}, options);
641
+ }
922
642
 
923
- /**
924
- * Logs in a user with a username (or email) and password. On success, this
925
- * saves the session to disk, so you can retrieve the currently logged in
926
- * user using <code>current</code>.
927
- *
928
- * @param {string} username The username (or email) to log in with.
929
- * @param {string} password The password to log in with.
930
- * @param {object} options
931
- * @static
932
- * @returns {Promise} A promise that is fulfilled with the user when
933
- * the login completes.
934
- */
935
- }, {
936
- key: "logIn",
937
- value: function (username /*: string*/, password /*: string*/, options /*:: ?: FullOptions*/) {
938
- if (typeof username !== 'string') {
939
- return _promise.default.reject(new _ParseError.default(_ParseError.default.OTHER_CAUSE, 'Username must be a string.'));
940
- } else if (typeof password !== 'string') {
941
- return _promise.default.reject(new _ParseError.default(_ParseError.default.OTHER_CAUSE, 'Password must be a string.'));
942
- }
943
- var user = new this();
944
- user._finishFetch({
945
- username: username,
946
- password: password
947
- });
948
- return user.logIn(options);
949
- }
643
+ /**
644
+ * Logs in a user with a username (or email) and password. On success, this
645
+ * saves the session to disk, so you can retrieve the currently logged in
646
+ * user using <code>current</code>.
647
+ *
648
+ * @param {string} username The username (or email) to log in with.
649
+ * @param {string} password The password to log in with.
650
+ * @param {object} options
651
+ * @static
652
+ * @returns {Promise} A promise that is fulfilled with the user when
653
+ * the login completes.
654
+ */
655
+ static logIn(username, password, options) {
656
+ if (typeof username !== 'string') {
657
+ return _promise.default.reject(new _ParseError.default(_ParseError.default.OTHER_CAUSE, 'Username must be a string.'));
658
+ } else if (typeof password !== 'string') {
659
+ return _promise.default.reject(new _ParseError.default(_ParseError.default.OTHER_CAUSE, 'Password must be a string.'));
660
+ }
661
+ const user = new this();
662
+ user._finishFetch({
663
+ username: username,
664
+ password: password
665
+ });
666
+ return user.logIn(options);
667
+ }
950
668
 
951
- /**
952
- * Logs in a user with a username (or email) and password, and authData. On success, this
953
- * saves the session to disk, so you can retrieve the currently logged in
954
- * user using <code>current</code>.
955
- *
956
- * @param {string} username The username (or email) to log in with.
957
- * @param {string} password The password to log in with.
958
- * @param {object} authData The authData to log in with.
959
- * @param {object} options
960
- * @static
961
- * @returns {Promise} A promise that is fulfilled with the user when
962
- * the login completes.
963
- */
964
- }, {
965
- key: "logInWithAdditionalAuth",
966
- value: function (username /*: string*/, password /*: string*/, authData /*: AuthData*/, options /*:: ?: FullOptions*/) {
967
- if (typeof username !== 'string') {
968
- return _promise.default.reject(new _ParseError.default(_ParseError.default.OTHER_CAUSE, 'Username must be a string.'));
969
- }
970
- if (typeof password !== 'string') {
971
- return _promise.default.reject(new _ParseError.default(_ParseError.default.OTHER_CAUSE, 'Password must be a string.'));
972
- }
973
- if (Object.prototype.toString.call(authData) !== '[object Object]') {
974
- return _promise.default.reject(new _ParseError.default(_ParseError.default.OTHER_CAUSE, 'Auth must be an object.'));
975
- }
976
- var user = new this();
977
- user._finishFetch({
978
- username: username,
979
- password: password,
980
- authData: authData
981
- });
982
- return user.logIn(options);
669
+ /**
670
+ * Logs in a user with a username (or email) and password, and authData. On success, this
671
+ * saves the session to disk, so you can retrieve the currently logged in
672
+ * user using <code>current</code>.
673
+ *
674
+ * @param {string} username The username (or email) to log in with.
675
+ * @param {string} password The password to log in with.
676
+ * @param {object} authData The authData to log in with.
677
+ * @param {object} options
678
+ * @static
679
+ * @returns {Promise} A promise that is fulfilled with the user when
680
+ * the login completes.
681
+ */
682
+ static logInWithAdditionalAuth(username, password, authData, options) {
683
+ if (typeof username !== 'string') {
684
+ return _promise.default.reject(new _ParseError.default(_ParseError.default.OTHER_CAUSE, 'Username must be a string.'));
983
685
  }
984
-
985
- /**
986
- * Logs in a user with an objectId. On success, this saves the session
987
- * to disk, so you can retrieve the currently logged in user using
988
- * <code>current</code>.
989
- *
990
- * @param {string} userId The objectId for the user.
991
- * @static
992
- * @returns {Promise} A promise that is fulfilled with the user when
993
- * the login completes.
994
- */
995
- }, {
996
- key: "loginAs",
997
- value: function (userId /*: string*/) {
998
- if (!userId) {
999
- throw new _ParseError.default(_ParseError.default.USERNAME_MISSING, 'Cannot log in as user with an empty user id');
1000
- }
1001
- var controller = _CoreManager.default.getUserController();
1002
- var user = new this();
1003
- return controller.loginAs(user, userId);
686
+ if (typeof password !== 'string') {
687
+ return _promise.default.reject(new _ParseError.default(_ParseError.default.OTHER_CAUSE, 'Password must be a string.'));
1004
688
  }
1005
-
1006
- /**
1007
- * Logs in a user with a session token. On success, this saves the session
1008
- * to disk, so you can retrieve the currently logged in user using
1009
- * <code>current</code>.
1010
- *
1011
- * @param {string} sessionToken The sessionToken to log in with.
1012
- * @param {object} options
1013
- * @static
1014
- * @returns {Promise} A promise that is fulfilled with the user when
1015
- * the login completes.
1016
- */
1017
- }, {
1018
- key: "become",
1019
- value: function (sessionToken /*: string*/, options /*:: ?: RequestOptions*/) {
1020
- if (!canUseCurrentUser) {
1021
- throw new Error('It is not memory-safe to become a user in a server environment');
1022
- }
1023
- options = options || {};
1024
- var becomeOptions /*: RequestOptions*/ = {
1025
- sessionToken: sessionToken
1026
- };
1027
- if (options.hasOwnProperty('useMasterKey')) {
1028
- becomeOptions.useMasterKey = options.useMasterKey;
1029
- }
1030
- var controller = _CoreManager.default.getUserController();
1031
- var user = new this();
1032
- return controller.become(user, becomeOptions);
689
+ if (Object.prototype.toString.call(authData) !== '[object Object]') {
690
+ return _promise.default.reject(new _ParseError.default(_ParseError.default.OTHER_CAUSE, 'Auth must be an object.'));
1033
691
  }
692
+ const user = new this();
693
+ user._finishFetch({
694
+ username: username,
695
+ password: password,
696
+ authData
697
+ });
698
+ return user.logIn(options);
699
+ }
1034
700
 
1035
- /**
1036
- * Retrieves a user with a session token.
1037
- *
1038
- * @param {string} sessionToken The sessionToken to get user with.
1039
- * @param {object} options
1040
- * @static
1041
- * @returns {Promise} A promise that is fulfilled with the user is fetched.
1042
- */
1043
- }, {
1044
- key: "me",
1045
- value: function (sessionToken /*: string*/) {
1046
- var options /*: RequestOptions*/ = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1047
- var controller = _CoreManager.default.getUserController();
1048
- var meOptions /*: RequestOptions*/ = {
1049
- sessionToken: sessionToken
1050
- };
1051
- if (options.useMasterKey) {
1052
- meOptions.useMasterKey = options.useMasterKey;
1053
- }
1054
- var user = new this();
1055
- return controller.me(user, meOptions);
701
+ /**
702
+ * Logs in a user with an objectId. On success, this saves the session
703
+ * to disk, so you can retrieve the currently logged in user using
704
+ * <code>current</code>.
705
+ *
706
+ * @param {string} userId The objectId for the user.
707
+ * @static
708
+ * @returns {Promise} A promise that is fulfilled with the user when
709
+ * the login completes.
710
+ */
711
+ static loginAs(userId) {
712
+ if (!userId) {
713
+ throw new _ParseError.default(_ParseError.default.USERNAME_MISSING, 'Cannot log in as user with an empty user id');
1056
714
  }
715
+ const controller = _CoreManager.default.getUserController();
716
+ const user = new this();
717
+ return controller.loginAs(user, userId);
718
+ }
1057
719
 
1058
- /**
1059
- * Logs in a user with a session token. On success, this saves the session
1060
- * to disk, so you can retrieve the currently logged in user using
1061
- * <code>current</code>. If there is no session token the user will not logged in.
1062
- *
1063
- * @param {object} userJSON The JSON map of the User's data
1064
- * @static
1065
- * @returns {Promise} A promise that is fulfilled with the user when
1066
- * the login completes.
1067
- */
1068
- }, {
1069
- key: "hydrate",
1070
- value: function (userJSON /*: AttributeMap*/) {
1071
- var controller = _CoreManager.default.getUserController();
1072
- var user = new this();
1073
- return controller.hydrate(user, userJSON);
720
+ /**
721
+ * Logs in a user with a session token. On success, this saves the session
722
+ * to disk, so you can retrieve the currently logged in user using
723
+ * <code>current</code>.
724
+ *
725
+ * @param {string} sessionToken The sessionToken to log in with.
726
+ * @param {object} options
727
+ * @static
728
+ * @returns {Promise} A promise that is fulfilled with the user when
729
+ * the login completes.
730
+ */
731
+ static become(sessionToken, options) {
732
+ if (!canUseCurrentUser) {
733
+ throw new Error('It is not memory-safe to become a user in a server environment');
1074
734
  }
1075
-
1076
- /**
1077
- * Static version of {@link https://parseplatform.org/Parse-SDK-JS/api/master/Parse.User.html#linkWith linkWith}
1078
- *
1079
- * @param provider
1080
- * @param options
1081
- * @param {object} [options.authData]
1082
- * @param saveOpts
1083
- * @static
1084
- * @returns {Promise}
1085
- */
1086
- }, {
1087
- key: "logInWith",
1088
- value: function (provider /*: any*/, options /*: { authData?: AuthData }*/, saveOpts /*:: ?: FullOptions*/) /*: Promise<ParseUser>*/{
1089
- var user = new this();
1090
- return user.linkWith(provider, options, saveOpts);
735
+ options = options || {};
736
+ const becomeOptions = {
737
+ sessionToken: sessionToken
738
+ };
739
+ if (options.hasOwnProperty('useMasterKey')) {
740
+ becomeOptions.useMasterKey = options.useMasterKey;
1091
741
  }
742
+ const controller = _CoreManager.default.getUserController();
743
+ const user = new this();
744
+ return controller.become(user, becomeOptions);
745
+ }
1092
746
 
1093
- /**
1094
- * Logs out the currently logged in user session. This will remove the
1095
- * session from disk, log out of linked services, and future calls to
1096
- * <code>current</code> will return <code>null</code>.
1097
- *
1098
- * @param {object} options
1099
- * @static
1100
- * @returns {Promise} A promise that is resolved when the session is
1101
- * destroyed on the server.
1102
- */
1103
- }, {
1104
- key: "logOut",
1105
- value: function () {
1106
- var options /*: RequestOptions*/ = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1107
- var controller = _CoreManager.default.getUserController();
1108
- return controller.logOut(options);
747
+ /**
748
+ * Retrieves a user with a session token.
749
+ *
750
+ * @param {string} sessionToken The sessionToken to get user with.
751
+ * @param {object} options
752
+ * @static
753
+ * @returns {Promise} A promise that is fulfilled with the user is fetched.
754
+ */
755
+ static me(sessionToken) {
756
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
757
+ const controller = _CoreManager.default.getUserController();
758
+ const meOptions = {
759
+ sessionToken: sessionToken
760
+ };
761
+ if (options.useMasterKey) {
762
+ meOptions.useMasterKey = options.useMasterKey;
1109
763
  }
764
+ const user = new this();
765
+ return controller.me(user, meOptions);
766
+ }
1110
767
 
1111
- /**
1112
- * Requests a password reset email to be sent to the specified email address
1113
- * associated with the user account. This email allows the user to securely
1114
- * reset their password on the Parse site.
1115
- *
1116
- * @param {string} email The email address associated with the user that
1117
- * forgot their password.
1118
- * @param {object} options
1119
- * @static
1120
- * @returns {Promise}
1121
- */
1122
- }, {
1123
- key: "requestPasswordReset",
1124
- value: function (email /*: string*/, options /*:: ?: RequestOptions*/) {
1125
- options = options || {};
1126
- var requestOptions /*: RequestOptions*/ = {};
1127
- if (options.hasOwnProperty('useMasterKey')) {
1128
- requestOptions.useMasterKey = options.useMasterKey;
1129
- }
1130
- var controller = _CoreManager.default.getUserController();
1131
- return controller.requestPasswordReset(email, requestOptions);
1132
- }
768
+ /**
769
+ * Logs in a user with a session token. On success, this saves the session
770
+ * to disk, so you can retrieve the currently logged in user using
771
+ * <code>current</code>. If there is no session token the user will not logged in.
772
+ *
773
+ * @param {object} userJSON The JSON map of the User's data
774
+ * @static
775
+ * @returns {Promise} A promise that is fulfilled with the user when
776
+ * the login completes.
777
+ */
778
+ static hydrate(userJSON) {
779
+ const controller = _CoreManager.default.getUserController();
780
+ const user = new this();
781
+ return controller.hydrate(user, userJSON);
782
+ }
1133
783
 
1134
- /**
1135
- * Request an email verification.
1136
- *
1137
- * @param {string} email The email address associated with the user that
1138
- * needs to verify their email.
1139
- * @param {object} options
1140
- * @static
1141
- * @returns {Promise}
1142
- */
1143
- }, {
1144
- key: "requestEmailVerification",
1145
- value: function (email /*: string*/, options /*:: ?: RequestOptions*/) {
1146
- options = options || {};
1147
- var requestOptions /*: RequestOptions*/ = {};
1148
- if (options.hasOwnProperty('useMasterKey')) {
1149
- requestOptions.useMasterKey = options.useMasterKey;
1150
- }
1151
- var controller = _CoreManager.default.getUserController();
1152
- return controller.requestEmailVerification(email, requestOptions);
1153
- }
784
+ /**
785
+ * Static version of {@link https://parseplatform.org/Parse-SDK-JS/api/master/Parse.User.html#linkWith linkWith}
786
+ *
787
+ * @param provider
788
+ * @param options
789
+ * @param {object} [options.authData]
790
+ * @param saveOpts
791
+ * @static
792
+ * @returns {Promise}
793
+ */
794
+ static logInWith(provider, options, saveOpts) {
795
+ const user = new this();
796
+ return user.linkWith(provider, options, saveOpts);
797
+ }
1154
798
 
1155
- /**
1156
- * Verify whether a given password is the password of the current user.
1157
- * @static
1158
- *
1159
- * @param {string} username The username of the user whose password should be verified.
1160
- * @param {string} password The password to be verified.
1161
- * @param {object} options The options.
1162
- * @param {boolean} [options.ignoreEmailVerification=false] Set to `true` to bypass email verification and verify
1163
- * the password regardless of whether the email has been verified. This requires the master key.
1164
- * @returns {Promise} A promise that is fulfilled with a user when the password is correct.
1165
- */
1166
- }, {
1167
- key: "verifyPassword",
1168
- value: function (username /*: string*/, password /*: string*/, options /*:: ?: RequestOptions*/) {
1169
- if (typeof username !== 'string') {
1170
- return _promise.default.reject(new _ParseError.default(_ParseError.default.OTHER_CAUSE, 'Username must be a string.'));
1171
- }
1172
- if (typeof password !== 'string') {
1173
- return _promise.default.reject(new _ParseError.default(_ParseError.default.OTHER_CAUSE, 'Password must be a string.'));
1174
- }
1175
- var controller = _CoreManager.default.getUserController();
1176
- return controller.verifyPassword(username, password, options || {});
1177
- }
799
+ /**
800
+ * Logs out the currently logged in user session. This will remove the
801
+ * session from disk, log out of linked services, and future calls to
802
+ * <code>current</code> will return <code>null</code>.
803
+ *
804
+ * @param {object} options
805
+ * @static
806
+ * @returns {Promise} A promise that is resolved when the session is
807
+ * destroyed on the server.
808
+ */
809
+ static logOut() {
810
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
811
+ const controller = _CoreManager.default.getUserController();
812
+ return controller.logOut(options);
813
+ }
814
+
815
+ /**
816
+ * Requests a password reset email to be sent to the specified email address
817
+ * associated with the user account. This email allows the user to securely
818
+ * reset their password on the Parse site.
819
+ *
820
+ * @param {string} email The email address associated with the user that
821
+ * forgot their password.
822
+ * @param {object} options
823
+ * @static
824
+ * @returns {Promise}
825
+ */
826
+ static requestPasswordReset(email, options) {
827
+ options = options || {};
828
+ const requestOptions = {};
829
+ if (options.hasOwnProperty('useMasterKey')) {
830
+ requestOptions.useMasterKey = options.useMasterKey;
831
+ }
832
+ const controller = _CoreManager.default.getUserController();
833
+ return controller.requestPasswordReset(email, requestOptions);
834
+ }
835
+
836
+ /**
837
+ * Request an email verification.
838
+ *
839
+ * @param {string} email The email address associated with the user that
840
+ * needs to verify their email.
841
+ * @param {object} options
842
+ * @static
843
+ * @returns {Promise}
844
+ */
845
+ static requestEmailVerification(email, options) {
846
+ options = options || {};
847
+ const requestOptions = {};
848
+ if (options.hasOwnProperty('useMasterKey')) {
849
+ requestOptions.useMasterKey = options.useMasterKey;
850
+ }
851
+ const controller = _CoreManager.default.getUserController();
852
+ return controller.requestEmailVerification(email, requestOptions);
853
+ }
1178
854
 
1179
- /**
1180
- * Allow someone to define a custom User class without className
1181
- * being rewritten to _User. The default behavior is to rewrite
1182
- * User to _User for legacy reasons. This allows developers to
1183
- * override that behavior.
1184
- *
1185
- * @param {boolean} isAllowed Whether or not to allow custom User class
1186
- * @static
1187
- */
1188
- }, {
1189
- key: "allowCustomUserClass",
1190
- value: function (isAllowed /*: boolean*/) {
1191
- _CoreManager.default.set('PERFORM_USER_REWRITE', !isAllowed);
855
+ /**
856
+ * Verify whether a given password is the password of the current user.
857
+ * @static
858
+ *
859
+ * @param {string} username The username of the user whose password should be verified.
860
+ * @param {string} password The password to be verified.
861
+ * @param {object} options The options.
862
+ * @param {boolean} [options.ignoreEmailVerification] Set to `true` to bypass email verification and verify
863
+ * the password regardless of whether the email has been verified. This requires the master key.
864
+ * @returns {Promise} A promise that is fulfilled with a user when the password is correct.
865
+ */
866
+ static verifyPassword(username, password, options) {
867
+ if (typeof username !== 'string') {
868
+ return _promise.default.reject(new _ParseError.default(_ParseError.default.OTHER_CAUSE, 'Username must be a string.'));
869
+ }
870
+ if (typeof password !== 'string') {
871
+ return _promise.default.reject(new _ParseError.default(_ParseError.default.OTHER_CAUSE, 'Password must be a string.'));
1192
872
  }
873
+ const controller = _CoreManager.default.getUserController();
874
+ return controller.verifyPassword(username, password, options || {});
875
+ }
1193
876
 
1194
- /**
1195
- * Allows a legacy application to start using revocable sessions. If the
1196
- * current session token is not revocable, a request will be made for a new,
1197
- * revocable session.
1198
- * It is not necessary to call this method from cloud code unless you are
1199
- * handling user signup or login from the server side. In a cloud code call,
1200
- * this function will not attempt to upgrade the current token.
1201
- *
1202
- * @param {object} options
1203
- * @static
1204
- * @returns {Promise} A promise that is resolved when the process has
1205
- * completed. If a replacement session token is requested, the promise
1206
- * will be resolved after a new token has been fetched.
1207
- */
1208
- }, {
1209
- key: "enableRevocableSession",
1210
- value: function (options /*:: ?: RequestOptions*/) {
1211
- options = options || {};
1212
- _CoreManager.default.set('FORCE_REVOCABLE_SESSION', true);
1213
- if (canUseCurrentUser) {
1214
- var current = ParseUser.current();
1215
- if (current) {
1216
- return current._upgradeToRevocableSession(options);
1217
- }
877
+ /**
878
+ * Allow someone to define a custom User class without className
879
+ * being rewritten to _User. The default behavior is to rewrite
880
+ * User to _User for legacy reasons. This allows developers to
881
+ * override that behavior.
882
+ *
883
+ * @param {boolean} isAllowed Whether or not to allow custom User class
884
+ * @static
885
+ */
886
+ static allowCustomUserClass(isAllowed) {
887
+ _CoreManager.default.set('PERFORM_USER_REWRITE', !isAllowed);
888
+ }
889
+
890
+ /**
891
+ * Allows a legacy application to start using revocable sessions. If the
892
+ * current session token is not revocable, a request will be made for a new,
893
+ * revocable session.
894
+ * It is not necessary to call this method from cloud code unless you are
895
+ * handling user signup or login from the server side. In a cloud code call,
896
+ * this function will not attempt to upgrade the current token.
897
+ *
898
+ * @param {object} options
899
+ * @static
900
+ * @returns {Promise} A promise that is resolved when the process has
901
+ * completed. If a replacement session token is requested, the promise
902
+ * will be resolved after a new token has been fetched.
903
+ */
904
+ static enableRevocableSession(options) {
905
+ options = options || {};
906
+ _CoreManager.default.set('FORCE_REVOCABLE_SESSION', true);
907
+ if (canUseCurrentUser) {
908
+ const current = ParseUser.current();
909
+ if (current) {
910
+ return current._upgradeToRevocableSession(options);
1218
911
  }
1219
- return _promise.default.resolve();
1220
912
  }
913
+ return _promise.default.resolve();
914
+ }
1221
915
 
1222
- /**
1223
- * Enables the use of become or the current user in a server
1224
- * environment. These features are disabled by default, since they depend on
1225
- * global objects that are not memory-safe for most servers.
1226
- *
1227
- * @static
1228
- */
1229
- }, {
1230
- key: "enableUnsafeCurrentUser",
1231
- value: function () {
1232
- canUseCurrentUser = true;
1233
- }
916
+ /**
917
+ * Enables the use of become or the current user in a server
918
+ * environment. These features are disabled by default, since they depend on
919
+ * global objects that are not memory-safe for most servers.
920
+ *
921
+ * @static
922
+ */
923
+ static enableUnsafeCurrentUser() {
924
+ canUseCurrentUser = true;
925
+ }
1234
926
 
1235
- /**
1236
- * Disables the use of become or the current user in any environment.
1237
- * These features are disabled on servers by default, since they depend on
1238
- * global objects that are not memory-safe for most servers.
1239
- *
1240
- * @static
1241
- */
1242
- }, {
1243
- key: "disableUnsafeCurrentUser",
1244
- value: function () {
1245
- canUseCurrentUser = false;
1246
- }
927
+ /**
928
+ * Disables the use of become or the current user in any environment.
929
+ * These features are disabled on servers by default, since they depend on
930
+ * global objects that are not memory-safe for most servers.
931
+ *
932
+ * @static
933
+ */
934
+ static disableUnsafeCurrentUser() {
935
+ canUseCurrentUser = false;
936
+ }
1247
937
 
1248
- /**
1249
- * When registering users with {@link https://parseplatform.org/Parse-SDK-JS/api/master/Parse.User.html#linkWith linkWith} a basic auth provider
1250
- * is automatically created for you.
1251
- *
1252
- * For advanced authentication, you can register an Auth provider to
1253
- * implement custom authentication, deauthentication.
1254
- *
1255
- * @param provider
1256
- * @see {@link https://parseplatform.org/Parse-SDK-JS/api/master/AuthProvider.html AuthProvider}
1257
- * @see {@link https://docs.parseplatform.org/js/guide/#custom-authentication-module Custom Authentication Module}
1258
- * @static
1259
- */
1260
- }, {
1261
- key: "_registerAuthenticationProvider",
1262
- value: function (provider /*: any*/) {
1263
- authProviders[provider.getAuthType()] = provider;
1264
- // Synchronize the current user with the auth provider.
1265
- ParseUser.currentAsync().then(function (current) {
1266
- if (current) {
1267
- current._synchronizeAuthData(provider.getAuthType());
1268
- }
1269
- });
1270
- }
938
+ /**
939
+ * When registering users with {@link https://parseplatform.org/Parse-SDK-JS/api/master/Parse.User.html#linkWith linkWith} a basic auth provider
940
+ * is automatically created for you.
941
+ *
942
+ * For advanced authentication, you can register an Auth provider to
943
+ * implement custom authentication, deauthentication.
944
+ *
945
+ * @param provider
946
+ * @see {@link https://parseplatform.org/Parse-SDK-JS/api/master/AuthProvider.html AuthProvider}
947
+ * @see {@link https://docs.parseplatform.org/js/guide/#custom-authentication-module Custom Authentication Module}
948
+ * @static
949
+ */
950
+ static _registerAuthenticationProvider(provider) {
951
+ authProviders[provider.getAuthType()] = provider;
952
+ // Synchronize the current user with the auth provider.
953
+ ParseUser.currentAsync().then(current => {
954
+ if (current) {
955
+ current._synchronizeAuthData(provider.getAuthType());
956
+ }
957
+ });
958
+ }
1271
959
 
1272
- /**
1273
- * @param provider
1274
- * @param options
1275
- * @param {object} [options.authData]
1276
- * @param saveOpts
1277
- * @deprecated since 2.9.0 see {@link https://parseplatform.org/Parse-SDK-JS/api/master/Parse.User.html#logInWith logInWith}
1278
- * @static
1279
- * @returns {Promise}
1280
- */
1281
- }, {
1282
- key: "_logInWith",
1283
- value: function (provider /*: any*/, options /*: { authData?: AuthData }*/, saveOpts /*:: ?: FullOptions*/) {
1284
- var user = new this();
1285
- return user.linkWith(provider, options, saveOpts);
1286
- }
1287
- }, {
1288
- key: "_clearCache",
1289
- value: function () {
1290
- currentUserCache = null;
1291
- currentUserCacheMatchesDisk = false;
1292
- }
1293
- }, {
1294
- key: "_setCurrentUserCache",
1295
- value: function (user /*: ParseUser*/) {
1296
- currentUserCache = user;
1297
- }
1298
- }]);
1299
- return ParseUser;
1300
- }(_ParseObject2.default);
1301
- _ParseObject2.default.registerSubclass('_User', ParseUser);
1302
- var DefaultController = {
1303
- updateUserOnDisk: function (user) {
1304
- var path = _Storage.default.generatePath(CURRENT_USER_KEY);
1305
- var json = user.toJSON();
960
+ /**
961
+ * @param provider
962
+ * @param options
963
+ * @param {object} [options.authData]
964
+ * @param saveOpts
965
+ * @deprecated since 2.9.0 see {@link https://parseplatform.org/Parse-SDK-JS/api/master/Parse.User.html#logInWith logInWith}
966
+ * @static
967
+ * @returns {Promise}
968
+ */
969
+ static _logInWith(provider, options, saveOpts) {
970
+ const user = new this();
971
+ return user.linkWith(provider, options, saveOpts);
972
+ }
973
+ static _clearCache() {
974
+ currentUserCache = null;
975
+ currentUserCacheMatchesDisk = false;
976
+ }
977
+ static _setCurrentUserCache(user) {
978
+ currentUserCache = user;
979
+ }
980
+ }
981
+ _ParseObject.default.registerSubclass('_User', ParseUser);
982
+ const DefaultController = {
983
+ updateUserOnDisk(user) {
984
+ const path = _Storage.default.generatePath(CURRENT_USER_KEY);
985
+ const json = user.toJSON();
1306
986
  delete json.password;
1307
987
  json.className = '_User';
1308
- var userData = (0, _stringify.default)(json);
988
+ let userData = (0, _stringify.default)(json);
1309
989
  if (_CoreManager.default.get('ENCRYPTED_USER')) {
1310
- var crypto = _CoreManager.default.getCryptoController();
990
+ const crypto = _CoreManager.default.getCryptoController();
1311
991
  userData = crypto.encrypt(json, _CoreManager.default.get('ENCRYPTED_KEY'));
1312
992
  }
1313
- return _Storage.default.setItemAsync(path, userData).then(function () {
993
+ return _Storage.default.setItemAsync(path, userData).then(() => {
1314
994
  return user;
1315
995
  });
1316
996
  },
1317
- removeUserFromDisk: function () {
1318
- var path = _Storage.default.generatePath(CURRENT_USER_KEY);
997
+ removeUserFromDisk() {
998
+ const path = _Storage.default.generatePath(CURRENT_USER_KEY);
1319
999
  currentUserCacheMatchesDisk = true;
1320
1000
  currentUserCache = null;
1321
1001
  return _Storage.default.removeItemAsync(path);
1322
1002
  },
1323
- setCurrentUser: function (user) {
1003
+ setCurrentUser(user) {
1324
1004
  currentUserCache = user;
1325
1005
  user._cleanupAuthData();
1326
1006
  user._synchronizeAllAuthData();
1327
1007
  return DefaultController.updateUserOnDisk(user);
1328
1008
  },
1329
- currentUser: function () /*: ParseUser | null*/{
1009
+ currentUser() {
1330
1010
  if (currentUserCache) {
1331
1011
  return currentUserCache;
1332
1012
  }
@@ -1336,15 +1016,15 @@ var DefaultController = {
1336
1016
  if (_Storage.default.async()) {
1337
1017
  throw new Error('Cannot call currentUser() when using a platform with an async ' + 'storage system. Call currentUserAsync() instead.');
1338
1018
  }
1339
- var path = _Storage.default.generatePath(CURRENT_USER_KEY);
1340
- var userData = _Storage.default.getItem(path);
1019
+ const path = _Storage.default.generatePath(CURRENT_USER_KEY);
1020
+ let userData = _Storage.default.getItem(path);
1341
1021
  currentUserCacheMatchesDisk = true;
1342
1022
  if (!userData) {
1343
1023
  currentUserCache = null;
1344
1024
  return null;
1345
1025
  }
1346
1026
  if (_CoreManager.default.get('ENCRYPTED_USER')) {
1347
- var crypto = _CoreManager.default.getCryptoController();
1027
+ const crypto = _CoreManager.default.getCryptoController();
1348
1028
  userData = crypto.decrypt(userData, _CoreManager.default.get('ENCRYPTED_KEY'));
1349
1029
  }
1350
1030
  userData = JSON.parse(userData);
@@ -1361,27 +1041,27 @@ var DefaultController = {
1361
1041
  userData.sessionToken = userData._sessionToken;
1362
1042
  delete userData._sessionToken;
1363
1043
  }
1364
- var current = _ParseObject2.default.fromJSON(userData);
1044
+ const current = _ParseObject.default.fromJSON(userData);
1365
1045
  currentUserCache = current;
1366
1046
  current._synchronizeAllAuthData();
1367
1047
  return current;
1368
1048
  },
1369
- currentUserAsync: function () /*: Promise<ParseUser | null>*/{
1049
+ currentUserAsync() {
1370
1050
  if (currentUserCache) {
1371
1051
  return _promise.default.resolve(currentUserCache);
1372
1052
  }
1373
1053
  if (currentUserCacheMatchesDisk) {
1374
1054
  return _promise.default.resolve(null);
1375
1055
  }
1376
- var path = _Storage.default.generatePath(CURRENT_USER_KEY);
1377
- return _Storage.default.getItemAsync(path).then(function (userData) {
1056
+ const path = _Storage.default.generatePath(CURRENT_USER_KEY);
1057
+ return _Storage.default.getItemAsync(path).then(userData => {
1378
1058
  currentUserCacheMatchesDisk = true;
1379
1059
  if (!userData) {
1380
1060
  currentUserCache = null;
1381
1061
  return _promise.default.resolve(null);
1382
1062
  }
1383
1063
  if (_CoreManager.default.get('ENCRYPTED_USER')) {
1384
- var crypto = _CoreManager.default.getCryptoController();
1064
+ const crypto = _CoreManager.default.getCryptoController();
1385
1065
  userData = crypto.decrypt(userData.toString(), _CoreManager.default.get('ENCRYPTED_KEY'));
1386
1066
  }
1387
1067
  userData = JSON.parse(userData);
@@ -1398,22 +1078,22 @@ var DefaultController = {
1398
1078
  userData.sessionToken = userData._sessionToken;
1399
1079
  delete userData._sessionToken;
1400
1080
  }
1401
- var current = _ParseObject2.default.fromJSON(userData);
1081
+ const current = _ParseObject.default.fromJSON(userData);
1402
1082
  currentUserCache = current;
1403
1083
  current._synchronizeAllAuthData();
1404
1084
  return _promise.default.resolve(current);
1405
1085
  });
1406
1086
  },
1407
- signUp: function (user /*: ParseUser*/, attrs /*: AttributeMap*/, options /*: RequestOptions*/) /*: Promise<ParseUser>*/{
1408
- var username = attrs && attrs.username || user.get('username');
1409
- var password = attrs && attrs.password || user.get('password');
1087
+ signUp(user, attrs, options) {
1088
+ const username = attrs && attrs.username || user.get('username');
1089
+ const password = attrs && attrs.password || user.get('password');
1410
1090
  if (!username || !username.length) {
1411
1091
  return _promise.default.reject(new _ParseError.default(_ParseError.default.OTHER_CAUSE, 'Cannot sign up user with an empty username.'));
1412
1092
  }
1413
1093
  if (!password || !password.length) {
1414
1094
  return _promise.default.reject(new _ParseError.default(_ParseError.default.OTHER_CAUSE, 'Cannot sign up user with an empty password.'));
1415
1095
  }
1416
- return user.save(attrs, options).then(function () {
1096
+ return user.save(attrs, options).then(() => {
1417
1097
  // Clear the password field
1418
1098
  user._finishFetch({
1419
1099
  password: undefined
@@ -1424,15 +1104,15 @@ var DefaultController = {
1424
1104
  return user;
1425
1105
  });
1426
1106
  },
1427
- logIn: function (user /*: ParseUser*/, options /*: RequestOptions*/) /*: Promise<ParseUser>*/{
1428
- var RESTController = _CoreManager.default.getRESTController();
1429
- var stateController = _CoreManager.default.getObjectStateController();
1430
- var auth = {
1107
+ logIn(user, options) {
1108
+ const RESTController = _CoreManager.default.getRESTController();
1109
+ const stateController = _CoreManager.default.getObjectStateController();
1110
+ const auth = {
1431
1111
  username: user.get('username'),
1432
1112
  password: user.get('password'),
1433
1113
  authData: user.get('authData')
1434
1114
  };
1435
- return RESTController.request(options.usePost ? 'POST' : 'GET', 'login', auth, options).then(function (response) {
1115
+ return RESTController.request(options.usePost ? 'POST' : 'GET', 'login', auth, options).then(response => {
1436
1116
  user._migrateId(response.objectId);
1437
1117
  user._setExisted(true);
1438
1118
  stateController.setPendingOp(user._getStateIdentifier(), 'username', undefined);
@@ -1446,13 +1126,13 @@ var DefaultController = {
1446
1126
  return DefaultController.setCurrentUser(user);
1447
1127
  });
1448
1128
  },
1449
- loginAs: function (user /*: ParseUser*/, userId /*: string*/) /*: Promise<ParseUser>*/{
1450
- var RESTController = _CoreManager.default.getRESTController();
1129
+ loginAs(user, userId) {
1130
+ const RESTController = _CoreManager.default.getRESTController();
1451
1131
  return RESTController.request('POST', 'loginAs', {
1452
- userId: userId
1132
+ userId
1453
1133
  }, {
1454
1134
  useMasterKey: true
1455
- }).then(function (response) {
1135
+ }).then(response => {
1456
1136
  user._finishFetch(response);
1457
1137
  user._setExisted(true);
1458
1138
  if (!canUseCurrentUser) {
@@ -1461,15 +1141,15 @@ var DefaultController = {
1461
1141
  return DefaultController.setCurrentUser(user);
1462
1142
  });
1463
1143
  },
1464
- become: function (user /*: ParseUser*/, options /*: RequestOptions*/) /*: Promise<ParseUser>*/{
1465
- var RESTController = _CoreManager.default.getRESTController();
1466
- return RESTController.request('GET', 'users/me', {}, options).then(function (response) {
1144
+ become(user, options) {
1145
+ const RESTController = _CoreManager.default.getRESTController();
1146
+ return RESTController.request('GET', 'users/me', {}, options).then(response => {
1467
1147
  user._finishFetch(response);
1468
1148
  user._setExisted(true);
1469
1149
  return DefaultController.setCurrentUser(user);
1470
1150
  });
1471
1151
  },
1472
- hydrate: function (user /*: ParseUser*/, userJSON /*: AttributeMap*/) /*: Promise<ParseUser>*/{
1152
+ hydrate(user, userJSON) {
1473
1153
  user._finishFetch(userJSON);
1474
1154
  user._setExisted(true);
1475
1155
  if (userJSON.sessionToken && canUseCurrentUser) {
@@ -1478,26 +1158,26 @@ var DefaultController = {
1478
1158
  return _promise.default.resolve(user);
1479
1159
  }
1480
1160
  },
1481
- me: function (user /*: ParseUser*/, options /*: RequestOptions*/) /*: Promise<ParseUser>*/{
1482
- var RESTController = _CoreManager.default.getRESTController();
1483
- return RESTController.request('GET', 'users/me', {}, options).then(function (response) {
1161
+ me(user, options) {
1162
+ const RESTController = _CoreManager.default.getRESTController();
1163
+ return RESTController.request('GET', 'users/me', {}, options).then(response => {
1484
1164
  user._finishFetch(response);
1485
1165
  user._setExisted(true);
1486
1166
  return user;
1487
1167
  });
1488
1168
  },
1489
- logOut: function (options /*: RequestOptions*/) /*: Promise<void>*/{
1490
- var RESTController = _CoreManager.default.getRESTController();
1169
+ logOut(options) {
1170
+ const RESTController = _CoreManager.default.getRESTController();
1491
1171
  if (options.sessionToken) {
1492
1172
  return RESTController.request('POST', 'logout', {}, options);
1493
1173
  }
1494
- return DefaultController.currentUserAsync().then(function (currentUser) {
1495
- var path = _Storage.default.generatePath(CURRENT_USER_KEY);
1496
- var promise = _Storage.default.removeItemAsync(path);
1174
+ return DefaultController.currentUserAsync().then(currentUser => {
1175
+ const path = _Storage.default.generatePath(CURRENT_USER_KEY);
1176
+ let promise = _Storage.default.removeItemAsync(path);
1497
1177
  if (currentUser !== null) {
1498
- var currentSession = currentUser.getSessionToken();
1178
+ const currentSession = currentUser.getSessionToken();
1499
1179
  if (currentSession && (0, _isRevocableSession.default)(currentSession)) {
1500
- promise = promise.then(function () {
1180
+ promise = promise.then(() => {
1501
1181
  return RESTController.request('POST', 'logout', {}, {
1502
1182
  sessionToken: currentSession
1503
1183
  });
@@ -1513,74 +1193,52 @@ var DefaultController = {
1513
1193
  return promise;
1514
1194
  });
1515
1195
  },
1516
- requestPasswordReset: function (email /*: string*/, options /*: RequestOptions*/) {
1517
- var RESTController = _CoreManager.default.getRESTController();
1196
+ requestPasswordReset(email, options) {
1197
+ const RESTController = _CoreManager.default.getRESTController();
1518
1198
  return RESTController.request('POST', 'requestPasswordReset', {
1519
1199
  email: email
1520
1200
  }, options);
1521
1201
  },
1522
- upgradeToRevocableSession: function (user /*: ParseUser*/, options /*: RequestOptions*/) {
1523
- return (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee6() {
1524
- var token, RESTController, result, current;
1525
- return _regenerator.default.wrap(function (_context6) {
1526
- while (1) switch (_context6.prev = _context6.next) {
1527
- case 0:
1528
- token = user.getSessionToken();
1529
- if (token) {
1530
- _context6.next = 3;
1531
- break;
1532
- }
1533
- return _context6.abrupt("return", _promise.default.reject(new _ParseError.default(_ParseError.default.SESSION_MISSING, 'Cannot upgrade a user with no session token')));
1534
- case 3:
1535
- options.sessionToken = token;
1536
- RESTController = _CoreManager.default.getRESTController();
1537
- _context6.next = 7;
1538
- return RESTController.request('POST', 'upgradeToRevocableSession', {}, options);
1539
- case 7:
1540
- result = _context6.sent;
1541
- user._finishFetch({
1542
- sessionToken: (result === null || result === void 0 ? void 0 : result.sessionToken) || ''
1543
- });
1544
- _context6.next = 11;
1545
- return user.isCurrentAsync();
1546
- case 11:
1547
- current = _context6.sent;
1548
- if (!current) {
1549
- _context6.next = 14;
1550
- break;
1551
- }
1552
- return _context6.abrupt("return", DefaultController.setCurrentUser(user));
1553
- case 14:
1554
- return _context6.abrupt("return", _promise.default.resolve(user));
1555
- case 15:
1556
- case "end":
1557
- return _context6.stop();
1558
- }
1559
- }, _callee6);
1560
- }))();
1202
+ async upgradeToRevocableSession(user, options) {
1203
+ const token = user.getSessionToken();
1204
+ if (!token) {
1205
+ return _promise.default.reject(new _ParseError.default(_ParseError.default.SESSION_MISSING, 'Cannot upgrade a user with no session token'));
1206
+ }
1207
+ options.sessionToken = token;
1208
+ const RESTController = _CoreManager.default.getRESTController();
1209
+ const result = await RESTController.request('POST', 'upgradeToRevocableSession', {}, options);
1210
+ user._finishFetch({
1211
+ sessionToken: result?.sessionToken || ''
1212
+ });
1213
+ const current = await user.isCurrentAsync();
1214
+ if (current) {
1215
+ return DefaultController.setCurrentUser(user);
1216
+ }
1217
+ return _promise.default.resolve(user);
1561
1218
  },
1562
- linkWith: function (user /*: ParseUser*/, authData /*: AuthData*/, options /*: FullOptions*/) {
1219
+ linkWith(user, authData, options) {
1563
1220
  return user.save({
1564
- authData: authData
1565
- }, options).then(function () {
1221
+ authData
1222
+ }, options).then(() => {
1566
1223
  if (canUseCurrentUser) {
1567
1224
  return DefaultController.setCurrentUser(user);
1568
1225
  }
1569
1226
  return user;
1570
1227
  });
1571
1228
  },
1572
- verifyPassword: function (username /*: string*/, password /*: string*/, options /*: RequestOptions*/) {
1573
- var RESTController = _CoreManager.default.getRESTController();
1574
- var data = _objectSpread({
1575
- username: username,
1576
- password: password
1577
- }, options.ignoreEmailVerification !== undefined && {
1578
- ignoreEmailVerification: options.ignoreEmailVerification
1579
- });
1229
+ verifyPassword(username, password, options) {
1230
+ const RESTController = _CoreManager.default.getRESTController();
1231
+ const data = {
1232
+ username,
1233
+ password,
1234
+ ...(options.ignoreEmailVerification !== undefined && {
1235
+ ignoreEmailVerification: options.ignoreEmailVerification
1236
+ })
1237
+ };
1580
1238
  return RESTController.request('GET', 'verifyPassword', data, options);
1581
1239
  },
1582
- requestEmailVerification: function (email /*: string*/, options /*: RequestOptions*/) {
1583
- var RESTController = _CoreManager.default.getRESTController();
1240
+ requestEmailVerification(email, options) {
1241
+ const RESTController = _CoreManager.default.getRESTController();
1584
1242
  return RESTController.request('POST', 'verificationEmailRequest', {
1585
1243
  email: email
1586
1244
  }, options);
@@ -1588,5 +1246,4 @@ var DefaultController = {
1588
1246
  };
1589
1247
  _CoreManager.default.setParseUser(ParseUser);
1590
1248
  _CoreManager.default.setUserController(DefaultController);
1591
- var _default = ParseUser;
1592
- exports.default = _default;
1249
+ var _default = exports.default = ParseUser;