@aws-amplify/notifications 2.0.1-console-preview.8d88eef.0 → 2.0.1-console-preview.be08038.0

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 (122) hide show
  1. package/lib/inAppMessaging/providers/pinpoint/apis/identifyUser.d.ts +4 -4
  2. package/lib/inAppMessaging/providers/pinpoint/apis/identifyUser.js +4 -4
  3. package/lib/inAppMessaging/providers/pinpoint/apis/initializeInAppMessaging.js +8 -10
  4. package/lib/inAppMessaging/providers/pinpoint/utils/messageProcessingHelpers.d.ts +1 -1
  5. package/lib/pushNotifications/errors/errorHelpers.d.ts +1 -0
  6. package/lib/pushNotifications/errors/errorHelpers.js +4 -0
  7. package/lib/pushNotifications/providers/pinpoint/apis/getBadgeCount.native.js +7 -3
  8. package/lib/pushNotifications/providers/pinpoint/apis/getLaunchNotification.native.js +2 -0
  9. package/lib/pushNotifications/providers/pinpoint/apis/getPermissionStatus.native.js +2 -0
  10. package/lib/pushNotifications/providers/pinpoint/apis/identifyUser.native.js +8 -4
  11. package/lib/pushNotifications/providers/pinpoint/apis/initializePushNotifications.native.js +8 -7
  12. package/lib/pushNotifications/providers/pinpoint/apis/onNotificationOpened.native.js +2 -0
  13. package/lib/pushNotifications/providers/pinpoint/apis/onNotificationReceivedInBackground.native.js +5 -1
  14. package/lib/pushNotifications/providers/pinpoint/apis/onNotificationReceivedInForeground.native.js +5 -1
  15. package/lib/pushNotifications/providers/pinpoint/apis/onTokenReceived.native.js +2 -0
  16. package/lib/pushNotifications/providers/pinpoint/apis/requestPermissions.native.js +2 -0
  17. package/lib/pushNotifications/providers/pinpoint/apis/setBadgeCount.native.js +5 -1
  18. package/lib/pushNotifications/providers/pinpoint/utils/createMessageEventRecorder.js +3 -4
  19. package/lib/pushNotifications/providers/pinpoint/utils/index.d.ts +0 -4
  20. package/lib/pushNotifications/providers/pinpoint/utils/index.js +0 -10
  21. package/lib/pushNotifications/utils/index.d.ts +4 -0
  22. package/lib/pushNotifications/utils/index.js +14 -0
  23. package/lib/pushNotifications/{providers/pinpoint/utils → utils}/resolveConfig.js +1 -1
  24. package/lib/pushNotifications/{providers/pinpoint/utils → utils}/resolveCredentials.js +1 -1
  25. package/lib/tsconfig.build.tsbuildinfo +330 -425
  26. package/lib-esm/inAppMessaging/providers/pinpoint/apis/identifyUser.d.ts +4 -4
  27. package/lib-esm/inAppMessaging/providers/pinpoint/apis/identifyUser.js +4 -4
  28. package/lib-esm/inAppMessaging/providers/pinpoint/apis/initializeInAppMessaging.js +3 -4
  29. package/lib-esm/inAppMessaging/providers/pinpoint/utils/helpers.js +1 -1
  30. package/lib-esm/inAppMessaging/providers/pinpoint/utils/messageProcessingHelpers.d.ts +1 -1
  31. package/lib-esm/pushNotifications/errors/errorHelpers.d.ts +1 -0
  32. package/lib-esm/pushNotifications/errors/errorHelpers.js +4 -0
  33. package/lib-esm/pushNotifications/providers/pinpoint/apis/getBadgeCount.native.js +7 -3
  34. package/lib-esm/pushNotifications/providers/pinpoint/apis/getLaunchNotification.native.js +2 -0
  35. package/lib-esm/pushNotifications/providers/pinpoint/apis/getPermissionStatus.native.js +2 -0
  36. package/lib-esm/pushNotifications/providers/pinpoint/apis/identifyUser.native.js +6 -2
  37. package/lib-esm/pushNotifications/providers/pinpoint/apis/initializePushNotifications.native.js +2 -1
  38. package/lib-esm/pushNotifications/providers/pinpoint/apis/onNotificationOpened.native.js +2 -0
  39. package/lib-esm/pushNotifications/providers/pinpoint/apis/onNotificationReceivedInBackground.native.js +5 -1
  40. package/lib-esm/pushNotifications/providers/pinpoint/apis/onNotificationReceivedInForeground.native.js +5 -1
  41. package/lib-esm/pushNotifications/providers/pinpoint/apis/onTokenReceived.native.js +2 -0
  42. package/lib-esm/pushNotifications/providers/pinpoint/apis/requestPermissions.native.js +2 -0
  43. package/lib-esm/pushNotifications/providers/pinpoint/apis/setBadgeCount.native.js +5 -1
  44. package/lib-esm/pushNotifications/providers/pinpoint/utils/createMessageEventRecorder.js +1 -2
  45. package/lib-esm/pushNotifications/providers/pinpoint/utils/index.d.ts +0 -4
  46. package/lib-esm/pushNotifications/providers/pinpoint/utils/index.js +0 -4
  47. package/lib-esm/pushNotifications/utils/index.d.ts +4 -0
  48. package/lib-esm/pushNotifications/utils/index.js +6 -0
  49. package/lib-esm/pushNotifications/{providers/pinpoint/utils → utils}/resolveConfig.js +1 -1
  50. package/lib-esm/pushNotifications/{providers/pinpoint/utils → utils}/resolveCredentials.js +1 -1
  51. package/lib-esm/tsconfig.build.tsbuildinfo +228 -233
  52. package/package.json +4 -4
  53. package/src/inAppMessaging/providers/pinpoint/apis/identifyUser.ts +4 -4
  54. package/src/inAppMessaging/providers/pinpoint/apis/initializeInAppMessaging.ts +3 -4
  55. package/src/inAppMessaging/providers/pinpoint/utils/helpers.ts +1 -3
  56. package/src/inAppMessaging/providers/pinpoint/utils/messageProcessingHelpers.ts +1 -1
  57. package/src/pushNotifications/errors/errorHelpers.ts +5 -0
  58. package/src/pushNotifications/providers/pinpoint/apis/getBadgeCount.native.ts +5 -1
  59. package/src/pushNotifications/providers/pinpoint/apis/getLaunchNotification.native.ts +5 -2
  60. package/src/pushNotifications/providers/pinpoint/apis/getPermissionStatus.native.ts +5 -2
  61. package/src/pushNotifications/providers/pinpoint/apis/identifyUser.native.ts +4 -6
  62. package/src/pushNotifications/providers/pinpoint/apis/initializePushNotifications.native.ts +5 -3
  63. package/src/pushNotifications/providers/pinpoint/apis/onNotificationOpened.native.ts +5 -2
  64. package/src/pushNotifications/providers/pinpoint/apis/onNotificationReceivedInBackground.native.ts +5 -1
  65. package/src/pushNotifications/providers/pinpoint/apis/onNotificationReceivedInForeground.native.ts +5 -1
  66. package/src/pushNotifications/providers/pinpoint/apis/onTokenReceived.native.ts +5 -2
  67. package/src/pushNotifications/providers/pinpoint/apis/requestPermissions.native.ts +5 -2
  68. package/src/pushNotifications/providers/pinpoint/apis/setBadgeCount.native.ts +5 -1
  69. package/src/pushNotifications/providers/pinpoint/utils/createMessageEventRecorder.ts +1 -2
  70. package/src/pushNotifications/providers/pinpoint/utils/index.ts +0 -4
  71. package/src/pushNotifications/utils/index.ts +7 -0
  72. package/src/pushNotifications/{providers/pinpoint/utils → utils}/resolveConfig.ts +1 -1
  73. package/src/pushNotifications/{providers/pinpoint/utils → utils}/resolveCredentials.ts +1 -1
  74. package/lib/inAppMessaging/sessionTracker/SessionTracker.d.ts +0 -9
  75. package/lib/inAppMessaging/sessionTracker/SessionTracker.js +0 -67
  76. package/lib/inAppMessaging/sessionTracker/SessionTracker.native.d.ts +0 -10
  77. package/lib/inAppMessaging/sessionTracker/SessionTracker.native.js +0 -52
  78. package/lib/inAppMessaging/sessionTracker/index.d.ts +0 -3
  79. package/lib/inAppMessaging/sessionTracker/index.js +0 -7
  80. package/lib/inAppMessaging/sessionTracker/types.d.ts +0 -6
  81. package/lib/inAppMessaging/sessionTracker/types.js +0 -4
  82. package/lib/pushNotifications/Platform/index.d.ts +0 -2
  83. package/lib/pushNotifications/Platform/index.js +0 -25
  84. package/lib/pushNotifications/Platform/index.native.d.ts +0 -2
  85. package/lib/pushNotifications/Platform/index.native.js +0 -7
  86. package/lib/pushNotifications/Platform/types.d.ts +0 -5
  87. package/lib/pushNotifications/Platform/types.js +0 -4
  88. package/lib-esm/inAppMessaging/sessionTracker/SessionTracker.d.ts +0 -9
  89. package/lib-esm/inAppMessaging/sessionTracker/SessionTracker.js +0 -64
  90. package/lib-esm/inAppMessaging/sessionTracker/SessionTracker.native.d.ts +0 -10
  91. package/lib-esm/inAppMessaging/sessionTracker/SessionTracker.native.js +0 -49
  92. package/lib-esm/inAppMessaging/sessionTracker/index.d.ts +0 -3
  93. package/lib-esm/inAppMessaging/sessionTracker/index.js +0 -4
  94. package/lib-esm/inAppMessaging/sessionTracker/types.d.ts +0 -6
  95. package/lib-esm/inAppMessaging/sessionTracker/types.js +0 -2
  96. package/lib-esm/pushNotifications/Platform/index.d.ts +0 -2
  97. package/lib-esm/pushNotifications/Platform/index.js +0 -23
  98. package/lib-esm/pushNotifications/Platform/index.native.d.ts +0 -2
  99. package/lib-esm/pushNotifications/Platform/index.native.js +0 -5
  100. package/lib-esm/pushNotifications/Platform/types.d.ts +0 -5
  101. package/lib-esm/pushNotifications/Platform/types.js +0 -2
  102. package/src/inAppMessaging/sessionTracker/SessionTracker.native.ts +0 -60
  103. package/src/inAppMessaging/sessionTracker/SessionTracker.ts +0 -78
  104. package/src/inAppMessaging/sessionTracker/index.ts +0 -6
  105. package/src/inAppMessaging/sessionTracker/types.ts +0 -11
  106. package/src/pushNotifications/Platform/index.native.ts +0 -9
  107. package/src/pushNotifications/Platform/index.ts +0 -22
  108. package/src/pushNotifications/Platform/types.ts +0 -15
  109. /package/lib/pushNotifications/{providers/pinpoint/utils → utils}/initializationManager.d.ts +0 -0
  110. /package/lib/pushNotifications/{providers/pinpoint/utils → utils}/initializationManager.js +0 -0
  111. /package/lib/pushNotifications/{providers/pinpoint/utils → utils}/resolveConfig.d.ts +0 -0
  112. /package/lib/pushNotifications/{providers/pinpoint/utils → utils}/resolveCredentials.d.ts +0 -0
  113. /package/lib/pushNotifications/{providers/pinpoint/utils → utils}/tokenManager.d.ts +0 -0
  114. /package/lib/pushNotifications/{providers/pinpoint/utils → utils}/tokenManager.js +0 -0
  115. /package/lib-esm/pushNotifications/{providers/pinpoint/utils → utils}/initializationManager.d.ts +0 -0
  116. /package/lib-esm/pushNotifications/{providers/pinpoint/utils → utils}/initializationManager.js +0 -0
  117. /package/lib-esm/pushNotifications/{providers/pinpoint/utils → utils}/resolveConfig.d.ts +0 -0
  118. /package/lib-esm/pushNotifications/{providers/pinpoint/utils → utils}/resolveCredentials.d.ts +0 -0
  119. /package/lib-esm/pushNotifications/{providers/pinpoint/utils → utils}/tokenManager.d.ts +0 -0
  120. /package/lib-esm/pushNotifications/{providers/pinpoint/utils → utils}/tokenManager.js +0 -0
  121. /package/src/pushNotifications/{providers/pinpoint/utils → utils}/initializationManager.ts +0 -0
  122. /package/src/pushNotifications/{providers/pinpoint/utils → utils}/tokenManager.ts +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-amplify/notifications",
3
- "version": "2.0.1-console-preview.8d88eef.0+8d88eef",
3
+ "version": "2.0.1-console-preview.be08038.0+be08038",
4
4
  "description": "Notifications category of aws-amplify",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib-esm/index.js",
@@ -97,15 +97,15 @@
97
97
  "lodash": "^4.17.21"
98
98
  },
99
99
  "peerDependencies": {
100
- "@aws-amplify/core": "6.0.1-console-preview.8d88eef.0+8d88eef"
100
+ "@aws-amplify/core": "6.0.1-console-preview.be08038.0+be08038"
101
101
  },
102
102
  "devDependencies": {
103
- "@aws-amplify/core": "6.0.1-console-preview.8d88eef.0+8d88eef",
103
+ "@aws-amplify/core": "6.0.1-console-preview.be08038.0+be08038",
104
104
  "@babel/core": "7.15.5",
105
105
  "@babel/plugin-proposal-class-properties": "^7.0.0",
106
106
  "@babel/plugin-proposal-private-methods": "^7.0.0",
107
107
  "@babel/plugin-proposal-private-property-in-object": "^7.0.0",
108
108
  "metro-react-native-babel-preset": "^0.66.2"
109
109
  },
110
- "gitHead": "8d88eef4137cef4fbe03d7d3683b5bec59feb7b8"
110
+ "gitHead": "be08038c5b37a510243f077c6d3209e5383f8866"
111
111
  }
@@ -59,10 +59,10 @@ import { assertIsInitialized } from '../../../utils';
59
59
  * },
60
60
  * options: {
61
61
  * address: 'device-address',
62
- * optOut: 'NONE',
63
- * userAttributes: {
64
- * interests: ['food']
65
- * },
62
+ * optOut: 'NONE',
63
+ * userAttributes: {
64
+ * interests: ['food']
65
+ * },
66
66
  * },
67
67
  * });
68
68
  */
@@ -1,7 +1,7 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import SessionTracker from '../../../sessionTracker';
4
+ import { sessionListener } from '@aws-amplify/core/internals/utils';
5
5
  import { InAppMessage, InAppMessagingEvent } from '../../../types';
6
6
  import { addEventListener } from '../../../../eventListeners';
7
7
  import { recordAnalyticsEvent } from '../utils/helpers';
@@ -26,9 +26,8 @@ export function initializeInAppMessaging(): void {
26
26
  if (isInitialized()) {
27
27
  return;
28
28
  }
29
- // set up the session tracker and start it
30
- const sessionTracker = new SessionTracker(sessionStateChangeHandler);
31
- sessionTracker.start();
29
+ // register with the session listener
30
+ sessionListener.addStateChangeListener(sessionStateChangeHandler, true);
32
31
 
33
32
  // wire up default Pinpoint message event handling
34
33
  addEventListener('messageDisplayed', (message: InAppMessage) => {
@@ -2,9 +2,7 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import { ConsoleLogger } from '@aws-amplify/core';
5
- import {
6
- InAppMessagingAction,
7
- } from '@aws-amplify/core/internals/utils';
5
+ import { InAppMessagingAction } from '@aws-amplify/core/internals/utils';
8
6
  import type { InAppMessageCampaign as PinpointInAppMessage } from '@aws-amplify/core/internals/aws-clients/pinpoint';
9
7
  import isEmpty from 'lodash/isEmpty';
10
8
  import {
@@ -18,7 +18,7 @@ import {
18
18
  } from './helpers';
19
19
  import type { InAppMessageCampaign as PinpointInAppMessage } from '@aws-amplify/core/internals/aws-clients/pinpoint';
20
20
  import { defaultStorage, ConsoleLogger } from '@aws-amplify/core';
21
- import { SessionState } from '../../../sessionTracker';
21
+ import { SessionState } from '@aws-amplify/core/internals/utils';
22
22
 
23
23
  const MESSAGE_DAILY_COUNT_KEY = 'pinpointProvider_inAppMessages_dailyCount';
24
24
  const MESSAGE_TOTAL_COUNT_KEY = 'pinpointProvider_inAppMessages_totalCount';
@@ -6,6 +6,7 @@ import {
6
6
  AssertionFunction,
7
7
  createAssertionFunction,
8
8
  } from '@aws-amplify/core/internals/utils';
9
+ import { isInitialized } from '../utils';
9
10
  import { PushNotificationError } from './PushNotificationError';
10
11
 
11
12
  export enum PushNotificationValidationErrorCode {
@@ -38,3 +39,7 @@ export const assert: AssertionFunction<PushNotificationValidationErrorCode> =
38
39
  pushNotificationValidationErrorMap,
39
40
  PushNotificationError
40
41
  );
42
+
43
+ export const assertIsInitialized = () => {
44
+ assert(isInitialized(), PushNotificationValidationErrorCode.NotInitialized);
45
+ };
@@ -2,8 +2,12 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import { loadAmplifyPushNotification } from '@aws-amplify/react-native';
5
+ import { assertIsInitialized } from '../../../errors/errorHelpers';
5
6
  import { GetBadgeCount } from '../types';
6
7
 
7
8
  const { getBadgeCount: getBadgeCountNative } = loadAmplifyPushNotification();
8
9
 
9
- export const getBadgeCount: GetBadgeCount = async () => getBadgeCountNative();
10
+ export const getBadgeCount: GetBadgeCount = async () => {
11
+ assertIsInitialized();
12
+ return getBadgeCountNative();
13
+ };
@@ -2,10 +2,13 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import { loadAmplifyPushNotification } from '@aws-amplify/react-native';
5
+ import { assertIsInitialized } from '../../../errors/errorHelpers';
5
6
  import { GetLaunchNotification } from '../types';
6
7
 
7
8
  const { getLaunchNotification: getLaunchNotificationNative } =
8
9
  loadAmplifyPushNotification();
9
10
 
10
- export const getLaunchNotification: GetLaunchNotification = () =>
11
- getLaunchNotificationNative();
11
+ export const getLaunchNotification: GetLaunchNotification = () => {
12
+ assertIsInitialized();
13
+ return getLaunchNotificationNative();
14
+ };
@@ -2,10 +2,13 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import { loadAmplifyPushNotification } from '@aws-amplify/react-native';
5
+ import { assertIsInitialized } from '../../../errors/errorHelpers';
5
6
  import { GetPermissionStatus } from '../types';
6
7
 
7
8
  const { getPermissionStatus: getPermissionStatusNative } =
8
9
  loadAmplifyPushNotification();
9
10
 
10
- export const getPermissionStatus: GetPermissionStatus = () =>
11
- getPermissionStatusNative();
11
+ export const getPermissionStatus: GetPermissionStatus = () => {
12
+ assertIsInitialized();
13
+ return getPermissionStatusNative();
14
+ };
@@ -3,12 +3,9 @@
3
3
 
4
4
  import { PushNotificationAction } from '@aws-amplify/core/internals/utils';
5
5
  import { updateEndpoint } from '@aws-amplify/core/internals/providers/pinpoint';
6
- import {
7
- getChannelType,
8
- getPushNotificationUserAgentString,
9
- resolveConfig,
10
- resolveCredentials,
11
- } from '../utils';
6
+ import { assertIsInitialized } from '../../../errors/errorHelpers';
7
+ import { resolveConfig, resolveCredentials } from '../../../utils';
8
+ import { getChannelType, getPushNotificationUserAgentString } from '../utils';
12
9
  import { IdentifyUser } from '../types';
13
10
 
14
11
  export const identifyUser: IdentifyUser = async ({
@@ -16,6 +13,7 @@ export const identifyUser: IdentifyUser = async ({
16
13
  userProfile,
17
14
  options,
18
15
  }) => {
16
+ assertIsInitialized();
19
17
  const { credentials, identityId } = await resolveCredentials();
20
18
  const { appId, region } = resolveConfig();
21
19
  const { address, optOut, userAttributes } = options ?? {};
@@ -12,15 +12,17 @@ import {
12
12
  notifyEventListenersAndAwaitHandlers,
13
13
  } from '../../../../eventListeners';
14
14
  import {
15
- createMessageEventRecorder,
16
- getChannelType,
17
- getPushNotificationUserAgentString,
18
15
  getToken,
19
16
  initialize,
20
17
  isInitialized,
21
18
  resolveConfig,
22
19
  resolveCredentials,
23
20
  setToken,
21
+ } from '../../../utils';
22
+ import {
23
+ createMessageEventRecorder,
24
+ getChannelType,
25
+ getPushNotificationUserAgentString,
24
26
  } from '../utils';
25
27
 
26
28
  const {
@@ -2,7 +2,10 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import { addEventListener } from '../../../../eventListeners';
5
+ import { assertIsInitialized } from '../../../errors/errorHelpers';
5
6
  import { OnNotificationOpened } from '../types';
6
7
 
7
- export const onNotificationOpened: OnNotificationOpened = input =>
8
- addEventListener('notificationOpened', input);
8
+ export const onNotificationOpened: OnNotificationOpened = input => {
9
+ assertIsInitialized();
10
+ return addEventListener('notificationOpened', input);
11
+ };
@@ -2,7 +2,11 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import { addEventListener } from '../../../../eventListeners';
5
+ import { assertIsInitialized } from '../../../errors/errorHelpers';
5
6
  import { OnNotificationReceivedInBackground } from '../types';
6
7
 
7
8
  export const onNotificationReceivedInBackground: OnNotificationReceivedInBackground =
8
- input => addEventListener('backgroundMessageReceived', input);
9
+ input => {
10
+ assertIsInitialized();
11
+ return addEventListener('backgroundMessageReceived', input);
12
+ };
@@ -2,7 +2,11 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import { addEventListener } from '../../../../eventListeners';
5
+ import { assertIsInitialized } from '../../../errors/errorHelpers';
5
6
  import { OnNotificationReceivedInForeground } from '../types';
6
7
 
7
8
  export const onNotificationReceivedInForeground: OnNotificationReceivedInForeground =
8
- input => addEventListener('foregroundMessageReceived', input);
9
+ input => {
10
+ assertIsInitialized();
11
+ return addEventListener('foregroundMessageReceived', input);
12
+ };
@@ -2,7 +2,10 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import { addEventListener } from '../../../../eventListeners';
5
+ import { assertIsInitialized } from '../../../errors/errorHelpers';
5
6
  import { OnTokenReceived } from '../types';
6
7
 
7
- export const onTokenReceived: OnTokenReceived = input =>
8
- addEventListener('tokenReceived', input);
8
+ export const onTokenReceived: OnTokenReceived = input => {
9
+ assertIsInitialized();
10
+ return addEventListener('tokenReceived', input);
11
+ };
@@ -2,10 +2,13 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import { loadAmplifyPushNotification } from '@aws-amplify/react-native';
5
+ import { assertIsInitialized } from '../../../errors/errorHelpers';
5
6
  import { RequestPermissions } from '../types';
6
7
 
7
8
  const { requestPermissions: requestPermissionsNative } =
8
9
  loadAmplifyPushNotification();
9
10
 
10
- export const requestPermissions: RequestPermissions = input =>
11
- requestPermissionsNative(input);
11
+ export const requestPermissions: RequestPermissions = input => {
12
+ assertIsInitialized();
13
+ return requestPermissionsNative(input);
14
+ };
@@ -2,8 +2,12 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import { loadAmplifyPushNotification } from '@aws-amplify/react-native';
5
+ import { assertIsInitialized } from '../../../errors/errorHelpers';
5
6
  import { SetBadgeCount } from '../types';
6
7
 
7
8
  const { setBadgeCount: setBadgeCountNative } = loadAmplifyPushNotification();
8
9
 
9
- export const setBadgeCount: SetBadgeCount = input => setBadgeCountNative(input);
10
+ export const setBadgeCount: SetBadgeCount = input => {
11
+ assertIsInitialized();
12
+ setBadgeCountNative(input);
13
+ };
@@ -11,8 +11,7 @@ import {
11
11
  } from '../../../types';
12
12
  import { getAnalyticsEvent } from './getAnalyticsEvent';
13
13
  import { getChannelType } from './getChannelType';
14
- import { resolveCredentials } from './resolveCredentials';
15
- import { resolveConfig } from './resolveConfig';
14
+ import { resolveConfig, resolveCredentials } from '../../../utils';
16
15
 
17
16
  const logger = new ConsoleLogger('PushNotification.recordMessageEvent');
18
17
 
@@ -4,7 +4,3 @@
4
4
  export { createMessageEventRecorder } from './createMessageEventRecorder';
5
5
  export { getChannelType } from './getChannelType';
6
6
  export { getPushNotificationUserAgentString } from './getPushNotificationUserAgentString';
7
- export { initialize, isInitialized } from './initializationManager';
8
- export { resolveConfig } from './resolveConfig';
9
- export { resolveCredentials } from './resolveCredentials';
10
- export { getToken, setToken } from './tokenManager';
@@ -0,0 +1,7 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ export { initialize, isInitialized } from './initializationManager';
5
+ export { resolveConfig } from './resolveConfig';
6
+ export { resolveCredentials } from './resolveCredentials';
7
+ export { getToken, setToken } from './tokenManager';
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import { Amplify } from '@aws-amplify/core';
5
- import { assert, PushNotificationValidationErrorCode } from '../../../errors';
5
+ import { assert, PushNotificationValidationErrorCode } from '../errors';
6
6
 
7
7
  /**
8
8
  * @internal
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import { fetchAuthSession } from '@aws-amplify/core';
5
- import { assert, PushNotificationValidationErrorCode } from '../../../errors';
5
+ import { assert, PushNotificationValidationErrorCode } from '../errors';
6
6
 
7
7
  /**
8
8
  * @internal
@@ -1,9 +0,0 @@
1
- import { SessionState, SessionStateChangeHandler, SessionTrackerInterface } from './types';
2
- export default class SessionTracker implements SessionTrackerInterface {
3
- private sessionStateChangeHandler;
4
- constructor(sessionStateChangeHandler?: SessionStateChangeHandler);
5
- start: () => SessionState;
6
- end: () => SessionState;
7
- private getSessionState;
8
- private visibilityChangeHandler;
9
- }
@@ -1,67 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var tslib_1 = require("tslib");
4
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
5
- // SPDX-License-Identifier: Apache-2.0
6
- var utils_1 = require("@aws-amplify/core/internals/utils");
7
- var core_1 = require("@aws-amplify/core");
8
- var noop_1 = tslib_1.__importDefault(require("lodash/noop"));
9
- // Per https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API
10
- var hidden;
11
- var visibilityChange;
12
- if (utils_1.isBrowser() && document) {
13
- if (typeof document.hidden !== 'undefined') {
14
- hidden = 'hidden';
15
- visibilityChange = 'visibilitychange';
16
- }
17
- else if (typeof document['msHidden'] !== 'undefined') {
18
- hidden = 'msHidden';
19
- visibilityChange = 'msvisibilitychange';
20
- }
21
- else if (typeof document['webkitHidden'] !== 'undefined') {
22
- hidden = 'webkitHidden';
23
- visibilityChange = 'webkitvisibilitychange';
24
- }
25
- }
26
- var logger = new core_1.ConsoleLogger('InAppMessagingSessionTracker');
27
- var SessionTracker = /** @class */ (function () {
28
- function SessionTracker(sessionStateChangeHandler) {
29
- var _this = this;
30
- if (sessionStateChangeHandler === void 0) { sessionStateChangeHandler = noop_1.default; }
31
- this.start = function () {
32
- if (utils_1.isBrowser()) {
33
- document === null || document === void 0 ? void 0 : document.addEventListener(visibilityChange, _this.visibilityChangeHandler);
34
- }
35
- return _this.getSessionState();
36
- };
37
- this.end = function () {
38
- if (utils_1.isBrowser()) {
39
- document === null || document === void 0 ? void 0 : document.removeEventListener(visibilityChange, _this.visibilityChangeHandler);
40
- }
41
- return _this.getSessionState();
42
- };
43
- this.getSessionState = function () {
44
- if (utils_1.isBrowser() && document && !document[hidden]) {
45
- return 'started';
46
- }
47
- // If, for any reason, document is undefined the session will never start
48
- return 'ended';
49
- };
50
- this.visibilityChangeHandler = function () {
51
- if (!utils_1.isBrowser() || !document) {
52
- return;
53
- }
54
- if (document[hidden]) {
55
- logger.debug('App is now hidden');
56
- _this.sessionStateChangeHandler('ended');
57
- }
58
- else {
59
- logger.debug('App is now visible');
60
- _this.sessionStateChangeHandler('started');
61
- }
62
- };
63
- this.sessionStateChangeHandler = sessionStateChangeHandler;
64
- }
65
- return SessionTracker;
66
- }());
67
- exports.default = SessionTracker;
@@ -1,10 +0,0 @@
1
- import { SessionState, SessionStateChangeHandler, SessionTrackerInterface } from './types';
2
- export default class SessionTracker implements SessionTrackerInterface {
3
- private currentAppState;
4
- private sessionStateChangeHandler;
5
- constructor(sessionStateChangeHandler?: SessionStateChangeHandler);
6
- start: () => SessionState;
7
- end: () => SessionState;
8
- private getSessionState;
9
- private appStateChangeHandler;
10
- }
@@ -1,52 +0,0 @@
1
- "use strict";
2
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
- // SPDX-License-Identifier: Apache-2.0
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- var tslib_1 = require("tslib");
6
- var core_1 = require("@aws-amplify/core");
7
- var react_native_1 = require("react-native");
8
- var noop_1 = tslib_1.__importDefault(require("lodash/noop"));
9
- var isActive = function (appState) { return appState === 'active'; };
10
- var isInactive = function (appState) {
11
- return appState === 'inactive' || appState === 'background';
12
- };
13
- var logger = new core_1.ConsoleLogger('InAppMessagingSessionTracker');
14
- var SessionTracker = /** @class */ (function () {
15
- function SessionTracker(sessionStateChangeHandler) {
16
- var _this = this;
17
- if (sessionStateChangeHandler === void 0) { sessionStateChangeHandler = noop_1.default; }
18
- this.start = function () {
19
- react_native_1.AppState.addEventListener('change', _this.appStateChangeHandler);
20
- return _this.getSessionState();
21
- };
22
- this.end = function () {
23
- react_native_1.AppState.removeEventListener('change', _this.appStateChangeHandler);
24
- return _this.getSessionState();
25
- };
26
- this.getSessionState = function () {
27
- if (isActive(_this.currentAppState)) {
28
- return 'started';
29
- }
30
- // consider any other app state as session ended
31
- return 'ended';
32
- };
33
- this.appStateChangeHandler = function (nextAppState) {
34
- // if going from active to inactive
35
- if (isActive(_this.currentAppState) && isInactive(nextAppState)) {
36
- logger.debug('App has gone to the background');
37
- _this.sessionStateChangeHandler('ended');
38
- }
39
- // if going from inactive to active
40
- if (isInactive(_this.currentAppState) && isActive(nextAppState)) {
41
- logger.debug('App has come to the foreground');
42
- _this.sessionStateChangeHandler('started');
43
- }
44
- // otherwise do nothing but always update current state
45
- _this.currentAppState = nextAppState;
46
- };
47
- this.currentAppState = 'active';
48
- this.sessionStateChangeHandler = sessionStateChangeHandler;
49
- }
50
- return SessionTracker;
51
- }());
52
- exports.default = SessionTracker;
@@ -1,3 +0,0 @@
1
- import { default as SessionTracker } from './SessionTracker';
2
- export * from './types';
3
- export default SessionTracker;
@@ -1,7 +0,0 @@
1
- "use strict";
2
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
- // SPDX-License-Identifier: Apache-2.0
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- var tslib_1 = require("tslib");
6
- var SessionTracker_1 = tslib_1.__importDefault(require("./SessionTracker"));
7
- exports.default = SessionTracker_1.default;
@@ -1,6 +0,0 @@
1
- export declare type SessionState = 'started' | 'ended';
2
- export declare type SessionStateChangeHandler = (state: SessionState) => void;
3
- export interface SessionTrackerInterface {
4
- start: () => SessionState;
5
- end: () => SessionState;
6
- }
@@ -1,4 +0,0 @@
1
- "use strict";
2
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
- // SPDX-License-Identifier: Apache-2.0
4
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +0,0 @@
1
- import { Platform as PlatformInterface } from './types';
2
- export declare const Platform: PlatformInterface;
@@ -1,25 +0,0 @@
1
- "use strict";
2
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
- // SPDX-License-Identifier: Apache-2.0
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- var userAgentIncludes = function (text) {
6
- var _a;
7
- return (_a = navigator === null || navigator === void 0 ? void 0 : navigator.userAgent) === null || _a === void 0 ? void 0 : _a.includes(text);
8
- };
9
- var getOS = function () {
10
- if (userAgentIncludes('Android'))
11
- return 'android';
12
- if (userAgentIncludes('like Mac'))
13
- return 'ios';
14
- if (userAgentIncludes('Win'))
15
- return 'windows';
16
- if (userAgentIncludes('Mac'))
17
- return 'macos';
18
- if (userAgentIncludes('Linux'))
19
- return 'linux';
20
- if (userAgentIncludes('X11'))
21
- return 'unix';
22
- return 'unknown';
23
- };
24
- var OS = getOS();
25
- exports.Platform = { OS: OS };
@@ -1,2 +0,0 @@
1
- import { Platform as PlatformInterface } from './types';
2
- export declare const Platform: PlatformInterface;
@@ -1,7 +0,0 @@
1
- "use strict";
2
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
- // SPDX-License-Identifier: Apache-2.0
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- var react_native_1 = require("react-native");
6
- var OS = react_native_1.Platform.OS;
7
- exports.Platform = { OS: OS };
@@ -1,5 +0,0 @@
1
- export interface Platform {
2
- OS: KnownOS | 'unknown';
3
- }
4
- declare type KnownOS = 'windows' | 'macos' | 'unix' | 'linux' | 'ios' | 'android' | 'web';
5
- export {};
@@ -1,4 +0,0 @@
1
- "use strict";
2
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
- // SPDX-License-Identifier: Apache-2.0
4
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,9 +0,0 @@
1
- import { SessionState, SessionStateChangeHandler, SessionTrackerInterface } from './types';
2
- export default class SessionTracker implements SessionTrackerInterface {
3
- private sessionStateChangeHandler;
4
- constructor(sessionStateChangeHandler?: SessionStateChangeHandler);
5
- start: () => SessionState;
6
- end: () => SessionState;
7
- private getSessionState;
8
- private visibilityChangeHandler;
9
- }
@@ -1,64 +0,0 @@
1
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- // SPDX-License-Identifier: Apache-2.0
3
- import { isBrowser } from '@aws-amplify/core/internals/utils';
4
- import { ConsoleLogger } from '@aws-amplify/core';
5
- import noop from 'lodash/noop';
6
- // Per https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API
7
- var hidden;
8
- var visibilityChange;
9
- if (isBrowser() && document) {
10
- if (typeof document.hidden !== 'undefined') {
11
- hidden = 'hidden';
12
- visibilityChange = 'visibilitychange';
13
- }
14
- else if (typeof document['msHidden'] !== 'undefined') {
15
- hidden = 'msHidden';
16
- visibilityChange = 'msvisibilitychange';
17
- }
18
- else if (typeof document['webkitHidden'] !== 'undefined') {
19
- hidden = 'webkitHidden';
20
- visibilityChange = 'webkitvisibilitychange';
21
- }
22
- }
23
- var logger = new ConsoleLogger('InAppMessagingSessionTracker');
24
- var SessionTracker = /** @class */ (function () {
25
- function SessionTracker(sessionStateChangeHandler) {
26
- var _this = this;
27
- if (sessionStateChangeHandler === void 0) { sessionStateChangeHandler = noop; }
28
- this.start = function () {
29
- if (isBrowser()) {
30
- document === null || document === void 0 ? void 0 : document.addEventListener(visibilityChange, _this.visibilityChangeHandler);
31
- }
32
- return _this.getSessionState();
33
- };
34
- this.end = function () {
35
- if (isBrowser()) {
36
- document === null || document === void 0 ? void 0 : document.removeEventListener(visibilityChange, _this.visibilityChangeHandler);
37
- }
38
- return _this.getSessionState();
39
- };
40
- this.getSessionState = function () {
41
- if (isBrowser() && document && !document[hidden]) {
42
- return 'started';
43
- }
44
- // If, for any reason, document is undefined the session will never start
45
- return 'ended';
46
- };
47
- this.visibilityChangeHandler = function () {
48
- if (!isBrowser() || !document) {
49
- return;
50
- }
51
- if (document[hidden]) {
52
- logger.debug('App is now hidden');
53
- _this.sessionStateChangeHandler('ended');
54
- }
55
- else {
56
- logger.debug('App is now visible');
57
- _this.sessionStateChangeHandler('started');
58
- }
59
- };
60
- this.sessionStateChangeHandler = sessionStateChangeHandler;
61
- }
62
- return SessionTracker;
63
- }());
64
- export default SessionTracker;