@aws-amplify/notifications 1.0.25 → 1.0.26-unstable.1b5840e.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (208) hide show
  1. package/lib/InAppMessaging/InAppMessaging.d.ts +10 -8
  2. package/lib/InAppMessaging/InAppMessaging.js +9 -11
  3. package/lib/InAppMessaging/InAppMessaging.js.map +1 -1
  4. package/lib/InAppMessaging/Providers/AWSPinpointProvider/index.d.ts +5 -25
  5. package/lib/InAppMessaging/Providers/AWSPinpointProvider/index.js +37 -252
  6. package/lib/InAppMessaging/Providers/AWSPinpointProvider/index.js.map +1 -1
  7. package/lib/InAppMessaging/Providers/AWSPinpointProvider/types.d.ts +0 -9
  8. package/lib/InAppMessaging/Providers/AWSPinpointProvider/types.js.map +1 -1
  9. package/lib/InAppMessaging/Providers/AWSPinpointProvider/utils.js +3 -9
  10. package/lib/InAppMessaging/Providers/AWSPinpointProvider/utils.js.map +1 -1
  11. package/lib/InAppMessaging/index.d.ts +1 -3
  12. package/lib/InAppMessaging/index.js +0 -2
  13. package/lib/InAppMessaging/index.js.map +1 -1
  14. package/lib/InAppMessaging/types.d.ts +30 -42
  15. package/lib/InAppMessaging/types.js +2 -0
  16. package/lib/InAppMessaging/types.js.map +1 -1
  17. package/lib/Notifications.d.ts +6 -2
  18. package/lib/Notifications.js +45 -0
  19. package/lib/Notifications.js.map +1 -1
  20. package/lib/PushNotification/NotEnabledError.d.ts +3 -0
  21. package/lib/PushNotification/NotEnabledError.js +16 -0
  22. package/lib/PushNotification/NotEnabledError.js.map +1 -0
  23. package/lib/PushNotification/Platform/index.d.ts +2 -0
  24. package/lib/PushNotification/Platform/index.js +26 -0
  25. package/lib/PushNotification/Platform/index.js.map +1 -0
  26. package/lib/PushNotification/Platform/index.native.d.ts +2 -0
  27. package/lib/PushNotification/Platform/index.native.js +8 -0
  28. package/lib/PushNotification/Platform/index.native.js.map +1 -0
  29. package/lib/PushNotification/Platform/types.d.ts +5 -0
  30. package/lib/PushNotification/Platform/types.js +5 -0
  31. package/lib/PushNotification/Platform/types.js.map +1 -0
  32. package/lib/PushNotification/PlatformNotSupportedError.d.ts +3 -0
  33. package/lib/PushNotification/PlatformNotSupportedError.js +16 -0
  34. package/lib/PushNotification/PlatformNotSupportedError.js.map +1 -0
  35. package/lib/PushNotification/Providers/AWSPinpointProvider/index.d.ts +15 -0
  36. package/lib/PushNotification/Providers/AWSPinpointProvider/index.js +115 -0
  37. package/lib/PushNotification/Providers/AWSPinpointProvider/index.js.map +1 -0
  38. package/lib/PushNotification/Providers/AWSPinpointProvider/types.d.ts +9 -0
  39. package/lib/PushNotification/Providers/AWSPinpointProvider/types.js +16 -0
  40. package/lib/PushNotification/Providers/AWSPinpointProvider/types.js.map +1 -0
  41. package/lib/PushNotification/Providers/AWSPinpointProvider/utils.d.ts +7 -0
  42. package/lib/PushNotification/Providers/AWSPinpointProvider/utils.js +58 -0
  43. package/lib/PushNotification/Providers/AWSPinpointProvider/utils.js.map +1 -0
  44. package/lib/PushNotification/Providers/index.d.ts +1 -0
  45. package/lib/PushNotification/Providers/index.js +7 -0
  46. package/lib/PushNotification/Providers/index.js.map +1 -0
  47. package/lib/PushNotification/PushNotification.d.ts +39 -0
  48. package/lib/PushNotification/PushNotification.js +91 -0
  49. package/lib/PushNotification/PushNotification.js.map +1 -0
  50. package/lib/PushNotification/PushNotification.native.d.ts +63 -0
  51. package/lib/PushNotification/PushNotification.native.js +327 -0
  52. package/lib/PushNotification/PushNotification.native.js.map +1 -0
  53. package/lib/PushNotification/index.d.ts +2 -0
  54. package/lib/PushNotification/index.js +9 -0
  55. package/lib/PushNotification/index.js.map +1 -0
  56. package/lib/PushNotification/types.d.ts +77 -0
  57. package/lib/PushNotification/types.js +12 -0
  58. package/lib/PushNotification/types.js.map +1 -0
  59. package/lib/PushNotification/utils.d.ts +3 -0
  60. package/lib/PushNotification/utils.js +81 -0
  61. package/lib/PushNotification/utils.js.map +1 -0
  62. package/lib/common/AWSPinpointProviderCommon/index.d.ts +34 -0
  63. package/lib/common/AWSPinpointProviderCommon/index.js +281 -0
  64. package/lib/common/AWSPinpointProviderCommon/index.js.map +1 -0
  65. package/lib/common/AWSPinpointProviderCommon/types.d.ts +9 -0
  66. package/lib/common/AWSPinpointProviderCommon/types.js +5 -0
  67. package/lib/common/AWSPinpointProviderCommon/types.js.map +1 -0
  68. package/lib/common/constants.d.ts +1 -0
  69. package/lib/common/constants.js +6 -0
  70. package/lib/common/constants.js.map +1 -0
  71. package/lib/common/eventListeners/index.d.ts +4 -0
  72. package/lib/common/eventListeners/index.js +55 -0
  73. package/lib/common/eventListeners/index.js.map +1 -0
  74. package/lib/common/eventListeners/types.d.ts +7 -0
  75. package/lib/common/eventListeners/types.js +5 -0
  76. package/lib/common/eventListeners/types.js.map +1 -0
  77. package/lib/common/index.d.ts +4 -0
  78. package/lib/common/index.js +13 -0
  79. package/lib/common/index.js.map +1 -0
  80. package/lib/index.d.ts +5 -2
  81. package/lib/index.js +4 -0
  82. package/lib/index.js.map +1 -1
  83. package/lib/types.d.ts +34 -2
  84. package/lib/types.js +2 -0
  85. package/lib/types.js.map +1 -1
  86. package/lib-esm/InAppMessaging/InAppMessaging.d.ts +10 -8
  87. package/lib-esm/InAppMessaging/InAppMessaging.js +9 -11
  88. package/lib-esm/InAppMessaging/InAppMessaging.js.map +1 -1
  89. package/lib-esm/InAppMessaging/Providers/AWSPinpointProvider/index.d.ts +5 -25
  90. package/lib-esm/InAppMessaging/Providers/AWSPinpointProvider/index.js +39 -254
  91. package/lib-esm/InAppMessaging/Providers/AWSPinpointProvider/index.js.map +1 -1
  92. package/lib-esm/InAppMessaging/Providers/AWSPinpointProvider/types.d.ts +0 -9
  93. package/lib-esm/InAppMessaging/Providers/AWSPinpointProvider/types.js.map +1 -1
  94. package/lib-esm/InAppMessaging/Providers/AWSPinpointProvider/utils.js +2 -8
  95. package/lib-esm/InAppMessaging/Providers/AWSPinpointProvider/utils.js.map +1 -1
  96. package/lib-esm/InAppMessaging/index.d.ts +1 -3
  97. package/lib-esm/InAppMessaging/index.js +0 -1
  98. package/lib-esm/InAppMessaging/index.js.map +1 -1
  99. package/lib-esm/InAppMessaging/types.d.ts +30 -42
  100. package/lib-esm/InAppMessaging/types.js +2 -0
  101. package/lib-esm/InAppMessaging/types.js.map +1 -1
  102. package/lib-esm/Notifications.d.ts +6 -2
  103. package/lib-esm/Notifications.js +48 -3
  104. package/lib-esm/Notifications.js.map +1 -1
  105. package/lib-esm/PushNotification/NotEnabledError.d.ts +3 -0
  106. package/lib-esm/PushNotification/NotEnabledError.js +14 -0
  107. package/lib-esm/PushNotification/NotEnabledError.js.map +1 -0
  108. package/lib-esm/PushNotification/Platform/index.d.ts +2 -0
  109. package/lib-esm/PushNotification/Platform/index.js +24 -0
  110. package/lib-esm/PushNotification/Platform/index.js.map +1 -0
  111. package/lib-esm/PushNotification/Platform/index.native.d.ts +2 -0
  112. package/lib-esm/PushNotification/Platform/index.native.js +6 -0
  113. package/lib-esm/PushNotification/Platform/index.native.js.map +1 -0
  114. package/lib-esm/PushNotification/Platform/types.d.ts +5 -0
  115. package/lib-esm/PushNotification/Platform/types.js +3 -0
  116. package/lib-esm/PushNotification/Platform/types.js.map +1 -0
  117. package/lib-esm/PushNotification/PlatformNotSupportedError.d.ts +3 -0
  118. package/lib-esm/PushNotification/PlatformNotSupportedError.js +14 -0
  119. package/lib-esm/PushNotification/PlatformNotSupportedError.js.map +1 -0
  120. package/lib-esm/PushNotification/Providers/AWSPinpointProvider/index.d.ts +15 -0
  121. package/lib-esm/PushNotification/Providers/AWSPinpointProvider/index.js +113 -0
  122. package/lib-esm/PushNotification/Providers/AWSPinpointProvider/index.js.map +1 -0
  123. package/lib-esm/PushNotification/Providers/AWSPinpointProvider/types.d.ts +9 -0
  124. package/lib-esm/PushNotification/Providers/AWSPinpointProvider/types.js +14 -0
  125. package/lib-esm/PushNotification/Providers/AWSPinpointProvider/types.js.map +1 -0
  126. package/lib-esm/PushNotification/Providers/AWSPinpointProvider/utils.d.ts +7 -0
  127. package/lib-esm/PushNotification/Providers/AWSPinpointProvider/utils.js +56 -0
  128. package/lib-esm/PushNotification/Providers/AWSPinpointProvider/utils.js.map +1 -0
  129. package/lib-esm/PushNotification/Providers/index.d.ts +1 -0
  130. package/lib-esm/PushNotification/Providers/index.js +4 -0
  131. package/lib-esm/PushNotification/Providers/index.js.map +1 -0
  132. package/lib-esm/PushNotification/PushNotification.d.ts +39 -0
  133. package/lib-esm/PushNotification/PushNotification.js +89 -0
  134. package/lib-esm/PushNotification/PushNotification.js.map +1 -0
  135. package/lib-esm/PushNotification/PushNotification.native.d.ts +63 -0
  136. package/lib-esm/PushNotification/PushNotification.native.js +325 -0
  137. package/lib-esm/PushNotification/PushNotification.native.js.map +1 -0
  138. package/lib-esm/PushNotification/index.d.ts +2 -0
  139. package/lib-esm/PushNotification/index.js +5 -0
  140. package/lib-esm/PushNotification/index.js.map +1 -0
  141. package/lib-esm/PushNotification/types.d.ts +77 -0
  142. package/lib-esm/PushNotification/types.js +10 -0
  143. package/lib-esm/PushNotification/types.js.map +1 -0
  144. package/lib-esm/PushNotification/utils.d.ts +3 -0
  145. package/lib-esm/PushNotification/utils.js +79 -0
  146. package/lib-esm/PushNotification/utils.js.map +1 -0
  147. package/lib-esm/common/AWSPinpointProviderCommon/index.d.ts +34 -0
  148. package/lib-esm/common/AWSPinpointProviderCommon/index.js +279 -0
  149. package/lib-esm/common/AWSPinpointProviderCommon/index.js.map +1 -0
  150. package/lib-esm/common/AWSPinpointProviderCommon/types.d.ts +9 -0
  151. package/lib-esm/common/AWSPinpointProviderCommon/types.js +3 -0
  152. package/lib-esm/common/AWSPinpointProviderCommon/types.js.map +1 -0
  153. package/lib-esm/common/constants.d.ts +1 -0
  154. package/lib-esm/common/constants.js +4 -0
  155. package/lib-esm/common/constants.js.map +1 -0
  156. package/lib-esm/common/eventListeners/index.d.ts +4 -0
  157. package/lib-esm/common/eventListeners/index.js +53 -0
  158. package/lib-esm/common/eventListeners/index.js.map +1 -0
  159. package/lib-esm/common/eventListeners/types.d.ts +7 -0
  160. package/lib-esm/common/eventListeners/types.js +3 -0
  161. package/lib-esm/common/eventListeners/types.js.map +1 -0
  162. package/lib-esm/common/index.d.ts +4 -0
  163. package/lib-esm/common/index.js +6 -0
  164. package/lib-esm/common/index.js.map +1 -0
  165. package/lib-esm/index.d.ts +5 -2
  166. package/lib-esm/index.js +2 -0
  167. package/lib-esm/index.js.map +1 -1
  168. package/lib-esm/types.d.ts +34 -2
  169. package/lib-esm/types.js +2 -0
  170. package/lib-esm/types.js.map +1 -1
  171. package/package.json +11 -50
  172. package/src/InAppMessaging/InAppMessaging.ts +27 -36
  173. package/src/InAppMessaging/Providers/AWSPinpointProvider/index.ts +45 -245
  174. package/src/InAppMessaging/Providers/AWSPinpointProvider/types.ts +0 -12
  175. package/src/InAppMessaging/Providers/AWSPinpointProvider/utils.ts +3 -12
  176. package/src/InAppMessaging/index.ts +0 -3
  177. package/src/InAppMessaging/types.ts +52 -56
  178. package/src/Notifications.ts +42 -4
  179. package/src/PushNotification/NotEnabledError.ts +11 -0
  180. package/src/PushNotification/Platform/index.native.ts +9 -0
  181. package/src/PushNotification/Platform/index.ts +22 -0
  182. package/src/PushNotification/Platform/types.ts +15 -0
  183. package/src/PushNotification/PlatformNotSupportedError.ts +9 -0
  184. package/src/PushNotification/Providers/AWSPinpointProvider/index.ts +137 -0
  185. package/src/PushNotification/Providers/AWSPinpointProvider/types.ts +13 -0
  186. package/src/PushNotification/Providers/AWSPinpointProvider/utils.ts +79 -0
  187. package/src/PushNotification/Providers/index.ts +4 -0
  188. package/src/PushNotification/PushNotification.native.ts +381 -0
  189. package/src/PushNotification/PushNotification.ts +107 -0
  190. package/src/PushNotification/index.ts +9 -0
  191. package/src/PushNotification/types.ts +114 -0
  192. package/src/PushNotification/utils.ts +112 -0
  193. package/src/common/AWSPinpointProviderCommon/index.ts +295 -0
  194. package/src/common/AWSPinpointProviderCommon/types.ts +14 -0
  195. package/src/common/constants.ts +5 -0
  196. package/src/common/eventListeners/index.ts +44 -0
  197. package/src/common/eventListeners/types.ts +12 -0
  198. package/src/common/index.ts +11 -0
  199. package/src/index.ts +9 -3
  200. package/src/types.ts +47 -2
  201. package/CHANGELOG.md +0 -215
  202. package/lib/InAppMessaging/eventListeners.d.ts +0 -3
  203. package/lib/InAppMessaging/eventListeners.js +0 -28
  204. package/lib/InAppMessaging/eventListeners.js.map +0 -1
  205. package/lib-esm/InAppMessaging/eventListeners.d.ts +0 -3
  206. package/lib-esm/InAppMessaging/eventListeners.js +0 -26
  207. package/lib-esm/InAppMessaging/eventListeners.js.map +0 -1
  208. package/src/InAppMessaging/eventListeners.ts +0 -42
@@ -0,0 +1,89 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { __awaiter, __generator } from "tslib";
4
+ import PlatformNotSupportedError from './PlatformNotSupportedError';
5
+ var PushNotification = /** @class */ (function () {
6
+ function PushNotification() {
7
+ var _this = this;
8
+ /**
9
+ * Configure PushNotification
10
+ * @param {Object} config - PushNotification configuration object
11
+ */
12
+ this.configure = function (_) {
13
+ if (_ === void 0) { _ = {}; }
14
+ throw new PlatformNotSupportedError();
15
+ };
16
+ /**
17
+ * Get a plugin from added plugins
18
+ * @param {string} providerName - the name of the plugin to get
19
+ */
20
+ this.getPluggable = function (_) {
21
+ throw new PlatformNotSupportedError();
22
+ };
23
+ /**
24
+ * Add plugin into PushNotification
25
+ * @param {PushNotificationProvider} pluggable - an instance of the plugin
26
+ */
27
+ this.addPluggable = function (_) {
28
+ throw new PlatformNotSupportedError();
29
+ };
30
+ /**
31
+ * Remove a plugin from added plugins
32
+ * @param {string} providerName - the name of the plugin to remove
33
+ */
34
+ this.removePluggable = function () {
35
+ throw new PlatformNotSupportedError();
36
+ };
37
+ this.enable = function () {
38
+ throw new PlatformNotSupportedError();
39
+ };
40
+ this.identifyUser = function () {
41
+ throw new PlatformNotSupportedError();
42
+ };
43
+ this.getLaunchNotification = function () { return __awaiter(_this, void 0, void 0, function () {
44
+ return __generator(this, function (_a) {
45
+ throw new PlatformNotSupportedError();
46
+ });
47
+ }); };
48
+ this.getBadgeCount = function () { return __awaiter(_this, void 0, void 0, function () {
49
+ return __generator(this, function (_a) {
50
+ throw new PlatformNotSupportedError();
51
+ });
52
+ }); };
53
+ this.setBadgeCount = function (_) {
54
+ throw new PlatformNotSupportedError();
55
+ };
56
+ this.getPermissionStatus = function () { return __awaiter(_this, void 0, void 0, function () {
57
+ return __generator(this, function (_a) {
58
+ throw new PlatformNotSupportedError();
59
+ });
60
+ }); };
61
+ this.requestPermissions = function (_) { return __awaiter(_this, void 0, void 0, function () {
62
+ return __generator(this, function (_a) {
63
+ throw new PlatformNotSupportedError();
64
+ });
65
+ }); };
66
+ this.onNotificationReceivedInBackground = function (_) {
67
+ throw new PlatformNotSupportedError();
68
+ };
69
+ this.onNotificationReceivedInForeground = function (_) {
70
+ throw new PlatformNotSupportedError();
71
+ };
72
+ this.onTokenReceived = function (_) {
73
+ throw new PlatformNotSupportedError();
74
+ };
75
+ this.onNotificationOpened = function (_) {
76
+ throw new PlatformNotSupportedError();
77
+ };
78
+ }
79
+ /**
80
+ * Get the name of this module
81
+ * @returns {string} name of this module
82
+ */
83
+ PushNotification.prototype.getModuleName = function () {
84
+ throw new PlatformNotSupportedError();
85
+ };
86
+ return PushNotification;
87
+ }());
88
+ export default PushNotification;
89
+ //# sourceMappingURL=PushNotification.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PushNotification.js","sourceRoot":"","sources":["../../src/PushNotification/PushNotification.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;;AAEtC,OAAO,yBAAyB,MAAM,6BAA6B,CAAC;AAapE;IAAA;QAAA,iBA0FC;QAzFA;;;WAGG;QACH,cAAS,GAAG,UAAC,CAA8B;YAA9B,kBAAA,EAAA,MAA8B;YAC1C,MAAM,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ACvC,CAAC,CAAC;IACH,CAAC;IAjFA;;;OAGG;IACH,wCAAa,GAAb;QACC,MAAM,IAAI,yBAAyB,EAAE,CAAC;IACvC,CAAC;IA2EF,uBAAC;AAAD,CAAC,AA1FD,IA0FC"}
@@ -0,0 +1,63 @@
1
+ import { EventListener } from '../common';
2
+ import { UserInfo } from '../types';
3
+ import { NotificationsSubCategory, OnPushNotificationMessageHandler, OnTokenReceivedHandler, PushNotificationConfig, PushNotificationInterface, PushNotificationMessage, PushNotificationPermissions, PushNotificationPermissionStatus, PushNotificationProvider } from './types';
4
+ export default class PushNotification implements PushNotificationInterface {
5
+ private isEnabled;
6
+ private config;
7
+ private nativeEvent;
8
+ private nativeEventEmitter;
9
+ private nativeHeadlessTaskKey;
10
+ private nativeModule;
11
+ private pluggables;
12
+ private token;
13
+ constructor();
14
+ /**
15
+ * Configure PushNotification
16
+ * @param {Object} config - PushNotification configuration object
17
+ */
18
+ configure: (config?: PushNotificationConfig) => PushNotificationConfig;
19
+ /**
20
+ * Get the name of this module
21
+ * @returns {string} name of this module
22
+ */
23
+ getModuleName(): NotificationsSubCategory;
24
+ /**
25
+ * Get a plugin from added plugins
26
+ * @param {string} providerName - the name of the plugin to get
27
+ */
28
+ getPluggable: (providerName: string) => PushNotificationProvider;
29
+ /**
30
+ * Add plugin into PushNotification
31
+ * @param {PushNotificationProvider} pluggable - an instance of the plugin
32
+ */
33
+ addPluggable: (pluggable: PushNotificationProvider) => void;
34
+ /**
35
+ * Remove a plugin from added plugins
36
+ * @param {string} providerName - the name of the plugin to remove
37
+ */
38
+ removePluggable: (providerName: string) => void;
39
+ enable: () => void;
40
+ identifyUser: (userId: string, userInfo: UserInfo) => Promise<void[]>;
41
+ getLaunchNotification: () => Promise<PushNotificationMessage>;
42
+ getBadgeCount: () => Promise<number>;
43
+ setBadgeCount: (count: number) => void;
44
+ getPermissionStatus: () => Promise<PushNotificationPermissionStatus>;
45
+ requestPermissions: (permissions?: PushNotificationPermissions) => Promise<boolean>;
46
+ /**
47
+ * Background notifications on will start the app (as a headless JS instance running on a background service on
48
+ * Android) in the background. Handlers registered via `onNotificationReceivedInBackground` should return Promises if
49
+ * it needs to be asynchronous (e.g. to perform some network requests). The app should run in the background as long
50
+ * as there are handlers still running (however, if they run for more than 30 seconds on iOS, subsequent tasks could
51
+ * get deprioritized!). If it is necessary for a handler to execute while the app is in quit state, it should be
52
+ * registered in the application entry point (e.g. index.js) since the application will not fully mount in that case.
53
+ *
54
+ * @param handler a function to be run when a BACKGROUND_MESSAGE_RECEIVED event is received
55
+ * @returns an event listener which should be removed when no longer needed
56
+ */
57
+ onNotificationReceivedInBackground: (handler: OnPushNotificationMessageHandler) => EventListener<OnPushNotificationMessageHandler>;
58
+ onNotificationReceivedInForeground: (handler: OnPushNotificationMessageHandler) => EventListener<OnPushNotificationMessageHandler>;
59
+ onNotificationOpened: (handler: OnPushNotificationMessageHandler) => EventListener<OnPushNotificationMessageHandler>;
60
+ onTokenReceived: (handler: OnTokenReceivedHandler) => EventListener<OnTokenReceivedHandler>;
61
+ private registerDevice;
62
+ private assertIsEnabled;
63
+ }
@@ -0,0 +1,325 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { __assign, __awaiter, __generator } from "tslib";
4
+ import { AppRegistry, NativeEventEmitter } from 'react-native';
5
+ import { ConsoleLogger as Logger } from '@aws-amplify/core';
6
+ import { AmplifyRTNPushNotification, } from '@aws-amplify/rtn-push-notification';
7
+ import { addEventListener, notifyEventListeners, notifyEventListenersAndAwaitHandlers, } from '../common';
8
+ import NotEnabledError from './NotEnabledError';
9
+ import { AWSPinpointProvider } from './Providers';
10
+ import { normalizeNativePermissionStatus, normalizeNativeMessage, } from './utils';
11
+ var logger = new Logger('Notifications.PushNotification');
12
+ var RTN_MODULE = '@aws-amplify/rtn-push-notification';
13
+ var BACKGROUND_TASK_TIMEOUT = 25; // seconds
14
+ var PushNotification = /** @class */ (function () {
15
+ function PushNotification() {
16
+ var _this = this;
17
+ this.isEnabled = false;
18
+ this.config = {};
19
+ this.pluggables = [];
20
+ /**
21
+ * Configure PushNotification
22
+ * @param {Object} config - PushNotification configuration object
23
+ */
24
+ this.configure = function (config) {
25
+ if (config === void 0) { config = {}; }
26
+ _this.config = __assign(__assign({}, _this.config), config);
27
+ logger.debug('configure PushNotification', _this.config);
28
+ _this.pluggables.forEach(function (pluggable) {
29
+ pluggable.configure(_this.config[pluggable.getProviderName()]);
30
+ });
31
+ if (_this.pluggables.length === 0) {
32
+ _this.addPluggable(new AWSPinpointProvider());
33
+ }
34
+ return _this.config;
35
+ };
36
+ /**
37
+ * Get a plugin from added plugins
38
+ * @param {string} providerName - the name of the plugin to get
39
+ */
40
+ this.getPluggable = function (providerName) {
41
+ var _a;
42
+ var pluggable = (_a = _this.pluggables.find(function (pluggable) { return pluggable.getProviderName() === providerName; })) !== null && _a !== void 0 ? _a : null;
43
+ if (!pluggable) {
44
+ logger.debug("No plugin found with name " + providerName);
45
+ }
46
+ return pluggable;
47
+ };
48
+ /**
49
+ * Add plugin into PushNotification
50
+ * @param {PushNotificationProvider} pluggable - an instance of the plugin
51
+ */
52
+ this.addPluggable = function (pluggable) {
53
+ if (pluggable &&
54
+ pluggable.getCategory() === 'Notifications' &&
55
+ pluggable.getSubCategory() === 'PushNotification') {
56
+ if (_this.getPluggable(pluggable.getProviderName())) {
57
+ throw new Error("Pluggable " + pluggable.getProviderName() + " has already been added.");
58
+ }
59
+ _this.pluggables.push(pluggable);
60
+ pluggable.configure(_this.config[pluggable.getProviderName()]);
61
+ }
62
+ };
63
+ /**
64
+ * Remove a plugin from added plugins
65
+ * @param {string} providerName - the name of the plugin to remove
66
+ */
67
+ this.removePluggable = function (providerName) {
68
+ var index = _this.pluggables.findIndex(function (pluggable) { return pluggable.getProviderName() === providerName; });
69
+ if (index === -1) {
70
+ logger.debug("No plugin found with name " + providerName);
71
+ }
72
+ else {
73
+ _this.pluggables.splice(index, 1);
74
+ }
75
+ };
76
+ this.enable = function () {
77
+ if (_this.isEnabled) {
78
+ logger.info('Notification listeners have already been enabled');
79
+ return;
80
+ }
81
+ var _a = _this.nativeEvent, BACKGROUND_MESSAGE_RECEIVED = _a.BACKGROUND_MESSAGE_RECEIVED, FOREGROUND_MESSAGE_RECEIVED = _a.FOREGROUND_MESSAGE_RECEIVED, LAUNCH_NOTIFICATION_OPENED = _a.LAUNCH_NOTIFICATION_OPENED, NOTIFICATION_OPENED = _a.NOTIFICATION_OPENED, TOKEN_RECEIVED = _a.TOKEN_RECEIVED;
82
+ if (_this.nativeHeadlessTaskKey) {
83
+ // on platforms that can handle headless tasks, register one to broadcast background message received to
84
+ // library listeners
85
+ AppRegistry.registerHeadlessTask(_this.nativeHeadlessTaskKey, function () { return function (message) { return __awaiter(_this, void 0, void 0, function () {
86
+ return __generator(this, function (_a) {
87
+ switch (_a.label) {
88
+ case 0:
89
+ // keep headless task running until handlers have completed their work
90
+ return [4 /*yield*/, notifyEventListenersAndAwaitHandlers(0 /* BACKGROUND_MESSAGE_RECEIVED */, normalizeNativeMessage(message))];
91
+ case 1:
92
+ // keep headless task running until handlers have completed their work
93
+ _a.sent();
94
+ return [2 /*return*/];
95
+ }
96
+ });
97
+ }); }; });
98
+ }
99
+ else if (BACKGROUND_MESSAGE_RECEIVED) {
100
+ // on platforms that can't handle headless tasks, listen for native background message received event and
101
+ // broadcast to library listeners
102
+ _this.nativeEventEmitter.addListener(BACKGROUND_MESSAGE_RECEIVED, function (message) { return __awaiter(_this, void 0, void 0, function () {
103
+ var err_1;
104
+ var _a, _b;
105
+ return __generator(this, function (_c) {
106
+ switch (_c.label) {
107
+ case 0:
108
+ _c.trys.push([0, 2, 3, 4]);
109
+ return [4 /*yield*/, Promise.race([
110
+ notifyEventListenersAndAwaitHandlers(0 /* BACKGROUND_MESSAGE_RECEIVED */, normalizeNativeMessage(message)),
111
+ // background tasks will get suspended and all future tasks be deprioritized by the OS if they run for
112
+ // more than 30 seconds so we reject with a error in a shorter amount of time to prevent this from
113
+ // happening
114
+ new Promise(function (_, reject) {
115
+ setTimeout(function () {
116
+ return reject("onNotificationReceivedInBackground handlers should complete their work within " + BACKGROUND_TASK_TIMEOUT + " seconds, but they did not.");
117
+ }, BACKGROUND_TASK_TIMEOUT * 1000);
118
+ }),
119
+ ])];
120
+ case 1:
121
+ _c.sent();
122
+ return [3 /*break*/, 4];
123
+ case 2:
124
+ err_1 = _c.sent();
125
+ logger.error(err_1);
126
+ return [3 /*break*/, 4];
127
+ case 3:
128
+ // notify native module that handlers have completed their work (or timed out)
129
+ (_b = (_a = this.nativeModule).completeNotification) === null || _b === void 0 ? void 0 : _b.call(_a, message.completionHandlerId);
130
+ return [7 /*endfinally*/];
131
+ case 4: return [2 /*return*/];
132
+ }
133
+ });
134
+ }); });
135
+ }
136
+ _this.nativeEventEmitter.addListener(
137
+ // listen for native foreground message received event and broadcast to library listeners
138
+ FOREGROUND_MESSAGE_RECEIVED, function (message) {
139
+ notifyEventListeners(1 /* FOREGROUND_MESSAGE_RECEIVED */, normalizeNativeMessage(message));
140
+ });
141
+ var launchNotificationOpenedListener = LAUNCH_NOTIFICATION_OPENED
142
+ ? _this.nativeEventEmitter.addListener(
143
+ // listen for native notification opened app (user tapped on notification, opening the app from quit -
144
+ // not background - state) event. This is broadcasted to an internal listener only as it is not intended
145
+ // for use otherwise as it produces inconsistent results when used within React Native app context
146
+ LAUNCH_NOTIFICATION_OPENED, function (message) {
147
+ notifyEventListeners(2 /* LAUNCH_NOTIFICATION_OPENED */, normalizeNativeMessage(message));
148
+ // once we are done with it we can remove the listener
149
+ launchNotificationOpenedListener === null || launchNotificationOpenedListener === void 0 ? void 0 : launchNotificationOpenedListener.remove();
150
+ })
151
+ : null;
152
+ _this.nativeEventEmitter.addListener(
153
+ // listen for native notification opened (user tapped on notification, opening the app from background -
154
+ // not quit - state) event and broadcast to library listeners
155
+ NOTIFICATION_OPENED, function (message) {
156
+ notifyEventListeners(3 /* NOTIFICATION_OPENED */, normalizeNativeMessage(message));
157
+ // if we are in this state, we no longer need the listener as the app was launched via some other means
158
+ launchNotificationOpenedListener === null || launchNotificationOpenedListener === void 0 ? void 0 : launchNotificationOpenedListener.remove();
159
+ });
160
+ _this.nativeEventEmitter.addListener(
161
+ // listen for native new token event, automatically re-register device with provider using new token and
162
+ // broadcast to library listeners
163
+ TOKEN_RECEIVED, function (_a) {
164
+ var token = _a.token;
165
+ // avoid a race condition where two endpoints are created with the same token on a fresh install
166
+ if (_this.token === token) {
167
+ return;
168
+ }
169
+ _this.token = token;
170
+ _this.registerDevice();
171
+ notifyEventListeners(4 /* TOKEN_RECEIVED */, token);
172
+ });
173
+ _this.isEnabled = true;
174
+ };
175
+ this.identifyUser = function (userId, userInfo) {
176
+ _this.assertIsEnabled();
177
+ return Promise.all(_this.pluggables.map(function (pluggable) { return __awaiter(_this, void 0, void 0, function () {
178
+ var err_2;
179
+ return __generator(this, function (_a) {
180
+ switch (_a.label) {
181
+ case 0:
182
+ _a.trys.push([0, 2, , 3]);
183
+ return [4 /*yield*/, pluggable.identifyUser(userId, userInfo)];
184
+ case 1:
185
+ _a.sent();
186
+ return [3 /*break*/, 3];
187
+ case 2:
188
+ err_2 = _a.sent();
189
+ logger.error('Failed to identify user', err_2);
190
+ throw err_2;
191
+ case 3: return [2 /*return*/];
192
+ }
193
+ });
194
+ }); }));
195
+ };
196
+ this.getLaunchNotification = function () { return __awaiter(_this, void 0, void 0, function () {
197
+ var _a;
198
+ var _b, _c;
199
+ return __generator(this, function (_d) {
200
+ switch (_d.label) {
201
+ case 0:
202
+ this.assertIsEnabled();
203
+ _a = normalizeNativeMessage;
204
+ return [4 /*yield*/, ((_c = (_b = this.nativeModule).getLaunchNotification) === null || _c === void 0 ? void 0 : _c.call(_b))];
205
+ case 1: return [2 /*return*/, _a.apply(void 0, [_d.sent()])];
206
+ }
207
+ });
208
+ }); };
209
+ this.getBadgeCount = function () { return __awaiter(_this, void 0, void 0, function () {
210
+ var _a, _b;
211
+ return __generator(this, function (_c) {
212
+ this.assertIsEnabled();
213
+ return [2 /*return*/, (_b = (_a = this.nativeModule).getBadgeCount) === null || _b === void 0 ? void 0 : _b.call(_a)];
214
+ });
215
+ }); };
216
+ this.setBadgeCount = function (count) {
217
+ var _a, _b;
218
+ _this.assertIsEnabled();
219
+ return (_b = (_a = _this.nativeModule).setBadgeCount) === null || _b === void 0 ? void 0 : _b.call(_a, count);
220
+ };
221
+ this.getPermissionStatus = function () { return __awaiter(_this, void 0, void 0, function () {
222
+ var _a;
223
+ var _b, _c;
224
+ return __generator(this, function (_d) {
225
+ switch (_d.label) {
226
+ case 0:
227
+ this.assertIsEnabled();
228
+ _a = normalizeNativePermissionStatus;
229
+ return [4 /*yield*/, ((_c = (_b = this.nativeModule).getPermissionStatus) === null || _c === void 0 ? void 0 : _c.call(_b))];
230
+ case 1: return [2 /*return*/, _a.apply(void 0, [_d.sent()])];
231
+ }
232
+ });
233
+ }); };
234
+ this.requestPermissions = function (permissions) {
235
+ if (permissions === void 0) { permissions = {
236
+ alert: true,
237
+ badge: true,
238
+ sound: true,
239
+ }; }
240
+ return __awaiter(_this, void 0, void 0, function () {
241
+ var _a, _b;
242
+ return __generator(this, function (_c) {
243
+ this.assertIsEnabled();
244
+ return [2 /*return*/, (_b = (_a = this.nativeModule).requestPermissions) === null || _b === void 0 ? void 0 : _b.call(_a, permissions)];
245
+ });
246
+ });
247
+ };
248
+ /**
249
+ * Background notifications on will start the app (as a headless JS instance running on a background service on
250
+ * Android) in the background. Handlers registered via `onNotificationReceivedInBackground` should return Promises if
251
+ * it needs to be asynchronous (e.g. to perform some network requests). The app should run in the background as long
252
+ * as there are handlers still running (however, if they run for more than 30 seconds on iOS, subsequent tasks could
253
+ * get deprioritized!). If it is necessary for a handler to execute while the app is in quit state, it should be
254
+ * registered in the application entry point (e.g. index.js) since the application will not fully mount in that case.
255
+ *
256
+ * @param handler a function to be run when a BACKGROUND_MESSAGE_RECEIVED event is received
257
+ * @returns an event listener which should be removed when no longer needed
258
+ */
259
+ this.onNotificationReceivedInBackground = function (handler) {
260
+ _this.assertIsEnabled();
261
+ return addEventListener(0 /* BACKGROUND_MESSAGE_RECEIVED */, handler);
262
+ };
263
+ this.onNotificationReceivedInForeground = function (handler) {
264
+ _this.assertIsEnabled();
265
+ return addEventListener(1 /* FOREGROUND_MESSAGE_RECEIVED */, handler);
266
+ };
267
+ this.onNotificationOpened = function (handler) {
268
+ _this.assertIsEnabled();
269
+ return addEventListener(3 /* NOTIFICATION_OPENED */, handler);
270
+ };
271
+ this.onTokenReceived = function (handler) {
272
+ _this.assertIsEnabled();
273
+ return addEventListener(4 /* TOKEN_RECEIVED */, handler);
274
+ };
275
+ this.registerDevice = function () { return __awaiter(_this, void 0, void 0, function () {
276
+ var _this = this;
277
+ return __generator(this, function (_a) {
278
+ return [2 /*return*/, Promise.all(this.pluggables.map(function (pluggable) { return __awaiter(_this, void 0, void 0, function () {
279
+ var err_3;
280
+ return __generator(this, function (_a) {
281
+ switch (_a.label) {
282
+ case 0:
283
+ _a.trys.push([0, 2, , 3]);
284
+ return [4 /*yield*/, pluggable.registerDevice(this.token)];
285
+ case 1:
286
+ _a.sent();
287
+ return [3 /*break*/, 3];
288
+ case 2:
289
+ err_3 = _a.sent();
290
+ logger.error('Failed to register device for push notifications', err_3);
291
+ throw err_3;
292
+ case 3: return [2 /*return*/];
293
+ }
294
+ });
295
+ }); }))];
296
+ });
297
+ }); };
298
+ this.assertIsEnabled = function () {
299
+ if (!_this.isEnabled) {
300
+ throw new NotEnabledError();
301
+ }
302
+ };
303
+ try {
304
+ this.nativeModule = AmplifyRTNPushNotification;
305
+ var _a = this.nativeModule.getConstants(), NativeEvent = _a.NativeEvent, NativeHeadlessTaskKey = _a.NativeHeadlessTaskKey;
306
+ this.nativeEvent = NativeEvent;
307
+ this.nativeHeadlessTaskKey = NativeHeadlessTaskKey;
308
+ this.nativeEventEmitter = new NativeEventEmitter(AmplifyRTNPushNotification);
309
+ }
310
+ catch (err) {
311
+ err.message = "Unable to find " + RTN_MODULE + ". " + err.message;
312
+ throw err;
313
+ }
314
+ }
315
+ /**
316
+ * Get the name of this module
317
+ * @returns {string} name of this module
318
+ */
319
+ PushNotification.prototype.getModuleName = function () {
320
+ return 'PushNotification';
321
+ };
322
+ return PushNotification;
323
+ }());
324
+ export default PushNotification;
325
+ //# sourceMappingURL=PushNotification.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PushNotification.native.js","sourceRoot":"","sources":["../../src/PushNotification/PushNotification.native.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;;AAEtC,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,EAAE,aAAa,IAAI,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EACN,0BAA0B,GAE1B,MAAM,oCAAoC,CAAC;AAE5C,OAAO,EACN,gBAAgB,EAEhB,oBAAoB,EACpB,oCAAoC,GACpC,MAAM,WAAW,CAAC;AAEnB,OAAO,eAAe,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAalD,OAAO,EACN,+BAA+B,EAC/B,sBAAsB,GACtB,MAAM,SAAS,CAAC;AAEjB,IAAM,MAAM,GAAG,IAAI,MAAM,CAAC,gCAAgC,CAAC,CAAC;AAC5D,IAAM,UAAU,GAAG,oCAAoC,CAAC;AACxD,IAAM,uBAAuB,GAAG,EAAE,CAAC,CAAC,UAAU;AAE9C;IAUC;QAAA,iBAcC;QAvBO,cAAS,GAAG,KAAK,CAAC;QAClB,WAAM,GAAwB,EAAE,CAAC;QAKjC,eAAU,GAA+B,EAAE,CAAC;QAmBpD;;;WAGG;QACH,cAAS,GAAG,UAAC,MAAmC;YAAnC,uBAAA,EAAA,WAAmC;YAC/C,KAAI,CAAC,MAAM,yBAAQ,KAAI,CAAC,MAAM,GAAK,MAAM,CAAE,CAAC;YAE5C,MA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AAc,CAAC,IAAI,CAAC,KAAK,CAAC,EAAA;;oCAA1C,SAA0C,CAAC;;;;oCAE3C,MAAM,CAAC,KAAK,CAAC,kDAAkD,EAAE,KAAG,CAAC,CAAC;oCACtE,MAAM,KAAG,CAAC;;;;yBAEX,CAAC,CACF,EAAC;;aACF,CAAC;QAEM,oBAAe,GAAG;YACzB,IAAI,CAAC,KAAI,CAAC,SAAS,EAAE;gBACpB,MAAM,IAAI,eAAe,EAAE,CAAC;aAC5B;QACF,CAAC,CAAC;QAxUD,IAAI;YACH,IAAI,CAAC,YAAY,GAAG,0BAA0B,CAAC;YACzC,IAAA,qCAC2B,EADzB,4BAAW,EAAE,gDACY,CAAC;YAClC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;YAC/B,IAAI,CAAC,qBAAqB,GAAG,qBAAqB,CAAC;YACnD,IAAI,CAAC,kBAAkB,GAAG,IAAI,kBAAkB,CAC/C,0BAA0B,CAC1B,CAAC;SACF;QAAC,OAAO,GAAG,EAAE;YACb,GAAG,CAAC,OAAO,GAAG,oBAAkB,UAAU,UAAK,GAAG,CAAC,OAAS,CAAC;YAC7D,MAAM,GAAG,CAAC;SACV;IACF,CAAC;IAsBD;;;OAGG;IACH,wCAAa,GAAb;QACC,OAAO,kBAAkB,CAAC;IAC3B,CAAC;IAgSF,uBAAC;AAAD,CAAC,AApVD,IAoVC"}
@@ -0,0 +1,2 @@
1
+ export { default } from './PushNotification';
2
+ export { PushNotificationEvent, PushNotificationMessage, PushNotificationPermissionStatus, } from './types';
@@ -0,0 +1,5 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ export { default } from './PushNotification';
4
+ export { PushNotificationPermissionStatus, } from './types';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/PushNotification/index.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAEtC,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAGN,gCAAgC,GAChC,MAAM,SAAS,CAAC"}
@@ -0,0 +1,77 @@
1
+ import { EventListener } from '../common';
2
+ import { AWSPinpointProviderConfig } from '../common/AWSPinpointProviderCommon/types';
3
+ import { NotificationsProvider, NotificationsSubCategory as NotificationsSubCategories, UserInfo } from '../types';
4
+ export declare type NotificationsSubCategory = Extract<NotificationsSubCategories, 'PushNotification'>;
5
+ export interface PushNotificationInterface {
6
+ configure: (config: PushNotificationConfig) => PushNotificationConfig;
7
+ getModuleName: () => NotificationsSubCategory;
8
+ getPluggable: (providerName: string) => PushNotificationProvider;
9
+ addPluggable: (pluggable: PushNotificationProvider) => void;
10
+ removePluggable: (providerName: string) => void;
11
+ enable: () => void;
12
+ identifyUser: (userId: string, userInfo: UserInfo) => Promise<void[]>;
13
+ getLaunchNotification: () => Promise<PushNotificationMessage>;
14
+ getBadgeCount: () => Promise<number>;
15
+ setBadgeCount: (count: number) => void;
16
+ getPermissionStatus: () => Promise<PushNotificationPermissionStatus>;
17
+ requestPermissions: (permissions?: PushNotificationPermissions) => Promise<boolean>;
18
+ onNotificationReceivedInBackground: (handler: OnPushNotificationMessageHandler) => EventListener<OnPushNotificationMessageHandler>;
19
+ onNotificationReceivedInForeground: (handler: OnPushNotificationMessageHandler) => EventListener<OnPushNotificationMessageHandler>;
20
+ onNotificationOpened: (handler: OnPushNotificationMessageHandler) => EventListener<OnPushNotificationMessageHandler>;
21
+ onTokenReceived: (handler: OnTokenReceivedHandler) => EventListener<OnTokenReceivedHandler>;
22
+ }
23
+ export interface PushNotificationProvider extends NotificationsProvider {
24
+ getSubCategory(): NotificationsSubCategory;
25
+ registerDevice(token: string): Promise<void>;
26
+ }
27
+ export interface PushNotificationConfig {
28
+ AWSPinpoint?: AWSPinpointProviderConfig;
29
+ }
30
+ export interface PushNotificationMessage {
31
+ title?: string;
32
+ body?: string;
33
+ imageUrl?: string;
34
+ deeplinkUrl?: string;
35
+ goToUrl?: string;
36
+ fcmOptions?: FcmPlatformOptions;
37
+ apnsOptions?: ApnsPlatformOptions;
38
+ data?: Record<string, unknown>;
39
+ }
40
+ interface FcmPlatformOptions {
41
+ channelId: string;
42
+ messageId: string;
43
+ senderId: string;
44
+ sendTime: Date;
45
+ }
46
+ interface ApnsPlatformOptions {
47
+ subtitle?: string;
48
+ }
49
+ export interface PushNotificationPermissions extends Record<string, boolean> {
50
+ alert?: boolean;
51
+ badge?: boolean;
52
+ sound?: boolean;
53
+ }
54
+ export declare enum PushNotificationPermissionStatus {
55
+ DENIED = "DENIED",
56
+ GRANTED = "GRANTED",
57
+ SHOULD_REQUEST = "SHOULD_REQUEST",
58
+ SHOULD_EXPLAIN_THEN_REQUEST = "SHOULD_EXPLAIN_THEN_REQUEST"
59
+ }
60
+ export declare type OnTokenReceivedHandler = (token: string) => any;
61
+ export declare type OnPushNotificationMessageHandler = (message: PushNotificationMessage) => any;
62
+ export declare const enum PushNotificationEvent {
63
+ BACKGROUND_MESSAGE_RECEIVED = 0,
64
+ FOREGROUND_MESSAGE_RECEIVED = 1,
65
+ LAUNCH_NOTIFICATION_OPENED = 2,
66
+ NOTIFICATION_OPENED = 3,
67
+ TOKEN_RECEIVED = 4
68
+ }
69
+ export interface NormalizedValues {
70
+ body?: string;
71
+ imageUrl?: string;
72
+ title?: string;
73
+ action?: Pick<PushNotificationMessage, 'goToUrl' | 'deeplinkUrl'>;
74
+ options?: Pick<PushNotificationMessage, 'apnsOptions' | 'fcmOptions'>;
75
+ data?: Record<string, unknown>;
76
+ }
77
+ export {};
@@ -0,0 +1,10 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ export var PushNotificationPermissionStatus;
4
+ (function (PushNotificationPermissionStatus) {
5
+ PushNotificationPermissionStatus["DENIED"] = "DENIED";
6
+ PushNotificationPermissionStatus["GRANTED"] = "GRANTED";
7
+ PushNotificationPermissionStatus["SHOULD_REQUEST"] = "SHOULD_REQUEST";
8
+ PushNotificationPermissionStatus["SHOULD_EXPLAIN_THEN_REQUEST"] = "SHOULD_EXPLAIN_THEN_REQUEST";
9
+ })(PushNotificationPermissionStatus || (PushNotificationPermissionStatus = {}));
10
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/PushNotification/types.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAoFtC,MAAM,CAAN,IAAY,gCAKX;AALD,WAAY,gCAAgC;IAC3C,qDAAiB,CAAA;IACjB,uDAAmB,CAAA;IACnB,qEAAiC,CAAA;IACjC,+FAA2D,CAAA;AAC5D,CAAC,EALW,gCAAgC,KAAhC,gCAAgC,QAK3C"}
@@ -0,0 +1,3 @@
1
+ import { PushNotificationMessage, PushNotificationPermissionStatus } from './types';
2
+ export declare const normalizeNativePermissionStatus: (nativeStatus?: any) => PushNotificationPermissionStatus;
3
+ export declare const normalizeNativeMessage: (nativeMessage?: any) => PushNotificationMessage;