ParseUser.js 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
  3. var _sliceInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/slice");
  4. var _reverseInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/reverse");
  5. var _Promise2 = require("@babel/runtime-corejs3/core-js-stable/promise");
  6. var _Object$setPrototypeOf = require("@babel/runtime-corejs3/core-js-stable/object/set-prototype-of");
  7. var _typeof3 = require("@babel/runtime-corejs3/helpers/typeof");
  8. var _forEachInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/for-each");
  9. var _Object$getPrototypeOf = require("@babel/runtime-corejs3/core-js-stable/object/get-prototype-of");
  10. var _Object$create = require("@babel/runtime-corejs3/core-js-stable/object/create");
  11. var _Object$defineProperty2 = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
  12. var _Symbol = require("@babel/runtime-corejs3/core-js-stable/symbol");
  13. var _Reflect$construct = require("@babel/runtime-corejs3/core-js-stable/reflect/construct");
  14. _Object$defineProperty2(exports, "__esModule", {
  15. value: true
  16. });
  17. exports.default = void 0;
  18. var _stringify = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/json/stringify"));
  19. var _defineProperty = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/define-property"));
  20. var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/asyncToGenerator"));
  21. var _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/promise"));
  22. var _typeof2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/typeof"));
  23. var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/classCallCheck"));
  24. var _createClass2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/createClass"));
  25. var _get2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/get"));
  26. var _inherits2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/inherits"));
  27. var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/possibleConstructorReturn"));
  28. var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/getPrototypeOf"));
  29. var _CoreManager = _interopRequireDefault(require("./CoreManager"));
  30. var _isRevocableSession = _interopRequireDefault(require("./isRevocableSession"));
  31. var _ParseError = _interopRequireDefault(require("./ParseError"));
  32. var _ParseObject2 = _interopRequireDefault(require("./ParseObject"));
  33. var _ParseSession = _interopRequireDefault(require("./ParseSession"));
  34. var _Storage = _interopRequireDefault(require("./Storage"));
  35. function _regeneratorRuntime() {
  36. "use strict";
  37. /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
  38. _regeneratorRuntime = function () {
  39. return exports;
  40. };
  41. var exports = {},
  42. Op = Object.prototype,
  43. hasOwn = Op.hasOwnProperty,
  44. $Symbol = "function" == typeof _Symbol ? _Symbol : {},
  45. iteratorSymbol = $Symbol.iterator || "@@iterator",
  46. asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
  47. toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
  48. function define(obj, key, value) {
  49. return _Object$defineProperty2(obj, key, {
  50. value: value,
  51. enumerable: !0,
  52. configurable: !0,
  53. writable: !0
  54. }), obj[key];
  55. }
  56. try {
  57. define({}, "");
  58. } catch (err) {
  59. define = function (obj, key, value) {
  60. return obj[key] = value;
  61. };
  62. }
  63. function wrap(innerFn, outerFn, self, tryLocsList) {
  64. var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
  65. generator = _Object$create(protoGenerator.prototype),
  66. context = new Context(tryLocsList || []);
  67. return generator._invoke = function (innerFn, self, context) {
  68. var state = "suspendedStart";
  69. return function (method, arg) {
  70. if ("executing" === state) throw new Error("Generator is already running");
  71. if ("completed" === state) {
  72. if ("throw" === method) throw arg;
  73. return doneResult();
  74. }
  75. for (context.method = method, context.arg = arg;;) {
  76. var delegate = context.delegate;
  77. if (delegate) {
  78. var delegateResult = maybeInvokeDelegate(delegate, context);
  79. if (delegateResult) {
  80. if (delegateResult === ContinueSentinel) continue;
  81. return delegateResult;
  82. }
  83. }
  84. if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
  85. if ("suspendedStart" === state) throw state = "completed", context.arg;
  86. context.dispatchException(context.arg);
  87. } else "return" === context.method && context.abrupt("return", context.arg);
  88. state = "executing";
  89. var record = tryCatch(innerFn, self, context);
  90. if ("normal" === record.type) {
  91. if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
  92. return {
  93. value: record.arg,
  94. done: context.done
  95. };
  96. }
  97. "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
  98. }
  99. };
  100. }(innerFn, self, context), generator;
  101. }
  102. function tryCatch(fn, obj, arg) {
  103. try {
  104. return {
  105. type: "normal",
  106. arg: fn.call(obj, arg)
  107. };
  108. } catch (err) {
  109. return {
  110. type: "throw",
  111. arg: err
  112. };
  113. }
  114. }
  115. exports.wrap = wrap;
  116. var ContinueSentinel = {};
  117. function Generator() {}
  118. function GeneratorFunction() {}
  119. function GeneratorFunctionPrototype() {}
  120. var IteratorPrototype = {};
  121. define(IteratorPrototype, iteratorSymbol, function () {
  122. return this;
  123. });
  124. var getProto = _Object$getPrototypeOf,
  125. NativeIteratorPrototype = getProto && getProto(getProto(values([])));
  126. NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
  127. var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = _Object$create(IteratorPrototype);
  128. function defineIteratorMethods(prototype) {
  129. var _context7;
  130. _forEachInstanceProperty(_context7 = ["next", "throw", "return"]).call(_context7, function (method) {
  131. define(prototype, method, function (arg) {
  132. return this._invoke(method, arg);
  133. });
  134. });
  135. }
  136. function AsyncIterator(generator, PromiseImpl) {
  137. function invoke(method, arg, resolve, reject) {
  138. var record = tryCatch(generator[method], generator, arg);
  139. if ("throw" !== record.type) {
  140. var result = record.arg,
  141. value = result.value;
  142. return value && "object" == _typeof3(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
  143. invoke("next", value, resolve, reject);
  144. }, function (err) {
  145. invoke("throw", err, resolve, reject);
  146. }) : PromiseImpl.resolve(value).then(function (unwrapped) {
  147. result.value = unwrapped, resolve(result);
  148. }, function (error) {
  149. return invoke("throw", error, resolve, reject);
  150. });
  151. }
  152. reject(record.arg);
  153. }
  154. var previousPromise;
  155. this._invoke = function (method, arg) {
  156. function callInvokeWithMethodAndArg() {
  157. return new PromiseImpl(function (resolve, reject) {
  158. invoke(method, arg, resolve, reject);
  159. });
  160. }
  161. return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
  162. };
  163. }
  164. function maybeInvokeDelegate(delegate, context) {
  165. var method = delegate.iterator[context.method];
  166. if (undefined === method) {
  167. if (context.delegate = null, "throw" === context.method) {
  168. if (delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel;
  169. context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method");
  170. }
  171. return ContinueSentinel;
  172. }
  173. var record = tryCatch(method, delegate.iterator, context.arg);
  174. if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
  175. var info = record.arg;
  176. return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel);
  177. }
  178. function pushTryEntry(locs) {
  179. var entry = {
  180. tryLoc: locs[0]
  181. };
  182. 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
  183. }
  184. function resetTryEntry(entry) {
  185. var record = entry.completion || {};
  186. record.type = "normal", delete record.arg, entry.completion = record;
  187. }
  188. function Context(tryLocsList) {
  189. this.tryEntries = [{
  190. tryLoc: "root"
  191. }], _forEachInstanceProperty(tryLocsList).call(tryLocsList, pushTryEntry, this), this.reset(!0);
  192. }
  193. function values(iterable) {
  194. if (iterable) {
  195. var iteratorMethod = iterable[iteratorSymbol];
  196. if (iteratorMethod) return iteratorMethod.call(iterable);
  197. if ("function" == typeof iterable.next) return iterable;
  198. if (!isNaN(iterable.length)) {
  199. var i = -1,
  200. next = function next() {
  201. for (; ++i < iterable.length;) {
  202. if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
  203. }
  204. return next.value = undefined, next.done = !0, next;
  205. };
  206. return next.next = next;
  207. }
  208. }
  209. return {
  210. next: doneResult
  211. };
  212. }
  213. function doneResult() {
  214. return {
  215. value: undefined,
  216. done: !0
  217. };
  218. }
  219. return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
  220. var ctor = "function" == typeof genFun && genFun.constructor;
  221. return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
  222. }, exports.mark = function (genFun) {
  223. return _Object$setPrototypeOf ? _Object$setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = _Object$create(Gp), genFun;
  224. }, exports.awrap = function (arg) {
  225. return {
  226. __await: arg
  227. };
  228. }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
  229. return this;
  230. }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
  231. void 0 === PromiseImpl && (PromiseImpl = _Promise2);
  232. var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
  233. return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
  234. return result.done ? result.value : iter.next();
  235. });
  236. }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
  237. return this;
  238. }), define(Gp, "toString", function () {
  239. return "[object Generator]";
  240. }), exports.keys = function (object) {
  241. var keys = [];
  242. for (var key in object) {
  243. keys.push(key);
  244. }
  245. return _reverseInstanceProperty(keys).call(keys), function next() {
  246. for (; keys.length;) {
  247. var key = keys.pop();
  248. if (key in object) return next.value = key, next.done = !1, next;
  249. }
  250. return next.done = !0, next;
  251. };
  252. }, exports.values = values, Context.prototype = {
  253. constructor: Context,
  254. reset: function (skipTempReset) {
  255. var _context8;
  256. if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, _forEachInstanceProperty(_context8 = this.tryEntries).call(_context8, resetTryEntry), !skipTempReset) for (var name in this) {
  257. "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+_sliceInstanceProperty(name).call(name, 1)) && (this[name] = undefined);
  258. }
  259. },
  260. stop: function () {
  261. this.done = !0;
  262. var rootRecord = this.tryEntries[0].completion;
  263. if ("throw" === rootRecord.type) throw rootRecord.arg;
  264. return this.rval;
  265. },
  266. dispatchException: function (exception) {
  267. if (this.done) throw exception;
  268. var context = this;
  269. function handle(loc, caught) {
  270. return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
  271. }
  272. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  273. var entry = this.tryEntries[i],
  274. record = entry.completion;
  275. if ("root" === entry.tryLoc) return handle("end");
  276. if (entry.tryLoc <= this.prev) {
  277. var hasCatch = hasOwn.call(entry, "catchLoc"),
  278. hasFinally = hasOwn.call(entry, "finallyLoc");
  279. if (hasCatch && hasFinally) {
  280. if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
  281. if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
  282. } else if (hasCatch) {
  283. if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
  284. } else {
  285. if (!hasFinally) throw new Error("try statement without catch or finally");
  286. if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
  287. }
  288. }
  289. }
  290. },
  291. abrupt: function (type, arg) {
  292. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  293. var entry = this.tryEntries[i];
  294. if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
  295. var finallyEntry = entry;
  296. break;
  297. }
  298. }
  299. finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
  300. var record = finallyEntry ? finallyEntry.completion : {};
  301. return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
  302. },
  303. complete: function (record, afterLoc) {
  304. if ("throw" === record.type) throw record.arg;
  305. return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel;
  306. },
  307. finish: function (finallyLoc) {
  308. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  309. var entry = this.tryEntries[i];
  310. if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
  311. }
  312. },
  313. catch: function (tryLoc) {
  314. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  315. var entry = this.tryEntries[i];
  316. if (entry.tryLoc === tryLoc) {
  317. var record = entry.completion;
  318. if ("throw" === record.type) {
  319. var thrown = record.arg;
  320. resetTryEntry(entry);
  321. }
  322. return thrown;
  323. }
  324. }
  325. throw new Error("illegal catch attempt");
  326. },
  327. delegateYield: function (iterable, resultName, nextLoc) {
  328. return this.delegate = {
  329. iterator: values(iterable),
  330. resultName: resultName,
  331. nextLoc: nextLoc
  332. }, "next" === this.method && (this.arg = undefined), ContinueSentinel;
  333. }
  334. }, exports;
  335. }
  336. function _createSuper(Derived) {
  337. var hasNativeReflectConstruct = _isNativeReflectConstruct();
  338. return function () {
  339. var Super = (0, _getPrototypeOf2.default)(Derived),
  340. result;
  341. if (hasNativeReflectConstruct) {
  342. var NewTarget = (0, _getPrototypeOf2.default)(this).constructor;
  343. result = _Reflect$construct(Super, arguments, NewTarget);
  344. } else {
  345. result = Super.apply(this, arguments);
  346. }
  347. return (0, _possibleConstructorReturn2.default)(this, result);
  348. };
  349. }
  350. function _isNativeReflectConstruct() {
  351. if (typeof Reflect === "undefined" || !_Reflect$construct) return false;
  352. if (_Reflect$construct.sham) return false;
  353. if (typeof Proxy === "function") return true;
  354. try {
  355. Boolean.prototype.valueOf.call(_Reflect$construct(Boolean, [], function () {}));
  356. return true;
  357. } catch (e) {
  358. return false;
  359. }
  360. }
  361. var CURRENT_USER_KEY = 'currentUser';
  362. var canUseCurrentUser = !_CoreManager.default.get('IS_NODE');
  363. var currentUserCacheMatchesDisk = false;
  364. var currentUserCache = null;
  365. var authProviders = {};
  366. /**
  367. * <p>A Parse.User object is a local representation of a user persisted to the
  368. * Parse cloud. This class is a subclass of a Parse.Object, and retains the
  369. * same functionality of a Parse.Object, but also extends it with various
  370. * user specific methods, like authentication, signing up, and validation of
  371. * uniqueness.</p>
  372. *
  373. * @alias Parse.User
  374. * @augments Parse.Object
  375. */
  376. var ParseUser = /*#__PURE__*/function (_ParseObject) {
  377. (0, _inherits2.default)(ParseUser, _ParseObject);
  378. var _super = _createSuper(ParseUser);
  379. /**
  380. * @param {object} attributes The initial set of data to store in the user.
  381. */
  382. function ParseUser(attributes
  383. /*: ?AttributeMap*/
  384. ) {
  385. var _this;
  386. (0, _classCallCheck2.default)(this, ParseUser);
  387. _this = _super.call(this, '_User');
  388. if (attributes && (0, _typeof2.default)(attributes) === 'object') {
  389. if (!_this.set(attributes || {})) {
  390. throw new Error("Can't create an invalid Parse User");
  391. }
  392. }
  393. return _this;
  394. }
  395. /**
  396. * Request a revocable session token to replace the older style of token.
  397. *
  398. * @param {object} options
  399. * @returns {Promise} A promise that is resolved when the replacement
  400. * token has been fetched.
  401. */
  402. (0, _createClass2.default)(ParseUser, [{
  403. key: "_upgradeToRevocableSession",
  404. value: function (options
  405. /*: RequestOptions*/
  406. )
  407. /*: Promise<void>*/
  408. {
  409. options = options || {};
  410. var upgradeOptions = {};
  411. if (options.hasOwnProperty('useMasterKey')) {
  412. upgradeOptions.useMasterKey = options.useMasterKey;
  413. }
  414. var controller = _CoreManager.default.getUserController();
  415. return controller.upgradeToRevocableSession(this, upgradeOptions);
  416. }
  417. /**
  418. * 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
  419. * your users to sign up or log into your application using their existing identities.
  420. * Since 2.9.0
  421. *
  422. * @see {@link https://docs.parseplatform.org/js/guide/#linking-users Linking Users}
  423. * @param {string | AuthProvider} provider Name of auth provider or {@link https://parseplatform.org/Parse-SDK-JS/api/master/AuthProvider.html AuthProvider}
  424. * @param {object} options
  425. * <ul>
  426. * <li>If provider is string, options is {@link http://docs.parseplatform.org/parse-server/guide/#supported-3rd-party-authentications authData}
  427. * <li>If provider is AuthProvider, options is saveOpts
  428. * </ul>
  429. * @param {object} saveOpts useMasterKey / sessionToken
  430. * @returns {Promise} A promise that is fulfilled with the user is linked
  431. */
  432. }, {
  433. key: "linkWith",
  434. value: function (provider
  435. /*: any*/
  436. , options
  437. /*: { authData?: AuthData }*/
  438. )
  439. /*: Promise<ParseUser>*/
  440. {
  441. var _this2 = this;
  442. var saveOpts
  443. /*:: ?: FullOptions*/
  444. = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  445. saveOpts.sessionToken = saveOpts.sessionToken || this.getSessionToken() || '';
  446. var authType;
  447. if (typeof provider === 'string') {
  448. authType = provider;
  449. if (authProviders[provider]) {
  450. provider = authProviders[provider];
  451. } else {
  452. var authProvider = {
  453. restoreAuthentication: function () {
  454. return true;
  455. },
  456. getAuthType: function () {
  457. return authType;
  458. }
  459. };
  460. authProviders[authProvider.getAuthType()] = authProvider;
  461. provider = authProvider;
  462. }
  463. } else {
  464. authType = provider.getAuthType();
  465. }
  466. if (options && options.hasOwnProperty('authData')) {
  467. var authData = this.get('authData') || {};
  468. if ((0, _typeof2.default)(authData) !== 'object') {
  469. throw new Error('Invalid type: authData field should be an object');
  470. }
  471. authData[authType] = options.authData;
  472. var controller = _CoreManager.default.getUserController();
  473. return controller.linkWith(this, authData, saveOpts);
  474. } else {
  475. return new _promise.default(function (resolve, reject) {
  476. provider.authenticate({
  477. success: function (provider, result) {
  478. var opts = {};
  479. opts.authData = result;
  480. _this2.linkWith(provider, opts, saveOpts).then(function () {
  481. resolve(_this2);
  482. }, function (error) {
  483. reject(error);
  484. });
  485. },
  486. error: function (provider, _error) {
  487. reject(_error);
  488. }
  489. });
  490. });
  491. }
  492. }
  493. /**
  494. * @param provider
  495. * @param options
  496. * @param saveOpts
  497. * @deprecated since 2.9.0 see {@link https://parseplatform.org/Parse-SDK-JS/api/master/Parse.User.html#linkWith linkWith}
  498. * @returns {Promise}
  499. */
  500. }, {
  501. key: "_linkWith",
  502. value: function (provider
  503. /*: any*/
  504. , options
  505. /*: { authData?: AuthData }*/
  506. )
  507. /*: Promise<ParseUser>*/
  508. {
  509. var saveOpts
  510. /*:: ?: FullOptions*/
  511. = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  512. return this.linkWith(provider, options, saveOpts);
  513. }
  514. /**
  515. * Synchronizes auth data for a provider (e.g. puts the access token in the
  516. * right place to be used by the Facebook SDK).
  517. *
  518. * @param provider
  519. */
  520. }, {
  521. key: "_synchronizeAuthData",
  522. value: function (provider
  523. /*: string*/
  524. ) {
  525. if (!this.isCurrent() || !provider) {
  526. return;
  527. }
  528. var authType;
  529. if (typeof provider === 'string') {
  530. authType = provider;
  531. provider = authProviders[authType];
  532. } else {
  533. authType = provider.getAuthType();
  534. }
  535. var authData = this.get('authData');
  536. if (!provider || !authData || (0, _typeof2.default)(authData) !== 'object') {
  537. return;
  538. }
  539. var success = provider.restoreAuthentication(authData[authType]);
  540. if (!success) {
  541. this._unlinkFrom(provider);
  542. }
  543. }
  544. /**
  545. * Synchronizes authData for all providers.
  546. */
  547. }, {
  548. key: "_synchronizeAllAuthData",
  549. value: function () {
  550. var authData = this.get('authData');
  551. if ((0, _typeof2.default)(authData) !== 'object') {
  552. return;
  553. }
  554. for (var _key in authData) {
  555. this._synchronizeAuthData(_key);
  556. }
  557. }
  558. /**
  559. * Removes null values from authData (which exist temporarily for unlinking)
  560. */
  561. }, {
  562. key: "_cleanupAuthData",
  563. value: function () {
  564. if (!this.isCurrent()) {
  565. return;
  566. }
  567. var authData = this.get('authData');
  568. if ((0, _typeof2.default)(authData) !== 'object') {
  569. return;
  570. }
  571. for (var _key2 in authData) {
  572. if (!authData[_key2]) {
  573. delete authData[_key2];
  574. }
  575. }
  576. }
  577. /**
  578. * Unlinks a user from a service.
  579. *
  580. * @param {string | AuthProvider} provider Name of auth provider or {@link https://parseplatform.org/Parse-SDK-JS/api/master/AuthProvider.html AuthProvider}
  581. * @param {object} options MasterKey / SessionToken
  582. * @returns {Promise} A promise that is fulfilled when the unlinking
  583. * finishes.
  584. */
  585. }, {
  586. key: "_unlinkFrom",
  587. value: function (provider
  588. /*: any*/
  589. , options
  590. /*:: ?: FullOptions*/
  591. )
  592. /*: Promise<ParseUser>*/
  593. {
  594. var _this3 = this;
  595. return this.linkWith(provider, {
  596. authData: null
  597. }, options).then(function () {
  598. _this3._synchronizeAuthData(provider);
  599. return _promise.default.resolve(_this3);
  600. });
  601. }
  602. /**
  603. * Checks whether a user is linked to a service.
  604. *
  605. * @param {object} provider service to link to
  606. * @returns {boolean} true if link was successful
  607. */
  608. }, {
  609. key: "_isLinked",
  610. value: function (provider
  611. /*: any*/
  612. )
  613. /*: boolean*/
  614. {
  615. var authType;
  616. if (typeof provider === 'string') {
  617. authType = provider;
  618. } else {
  619. authType = provider.getAuthType();
  620. }
  621. var authData = this.get('authData') || {};
  622. if ((0, _typeof2.default)(authData) !== 'object') {
  623. return false;
  624. }
  625. return !!authData[authType];
  626. }
  627. /**
  628. * Deauthenticates all providers.
  629. */
  630. }, {
  631. key: "_logOutWithAll",
  632. value: function () {
  633. var authData = this.get('authData');
  634. if ((0, _typeof2.default)(authData) !== 'object') {
  635. return;
  636. }
  637. for (var _key3 in authData) {
  638. this._logOutWith(_key3);
  639. }
  640. }
  641. /**
  642. * Deauthenticates a single provider (e.g. removing access tokens from the
  643. * Facebook SDK).
  644. *
  645. * @param {object} provider service to logout of
  646. */
  647. }, {
  648. key: "_logOutWith",
  649. value: function (provider
  650. /*: any*/
  651. ) {
  652. if (!this.isCurrent()) {
  653. return;
  654. }
  655. if (typeof provider === 'string') {
  656. provider = authProviders[provider];
  657. }
  658. if (provider && provider.deauthenticate) {
  659. provider.deauthenticate();
  660. }
  661. }
  662. /**
  663. * Class instance method used to maintain specific keys when a fetch occurs.
  664. * Used to ensure that the session token is not lost.
  665. *
  666. * @returns {object} sessionToken
  667. */
  668. }, {
  669. key: "_preserveFieldsOnFetch",
  670. value: function ()
  671. /*: AttributeMap*/
  672. {
  673. return {
  674. sessionToken: this.get('sessionToken')
  675. };
  676. }
  677. /**
  678. * Returns true if <code>current</code> would return this user.
  679. *
  680. * @returns {boolean} true if user is cached on disk
  681. */
  682. }, {
  683. key: "isCurrent",
  684. value: function ()
  685. /*: boolean*/
  686. {
  687. var current = ParseUser.current();
  688. return !!current && current.id === this.id;
  689. }
  690. /**
  691. * Returns true if <code>current</code> would return this user.
  692. *
  693. * @returns {Promise<boolean>} true if user is cached on disk
  694. */
  695. }, {
  696. key: "isCurrentAsync",
  697. value: function () {
  698. var _isCurrentAsync = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
  699. var current;
  700. return _regeneratorRuntime().wrap(function _callee$(_context) {
  701. while (1) {
  702. switch (_context.prev = _context.next) {
  703. case 0:
  704. _context.next = 2;
  705. return ParseUser.currentAsync();
  706. case 2:
  707. current = _context.sent;
  708. return _context.abrupt("return", !!current && current.id === this.id);
  709. case 4:
  710. case "end":
  711. return _context.stop();
  712. }
  713. }
  714. }, _callee, this);
  715. }));
  716. function isCurrentAsync() {
  717. return _isCurrentAsync.apply(this, arguments);
  718. }
  719. return isCurrentAsync;
  720. }()
  721. /**
  722. * Returns get("username").
  723. *
  724. * @returns {string}
  725. */
  726. }, {
  727. key: "getUsername",
  728. value: function getUsername()
  729. /*: ?string*/
  730. {
  731. var username = this.get('username');
  732. if (username == null || typeof username === 'string') {
  733. return username;
  734. }
  735. return '';
  736. }
  737. /**
  738. * Calls set("username", username, options) and returns the result.
  739. *
  740. * @param {string} username
  741. */
  742. }, {
  743. key: "setUsername",
  744. value: function setUsername(username
  745. /*: string*/
  746. ) {
  747. // Strip anonymity
  748. var authData = this.get('authData');
  749. if (authData && (0, _typeof2.default)(authData) === 'object' && authData.hasOwnProperty('anonymous')) {
  750. // We need to set anonymous to null instead of deleting it in order to remove it from Parse.
  751. authData.anonymous = null;
  752. }
  753. this.set('username', username);
  754. }
  755. /**
  756. * Calls set("password", password, options) and returns the result.
  757. *
  758. * @param {string} password User's Password
  759. */
  760. }, {
  761. key: "setPassword",
  762. value: function setPassword(password
  763. /*: string*/
  764. ) {
  765. this.set('password', password);
  766. }
  767. /**
  768. * Returns get("email").
  769. *
  770. * @returns {string} User's Email
  771. */
  772. }, {
  773. key: "getEmail",
  774. value: function getEmail()
  775. /*: ?string*/
  776. {
  777. var email = this.get('email');
  778. if (email == null || typeof email === 'string') {
  779. return email;
  780. }
  781. return '';
  782. }
  783. /**
  784. * Calls set("email", email) and returns the result.
  785. *
  786. * @param {string} email
  787. * @returns {boolean}
  788. */
  789. }, {
  790. key: "setEmail",
  791. value: function setEmail(email
  792. /*: string*/
  793. ) {
  794. return this.set('email', email);
  795. }
  796. /**
  797. * Returns the session token for this user, if the user has been logged in,
  798. * or if it is the result of a query with the master key. Otherwise, returns
  799. * undefined.
  800. *
  801. * @returns {string} the session token, or undefined
  802. */
  803. }, {
  804. key: "getSessionToken",
  805. value: function getSessionToken()
  806. /*: ?string*/
  807. {
  808. var token = this.get('sessionToken');
  809. if (token == null || typeof token === 'string') {
  810. return token;
  811. }
  812. return '';
  813. }
  814. /**
  815. * Checks whether this user is the current user and has been authenticated.
  816. *
  817. * @returns {boolean} whether this user is the current user and is logged in.
  818. */
  819. }, {
  820. key: "authenticated",
  821. value: function authenticated()
  822. /*: boolean*/
  823. {
  824. var current = ParseUser.current();
  825. return !!this.get('sessionToken') && !!current && current.id === this.id;
  826. }
  827. /**
  828. * Signs up a new user. You should call this instead of save for
  829. * new Parse.Users. This will create a new Parse.User on the server, and
  830. * also persist the session on disk so that you can access the user using
  831. * <code>current</code>.
  832. *
  833. * <p>A username and password must be set before calling signUp.</p>
  834. *
  835. * @param {object} attrs Extra fields to set on the new user, or null.
  836. * @param {object} options
  837. * @returns {Promise} A promise that is fulfilled when the signup
  838. * finishes.
  839. */
  840. }, {
  841. key: "signUp",
  842. value: function signUp(attrs
  843. /*: AttributeMap*/
  844. , options
  845. /*:: ?: FullOptions*/
  846. )
  847. /*: Promise<ParseUser>*/
  848. {
  849. options = options || {};
  850. var signupOptions = {};
  851. if (options.hasOwnProperty('useMasterKey')) {
  852. signupOptions.useMasterKey = options.useMasterKey;
  853. }
  854. if (options.hasOwnProperty('installationId')) {
  855. signupOptions.installationId = options.installationId;
  856. }
  857. if (options.hasOwnProperty('context') && Object.prototype.toString.call(options.context) === '[object Object]') {
  858. signupOptions.context = options.context;
  859. }
  860. var controller = _CoreManager.default.getUserController();
  861. return controller.signUp(this, attrs, signupOptions);
  862. }
  863. /**
  864. * Logs in a Parse.User. On success, this saves the session to disk,
  865. * so you can retrieve the currently logged in user using
  866. * <code>current</code>.
  867. *
  868. * <p>A username and password must be set before calling logIn.</p>
  869. *
  870. * @param {object} options
  871. * @returns {Promise} A promise that is fulfilled with the user when
  872. * the login is complete.
  873. */
  874. }, {
  875. key: "logIn",
  876. value: function logIn(options
  877. /*:: ?: FullOptions*/
  878. )
  879. /*: Promise<ParseUser>*/
  880. {
  881. options = options || {};
  882. var loginOptions = {
  883. usePost: true
  884. };
  885. if (options.hasOwnProperty('useMasterKey')) {
  886. loginOptions.useMasterKey = options.useMasterKey;
  887. }
  888. if (options.hasOwnProperty('installationId')) {
  889. loginOptions.installationId = options.installationId;
  890. }
  891. if (options.hasOwnProperty('usePost')) {
  892. loginOptions.usePost = options.usePost;
  893. }
  894. var controller = _CoreManager.default.getUserController();
  895. return controller.logIn(this, loginOptions);
  896. }
  897. /**
  898. * Wrap the default save behavior with functionality to save to local
  899. * storage if this is current user.
  900. *
  901. * @param {...any} args
  902. * @returns {Promise}
  903. */
  904. }, {
  905. key: "save",
  906. value: function () {
  907. var _save = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
  908. var _len,
  909. args,
  910. _key4,
  911. current,
  912. _args2 = arguments;
  913. return _regeneratorRuntime().wrap(function _callee2$(_context2) {
  914. while (1) {
  915. switch (_context2.prev = _context2.next) {
  916. case 0:
  917. for (_len = _args2.length, args = new Array(_len), _key4 = 0; _key4 < _len; _key4++) {
  918. args[_key4] = _args2[_key4];
  919. }
  920. _context2.next = 3;
  921. return (0, _get2.default)((0, _getPrototypeOf2.default)(ParseUser.prototype), "save", this).apply(this, args);
  922. case 3:
  923. _context2.next = 5;
  924. return this.isCurrentAsync();
  925. case 5:
  926. current = _context2.sent;
  927. if (!current) {
  928. _context2.next = 8;
  929. break;
  930. }
  931. return _context2.abrupt("return", _CoreManager.default.getUserController().updateUserOnDisk(this));
  932. case 8:
  933. return _context2.abrupt("return", this);
  934. case 9:
  935. case "end":
  936. return _context2.stop();
  937. }
  938. }
  939. }, _callee2, this);
  940. }));
  941. function save() {
  942. return _save.apply(this, arguments);
  943. }
  944. return save;
  945. }()
  946. /**
  947. * Wrap the default destroy behavior with functionality that logs out
  948. * the current user when it is destroyed
  949. *
  950. * @param {...any} args
  951. * @returns {Parse.User}
  952. */
  953. }, {
  954. key: "destroy",
  955. value: function () {
  956. var _destroy = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
  957. var _len2,
  958. args,
  959. _key5,
  960. current,
  961. _args3 = arguments;
  962. return _regeneratorRuntime().wrap(function _callee3$(_context3) {
  963. while (1) {
  964. switch (_context3.prev = _context3.next) {
  965. case 0:
  966. for (_len2 = _args3.length, args = new Array(_len2), _key5 = 0; _key5 < _len2; _key5++) {
  967. args[_key5] = _args3[_key5];
  968. }
  969. _context3.next = 3;
  970. return (0, _get2.default)((0, _getPrototypeOf2.default)(ParseUser.prototype), "destroy", this).apply(this, args);
  971. case 3:
  972. _context3.next = 5;
  973. return this.isCurrentAsync();
  974. case 5:
  975. current = _context3.sent;
  976. if (!current) {
  977. _context3.next = 8;
  978. break;
  979. }
  980. return _context3.abrupt("return", _CoreManager.default.getUserController().removeUserFromDisk());
  981. case 8:
  982. return _context3.abrupt("return", this);
  983. case 9:
  984. case "end":
  985. return _context3.stop();
  986. }
  987. }
  988. }, _callee3, this);
  989. }));
  990. function destroy() {
  991. return _destroy.apply(this, arguments);
  992. }
  993. return destroy;
  994. }()
  995. /**
  996. * Wrap the default fetch behavior with functionality to save to local
  997. * storage if this is current user.
  998. *
  999. * @param {...any} args
  1000. * @returns {Parse.User}
  1001. */
  1002. }, {
  1003. key: "fetch",
  1004. value: function () {
  1005. var _fetch = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
  1006. var _len3,
  1007. args,
  1008. _key6,
  1009. current,
  1010. _args4 = arguments;
  1011. return _regeneratorRuntime().wrap(function _callee4$(_context4) {
  1012. while (1) {
  1013. switch (_context4.prev = _context4.next) {
  1014. case 0:
  1015. for (_len3 = _args4.length, args = new Array(_len3), _key6 = 0; _key6 < _len3; _key6++) {
  1016. args[_key6] = _args4[_key6];
  1017. }
  1018. _context4.next = 3;
  1019. return (0, _get2.default)((0, _getPrototypeOf2.default)(ParseUser.prototype), "fetch", this).apply(this, args);
  1020. case 3:
  1021. _context4.next = 5;
  1022. return this.isCurrentAsync();
  1023. case 5:
  1024. current = _context4.sent;
  1025. if (!current) {
  1026. _context4.next = 8;
  1027. break;
  1028. }
  1029. return _context4.abrupt("return", _CoreManager.default.getUserController().updateUserOnDisk(this));
  1030. case 8:
  1031. return _context4.abrupt("return", this);
  1032. case 9:
  1033. case "end":
  1034. return _context4.stop();
  1035. }
  1036. }
  1037. }, _callee4, this);
  1038. }));
  1039. function fetch() {
  1040. return _fetch.apply(this, arguments);
  1041. }
  1042. return fetch;
  1043. }()
  1044. /**
  1045. * Wrap the default fetchWithInclude behavior with functionality to save to local
  1046. * storage if this is current user.
  1047. *
  1048. * @param {...any} args
  1049. * @returns {Parse.User}
  1050. */
  1051. }, {
  1052. key: "fetchWithInclude",
  1053. value: function () {
  1054. var _fetchWithInclude = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
  1055. var _len4,
  1056. args,
  1057. _key7,
  1058. current,
  1059. _args5 = arguments;
  1060. return _regeneratorRuntime().wrap(function _callee5$(_context5) {
  1061. while (1) {
  1062. switch (_context5.prev = _context5.next) {
  1063. case 0:
  1064. for (_len4 = _args5.length, args = new Array(_len4), _key7 = 0; _key7 < _len4; _key7++) {
  1065. args[_key7] = _args5[_key7];
  1066. }
  1067. _context5.next = 3;
  1068. return (0, _get2.default)((0, _getPrototypeOf2.default)(ParseUser.prototype), "fetchWithInclude", this).apply(this, args);
  1069. case 3:
  1070. _context5.next = 5;
  1071. return this.isCurrentAsync();
  1072. case 5:
  1073. current = _context5.sent;
  1074. if (!current) {
  1075. _context5.next = 8;
  1076. break;
  1077. }
  1078. return _context5.abrupt("return", _CoreManager.default.getUserController().updateUserOnDisk(this));
  1079. case 8:
  1080. return _context5.abrupt("return", this);
  1081. case 9:
  1082. case "end":
  1083. return _context5.stop();
  1084. }
  1085. }
  1086. }, _callee5, this);
  1087. }));
  1088. function fetchWithInclude() {
  1089. return _fetchWithInclude.apply(this, arguments);
  1090. }
  1091. return fetchWithInclude;
  1092. }()
  1093. /**
  1094. * Verify whether a given password is the password of the current user.
  1095. *
  1096. * @param {string} password A password to be verified
  1097. * @param {object} options
  1098. * @returns {Promise} A promise that is fulfilled with a user
  1099. * when the password is correct.
  1100. */
  1101. }, {
  1102. key: "verifyPassword",
  1103. value: function verifyPassword(password
  1104. /*: string*/
  1105. , options
  1106. /*:: ?: RequestOptions*/
  1107. )
  1108. /*: Promise<ParseUser>*/
  1109. {
  1110. var username = this.getUsername() || '';
  1111. return ParseUser.verifyPassword(username, password, options);
  1112. }
  1113. }], [{
  1114. key: "readOnlyAttributes",
  1115. value: function readOnlyAttributes() {
  1116. return ['sessionToken'];
  1117. }
  1118. /**
  1119. * Adds functionality to the existing Parse.User class.
  1120. *
  1121. * @param {object} protoProps A set of properties to add to the prototype
  1122. * @param {object} classProps A set of static properties to add to the class
  1123. * @static
  1124. * @returns {Parse.User} The newly extended Parse.User class
  1125. */
  1126. }, {
  1127. key: "extend",
  1128. value: function extend(protoProps
  1129. /*: { [prop: string]: any }*/
  1130. , classProps
  1131. /*: { [prop: string]: any }*/
  1132. ) {
  1133. if (protoProps) {
  1134. for (var _prop in protoProps) {
  1135. if (_prop !== 'className') {
  1136. (0, _defineProperty.default)(ParseUser.prototype, _prop, {
  1137. value: protoProps[_prop],
  1138. enumerable: false,
  1139. writable: true,
  1140. configurable: true
  1141. });
  1142. }
  1143. }
  1144. }
  1145. if (classProps) {
  1146. for (var _prop2 in classProps) {
  1147. if (_prop2 !== 'className') {
  1148. (0, _defineProperty.default)(ParseUser, _prop2, {
  1149. value: classProps[_prop2],
  1150. enumerable: false,
  1151. writable: true,
  1152. configurable: true
  1153. });
  1154. }
  1155. }
  1156. }
  1157. return ParseUser;
  1158. }
  1159. /**
  1160. * Retrieves the currently logged in ParseUser with a valid session,
  1161. * either from memory or localStorage, if necessary.
  1162. *
  1163. * @static
  1164. * @returns {Parse.Object} The currently logged in Parse.User.
  1165. */
  1166. }, {
  1167. key: "current",
  1168. value: function current()
  1169. /*: ?ParseUser*/
  1170. {
  1171. if (!canUseCurrentUser) {
  1172. return null;
  1173. }
  1174. var controller = _CoreManager.default.getUserController();
  1175. return controller.currentUser();
  1176. }
  1177. /**
  1178. * Retrieves the currently logged in ParseUser from asynchronous Storage.
  1179. *
  1180. * @static
  1181. * @returns {Promise} A Promise that is resolved with the currently
  1182. * logged in Parse User
  1183. */
  1184. }, {
  1185. key: "currentAsync",
  1186. value: function currentAsync()
  1187. /*: Promise<?ParseUser>*/
  1188. {
  1189. if (!canUseCurrentUser) {
  1190. return _promise.default.resolve(null);
  1191. }
  1192. var controller = _CoreManager.default.getUserController();
  1193. return controller.currentUserAsync();
  1194. }
  1195. /**
  1196. * Signs up a new user with a username (or email) and password.
  1197. * This will create a new Parse.User on the server, and also persist the
  1198. * session in localStorage so that you can access the user using
  1199. * {@link #current}.
  1200. *
  1201. * @param {string} username The username (or email) to sign up with.
  1202. * @param {string} password The password to sign up with.
  1203. * @param {object} attrs Extra fields to set on the new user.
  1204. * @param {object} options
  1205. * @static
  1206. * @returns {Promise} A promise that is fulfilled with the user when
  1207. * the signup completes.
  1208. */
  1209. }, {
  1210. key: "signUp",
  1211. value: function signUp(username
  1212. /*: string*/
  1213. , password
  1214. /*: string*/
  1215. , attrs
  1216. /*: AttributeMap*/
  1217. , options
  1218. /*:: ?: FullOptions*/
  1219. ) {
  1220. attrs = attrs || {};
  1221. attrs.username = username;
  1222. attrs.password = password;
  1223. var user = new this(attrs);
  1224. return user.signUp({}, options);
  1225. }
  1226. /**
  1227. * Logs in a user with a username (or email) and password. On success, this
  1228. * saves the session to disk, so you can retrieve the currently logged in
  1229. * user using <code>current</code>.
  1230. *
  1231. * @param {string} username The username (or email) to log in with.
  1232. * @param {string} password The password to log in with.
  1233. * @param {object} options
  1234. * @static
  1235. * @returns {Promise} A promise that is fulfilled with the user when
  1236. * the login completes.
  1237. */
  1238. }, {
  1239. key: "logIn",
  1240. value: function logIn(username
  1241. /*: string*/
  1242. , password
  1243. /*: string*/
  1244. , options
  1245. /*:: ?: FullOptions*/
  1246. ) {
  1247. if (typeof username !== 'string') {
  1248. return _promise.default.reject(new _ParseError.default(_ParseError.default.OTHER_CAUSE, 'Username must be a string.'));
  1249. } else if (typeof password !== 'string') {
  1250. return _promise.default.reject(new _ParseError.default(_ParseError.default.OTHER_CAUSE, 'Password must be a string.'));
  1251. }
  1252. var user = new this();
  1253. user._finishFetch({
  1254. username: username,
  1255. password: password
  1256. });
  1257. return user.logIn(options);
  1258. }
  1259. /**
  1260. * Logs in a user with a session token. On success, this saves the session
  1261. * to disk, so you can retrieve the currently logged in user using
  1262. * <code>current</code>.
  1263. *
  1264. * @param {string} sessionToken The sessionToken to log in with.
  1265. * @param {object} options
  1266. * @static
  1267. * @returns {Promise} A promise that is fulfilled with the user when
  1268. * the login completes.
  1269. */
  1270. }, {
  1271. key: "become",
  1272. value: function become(sessionToken
  1273. /*: string*/
  1274. , options
  1275. /*:: ?: RequestOptions*/
  1276. ) {
  1277. if (!canUseCurrentUser) {
  1278. throw new Error('It is not memory-safe to become a user in a server environment');
  1279. }
  1280. options = options || {};
  1281. var becomeOptions
  1282. /*: RequestOptions*/
  1283. = {
  1284. sessionToken: sessionToken
  1285. };
  1286. if (options.hasOwnProperty('useMasterKey')) {
  1287. becomeOptions.useMasterKey = options.useMasterKey;
  1288. }
  1289. var controller = _CoreManager.default.getUserController();
  1290. var user = new this();
  1291. return controller.become(user, becomeOptions);
  1292. }
  1293. /**
  1294. * Retrieves a user with a session token.
  1295. *
  1296. * @param {string} sessionToken The sessionToken to get user with.
  1297. * @param {object} options
  1298. * @static
  1299. * @returns {Promise} A promise that is fulfilled with the user is fetched.
  1300. */
  1301. }, {
  1302. key: "me",
  1303. value: function me(sessionToken
  1304. /*: string*/
  1305. ) {
  1306. var options
  1307. /*:: ?: RequestOptions*/
  1308. = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  1309. var controller = _CoreManager.default.getUserController();
  1310. var meOptions
  1311. /*: RequestOptions*/
  1312. = {
  1313. sessionToken: sessionToken
  1314. };
  1315. if (options.useMasterKey) {
  1316. meOptions.useMasterKey = options.useMasterKey;
  1317. }
  1318. var user = new this();
  1319. return controller.me(user, meOptions);
  1320. }
  1321. /**
  1322. * Logs in a user with a session token. On success, this saves the session
  1323. * to disk, so you can retrieve the currently logged in user using
  1324. * <code>current</code>. If there is no session token the user will not logged in.
  1325. *
  1326. * @param {object} userJSON The JSON map of the User's data
  1327. * @static
  1328. * @returns {Promise} A promise that is fulfilled with the user when
  1329. * the login completes.
  1330. */
  1331. }, {
  1332. key: "hydrate",
  1333. value: function hydrate(userJSON
  1334. /*: AttributeMap*/
  1335. ) {
  1336. var controller = _CoreManager.default.getUserController();
  1337. var user = new this();
  1338. return controller.hydrate(user, userJSON);
  1339. }
  1340. /**
  1341. * Static version of {@link https://parseplatform.org/Parse-SDK-JS/api/master/Parse.User.html#linkWith linkWith}
  1342. *
  1343. * @param provider
  1344. * @param options
  1345. * @param saveOpts
  1346. * @static
  1347. * @returns {Promise}
  1348. */
  1349. }, {
  1350. key: "logInWith",
  1351. value: function logInWith(provider
  1352. /*: any*/
  1353. , options
  1354. /*: { authData?: AuthData }*/
  1355. , saveOpts
  1356. /*:: ?: FullOptions*/
  1357. )
  1358. /*: Promise<ParseUser>*/
  1359. {
  1360. var user = new this();
  1361. return user.linkWith(provider, options, saveOpts);
  1362. }
  1363. /**
  1364. * Logs out the currently logged in user session. This will remove the
  1365. * session from disk, log out of linked services, and future calls to
  1366. * <code>current</code> will return <code>null</code>.
  1367. *
  1368. * @param {object} options
  1369. * @static
  1370. * @returns {Promise} A promise that is resolved when the session is
  1371. * destroyed on the server.
  1372. */
  1373. }, {
  1374. key: "logOut",
  1375. value: function logOut() {
  1376. var options
  1377. /*: RequestOptions*/
  1378. = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  1379. var controller = _CoreManager.default.getUserController();
  1380. return controller.logOut(options);
  1381. }
  1382. /**
  1383. * Requests a password reset email to be sent to the specified email address
  1384. * associated with the user account. This email allows the user to securely
  1385. * reset their password on the Parse site.
  1386. *
  1387. * @param {string} email The email address associated with the user that
  1388. * forgot their password.
  1389. * @param {object} options
  1390. * @static
  1391. * @returns {Promise}
  1392. */
  1393. }, {
  1394. key: "requestPasswordReset",
  1395. value: function requestPasswordReset(email
  1396. /*: string*/
  1397. , options
  1398. /*:: ?: RequestOptions*/
  1399. ) {
  1400. options = options || {};
  1401. var requestOptions = {};
  1402. if (options.hasOwnProperty('useMasterKey')) {
  1403. requestOptions.useMasterKey = options.useMasterKey;
  1404. }
  1405. var controller = _CoreManager.default.getUserController();
  1406. return controller.requestPasswordReset(email, requestOptions);
  1407. }
  1408. /**
  1409. * Request an email verification.
  1410. *
  1411. * @param {string} email The email address associated with the user that
  1412. * needs to verify their email.
  1413. * @param {object} options
  1414. * @static
  1415. * @returns {Promise}
  1416. */
  1417. }, {
  1418. key: "requestEmailVerification",
  1419. value: function requestEmailVerification(email
  1420. /*: string*/
  1421. , options
  1422. /*:: ?: RequestOptions*/
  1423. ) {
  1424. options = options || {};
  1425. var requestOptions = {};
  1426. if (options.hasOwnProperty('useMasterKey')) {
  1427. requestOptions.useMasterKey = options.useMasterKey;
  1428. }
  1429. var controller = _CoreManager.default.getUserController();
  1430. return controller.requestEmailVerification(email, requestOptions);
  1431. }
  1432. /**
  1433. * Verify whether a given password is the password of the current user.
  1434. *
  1435. * @param {string} username A username to be used for identificaiton
  1436. * @param {string} password A password to be verified
  1437. * @param {object} options
  1438. * @static
  1439. * @returns {Promise} A promise that is fulfilled with a user
  1440. * when the password is correct.
  1441. */
  1442. }, {
  1443. key: "verifyPassword",
  1444. value: function verifyPassword(username
  1445. /*: string*/
  1446. , password
  1447. /*: string*/
  1448. , options
  1449. /*:: ?: RequestOptions*/
  1450. ) {
  1451. if (typeof username !== 'string') {
  1452. return _promise.default.reject(new _ParseError.default(_ParseError.default.OTHER_CAUSE, 'Username must be a string.'));
  1453. }
  1454. if (typeof password !== 'string') {
  1455. return _promise.default.reject(new _ParseError.default(_ParseError.default.OTHER_CAUSE, 'Password must be a string.'));
  1456. }
  1457. options = options || {};
  1458. var verificationOption = {};
  1459. if (options.hasOwnProperty('useMasterKey')) {
  1460. verificationOption.useMasterKey = options.useMasterKey;
  1461. }
  1462. var controller = _CoreManager.default.getUserController();
  1463. return controller.verifyPassword(username, password, verificationOption);
  1464. }
  1465. /**
  1466. * Allow someone to define a custom User class without className
  1467. * being rewritten to _User. The default behavior is to rewrite
  1468. * User to _User for legacy reasons. This allows developers to
  1469. * override that behavior.
  1470. *
  1471. * @param {boolean} isAllowed Whether or not to allow custom User class
  1472. * @static
  1473. */
  1474. }, {
  1475. key: "allowCustomUserClass",
  1476. value: function allowCustomUserClass(isAllowed
  1477. /*: boolean*/
  1478. ) {
  1479. _CoreManager.default.set('PERFORM_USER_REWRITE', !isAllowed);
  1480. }
  1481. /**
  1482. * Allows a legacy application to start using revocable sessions. If the
  1483. * current session token is not revocable, a request will be made for a new,
  1484. * revocable session.
  1485. * It is not necessary to call this method from cloud code unless you are
  1486. * handling user signup or login from the server side. In a cloud code call,
  1487. * this function will not attempt to upgrade the current token.
  1488. *
  1489. * @param {object} options
  1490. * @static
  1491. * @returns {Promise} A promise that is resolved when the process has
  1492. * completed. If a replacement session token is requested, the promise
  1493. * will be resolved after a new token has been fetched.
  1494. */
  1495. }, {
  1496. key: "enableRevocableSession",
  1497. value: function enableRevocableSession(options
  1498. /*:: ?: RequestOptions*/
  1499. ) {
  1500. options = options || {};
  1501. _CoreManager.default.set('FORCE_REVOCABLE_SESSION', true);
  1502. if (canUseCurrentUser) {
  1503. var current = ParseUser.current();
  1504. if (current) {
  1505. return current._upgradeToRevocableSession(options);
  1506. }
  1507. }
  1508. return _promise.default.resolve();
  1509. }
  1510. /**
  1511. * Enables the use of become or the current user in a server
  1512. * environment. These features are disabled by default, since they depend on
  1513. * global objects that are not memory-safe for most servers.
  1514. *
  1515. * @static
  1516. */
  1517. }, {
  1518. key: "enableUnsafeCurrentUser",
  1519. value: function enableUnsafeCurrentUser() {
  1520. canUseCurrentUser = true;
  1521. }
  1522. /**
  1523. * Disables the use of become or the current user in any environment.
  1524. * These features are disabled on servers by default, since they depend on
  1525. * global objects that are not memory-safe for most servers.
  1526. *
  1527. * @static
  1528. */
  1529. }, {
  1530. key: "disableUnsafeCurrentUser",
  1531. value: function disableUnsafeCurrentUser() {
  1532. canUseCurrentUser = false;
  1533. }
  1534. /**
  1535. * When registering users with {@link https://parseplatform.org/Parse-SDK-JS/api/master/Parse.User.html#linkWith linkWith} a basic auth provider
  1536. * is automatically created for you.
  1537. *
  1538. * For advanced authentication, you can register an Auth provider to
  1539. * implement custom authentication, deauthentication.
  1540. *
  1541. * @param provider
  1542. * @see {@link https://parseplatform.org/Parse-SDK-JS/api/master/AuthProvider.html AuthProvider}
  1543. * @see {@link https://docs.parseplatform.org/js/guide/#custom-authentication-module Custom Authentication Module}
  1544. * @static
  1545. */
  1546. }, {
  1547. key: "_registerAuthenticationProvider",
  1548. value: function _registerAuthenticationProvider(provider
  1549. /*: any*/
  1550. ) {
  1551. authProviders[provider.getAuthType()] = provider; // Synchronize the current user with the auth provider.
  1552. ParseUser.currentAsync().then(function (current) {
  1553. if (current) {
  1554. current._synchronizeAuthData(provider.getAuthType());
  1555. }
  1556. });
  1557. }
  1558. /**
  1559. * @param provider
  1560. * @param options
  1561. * @param saveOpts
  1562. * @deprecated since 2.9.0 see {@link https://parseplatform.org/Parse-SDK-JS/api/master/Parse.User.html#logInWith logInWith}
  1563. * @static
  1564. * @returns {Promise}
  1565. */
  1566. }, {
  1567. key: "_logInWith",
  1568. value: function _logInWith(provider
  1569. /*: any*/
  1570. , options
  1571. /*: { authData?: AuthData }*/
  1572. , saveOpts
  1573. /*:: ?: FullOptions*/
  1574. ) {
  1575. var user = new this();
  1576. return user.linkWith(provider, options, saveOpts);
  1577. }
  1578. }, {
  1579. key: "_clearCache",
  1580. value: function _clearCache() {
  1581. currentUserCache = null;
  1582. currentUserCacheMatchesDisk = false;
  1583. }
  1584. }, {
  1585. key: "_setCurrentUserCache",
  1586. value: function _setCurrentUserCache(user
  1587. /*: ParseUser*/
  1588. ) {
  1589. currentUserCache = user;
  1590. }
  1591. }]);
  1592. return ParseUser;
  1593. }(_ParseObject2.default);
  1594. _ParseObject2.default.registerSubclass('_User', ParseUser);
  1595. var DefaultController = {
  1596. updateUserOnDisk: function updateUserOnDisk(user) {
  1597. var path = _Storage.default.generatePath(CURRENT_USER_KEY);
  1598. var json = user.toJSON();
  1599. delete json.password;
  1600. json.className = '_User';
  1601. var userData = (0, _stringify.default)(json);
  1602. if (_CoreManager.default.get('ENCRYPTED_USER')) {
  1603. var crypto = _CoreManager.default.getCryptoController();
  1604. userData = crypto.encrypt(json, _CoreManager.default.get('ENCRYPTED_KEY'));
  1605. }
  1606. return _Storage.default.setItemAsync(path, userData).then(function () {
  1607. return user;
  1608. });
  1609. },
  1610. removeUserFromDisk: function removeUserFromDisk() {
  1611. var path = _Storage.default.generatePath(CURRENT_USER_KEY);
  1612. currentUserCacheMatchesDisk = true;
  1613. currentUserCache = null;
  1614. return _Storage.default.removeItemAsync(path);
  1615. },
  1616. setCurrentUser: function setCurrentUser(user) {
  1617. currentUserCache = user;
  1618. user._cleanupAuthData();
  1619. user._synchronizeAllAuthData();
  1620. return DefaultController.updateUserOnDisk(user);
  1621. },
  1622. currentUser: function currentUser()
  1623. /*: ?ParseUser*/
  1624. {
  1625. if (currentUserCache) {
  1626. return currentUserCache;
  1627. }
  1628. if (currentUserCacheMatchesDisk) {
  1629. return null;
  1630. }
  1631. if (_Storage.default.async()) {
  1632. throw new Error('Cannot call currentUser() when using a platform with an async ' + 'storage system. Call currentUserAsync() instead.');
  1633. }
  1634. var path = _Storage.default.generatePath(CURRENT_USER_KEY);
  1635. var userData = _Storage.default.getItem(path);
  1636. currentUserCacheMatchesDisk = true;
  1637. if (!userData) {
  1638. currentUserCache = null;
  1639. return null;
  1640. }
  1641. if (_CoreManager.default.get('ENCRYPTED_USER')) {
  1642. var crypto = _CoreManager.default.getCryptoController();
  1643. userData = crypto.decrypt(userData, _CoreManager.default.get('ENCRYPTED_KEY'));
  1644. }
  1645. userData = JSON.parse(userData);
  1646. if (!userData.className) {
  1647. userData.className = '_User';
  1648. }
  1649. if (userData._id) {
  1650. if (userData.objectId !== userData._id) {
  1651. userData.objectId = userData._id;
  1652. }
  1653. delete userData._id;
  1654. }
  1655. if (userData._sessionToken) {
  1656. userData.sessionToken = userData._sessionToken;
  1657. delete userData._sessionToken;
  1658. }
  1659. var current = _ParseObject2.default.fromJSON(userData);
  1660. currentUserCache = current;
  1661. current._synchronizeAllAuthData();
  1662. return current;
  1663. },
  1664. currentUserAsync: function currentUserAsync()
  1665. /*: Promise<?ParseUser>*/
  1666. {
  1667. if (currentUserCache) {
  1668. return _promise.default.resolve(currentUserCache);
  1669. }
  1670. if (currentUserCacheMatchesDisk) {
  1671. return _promise.default.resolve(null);
  1672. }
  1673. var path = _Storage.default.generatePath(CURRENT_USER_KEY);
  1674. return _Storage.default.getItemAsync(path).then(function (userData) {
  1675. currentUserCacheMatchesDisk = true;
  1676. if (!userData) {
  1677. currentUserCache = null;
  1678. return _promise.default.resolve(null);
  1679. }
  1680. if (_CoreManager.default.get('ENCRYPTED_USER')) {
  1681. var crypto = _CoreManager.default.getCryptoController();
  1682. userData = crypto.decrypt(userData.toString(), _CoreManager.default.get('ENCRYPTED_KEY'));
  1683. }
  1684. userData = JSON.parse(userData);
  1685. if (!userData.className) {
  1686. userData.className = '_User';
  1687. }
  1688. if (userData._id) {
  1689. if (userData.objectId !== userData._id) {
  1690. userData.objectId = userData._id;
  1691. }
  1692. delete userData._id;
  1693. }
  1694. if (userData._sessionToken) {
  1695. userData.sessionToken = userData._sessionToken;
  1696. delete userData._sessionToken;
  1697. }
  1698. var current = _ParseObject2.default.fromJSON(userData);
  1699. currentUserCache = current;
  1700. current._synchronizeAllAuthData();
  1701. return _promise.default.resolve(current);
  1702. });
  1703. },
  1704. signUp: function signUp(user
  1705. /*: ParseUser*/
  1706. , attrs
  1707. /*: AttributeMap*/
  1708. , options
  1709. /*: RequestOptions*/
  1710. )
  1711. /*: Promise<ParseUser>*/
  1712. {
  1713. var username = attrs && attrs.username || user.get('username');
  1714. var password = attrs && attrs.password || user.get('password');
  1715. if (!username || !username.length) {
  1716. return _promise.default.reject(new _ParseError.default(_ParseError.default.OTHER_CAUSE, 'Cannot sign up user with an empty username.'));
  1717. }
  1718. if (!password || !password.length) {
  1719. return _promise.default.reject(new _ParseError.default(_ParseError.default.OTHER_CAUSE, 'Cannot sign up user with an empty password.'));
  1720. }
  1721. return user.save(attrs, options).then(function () {
  1722. // Clear the password field
  1723. user._finishFetch({
  1724. password: undefined
  1725. });
  1726. if (canUseCurrentUser) {
  1727. return DefaultController.setCurrentUser(user);
  1728. }
  1729. return user;
  1730. });
  1731. },
  1732. logIn: function logIn(user
  1733. /*: ParseUser*/
  1734. , options
  1735. /*: RequestOptions*/
  1736. )
  1737. /*: Promise<ParseUser>*/
  1738. {
  1739. var RESTController = _CoreManager.default.getRESTController();
  1740. var stateController = _CoreManager.default.getObjectStateController();
  1741. var auth = {
  1742. username: user.get('username'),
  1743. password: user.get('password')
  1744. };
  1745. return RESTController.request(options.usePost ? 'POST' : 'GET', 'login', auth, options).then(function (response) {
  1746. user._migrateId(response.objectId);
  1747. user._setExisted(true);
  1748. stateController.setPendingOp(user._getStateIdentifier(), 'username', undefined);
  1749. stateController.setPendingOp(user._getStateIdentifier(), 'password', undefined);
  1750. response.password = undefined;
  1751. user._finishFetch(response);
  1752. if (!canUseCurrentUser) {
  1753. // We can't set the current user, so just return the one we logged in
  1754. return _promise.default.resolve(user);
  1755. }
  1756. return DefaultController.setCurrentUser(user);
  1757. });
  1758. },
  1759. become: function become(user
  1760. /*: ParseUser*/
  1761. , options
  1762. /*: RequestOptions*/
  1763. )
  1764. /*: Promise<ParseUser>*/
  1765. {
  1766. var RESTController = _CoreManager.default.getRESTController();
  1767. return RESTController.request('GET', 'users/me', {}, options).then(function (response) {
  1768. user._finishFetch(response);
  1769. user._setExisted(true);
  1770. return DefaultController.setCurrentUser(user);
  1771. });
  1772. },
  1773. hydrate: function hydrate(user
  1774. /*: ParseUser*/
  1775. , userJSON
  1776. /*: AttributeMap*/
  1777. )
  1778. /*: Promise<ParseUser>*/
  1779. {
  1780. user._finishFetch(userJSON);
  1781. user._setExisted(true);
  1782. if (userJSON.sessionToken && canUseCurrentUser) {
  1783. return DefaultController.setCurrentUser(user);
  1784. } else {
  1785. return _promise.default.resolve(user);
  1786. }
  1787. },
  1788. me: function me(user
  1789. /*: ParseUser*/
  1790. , options
  1791. /*: RequestOptions*/
  1792. )
  1793. /*: Promise<ParseUser>*/
  1794. {
  1795. var RESTController = _CoreManager.default.getRESTController();
  1796. return RESTController.request('GET', 'users/me', {}, options).then(function (response) {
  1797. user._finishFetch(response);
  1798. user._setExisted(true);
  1799. return user;
  1800. });
  1801. },
  1802. logOut: function logOut(options
  1803. /*: RequestOptions*/
  1804. )
  1805. /*: Promise<ParseUser>*/
  1806. {
  1807. var RESTController = _CoreManager.default.getRESTController();
  1808. if (options.sessionToken) {
  1809. return RESTController.request('POST', 'logout', {}, options);
  1810. }
  1811. return DefaultController.currentUserAsync().then(function (currentUser) {
  1812. var path = _Storage.default.generatePath(CURRENT_USER_KEY);
  1813. var promise = _Storage.default.removeItemAsync(path);
  1814. if (currentUser !== null) {
  1815. var currentSession = currentUser.getSessionToken();
  1816. if (currentSession && (0, _isRevocableSession.default)(currentSession)) {
  1817. promise = promise.then(function () {
  1818. return RESTController.request('POST', 'logout', {}, {
  1819. sessionToken: currentSession
  1820. });
  1821. });
  1822. }
  1823. currentUser._logOutWithAll();
  1824. currentUser._finishFetch({
  1825. sessionToken: undefined
  1826. });
  1827. }
  1828. currentUserCacheMatchesDisk = true;
  1829. currentUserCache = null;
  1830. return promise;
  1831. });
  1832. },
  1833. requestPasswordReset: function requestPasswordReset(email
  1834. /*: string*/
  1835. , options
  1836. /*: RequestOptions*/
  1837. ) {
  1838. var RESTController = _CoreManager.default.getRESTController();
  1839. return RESTController.request('POST', 'requestPasswordReset', {
  1840. email: email
  1841. }, options);
  1842. },
  1843. upgradeToRevocableSession: function upgradeToRevocableSession(user
  1844. /*: ParseUser*/
  1845. , options
  1846. /*: RequestOptions*/
  1847. ) {
  1848. return (0, _asyncToGenerator2.default)( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
  1849. var token, RESTController, result, session, current;
  1850. return _regeneratorRuntime().wrap(function _callee6$(_context6) {
  1851. while (1) {
  1852. switch (_context6.prev = _context6.next) {
  1853. case 0:
  1854. token = user.getSessionToken();
  1855. if (token) {
  1856. _context6.next = 3;
  1857. break;
  1858. }
  1859. return _context6.abrupt("return", _promise.default.reject(new _ParseError.default(_ParseError.default.SESSION_MISSING, 'Cannot upgrade a user with no session token')));
  1860. case 3:
  1861. options.sessionToken = token;
  1862. RESTController = _CoreManager.default.getRESTController();
  1863. _context6.next = 7;
  1864. return RESTController.request('POST', 'upgradeToRevocableSession', {}, options);
  1865. case 7:
  1866. result = _context6.sent;
  1867. session = new _ParseSession.default();
  1868. session._finishFetch(result);
  1869. user._finishFetch({
  1870. sessionToken: session.getSessionToken()
  1871. });
  1872. _context6.next = 13;
  1873. return user.isCurrentAsync();
  1874. case 13:
  1875. current = _context6.sent;
  1876. if (!current) {
  1877. _context6.next = 16;
  1878. break;
  1879. }
  1880. return _context6.abrupt("return", DefaultController.setCurrentUser(user));
  1881. case 16:
  1882. return _context6.abrupt("return", _promise.default.resolve(user));
  1883. case 17:
  1884. case "end":
  1885. return _context6.stop();
  1886. }
  1887. }
  1888. }, _callee6);
  1889. }))();
  1890. },
  1891. linkWith: function linkWith(user
  1892. /*: ParseUser*/
  1893. , authData
  1894. /*: AuthData*/
  1895. , options
  1896. /*: FullOptions*/
  1897. ) {
  1898. return user.save({
  1899. authData: authData
  1900. }, options).then(function () {
  1901. if (canUseCurrentUser) {
  1902. return DefaultController.setCurrentUser(user);
  1903. }
  1904. return user;
  1905. });
  1906. },
  1907. verifyPassword: function verifyPassword(username
  1908. /*: string*/
  1909. , password
  1910. /*: string*/
  1911. , options
  1912. /*: RequestOptions*/
  1913. ) {
  1914. var RESTController = _CoreManager.default.getRESTController();
  1915. return RESTController.request('GET', 'verifyPassword', {
  1916. username: username,
  1917. password: password
  1918. }, options);
  1919. },
  1920. requestEmailVerification: function requestEmailVerification(email
  1921. /*: string*/
  1922. , options
  1923. /*: RequestOptions*/
  1924. ) {
  1925. var RESTController = _CoreManager.default.getRESTController();
  1926. return RESTController.request('POST', 'verificationEmailRequest', {
  1927. email: email
  1928. }, options);
  1929. }
  1930. };
  1931. _CoreManager.default.setUserController(DefaultController);
  1932. var _default = ParseUser;
  1933. exports.default = _default;