InstallationController.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
  3. var _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/promise"));
  4. var _Storage = _interopRequireDefault(require("./Storage"));
  5. /**
  6. * Copyright (c) 2015-present, Parse, LLC.
  7. * All rights reserved.
  8. *
  9. * This source code is licensed under the BSD-style license found in the
  10. * LICENSE file in the root directory of this source tree. An additional grant
  11. * of patent rights can be found in the PATENTS file in the same directory.
  12. *
  13. * @flow
  14. */
  15. var _require = require('uuid'),
  16. uuidv4 = _require.v4;
  17. var iidCache = null;
  18. var InstallationController = {
  19. currentInstallationId: function ()
  20. /*: Promise<string>*/
  21. {
  22. if (typeof iidCache === 'string') {
  23. return _promise.default.resolve(iidCache);
  24. }
  25. var path = _Storage.default.generatePath('installationId');
  26. return _Storage.default.getItemAsync(path).then(function (iid) {
  27. if (!iid) {
  28. iid = uuidv4();
  29. return _Storage.default.setItemAsync(path, iid).then(function () {
  30. iidCache = iid;
  31. return iid;
  32. });
  33. }
  34. iidCache = iid;
  35. return iid;
  36. });
  37. },
  38. _clearCache: function () {
  39. iidCache = null;
  40. },
  41. _setInstallationIdCache: function (iid
  42. /*: string*/
  43. ) {
  44. iidCache = iid;
  45. }
  46. };
  47. module.exports = InstallationController;