@aws-amplify/notifications 1.0.25 → 1.0.26-unstable.1116fef.4

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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-amplify/notifications",
3
- "version": "1.0.25",
3
+ "version": "1.0.26-unstable.1116fef.4+1116feff6",
4
4
  "description": "Notifications category of aws-amplify",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib-esm/index.js",
@@ -13,7 +13,9 @@
13
13
  "access": "public"
14
14
  },
15
15
  "scripts": {
16
- "test": "npm run lint && jest -w 1 --coverage",
16
+ "test": "npm run lint && npm run test:default && npm run test:native",
17
+ "test:default": "jest -w 1 --coverage",
18
+ "test:native": "jest -w 1 --coverage --config=jest.native.config.js --coverageDirectory=coverage-native",
17
19
  "test:watch": "tslint 'src/**/*.ts' && jest -w 1 --watch",
18
20
  "test:size": "size-limit",
19
21
  "build-with-test": "npm run clean && npm test && tsc && webpack",
@@ -47,8 +49,8 @@
47
49
  "src"
48
50
  ],
49
51
  "dependencies": {
50
- "@aws-amplify/cache": "5.0.25",
51
- "@aws-amplify/core": "5.1.8",
52
+ "@aws-amplify/cache": "5.0.26-unstable.1116fef.4+1116feff6",
53
+ "@aws-amplify/core": "5.1.9-unstable.1116fef.4+1116feff6",
52
54
  "@aws-sdk/client-pinpoint": "3.186.1",
53
55
  "lodash": "^4.17.21",
54
56
  "uuid": "^3.2.1"
@@ -58,58 +60,17 @@
58
60
  "name": "Notifications (top-level class)",
59
61
  "path": "./lib-esm/index.js",
60
62
  "import": "{ Amplify, Notifications }",
61
- "limit": "70.5 kB"
63
+ "limit": "71 kB"
62
64
  },
63
65
  {
64
66
  "name": "Notifications (with Analytics)",
65
67
  "path": "./lib-esm/index.js",
66
68
  "import": "{ Amplify, Notifications, Analytics }",
67
- "limit": "70.5 kB"
69
+ "limit": "71 kB"
68
70
  }
69
71
  ],
70
- "jest": {
71
- "globals": {
72
- "ts-jest": {
73
- "diagnostics": false,
74
- "tsConfig": {
75
- "lib": [
76
- "es5",
77
- "es2015",
78
- "dom",
79
- "esnext.asynciterable",
80
- "es2017.object"
81
- ],
82
- "allowJs": true
83
- }
84
- }
85
- },
86
- "transform": {
87
- "^.+\\.(js|jsx|ts|tsx)$": "ts-jest"
88
- },
89
- "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(tsx?|jsx?)$",
90
- "moduleFileExtensions": [
91
- "ts",
92
- "tsx",
93
- "js",
94
- "json",
95
- "jsx"
96
- ],
97
- "testEnvironment": "jsdom",
98
- "testURL": "http://localhost/",
99
- "coverageThreshold": {
100
- "global": {
101
- "branches": 0,
102
- "functions": 0,
103
- "lines": 0,
104
- "statements": 0
105
- }
106
- },
107
- "coveragePathIgnorePatterns": [
108
- "/node_modules/",
109
- "dist",
110
- "lib",
111
- "lib-esm"
112
- ]
72
+ "devDependencies": {
73
+ "@aws-amplify/rtn-push-notification": "1.0.1-unstable.1116fef.7813+1116feff6"
113
74
  },
114
- "gitHead": "4d169725f09cd910ca5a55a4fa7302a602a780fd"
75
+ "gitHead": "1116feff67ae991d21b77e5dd73dac66d58e8004"
115
76
  }
@@ -9,29 +9,31 @@ import {
9
9
  StorageHelper,
10
10
  } from '@aws-amplify/core';
11
11
  import flatten from 'lodash/flatten';
12
- import { AWSPinpointProvider } from './Providers';
12
+
13
13
  import {
14
- addMessageInteractionEventListener,
15
- notifyMessageInteractionEventListeners,
16
- } from './eventListeners';
14
+ addEventListener,
15
+ EventListener,
16
+ notifyEventListeners,
17
+ } from '../common';
18
+ import { UserInfo } from '../types';
19
+ import { AWSPinpointProvider } from './Providers';
17
20
  import {
18
21
  InAppMessage,
19
22
  InAppMessageInteractionEvent,
23
+ InAppMessagingInterface,
20
24
  InAppMessagingConfig,
21
25
  InAppMessageConflictHandler,
22
26
  InAppMessagingEvent,
23
27
  InAppMessagingProvider,
24
- NotificationsSubcategory,
28
+ NotificationsSubCategory,
25
29
  OnMessageInteractionEventHandler,
26
- OnMessageInteractionEventListener,
27
- UserInfo,
28
30
  } from './types';
29
31
 
30
32
  const STORAGE_KEY_SUFFIX = '_inAppMessages';
31
33
 
32
34
  const logger = new Logger('Notifications.InAppMessaging');
33
35
 
34
- export default class InAppMessaging {
36
+ export default class InAppMessaging implements InAppMessagingInterface {
35
37
  private config: Record<string, any> = {};
36
38
  private conflictHandler: InAppMessageConflictHandler;
37
39
  private listeningForAnalyticEvents = false;
@@ -39,9 +41,7 @@ export default class InAppMessaging {
39
41
  private storageSynced = false;
40
42
 
41
43
  constructor() {
42
- this.config = {
43
- storage: new StorageHelper().getStorage(),
44
- };
44
+ this.config = { storage: new StorageHelper().getStorage() };
45
45
  this.setConflictHandler(this.defaultConflictHandler);
46
46
  }
47
47
 
@@ -77,7 +77,7 @@ export default class InAppMessaging {
77
77
  * Get the name of this module
78
78
  * @returns {string} name of this module
79
79
  */
80
- getModuleName(): NotificationsSubcategory {
80
+ getModuleName(): NotificationsSubCategory {
81
81
  return 'InAppMessaging';
82
82
  }
83
83
 
@@ -172,9 +172,9 @@ export default class InAppMessaging {
172
172
  const flattenedMessages = flatten(messages);
173
173
 
174
174
  if (flattenedMessages.length) {
175
- notifyMessageInteractionEventListeners(
176
- this.conflictHandler(flattenedMessages),
177
- InAppMessageInteractionEvent.MESSAGE_RECEIVED
175
+ notifyEventListeners(
176
+ InAppMessageInteractionEvent.MESSAGE_RECEIVED,
177
+ this.conflictHandler(flattenedMessages)
178
178
  );
179
179
  }
180
180
  };
@@ -193,41 +193,32 @@ export default class InAppMessaging {
193
193
 
194
194
  onMessageReceived = (
195
195
  handler: OnMessageInteractionEventHandler
196
- ): OnMessageInteractionEventListener =>
197
- addMessageInteractionEventListener(
198
- handler,
199
- InAppMessageInteractionEvent.MESSAGE_RECEIVED
200
- );
196
+ ): EventListener<OnMessageInteractionEventHandler> =>
197
+ addEventListener(InAppMessageInteractionEvent.MESSAGE_RECEIVED, handler);
201
198
 
202
199
  onMessageDisplayed = (
203
200
  handler: OnMessageInteractionEventHandler
204
- ): OnMessageInteractionEventListener =>
205
- addMessageInteractionEventListener(
206
- handler,
207
- InAppMessageInteractionEvent.MESSAGE_DISPLAYED
208
- );
201
+ ): EventListener<OnMessageInteractionEventHandler> =>
202
+ addEventListener(InAppMessageInteractionEvent.MESSAGE_DISPLAYED, handler);
209
203
 
210
204
  onMessageDismissed = (
211
205
  handler: OnMessageInteractionEventHandler
212
- ): OnMessageInteractionEventListener =>
213
- addMessageInteractionEventListener(
214
- handler,
215
- InAppMessageInteractionEvent.MESSAGE_DISMISSED
216
- );
206
+ ): EventListener<OnMessageInteractionEventHandler> =>
207
+ addEventListener(InAppMessageInteractionEvent.MESSAGE_DISMISSED, handler);
217
208
 
218
209
  onMessageActionTaken = (
219
210
  handler: OnMessageInteractionEventHandler
220
- ): OnMessageInteractionEventListener =>
221
- addMessageInteractionEventListener(
222
- handler,
223
- InAppMessageInteractionEvent.MESSAGE_ACTION_TAKEN
211
+ ): EventListener<OnMessageInteractionEventHandler> =>
212
+ addEventListener(
213
+ InAppMessageInteractionEvent.MESSAGE_ACTION_TAKEN,
214
+ handler
224
215
  );
225
216
 
226
217
  notifyMessageInteraction = (
227
218
  message: InAppMessage,
228
- event: InAppMessageInteractionEvent
219
+ type: InAppMessageInteractionEvent
229
220
  ): void => {
230
- notifyMessageInteractionEventListeners(message, event);
221
+ notifyEventListeners(type, message);
231
222
  };
232
223
 
233
224
  setConflictHandler = (handler: InAppMessageConflictHandler): void => {
@@ -1,27 +1,14 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import {
5
- ClientDevice,
6
- Credentials,
7
- getAmplifyUserAgent,
8
- StorageHelper,
9
- transferKeyToUpperCase,
10
- } from '@aws-amplify/core';
11
- import { Cache } from '@aws-amplify/cache';
12
4
  import {
13
5
  ChannelType,
14
6
  GetInAppMessagesCommand,
15
7
  GetInAppMessagesCommandInput,
16
8
  InAppMessageCampaign as PinpointInAppMessage,
17
- UpdateEndpointCommand,
18
- UpdateEndpointCommandInput,
19
- PinpointClient,
20
9
  } from '@aws-sdk/client-pinpoint';
21
- import { v4 as uuid } from 'uuid';
22
10
 
23
- import { addMessageInteractionEventListener } from '../../eventListeners';
24
- import { NotificationsCategory } from '../../../types';
11
+ import { addEventListener, AWSPinpointProviderCommon } from '../../../common';
25
12
  import SessionTracker, {
26
13
  SessionState,
27
14
  SessionStateChangeHandler,
@@ -29,15 +16,12 @@ import SessionTracker, {
29
16
  import {
30
17
  InAppMessage,
31
18
  InAppMessageInteractionEvent,
32
- InAppMessageLayout,
33
19
  InAppMessagingEvent,
34
20
  InAppMessagingProvider,
35
- NotificationsSubcategory,
36
- UserInfo,
21
+ NotificationsSubCategory,
37
22
  } from '../../types';
38
23
  import {
39
24
  AWSPinpointMessageEvent,
40
- AWSPinpointUserInfo,
41
25
  DailyInAppMessageCounter,
42
26
  InAppMessageCountMap,
43
27
  InAppMessageCounts,
@@ -60,32 +44,19 @@ import {
60
44
  const MESSAGE_DAILY_COUNT_KEY = 'pinpointProvider_inAppMessages_dailyCount';
61
45
  const MESSAGE_TOTAL_COUNT_KEY = 'pinpointProvider_inAppMessages_totalCount';
62
46
 
63
- export default class AWSPinpointProvider implements InAppMessagingProvider {
64
- static category: NotificationsCategory = 'Notifications';
65
- static subCategory: NotificationsSubcategory = 'InAppMessaging';
66
- static providerName = 'AWSPinpoint';
47
+ export default class AWSPinpointProvider
48
+ extends AWSPinpointProviderCommon
49
+ implements InAppMessagingProvider
50
+ {
51
+ static subCategory: NotificationsSubCategory = 'InAppMessaging';
67
52
 
68
- private clientInfo;
69
- private config: Record<string, any> = {};
70
53
  private configured = false;
71
- private endpointInitialized = false;
72
- private initialized = false;
73
54
  private sessionMessageCountMap: InAppMessageCountMap;
74
55
  private sessionTracker: SessionTracker;
75
56
 
76
57
  constructor() {
58
+ super(logger);
77
59
  this.sessionMessageCountMap = {};
78
- this.config = {
79
- storage: new StorageHelper().getStorage(),
80
- };
81
- this.clientInfo = ClientDevice.clientInfo() ?? {};
82
- }
83
-
84
- /**
85
- * get the category of the plugin
86
- */
87
- getCategory() {
88
- return AWSPinpointProvider.category;
89
60
  }
90
61
 
91
62
  /**
@@ -95,41 +66,44 @@ export default class AWSPinpointProvider implements InAppMessagingProvider {
95
66
  return AWSPinpointProvider.subCategory;
96
67
  }
97
68
 
98
- /**
99
- * get provider name of the plugin
100
- */
101
- getProviderName(): string {
102
- return AWSPinpointProvider.providerName;
103
- }
104
-
105
- configure = (config = {}): object => {
106
- this.config = { ...this.config, ...config };
107
-
108
- logger.debug('configure AWSPinpointProvider', this.config);
69
+ configure = (config = {}): Record<string, any> => {
70
+ this.config = {
71
+ ...super.configure(config),
72
+ endpointInfo: { channelType: ChannelType.IN_APP },
73
+ };
109
74
 
110
75
  // some configuration steps should not be re-run even if provider is re-configured for some reason
111
76
  if (!this.configured) {
112
77
  this.sessionTracker = new SessionTracker(this.sessionStateChangeHandler);
113
78
  this.sessionTracker.start();
114
79
  // wire up default Pinpoint message event handling
115
- addMessageInteractionEventListener((message: InAppMessage) => {
116
- this.recordMessageEvent(
117
- message,
118
- AWSPinpointMessageEvent.MESSAGE_DISPLAYED
119
- );
120
- }, InAppMessageInteractionEvent.MESSAGE_DISPLAYED);
121
- addMessageInteractionEventListener((message: InAppMessage) => {
122
- this.recordMessageEvent(
123
- message,
124
- AWSPinpointMessageEvent.MESSAGE_DISMISSED
125
- );
126
- }, InAppMessageInteractionEvent.MESSAGE_DISMISSED);
127
- addMessageInteractionEventListener((message: InAppMessage) => {
128
- this.recordMessageEvent(
129
- message,
130
- AWSPinpointMessageEvent.MESSAGE_ACTION_TAKEN
131
- );
132
- }, InAppMessageInteractionEvent.MESSAGE_ACTION_TAKEN);
80
+ addEventListener(
81
+ InAppMessageInteractionEvent.MESSAGE_DISPLAYED,
82
+ (message: InAppMessage) => {
83
+ this.recordMessageEvent(
84
+ message,
85
+ AWSPinpointMessageEvent.MESSAGE_DISPLAYED
86
+ );
87
+ }
88
+ );
89
+ addEventListener(
90
+ InAppMessageInteractionEvent.MESSAGE_DISMISSED,
91
+ (message: InAppMessage) => {
92
+ this.recordMessageEvent(
93
+ message,
94
+ AWSPinpointMessageEvent.MESSAGE_DISMISSED
95
+ );
96
+ }
97
+ );
98
+ addEventListener(
99
+ InAppMessageInteractionEvent.MESSAGE_ACTION_TAKEN,
100
+ (message: InAppMessage) => {
101
+ this.recordMessageEvent(
102
+ message,
103
+ AWSPinpointMessageEvent.MESSAGE_ACTION_TAKEN
104
+ );
105
+ }
106
+ );
133
107
  }
134
108
 
135
109
  this.configured = true;
@@ -155,14 +129,14 @@ export default class AWSPinpointProvider implements InAppMessagingProvider {
155
129
  const command: GetInAppMessagesCommand = new GetInAppMessagesCommand(
156
130
  input
157
131
  );
158
- logger.debug('getting in-app messages', input);
132
+ this.logger.debug('getting in-app messages');
159
133
  const response = await pinpointClient.send(command);
160
134
  const { InAppMessageCampaigns: messages } =
161
135
  response.InAppMessagesResponse;
162
136
  dispatchInAppMessagingEvent('getInAppMessages', messages);
163
137
  return messages;
164
138
  } catch (err) {
165
- logger.error('Error getting in-app messages', err);
139
+ this.logger.error('Error getting in-app messages', err);
166
140
  throw err;
167
141
  }
168
142
  };
@@ -212,180 +186,6 @@ export default class AWSPinpointProvider implements InAppMessagingProvider {
212
186
  );
213
187
  };
214
188
 
215
- identifyUser = async (userId: string, userInfo: UserInfo): Promise<void> => {
216
- if (!this.initialized) {
217
- await this.init();
218
- }
219
- try {
220
- await this.updateEndpoint(userId, userInfo);
221
- } catch (err) {
222
- logger.error('Error identifying user', err);
223
- throw err;
224
- }
225
- };
226
-
227
- private init = async () => {
228
- const { endpointId, storage } = this.config;
229
- const providerName = this.getProviderName();
230
- try {
231
- // Only run sync() if it's available (i.e. React Native)
232
- if (typeof storage.sync === 'function') {
233
- await storage.sync();
234
- }
235
- // If an endpoint was not provided via configuration, try to get it from cache
236
- if (!endpointId) {
237
- this.config.endpointId = await this.getEndpointId();
238
- }
239
- this.initialized = true;
240
- } catch (err) {
241
- logger.error(`Failed to initialize ${providerName}`, err);
242
- }
243
- };
244
-
245
- private initPinpointClient = async () => {
246
- const { appId, credentials, pinpointClient, region } = this.config;
247
-
248
- if (!appId || !credentials || !region) {
249
- throw new Error(
250
- 'One or more of credentials, appId or region is not configured'
251
- );
252
- }
253
-
254
- if (pinpointClient) {
255
- pinpointClient.destroy();
256
- }
257
-
258
- this.config.pinpointClient = new PinpointClient({
259
- region,
260
- credentials,
261
- customUserAgent: getAmplifyUserAgent(),
262
- });
263
- };
264
-
265
- private getEndpointId = async () => {
266
- const { appId } = this.config;
267
- // Each Pinpoint channel requires its own Endpoint ID
268
- const cacheKey = `${this.getSubCategory()}:${this.getProviderName()}:${appId}`;
269
- // First attempt to retrieve the ID from cache
270
- const cachedEndpointId = await Cache.getItem(cacheKey);
271
- // Found in cache, just return it
272
- if (cachedEndpointId) {
273
- return cachedEndpointId;
274
- }
275
- // Otherwise, generate a new ID and store it in long-lived cache before returning it
276
- const endpointId = uuid();
277
- // Set a longer TTL to avoid endpoint id being deleted after the default TTL (3 days)
278
- // Also set its priority to the highest to reduce its chance of being deleted when cache is full
279
- const ttl = 1000 * 60 * 60 * 24 * 365 * 100; // 100 years
280
- const expiration = new Date().getTime() + ttl;
281
- Cache.setItem(cacheKey, endpointId, {
282
- expires: expiration,
283
- priority: 1,
284
- });
285
- return endpointId;
286
- };
287
-
288
- private updateEndpoint = async (
289
- userId: string = null,
290
- userInfo: AWSPinpointUserInfo = null
291
- ) => {
292
- const {
293
- appId,
294
- credentials,
295
- endpointId,
296
- endpointInfo = {},
297
- pinpointClient,
298
- } = this.config;
299
- const currentCredentials = await this.getCredentials();
300
- // Shallow compare to determine if credentials stored here are outdated
301
- const credentialsUpdated =
302
- !credentials ||
303
- Object.keys(currentCredentials).some(
304
- key => currentCredentials[key] !== credentials[key]
305
- );
306
- // If endpoint is already initialized, and nothing else is changing, just early return
307
- if (
308
- this.endpointInitialized &&
309
- !credentialsUpdated &&
310
- !userId &&
311
- !userInfo
312
- ) {
313
- return;
314
- }
315
- // Update credentials
316
- this.config.credentials = currentCredentials;
317
- try {
318
- // Initialize a new pinpoint client if one isn't already configured or if credentials changed
319
- if (!pinpointClient || credentialsUpdated) {
320
- await this.initPinpointClient();
321
- }
322
- const { address, attributes, demographic, location, metrics, optOut } =
323
- userInfo ?? {};
324
- const { appVersion, make, model, platform, version } = this.clientInfo;
325
- // Create the UpdateEndpoint input, prioritizing passed in user info and falling back to
326
- // defaults (if any) obtained from the config
327
- const input: UpdateEndpointCommandInput = {
328
- ApplicationId: appId,
329
- EndpointId: endpointId,
330
- EndpointRequest: {
331
- RequestId: uuid(),
332
- EffectiveDate: new Date().toISOString(),
333
- ChannelType: ChannelType.IN_APP,
334
- Address: address ?? endpointInfo.address,
335
- Attributes: {
336
- ...endpointInfo.attributes,
337
- ...attributes,
338
- },
339
- Demographic: {
340
- AppVersion: appVersion,
341
- Make: make,
342
- Model: model,
343
- ModelVersion: version,
344
- Platform: platform,
345
- ...transferKeyToUpperCase({
346
- ...endpointInfo.demographic,
347
- ...demographic,
348
- }),
349
- },
350
- Location: transferKeyToUpperCase({
351
- ...endpointInfo.location,
352
- ...location,
353
- }),
354
- Metrics: {
355
- ...endpointInfo.metrics,
356
- ...metrics,
357
- },
358
- OptOut: optOut ?? endpointInfo.optOut,
359
- User: {
360
- UserId:
361
- userId ?? endpointInfo.userId ?? currentCredentials.identityId,
362
- UserAttributes: attributes ?? endpointInfo.userAttributes,
363
- },
364
- },
365
- };
366
- const command: UpdateEndpointCommand = new UpdateEndpointCommand(input);
367
- logger.debug('updating endpoint', input);
368
- await this.config.pinpointClient.send(command);
369
- this.endpointInitialized = true;
370
- } catch (err) {
371
- throw err;
372
- }
373
- };
374
-
375
- private getCredentials = async () => {
376
- try {
377
- const credentials = await Credentials.get();
378
- if (!credentials) {
379
- logger.debug('no credentials found');
380
- return null;
381
- }
382
- return Credentials.shear(credentials);
383
- } catch (err) {
384
- logger.error('Error getting credentials:', err);
385
- return null;
386
- }
387
- };
388
-
389
189
  private sessionStateChangeHandler: SessionStateChangeHandler = (
390
190
  state: SessionState
391
191
  ) => {
@@ -447,7 +247,7 @@ export default class AWSPinpointProvider implements InAppMessagingProvider {
447
247
  totalCount: this.getTotalCount(messageId),
448
248
  };
449
249
  } catch (err) {
450
- logger.error('Failed to get message counts from storage', err);
250
+ this.logger.error('Failed to get message counts from storage', err);
451
251
  }
452
252
  };
453
253
 
@@ -464,7 +264,7 @@ export default class AWSPinpointProvider implements InAppMessagingProvider {
464
264
  try {
465
265
  storage.setItem(MESSAGE_DAILY_COUNT_KEY, JSON.stringify(dailyCount));
466
266
  } catch (err) {
467
- logger.error('Failed to save daily message count to storage', err);
267
+ this.logger.error('Failed to save daily message count to storage', err);
468
268
  }
469
269
  };
470
270
 
@@ -473,7 +273,7 @@ export default class AWSPinpointProvider implements InAppMessagingProvider {
473
273
  try {
474
274
  storage.setItem(MESSAGE_TOTAL_COUNT_KEY, JSON.stringify(countMap));
475
275
  } catch (err) {
476
- logger.error('Failed to save total count to storage', err);
276
+ this.logger.error('Failed to save total count to storage', err);
477
277
  }
478
278
  };
479
279
 
@@ -1,8 +1,6 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { UserInfo } from '../../types';
5
-
6
4
  export type InAppMessageCountMap = Record<string, number>;
7
5
 
8
6
  export type DailyInAppMessageCounter = {
@@ -21,18 +19,8 @@ export type MetricsComparator = (
21
19
  eventVal: number
22
20
  ) => boolean;
23
21
 
24
- export interface AWSPinpointProviderConfig {
25
- appId: string;
26
- region: string;
27
- }
28
-
29
22
  export enum AWSPinpointMessageEvent {
30
23
  MESSAGE_DISPLAYED = '_inapp.message_displayed',
31
24
  MESSAGE_DISMISSED = '_inapp.message_dismissed',
32
25
  MESSAGE_ACTION_TAKEN = '_inapp.message_clicked',
33
26
  }
34
-
35
- export interface AWSPinpointUserInfo extends UserInfo {
36
- address?: string;
37
- optOut?: 'ALL' | 'NONE';
38
- }
@@ -7,6 +7,7 @@ import {
7
7
  Layout as PinpointInAppMessageLayout,
8
8
  } from '@aws-sdk/client-pinpoint';
9
9
  import isEmpty from 'lodash/isEmpty';
10
+ import { AMPLIFY_SYMBOL } from '../../../common';
10
11
  import {
11
12
  InAppMessage,
12
13
  InAppMessageAction,
@@ -15,20 +16,16 @@ import {
15
16
  InAppMessageTextAlign,
16
17
  InAppMessagingEvent,
17
18
  } from '../../types';
19
+
18
20
  import { AWSPinpointMessageEvent, MetricsComparator } from './types';
19
21
 
20
- const AMPLIFY_SYMBOL = (
21
- typeof Symbol !== 'undefined' && typeof Symbol.for === 'function'
22
- ? Symbol.for('amplify_default')
23
- : '@@amplify_default'
24
- ) as Symbol;
25
22
  const DELIVERY_TYPE = 'IN_APP_MESSAGE';
26
23
 
27
24
  let eventNameMemo = {};
28
25
  let eventAttributesMemo = {};
29
26
  let eventMetricsMemo = {};
30
27
 
31
- export const logger = new ConsoleLogger('AWSPinpointProvider');
28
+ export const logger = new ConsoleLogger('InAppMessaging.AWSPinpointProvider');
32
29
 
33
30
  export const dispatchInAppMessagingEvent = (
34
31
  event: string,
@@ -47,12 +44,6 @@ export const recordAnalyticsEvent = (
47
44
  event: AWSPinpointMessageEvent,
48
45
  message: InAppMessage
49
46
  ) => {
50
- if (!message) {
51
- logger.debug(
52
- 'Unable to record analytics event - no InAppMessage was received'
53
- );
54
- return;
55
- }
56
47
  if (Amplify.Analytics && typeof Amplify.Analytics.record === 'function') {
57
48
  const { id, metadata } = message;
58
49
  Amplify.Analytics.record({
@@ -2,8 +2,6 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  export { default } from './InAppMessaging';
5
- export { AWSPinpointProvider } from './Providers';
6
- export { AWSPinpointUserInfo } from './Providers/AWSPinpointProvider/types';
7
5
  export {
8
6
  InAppMessage,
9
7
  InAppMessageAction,
@@ -16,5 +14,4 @@ export {
16
14
  InAppMessageTextAlign,
17
15
  InAppMessagingConfig,
18
16
  InAppMessagingEvent,
19
- UserInfo,
20
17
  } from './types';