@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.
- package/lib/Cache/StorageCacheCommon.js +1 -4
- package/lib/I18n/I18n.js +1 -6
- package/lib/Platform/types.d.ts +18 -8
- package/lib/Platform/types.js +10 -2
- package/lib/Platform/version.d.ts +1 -1
- package/lib/Platform/version.js +1 -1
- package/lib/Reachability/Reachability.js +6 -1
- package/lib/errors/errorHelpers.d.ts +2 -0
- package/lib/errors/errorHelpers.js +20 -0
- package/lib/errors/index.d.ts +1 -0
- package/lib/errors/index.js +3 -1
- package/lib/index.d.ts +3 -1
- package/lib/index.js +4 -1
- package/lib/libraryUtils.d.ts +6 -5
- package/lib/libraryUtils.js +12 -12
- package/lib/parseAWSExports.js +34 -19
- package/lib/providers/pinpoint/apis/record.d.ts +1 -1
- package/lib/providers/pinpoint/apis/record.js +5 -21
- package/lib/providers/pinpoint/index.d.ts +2 -2
- package/lib/providers/pinpoint/index.js +4 -2
- package/lib/providers/pinpoint/types/errors.d.ts +9 -0
- package/lib/providers/pinpoint/types/errors.js +15 -0
- package/lib/providers/pinpoint/types/index.d.ts +1 -0
- package/lib/providers/pinpoint/types/index.js +3 -0
- package/lib/providers/pinpoint/types/pinpoint.d.ts +2 -2
- package/lib/providers/pinpoint/utils/index.d.ts +1 -0
- package/lib/providers/pinpoint/utils/index.js +3 -1
- package/lib/providers/pinpoint/utils/resolveEndpointId.d.ts +8 -0
- package/lib/providers/pinpoint/utils/resolveEndpointId.js +85 -0
- package/lib/singleton/Interactions/types.d.ts +21 -0
- package/lib/singleton/Interactions/types.js +4 -0
- package/lib/singleton/Notifications/PushNotification/types.d.ts +2 -0
- package/lib/singleton/Notifications/PushNotification/types.js +4 -0
- package/lib/singleton/Notifications/types.d.ts +3 -1
- package/lib/singleton/types.d.ts +3 -5
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types/errors.d.ts +1 -0
- package/lib/types/errors.js +1 -0
- package/lib/utils/deepFreeze.js +1 -1
- package/lib/utils/sessionListener/SessionListener.d.ts +10 -0
- package/lib/utils/sessionListener/SessionListener.js +55 -0
- package/lib/utils/sessionListener/SessionListener.native.d.ts +10 -0
- package/lib/utils/sessionListener/SessionListener.native.js +54 -0
- package/lib/utils/sessionListener/index.d.ts +2 -0
- package/lib/utils/sessionListener/index.js +7 -0
- package/lib/utils/sessionListener/types.d.ts +6 -0
- package/lib/utils/sessionListener/types.js +4 -0
- package/lib-esm/Cache/StorageCacheCommon.js +1 -4
- package/lib-esm/I18n/I18n.js +1 -6
- package/lib-esm/Platform/types.d.ts +18 -8
- package/lib-esm/Platform/types.js +10 -2
- package/lib-esm/Platform/version.d.ts +1 -1
- package/lib-esm/Platform/version.js +1 -1
- package/lib-esm/Reachability/Reachability.js +7 -2
- package/lib-esm/errors/errorHelpers.d.ts +2 -0
- package/lib-esm/errors/errorHelpers.js +17 -0
- package/lib-esm/errors/index.d.ts +1 -0
- package/lib-esm/errors/index.js +1 -0
- package/lib-esm/index.d.ts +3 -1
- package/lib-esm/index.js +2 -0
- package/lib-esm/libraryUtils.d.ts +6 -5
- package/lib-esm/libraryUtils.js +5 -4
- package/lib-esm/parseAWSExports.js +34 -19
- package/lib-esm/providers/pinpoint/apis/record.d.ts +1 -1
- package/lib-esm/providers/pinpoint/apis/record.js +6 -22
- package/lib-esm/providers/pinpoint/index.d.ts +2 -2
- package/lib-esm/providers/pinpoint/index.js +2 -1
- package/lib-esm/providers/pinpoint/types/errors.d.ts +9 -0
- package/lib-esm/providers/pinpoint/types/errors.js +12 -0
- package/lib-esm/providers/pinpoint/types/index.d.ts +1 -0
- package/lib-esm/providers/pinpoint/types/index.js +1 -0
- package/lib-esm/providers/pinpoint/types/pinpoint.d.ts +2 -2
- package/lib-esm/providers/pinpoint/utils/index.d.ts +1 -0
- package/lib-esm/providers/pinpoint/utils/index.js +1 -0
- package/lib-esm/providers/pinpoint/utils/resolveEndpointId.d.ts +8 -0
- package/lib-esm/providers/pinpoint/utils/resolveEndpointId.js +81 -0
- package/lib-esm/singleton/Interactions/types.d.ts +21 -0
- package/lib-esm/singleton/Interactions/types.js +3 -0
- package/lib-esm/singleton/Notifications/PushNotification/types.d.ts +2 -0
- package/lib-esm/singleton/Notifications/PushNotification/types.js +3 -0
- package/lib-esm/singleton/Notifications/types.d.ts +3 -1
- package/lib-esm/singleton/types.d.ts +3 -5
- package/lib-esm/tsconfig.tsbuildinfo +1 -1
- package/lib-esm/types/errors.d.ts +1 -0
- package/lib-esm/types/errors.js +1 -0
- package/lib-esm/utils/deepFreeze.js +1 -1
- package/lib-esm/utils/sessionListener/SessionListener.d.ts +10 -0
- package/lib-esm/utils/sessionListener/SessionListener.js +52 -0
- package/lib-esm/utils/sessionListener/SessionListener.native.d.ts +10 -0
- package/lib-esm/utils/sessionListener/SessionListener.native.js +51 -0
- package/lib-esm/utils/sessionListener/index.d.ts +2 -0
- package/lib-esm/utils/sessionListener/index.js +4 -0
- package/lib-esm/utils/sessionListener/types.d.ts +6 -0
- package/lib-esm/utils/sessionListener/types.js +3 -0
- package/package.json +4 -4
- package/src/Cache/StorageCacheCommon.ts +0 -4
- package/src/I18n/I18n.ts +1 -6
- package/src/Platform/types.ts +20 -11
- package/src/Platform/version.ts +1 -1
- package/src/Reachability/Reachability.ts +8 -2
- package/src/errors/errorHelpers.ts +20 -0
- package/src/errors/index.ts +1 -0
- package/src/index.ts +4 -1
- package/src/libraryUtils.ts +15 -8
- package/src/parseAWSExports.ts +28 -14
- package/src/providers/pinpoint/apis/record.ts +11 -25
- package/src/providers/pinpoint/index.ts +6 -2
- package/src/providers/pinpoint/types/errors.ts +12 -0
- package/src/providers/pinpoint/types/index.ts +1 -0
- package/src/providers/pinpoint/types/pinpoint.ts +2 -2
- package/src/providers/pinpoint/utils/index.ts +1 -0
- package/src/providers/pinpoint/utils/resolveEndpointId.ts +46 -0
- package/src/singleton/Interactions/types.ts +29 -0
- package/src/singleton/Notifications/PushNotification/types.ts +6 -0
- package/src/singleton/Notifications/types.ts +3 -1
- package/src/singleton/types.ts +3 -7
- package/src/types/errors.ts +1 -0
- package/src/utils/deepFreeze.ts +1 -1
- package/src/utils/sessionListener/SessionListener.native.ts +70 -0
- package/src/utils/sessionListener/SessionListener.ts +74 -0
- package/src/utils/sessionListener/index.ts +6 -0
- 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
|
+
>;
|
|
@@ -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
|
|
8
|
+
InAppMessaging?: InAppMessagingConfig;
|
|
9
|
+
PushNotification?: PushNotificationConfig;
|
|
8
10
|
};
|
package/src/singleton/types.ts
CHANGED
|
@@ -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
|
-
|
|
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,
|
package/src/types/errors.ts
CHANGED
package/src/utils/deepFreeze.ts
CHANGED
|
@@ -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 ===
|
|
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,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
|
+
}
|