{"ast":null,"code":"import _toConsumableArray from \"@babel/runtime/helpers/toConsumableArray\";\nimport _defineProperty from \"@babel/runtime/helpers/defineProperty\";\nimport _objectWithoutProperties from \"@babel/runtime/helpers/objectWithoutProperties\";\nvar _excluded = [\"web\"];\n\nfunction _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== \"undefined\" && o[Symbol.iterator] || o[\"@@iterator\"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === \"number\") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError(\"Invalid attempt to iterate non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\"); }\n\nfunction _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === \"string\") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === \"Object\" && o.constructor) n = o.constructor.name; if (n === \"Map\" || n === \"Set\") return Array.from(o); if (n === \"Arguments\" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }\n\nfunction _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }\n\nimport _regeneratorRuntime from \"@babel/runtime/regenerator\";\n\nfunction ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }\n\nfunction _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }\n\nimport * as badgin from 'badgin';\nimport { v4 as uuidv4 } from 'uuid';\nimport { guardPermission, getExponentPushTokenAsync as _getExponentPushTokenAsync, getDevicePushTokenAsync as _getDevicePushTokenAsync } from \"./ExponentNotificationsHelper.web\";\nimport \"./ExponentNotifications.fx.web\";\nvar currentBadgeNumber = 0;\n\nfunction transformLocalNotification(notification, tag) {\n  var _notification$web = notification.web,\n      web = _notification$web === void 0 ? {} : _notification$web,\n      abstractNotification = _objectWithoutProperties(notification, _excluded);\n\n  tag = web.tag || tag;\n\n  var nativeNotification = _objectSpread(_objectSpread(_objectSpread({}, abstractNotification), {}, {\n    tag: tag\n  }, web), {}, {\n    _isLocal: true\n  });\n\n  return [nativeNotification.title, nativeNotification];\n}\n\nfunction getRegistrationAsync() {\n  var registration;\n  return _regeneratorRuntime.async(function getRegistrationAsync$(_context) {\n    while (1) {\n      switch (_context.prev = _context.next) {\n        case 0:\n          guardPermission();\n          _context.next = 3;\n          return _regeneratorRuntime.awrap(navigator.serviceWorker.getRegistration());\n\n        case 3:\n          registration = _context.sent;\n\n          if (registration) {\n            _context.next = 6;\n            break;\n          }\n\n          throw new Error('Failed to get notification registration!');\n\n        case 6:\n          return _context.abrupt(\"return\", registration);\n\n        case 7:\n        case \"end\":\n          return _context.stop();\n      }\n    }\n  }, null, null, null, Promise);\n}\n\nfunction getNotificationsAsync(tag) {\n  var registration, notifications;\n  return _regeneratorRuntime.async(function getNotificationsAsync$(_context2) {\n    while (1) {\n      switch (_context2.prev = _context2.next) {\n        case 0:\n          _context2.next = 2;\n          return _regeneratorRuntime.awrap(getRegistrationAsync());\n\n        case 2:\n          registration = _context2.sent;\n          _context2.next = 5;\n          return _regeneratorRuntime.awrap(registration.getNotifications(tag ? {\n            tag: tag\n          } : undefined));\n\n        case 5:\n          notifications = _context2.sent;\n          return _context2.abrupt(\"return\", notifications);\n\n        case 7:\n        case \"end\":\n          return _context2.stop();\n      }\n    }\n  }, null, null, null, Promise);\n}\n\nexport default {\n  presentLocalNotification: function presentLocalNotification(notification) {\n    var registration, tag;\n    return _regeneratorRuntime.async(function presentLocalNotification$(_context3) {\n      while (1) {\n        switch (_context3.prev = _context3.next) {\n          case 0:\n            _context3.next = 2;\n            return _regeneratorRuntime.awrap(getRegistrationAsync());\n\n          case 2:\n            registration = _context3.sent;\n            tag = uuidv4();\n            registration.showNotification.apply(registration, _toConsumableArray(transformLocalNotification(notification, tag)));\n            return _context3.abrupt(\"return\", tag);\n\n          case 6:\n          case \"end\":\n            return _context3.stop();\n        }\n      }\n    }, null, null, null, Promise);\n  },\n  scheduleLocalNotification: function scheduleLocalNotification(notification) {\n    var options,\n        registration,\n        tag,\n        intervalMs,\n        _args4 = arguments;\n    return _regeneratorRuntime.async(function scheduleLocalNotification$(_context4) {\n      while (1) {\n        switch (_context4.prev = _context4.next) {\n          case 0:\n            options = _args4.length > 1 && _args4[1] !== undefined ? _args4[1] : {};\n\n            if (!options.intervalMs) {\n              _context4.next = 10;\n              break;\n            }\n\n            _context4.next = 4;\n            return _regeneratorRuntime.awrap(getRegistrationAsync());\n\n          case 4:\n            registration = _context4.sent;\n            tag = uuidv4();\n            setTimeout(function () {\n              registration.showNotification.apply(registration, _toConsumableArray(transformLocalNotification(notification, tag)));\n            }, options.intervalMs);\n            return _context4.abrupt(\"return\", tag);\n\n          case 10:\n            if (!options.time) {\n              _context4.next = 15;\n              break;\n            }\n\n            intervalMs = options.time - Date.now();\n\n            if (!(intervalMs < 0)) {\n              _context4.next = 14;\n              break;\n            }\n\n            throw new Error('Expo.Notifications.scheduleLocalNotification(): options.time must be some time in the future.');\n\n          case 14:\n            return _context4.abrupt(\"return\", this.scheduleLocalNotification(notification, {\n              intervalMs: intervalMs\n            }));\n\n          case 15:\n            throw new Error(\"Expo.Notifications.scheduleLocalNotification() options \" + JSON.stringify(options, null, 2) + \" are not supported yet.\");\n\n          case 16:\n          case \"end\":\n            return _context4.stop();\n        }\n      }\n    }, null, this, null, Promise);\n  },\n  dismissNotification: function dismissNotification(notificationId) {\n    var notifications, _iterator, _step, notification;\n\n    return _regeneratorRuntime.async(function dismissNotification$(_context5) {\n      while (1) {\n        switch (_context5.prev = _context5.next) {\n          case 0:\n            _context5.next = 2;\n            return _regeneratorRuntime.awrap(getNotificationsAsync(notificationId));\n\n          case 2:\n            notifications = _context5.sent;\n\n            for (_iterator = _createForOfIteratorHelperLoose(notifications); !(_step = _iterator()).done;) {\n              notification = _step.value;\n              notification.close();\n            }\n\n          case 4:\n          case \"end\":\n            return _context5.stop();\n        }\n      }\n    }, null, null, null, Promise);\n  },\n  dismissAllNotifications: function dismissAllNotifications() {\n    return _regeneratorRuntime.async(function dismissAllNotifications$(_context6) {\n      while (1) {\n        switch (_context6.prev = _context6.next) {\n          case 0:\n            this.dismissNotification();\n\n          case 1:\n          case \"end\":\n            return _context6.stop();\n        }\n      }\n    }, null, this, null, Promise);\n  },\n  cancelScheduledNotificationAsync: function cancelScheduledNotificationAsync(notificationId) {\n    return _regeneratorRuntime.async(function cancelScheduledNotificationAsync$(_context7) {\n      while (1) {\n        switch (_context7.prev = _context7.next) {\n          case 0:\n            this.dismissNotification(notificationId);\n\n          case 1:\n          case \"end\":\n            return _context7.stop();\n        }\n      }\n    }, null, this, null, Promise);\n  },\n  cancelAllScheduledNotificationsAsync: function cancelAllScheduledNotificationsAsync() {\n    return _regeneratorRuntime.async(function cancelAllScheduledNotificationsAsync$(_context8) {\n      while (1) {\n        switch (_context8.prev = _context8.next) {\n          case 0:\n            this.dismissNotification();\n\n          case 1:\n          case \"end\":\n            return _context8.stop();\n        }\n      }\n    }, null, this, null, Promise);\n  },\n  getExponentPushTokenAsync: function getExponentPushTokenAsync() {\n    return _regeneratorRuntime.async(function getExponentPushTokenAsync$(_context9) {\n      while (1) {\n        switch (_context9.prev = _context9.next) {\n          case 0:\n            _context9.next = 2;\n            return _regeneratorRuntime.awrap(_getExponentPushTokenAsync());\n\n          case 2:\n            return _context9.abrupt(\"return\", _context9.sent);\n\n          case 3:\n          case \"end\":\n            return _context9.stop();\n        }\n      }\n    }, null, null, null, Promise);\n  },\n  getDevicePushTokenAsync: function getDevicePushTokenAsync() {\n    return _regeneratorRuntime.async(function getDevicePushTokenAsync$(_context10) {\n      while (1) {\n        switch (_context10.prev = _context10.next) {\n          case 0:\n            _context10.next = 2;\n            return _regeneratorRuntime.awrap(_getDevicePushTokenAsync());\n\n          case 2:\n            return _context10.abrupt(\"return\", _context10.sent);\n\n          case 3:\n          case \"end\":\n            return _context10.stop();\n        }\n      }\n    }, null, null, null, Promise);\n  },\n  getBadgeNumberAsync: function getBadgeNumberAsync() {\n    return _regeneratorRuntime.async(function getBadgeNumberAsync$(_context11) {\n      while (1) {\n        switch (_context11.prev = _context11.next) {\n          case 0:\n            return _context11.abrupt(\"return\", currentBadgeNumber);\n\n          case 1:\n          case \"end\":\n            return _context11.stop();\n        }\n      }\n    }, null, null, null, Promise);\n  },\n  setBadgeNumberAsync: function setBadgeNumberAsync(badgeNumber) {\n    return _regeneratorRuntime.async(function setBadgeNumberAsync$(_context12) {\n      while (1) {\n        switch (_context12.prev = _context12.next) {\n          case 0:\n            currentBadgeNumber = badgeNumber;\n            badgin.set(badgeNumber);\n\n          case 2:\n          case \"end\":\n            return _context12.stop();\n        }\n      }\n    }, null, null, null, Promise);\n  }\n};","map":{"version":3,"sources":["../../src/Notifications/ExponentNotifications.web.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,OAAO,KAAK,MAAZ,MAAwB,QAAxB;AACA,SAAS,EAAE,IAAI,MAAf,QAA6B,MAA7B;AAEA,SACE,eADF,EAEE,yBAAyB,IAAzB,0BAFF,EAGE,uBAAuB,IAAvB,wBAHF;AAQA;AAEA,IAAI,kBAAkB,GAAG,CAAzB;;AAEA,SAAS,0BAAT,CACE,YADF,EAE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AA0C;AAA/B,cAAA,YAA+B;AACxC,cAAA,YAAY,CAAC,KAAb;AACD;;AA9CU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAgDP,EAAA,uBAhDO;AAAA;AAAA;AAAA;AAAA;AAiDX,iBAAK,mBAAL;;AAjDW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAmDP,EAAA,gCAnDO,4CAmD0B,cAnD1B;AAAA;AAAA;AAAA;AAAA;AAoDX,iBAAK,mBAAL,CAAyB,cAAzB;;AApDW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAsDP,EAAA,oCAtDO;AAAA;AAAA;AAAA;AAAA;AAuDX,iBAAK,mBAAL;;AAvDW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA0DP,EAAA,yBA1DO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,6CA2DE,0BAAyB,EA3D3B;;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA8DP,EAAA,uBA9DO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,6CA+DE,wBAAuB,EA/DzB;;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkEP,EAAA,mBAlEO;AAAA;AAAA;AAAA;AAAA;AAAA,+CAmEJ,kBAnEI;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAsEP,EAAA,mBAtEO,+BAsEa,WAtEb;AAAA;AAAA;AAAA;AAAA;AAuEX,YAAA,kBAAkB,GAAG,WAArB;AACA,YAAA,MAAM,CAAC,GAAP,CAAW,WAAX;;AAxEW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAAf","sourcesContent":["import * as badgin from 'badgin';\nimport { v4 as uuidv4 } from 'uuid';\n\nimport {\n  guardPermission,\n  getExponentPushTokenAsync,\n  getDevicePushTokenAsync,\n} from './ExponentNotificationsHelper.web';\nimport { LocalNotification, LocalNotificationId } from './Notifications.types';\n\n// Register `message`'s event listener (side-effect)\nimport './ExponentNotifications.fx.web';\n\nlet currentBadgeNumber = 0;\n\nfunction transformLocalNotification(\n  notification: LocalNotification,\n  tag: string\n): [string, NotificationOptions] {\n  const { web = {}, ...abstractNotification } = notification;\n  tag = web.tag || tag;\n  const nativeNotification = {\n    ...abstractNotification,\n    tag,\n    ...web,\n    // Show that this notification is a local notification\n    _isLocal: true,\n  };\n  return [nativeNotification.title, nativeNotification];\n}\n\nasync function getRegistrationAsync(): Promise<ServiceWorkerRegistration> {\n  guardPermission();\n  const registration = await navigator.serviceWorker.getRegistration();\n  if (!registration) {\n    throw new Error('Failed to get notification registration!');\n  }\n  return registration;\n}\n\nasync function getNotificationsAsync(tag?: string): Promise<Notification[]> {\n  const registration = await getRegistrationAsync();\n  const notifications = await registration.getNotifications(tag ? { tag } : undefined);\n  return notifications;\n}\n\nexport default {\n  async presentLocalNotification(notification: LocalNotification): Promise<LocalNotificationId> {\n    const registration = await getRegistrationAsync();\n    const tag = uuidv4();\n    registration.showNotification(...transformLocalNotification(notification, tag));\n    return tag;\n  },\n  async scheduleLocalNotification(\n    notification: any,\n    options: {\n      time?: Date | number;\n      repeat?: 'minute' | 'hour' | 'day' | 'week' | 'month' | 'year';\n      intervalMs?: number;\n    } = {}\n  ): Promise<string> {\n    if (options.intervalMs) {\n      const registration = await getRegistrationAsync();\n      const tag = uuidv4();\n      setTimeout(() => {\n        registration.showNotification(...transformLocalNotification(notification, tag));\n      }, options.intervalMs);\n      return tag;\n    } else if (options.time) {\n      const intervalMs = (options.time as number) - Date.now();\n      if (intervalMs < 0) {\n        throw new Error(\n          'Expo.Notifications.scheduleLocalNotification(): options.time must be some time in the future.'\n        );\n      }\n      return this.scheduleLocalNotification(notification, {\n        intervalMs,\n      });\n    }\n    throw new Error(\n      `Expo.Notifications.scheduleLocalNotification() options ${JSON.stringify(\n        options,\n        null,\n        2\n      )} are not supported yet.`\n    );\n  },\n\n  async dismissNotification(notificationId?: string): Promise<void> {\n    const notifications = await getNotificationsAsync(notificationId);\n    for (const notification of notifications) {\n      notification.close();\n    }\n  },\n  async dismissAllNotifications(): Promise<void> {\n    this.dismissNotification();\n  },\n  async cancelScheduledNotificationAsync(notificationId: string): Promise<void> {\n    this.dismissNotification(notificationId);\n  },\n  async cancelAllScheduledNotificationsAsync(): Promise<void> {\n    this.dismissNotification();\n  },\n\n  async getExponentPushTokenAsync(): Promise<string> {\n    return await getExponentPushTokenAsync();\n  },\n\n  async getDevicePushTokenAsync(): Promise<{ type: string; data: object }> {\n    return await getDevicePushTokenAsync();\n  },\n\n  async getBadgeNumberAsync(): Promise<number> {\n    return currentBadgeNumber;\n  },\n\n  async setBadgeNumberAsync(badgeNumber: number): Promise<void> {\n    currentBadgeNumber = badgeNumber;\n    badgin.set(badgeNumber);\n  },\n};\n"],"sourceRoot":""},"metadata":{},"sourceType":"module"}