parse 3.5.1 → 4.0.0-alpha.10

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