@aws-amplify/core 6.0.1-console-preview.8f82e46.0 → 6.0.1-console-preview.b278dcb.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/Cache/StorageCacheCommon.js +1 -4
  2. package/lib/I18n/I18n.js +1 -6
  3. package/lib/Platform/types.d.ts +18 -8
  4. package/lib/Platform/types.js +10 -2
  5. package/lib/Platform/version.d.ts +1 -1
  6. package/lib/Platform/version.js +1 -1
  7. package/lib/Reachability/Reachability.js +6 -1
  8. package/lib/errors/errorHelpers.d.ts +2 -0
  9. package/lib/errors/errorHelpers.js +20 -0
  10. package/lib/errors/index.d.ts +1 -0
  11. package/lib/errors/index.js +3 -1
  12. package/lib/index.d.ts +3 -1
  13. package/lib/index.js +4 -1
  14. package/lib/libraryUtils.d.ts +6 -5
  15. package/lib/libraryUtils.js +12 -12
  16. package/lib/parseAWSExports.js +34 -19
  17. package/lib/providers/pinpoint/apis/record.d.ts +1 -1
  18. package/lib/providers/pinpoint/apis/record.js +5 -21
  19. package/lib/providers/pinpoint/index.d.ts +2 -2
  20. package/lib/providers/pinpoint/index.js +4 -2
  21. package/lib/providers/pinpoint/types/errors.d.ts +9 -0
  22. package/lib/providers/pinpoint/types/errors.js +15 -0
  23. package/lib/providers/pinpoint/types/index.d.ts +1 -0
  24. package/lib/providers/pinpoint/types/index.js +3 -0
  25. package/lib/providers/pinpoint/types/pinpoint.d.ts +2 -2
  26. package/lib/providers/pinpoint/utils/index.d.ts +1 -0
  27. package/lib/providers/pinpoint/utils/index.js +3 -1
  28. package/lib/providers/pinpoint/utils/resolveEndpointId.d.ts +8 -0
  29. package/lib/providers/pinpoint/utils/resolveEndpointId.js +85 -0
  30. package/lib/singleton/Interactions/types.d.ts +21 -0
  31. package/lib/singleton/Interactions/types.js +4 -0
  32. package/lib/singleton/Notifications/PushNotification/types.d.ts +2 -0
  33. package/lib/singleton/Notifications/PushNotification/types.js +4 -0
  34. package/lib/singleton/Notifications/types.d.ts +3 -1
  35. package/lib/singleton/types.d.ts +3 -5
  36. package/lib/tsconfig.tsbuildinfo +1 -1
  37. package/lib/types/errors.d.ts +1 -0
  38. package/lib/types/errors.js +1 -0
  39. package/lib/utils/deepFreeze.js +1 -1
  40. package/lib/utils/sessionListener/SessionListener.d.ts +10 -0
  41. package/lib/utils/sessionListener/SessionListener.js +55 -0
  42. package/lib/utils/sessionListener/SessionListener.native.d.ts +10 -0
  43. package/lib/utils/sessionListener/SessionListener.native.js +54 -0
  44. package/lib/utils/sessionListener/index.d.ts +2 -0
  45. package/lib/utils/sessionListener/index.js +7 -0
  46. package/lib/utils/sessionListener/types.d.ts +6 -0
  47. package/lib/utils/sessionListener/types.js +4 -0
  48. package/lib-esm/Cache/StorageCacheCommon.js +1 -4
  49. package/lib-esm/I18n/I18n.js +1 -6
  50. package/lib-esm/Platform/types.d.ts +18 -8
  51. package/lib-esm/Platform/types.js +10 -2
  52. package/lib-esm/Platform/version.d.ts +1 -1
  53. package/lib-esm/Platform/version.js +1 -1
  54. package/lib-esm/Reachability/Reachability.js +7 -2
  55. package/lib-esm/errors/errorHelpers.d.ts +2 -0
  56. package/lib-esm/errors/errorHelpers.js +17 -0
  57. package/lib-esm/errors/index.d.ts +1 -0
  58. package/lib-esm/errors/index.js +1 -0
  59. package/lib-esm/index.d.ts +3 -1
  60. package/lib-esm/index.js +2 -0
  61. package/lib-esm/libraryUtils.d.ts +6 -5
  62. package/lib-esm/libraryUtils.js +5 -4
  63. package/lib-esm/parseAWSExports.js +34 -19
  64. package/lib-esm/providers/pinpoint/apis/record.d.ts +1 -1
  65. package/lib-esm/providers/pinpoint/apis/record.js +6 -22
  66. package/lib-esm/providers/pinpoint/index.d.ts +2 -2
  67. package/lib-esm/providers/pinpoint/index.js +2 -1
  68. package/lib-esm/providers/pinpoint/types/errors.d.ts +9 -0
  69. package/lib-esm/providers/pinpoint/types/errors.js +12 -0
  70. package/lib-esm/providers/pinpoint/types/index.d.ts +1 -0
  71. package/lib-esm/providers/pinpoint/types/index.js +1 -0
  72. package/lib-esm/providers/pinpoint/types/pinpoint.d.ts +2 -2
  73. package/lib-esm/providers/pinpoint/utils/index.d.ts +1 -0
  74. package/lib-esm/providers/pinpoint/utils/index.js +1 -0
  75. package/lib-esm/providers/pinpoint/utils/resolveEndpointId.d.ts +8 -0
  76. package/lib-esm/providers/pinpoint/utils/resolveEndpointId.js +81 -0
  77. package/lib-esm/singleton/Interactions/types.d.ts +21 -0
  78. package/lib-esm/singleton/Interactions/types.js +3 -0
  79. package/lib-esm/singleton/Notifications/PushNotification/types.d.ts +2 -0
  80. package/lib-esm/singleton/Notifications/PushNotification/types.js +3 -0
  81. package/lib-esm/singleton/Notifications/types.d.ts +3 -1
  82. package/lib-esm/singleton/types.d.ts +3 -5
  83. package/lib-esm/tsconfig.tsbuildinfo +1 -1
  84. package/lib-esm/types/errors.d.ts +1 -0
  85. package/lib-esm/types/errors.js +1 -0
  86. package/lib-esm/utils/deepFreeze.js +1 -1
  87. package/lib-esm/utils/sessionListener/SessionListener.d.ts +10 -0
  88. package/lib-esm/utils/sessionListener/SessionListener.js +52 -0
  89. package/lib-esm/utils/sessionListener/SessionListener.native.d.ts +10 -0
  90. package/lib-esm/utils/sessionListener/SessionListener.native.js +51 -0
  91. package/lib-esm/utils/sessionListener/index.d.ts +2 -0
  92. package/lib-esm/utils/sessionListener/index.js +4 -0
  93. package/lib-esm/utils/sessionListener/types.d.ts +6 -0
  94. package/lib-esm/utils/sessionListener/types.js +3 -0
  95. package/package.json +4 -4
  96. package/src/Cache/StorageCacheCommon.ts +0 -4
  97. package/src/I18n/I18n.ts +1 -6
  98. package/src/Platform/types.ts +20 -11
  99. package/src/Platform/version.ts +1 -1
  100. package/src/Reachability/Reachability.ts +8 -2
  101. package/src/errors/errorHelpers.ts +20 -0
  102. package/src/errors/index.ts +1 -0
  103. package/src/index.ts +4 -1
  104. package/src/libraryUtils.ts +15 -8
  105. package/src/parseAWSExports.ts +28 -14
  106. package/src/providers/pinpoint/apis/record.ts +11 -25
  107. package/src/providers/pinpoint/index.ts +6 -2
  108. package/src/providers/pinpoint/types/errors.ts +12 -0
  109. package/src/providers/pinpoint/types/index.ts +1 -0
  110. package/src/providers/pinpoint/types/pinpoint.ts +2 -2
  111. package/src/providers/pinpoint/utils/index.ts +1 -0
  112. package/src/providers/pinpoint/utils/resolveEndpointId.ts +46 -0
  113. package/src/singleton/Interactions/types.ts +29 -0
  114. package/src/singleton/Notifications/PushNotification/types.ts +6 -0
  115. package/src/singleton/Notifications/types.ts +3 -1
  116. package/src/singleton/types.ts +3 -7
  117. package/src/types/errors.ts +1 -0
  118. package/src/utils/deepFreeze.ts +1 -1
  119. package/src/utils/sessionListener/SessionListener.native.ts +70 -0
  120. package/src/utils/sessionListener/SessionListener.ts +74 -0
  121. package/src/utils/sessionListener/index.ts +6 -0
  122. package/src/utils/sessionListener/types.ts +11 -0
@@ -0,0 +1,46 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { assert } from '../../../errors';
5
+ import { AmplifyErrorCode } from '../../../types';
6
+ import { updateEndpoint } from '../apis';
7
+ import { PinpointUpdateEndpointInput } from '../types';
8
+ import { getEndpointId } from './getEndpointId';
9
+
10
+ /**
11
+ * Resolves an endpoint id from cache or prepare via updateEndpoint if one does not already exist,
12
+ * which will generate and cache an endpoint id between calls.
13
+ *
14
+ * @internal
15
+ */
16
+ export const resolveEndpointId = async ({
17
+ address,
18
+ appId,
19
+ category,
20
+ channelType,
21
+ credentials,
22
+ identityId,
23
+ region,
24
+ userAgentValue,
25
+ }: PinpointUpdateEndpointInput) => {
26
+ let endpointId = await getEndpointId(appId, category);
27
+
28
+ if (!endpointId) {
29
+ await updateEndpoint({
30
+ address,
31
+ appId,
32
+ category,
33
+ channelType,
34
+ credentials,
35
+ identityId,
36
+ region,
37
+ userAgentValue,
38
+ });
39
+
40
+ endpointId = await getEndpointId(appId, category);
41
+ }
42
+
43
+ assert(!!endpointId, AmplifyErrorCode.NoEndpointId);
44
+
45
+ return endpointId;
46
+ };
@@ -0,0 +1,29 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ interface LexV1BotConfig {
5
+ alias: string;
6
+ region: string;
7
+ }
8
+
9
+ interface LexV2BotConfig {
10
+ botId: string;
11
+ aliasId: string;
12
+ localeId: string;
13
+ region: string;
14
+ }
15
+
16
+ type InteractionsLexV1Config = {
17
+ LexV1: Record<string, LexV1BotConfig>;
18
+ };
19
+
20
+ type InteractionsLexV2Config = {
21
+ LexV2: Record<string, LexV2BotConfig>;
22
+ };
23
+
24
+ type AtLeastOne<T, U = { [K in keyof T]: Pick<T, K> }> = Partial<T> &
25
+ U[keyof U];
26
+
27
+ export type InteractionsConfig = AtLeastOne<
28
+ InteractionsLexV1Config & InteractionsLexV2Config
29
+ >;
@@ -0,0 +1,6 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { PinpointProviderConfig } from '../../../providers/pinpoint/types';
5
+
6
+ export type PushNotificationConfig = PinpointProviderConfig;
@@ -2,7 +2,9 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import { InAppMessagingConfig } from './InAppMessaging/types';
5
+ import { PushNotificationConfig } from './PushNotification/types';
5
6
 
6
7
  export type NotificationsConfig = {
7
- InAppMessaging: InAppMessagingConfig;
8
+ InAppMessaging?: InAppMessagingConfig;
9
+ PushNotification?: PushNotificationConfig;
8
10
  };
@@ -12,15 +12,14 @@ import {
12
12
  GetCredentialsOptions,
13
13
  CognitoIdentityPoolConfig,
14
14
  } from './Auth/types';
15
- import { CacheConfig } from './Cache/types';
16
15
  import { GeoConfig } from './Geo/types';
17
16
  import {
18
17
  LibraryStorageOptions,
19
18
  StorageAccessLevel,
20
19
  StorageConfig,
21
20
  } from './Storage/types';
22
- import { I18nConfig } from '../I18n/types';
23
21
  import { NotificationsConfig } from './Notifications/types';
22
+ import { InteractionsConfig } from './Interactions/types';
24
23
 
25
24
  export type LegacyConfig = {
26
25
  /**
@@ -33,10 +32,7 @@ export type ResourcesConfig = {
33
32
  API?: APIConfig;
34
33
  Analytics?: AnalyticsConfig;
35
34
  Auth?: AuthConfig;
36
- Cache?: CacheConfig;
37
- // DataStore?: {};
38
- I18n?: I18nConfig;
39
- // Interactions?: {};
35
+ Interactions?: InteractionsConfig;
40
36
  Notifications?: NotificationsConfig;
41
37
  // Predictions?: {};
42
38
  Storage?: StorageConfig;
@@ -56,8 +52,8 @@ export {
56
52
  AuthUserPoolConfig,
57
53
  AuthIdentityPoolConfig,
58
54
  AuthUserPoolAndIdentityPoolConfig,
59
- CacheConfig,
60
55
  GetCredentialsOptions,
56
+ InteractionsConfig,
61
57
  StorageAccessLevel,
62
58
  StorageConfig,
63
59
  AnalyticsConfig,
@@ -2,6 +2,7 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  export enum AmplifyErrorCode {
5
+ NoEndpointId = 'NoEndpointId',
5
6
  PlatformNotSupported = 'PlatformNotSupported',
6
7
  Unknown = 'Unknown',
7
8
  }
@@ -7,7 +7,7 @@ export const deepFreeze = (object: any) => {
7
7
  for (const name of propNames) {
8
8
  const value = object[name];
9
9
 
10
- if ((value && typeof value === "object") || typeof value === "function") {
10
+ if ((value && typeof value === 'object') || typeof value === 'function') {
11
11
  deepFreeze(value);
12
12
  }
13
13
  }
@@ -0,0 +1,70 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { loadAppState } from '@aws-amplify/react-native';
5
+ import {
6
+ SessionStateChangeListener,
7
+ SessionState,
8
+ SessionListenerInterface,
9
+ } from './types';
10
+
11
+ const stateChangeListeners = new Set<SessionStateChangeListener>();
12
+ const isActive = (appState?: string) => appState === 'active';
13
+ const isInactive = (appState?: string) =>
14
+ appState === 'inactive' || appState === 'background';
15
+
16
+ export class SessionListener implements SessionListenerInterface {
17
+ private currentAppState?: string;
18
+
19
+ constructor() {
20
+ this.handleStateChange = this.handleStateChange.bind(this);
21
+
22
+ // Setup state listeners
23
+ loadAppState().addEventListener('change', this.handleStateChange);
24
+ }
25
+
26
+ public addStateChangeListener(
27
+ listener: SessionStateChangeListener,
28
+ notifyOnAdd: boolean = false
29
+ ) {
30
+ stateChangeListeners.add(listener);
31
+
32
+ // Notify new handlers of the current state on add if the current state has been determined
33
+ if (notifyOnAdd && this.currentAppState !== undefined) {
34
+ listener(this.getSessionState());
35
+ }
36
+ }
37
+
38
+ public removeStateChangeListener(handler: SessionStateChangeListener) {
39
+ stateChangeListeners.delete(handler);
40
+ }
41
+
42
+ private handleStateChange(nextAppState: string) {
43
+ if (
44
+ (this.currentAppState === undefined ||
45
+ isInactive(this.currentAppState)) &&
46
+ isActive(nextAppState)
47
+ ) {
48
+ this.notifyHandlers('started');
49
+ } else if (isActive(this.currentAppState) && isInactive(nextAppState)) {
50
+ this.notifyHandlers('ended');
51
+ }
52
+
53
+ this.currentAppState = nextAppState;
54
+ }
55
+
56
+ private notifyHandlers(state: SessionState) {
57
+ stateChangeListeners.forEach(listener => {
58
+ listener(state);
59
+ });
60
+ }
61
+
62
+ private getSessionState() {
63
+ if (isActive(this.currentAppState)) {
64
+ return 'started';
65
+ }
66
+
67
+ // Consider any other app state as ended
68
+ return 'ended';
69
+ }
70
+ }
@@ -0,0 +1,74 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { isBrowser } from '../isBrowser';
5
+ import { SessionStateChangeListener, SessionListenerInterface } from './types';
6
+
7
+ const stateChangeListeners = new Set<SessionStateChangeListener>();
8
+
9
+ export class SessionListener implements SessionListenerInterface {
10
+ private listenerActive: boolean;
11
+
12
+ constructor() {
13
+ this.listenerActive = false;
14
+ this.handleVisibilityChange = this.handleVisibilityChange.bind(this);
15
+
16
+ // Setup state listeners
17
+ if (isBrowser()) {
18
+ document.addEventListener(
19
+ 'visibilitychange',
20
+ this.handleVisibilityChange,
21
+ false
22
+ );
23
+
24
+ this.listenerActive = true;
25
+ }
26
+ }
27
+
28
+ public addStateChangeListener(
29
+ listener: SessionStateChangeListener,
30
+ notifyOnAdd: boolean = false
31
+ ) {
32
+ // No-op if document listener is not active
33
+ if (!this.listenerActive) {
34
+ return;
35
+ }
36
+
37
+ stateChangeListeners.add(listener);
38
+
39
+ // Notify new handlers of the current status on add
40
+ if (notifyOnAdd) {
41
+ listener(this.getSessionState());
42
+ }
43
+ }
44
+
45
+ public removeStateChangeListener(handler: SessionStateChangeListener) {
46
+ // No-op if document listener is not active
47
+ if (!this.listenerActive) {
48
+ return;
49
+ }
50
+
51
+ stateChangeListeners.delete(handler);
52
+ }
53
+
54
+ private handleVisibilityChange() {
55
+ this.notifyHandlers();
56
+ }
57
+
58
+ private notifyHandlers() {
59
+ const sessionState = this.getSessionState();
60
+
61
+ stateChangeListeners.forEach(listener => {
62
+ listener(sessionState);
63
+ });
64
+ }
65
+
66
+ private getSessionState() {
67
+ if (isBrowser() && document.visibilityState !== 'hidden') {
68
+ return 'started';
69
+ }
70
+
71
+ // If, for any reason, document is undefined the session will never start
72
+ return 'ended';
73
+ }
74
+ }
@@ -0,0 +1,6 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { SessionListener } from './SessionListener';
5
+
6
+ export const sessionListener = new SessionListener();
@@ -0,0 +1,11 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ export type SessionState = 'started' | 'ended';
5
+
6
+ export type SessionStateChangeListener = (state: SessionState) => void;
7
+
8
+ export interface SessionListenerInterface {
9
+ addStateChangeListener: (listener: SessionStateChangeListener) => void;
10
+ removeStateChangeListener: (listener: SessionStateChangeListener) => void;
11
+ }