@aws-amplify/core 4.4.1 → 4.4.2-api-logging.2
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/dist/aws-amplify-core.js +1104 -202
- package/dist/aws-amplify-core.js.map +1 -1
- package/dist/aws-amplify-core.min.js +7 -7
- package/dist/aws-amplify-core.min.js.map +1 -1
- package/lib/Logger/ConsoleLogger.d.ts +12 -1
- package/lib/Logger/ConsoleLogger.js +61 -6
- package/lib/Logger/ConsoleLogger.js.map +1 -1
- package/lib/Platform/version.d.ts +1 -1
- package/lib/Platform/version.js +1 -1
- package/lib/Providers/APIProvider/APILoggingProvider.d.ts +28 -0
- package/lib/Providers/APIProvider/APILoggingProvider.js +311 -0
- package/lib/Providers/APIProvider/APILoggingProvider.js.map +1 -0
- package/lib/Providers/APIProvider/CloudWatchEventFormatter.d.ts +5 -0
- package/lib/Providers/APIProvider/CloudWatchEventFormatter.js +78 -0
- package/lib/Providers/APIProvider/CloudWatchEventFormatter.js.map +1 -0
- package/lib/Providers/APIProvider/Fetch.d.ts +10 -0
- package/lib/Providers/APIProvider/Fetch.js +13 -0
- package/lib/Providers/APIProvider/Fetch.js.map +1 -0
- package/lib/Providers/APIProvider/LoggerReachability/index.d.ts +3 -0
- package/lib/Providers/APIProvider/LoggerReachability/index.js +5 -0
- package/lib/Providers/APIProvider/LoggerReachability/index.js.map +1 -0
- package/lib/Providers/APIProvider/LoggerReachability/index.native.d.ts +3 -0
- package/lib/Providers/APIProvider/LoggerReachability/index.native.js +9 -0
- package/lib/Providers/APIProvider/LoggerReachability/index.native.js.map +1 -0
- package/lib/Providers/APIProvider/index.d.ts +1 -0
- package/lib/Providers/APIProvider/index.js +5 -0
- package/lib/Providers/APIProvider/index.js.map +1 -0
- package/lib/Providers/APIProvider/loggerConnectivity.d.ts +14 -0
- package/lib/Providers/APIProvider/loggerConnectivity.js +55 -0
- package/lib/Providers/APIProvider/loggerConnectivity.js.map +1 -0
- package/lib/Providers/index.d.ts +1 -0
- package/lib/Providers/index.js +2 -0
- package/lib/Providers/index.js.map +1 -1
- package/lib/Util/Constants.d.ts +3 -1
- package/lib/Util/Constants.js +4 -0
- package/lib/Util/Constants.js.map +1 -1
- package/lib/Util/Reachability.js +7 -5
- package/lib/Util/Reachability.js.map +1 -1
- package/lib/Util/Retry.js +2 -2
- package/lib/Util/Retry.js.map +1 -1
- package/lib/Util/StringUtils.d.ts +1 -0
- package/lib/Util/StringUtils.js +11 -6
- package/lib/Util/StringUtils.js.map +1 -1
- package/lib/types/index.js +4 -0
- package/lib/types/index.js.map +1 -1
- package/lib/types/types.d.ts +26 -1
- package/lib/types/types.js +5 -0
- package/lib/types/types.js.map +1 -1
- package/lib-esm/Logger/ConsoleLogger.d.ts +12 -1
- package/lib-esm/Logger/ConsoleLogger.js +59 -4
- package/lib-esm/Logger/ConsoleLogger.js.map +1 -1
- package/lib-esm/Platform/version.d.ts +1 -1
- package/lib-esm/Platform/version.js +1 -1
- package/lib-esm/Providers/APIProvider/APILoggingProvider.d.ts +28 -0
- package/lib-esm/Providers/APIProvider/APILoggingProvider.js +306 -0
- package/lib-esm/Providers/APIProvider/APILoggingProvider.js.map +1 -0
- package/lib-esm/Providers/APIProvider/CloudWatchEventFormatter.d.ts +5 -0
- package/lib-esm/Providers/APIProvider/CloudWatchEventFormatter.js +76 -0
- package/lib-esm/Providers/APIProvider/CloudWatchEventFormatter.js.map +1 -0
- package/lib-esm/Providers/APIProvider/Fetch.d.ts +10 -0
- package/lib-esm/Providers/APIProvider/Fetch.js +11 -0
- package/lib-esm/Providers/APIProvider/Fetch.js.map +1 -0
- package/lib-esm/Providers/APIProvider/LoggerReachability/index.d.ts +3 -0
- package/lib-esm/Providers/APIProvider/LoggerReachability/index.js +3 -0
- package/lib-esm/Providers/APIProvider/LoggerReachability/index.js.map +1 -0
- package/lib-esm/Providers/APIProvider/LoggerReachability/index.native.d.ts +3 -0
- package/lib-esm/Providers/APIProvider/LoggerReachability/index.native.js +4 -0
- package/lib-esm/Providers/APIProvider/LoggerReachability/index.native.js.map +1 -0
- package/lib-esm/Providers/APIProvider/index.d.ts +1 -0
- package/lib-esm/Providers/APIProvider/index.js +2 -0
- package/lib-esm/Providers/APIProvider/index.js.map +1 -0
- package/lib-esm/Providers/APIProvider/loggerConnectivity.d.ts +14 -0
- package/lib-esm/Providers/APIProvider/loggerConnectivity.js +50 -0
- package/lib-esm/Providers/APIProvider/loggerConnectivity.js.map +1 -0
- package/lib-esm/Providers/index.d.ts +1 -0
- package/lib-esm/Providers/index.js +1 -0
- package/lib-esm/Providers/index.js.map +1 -1
- package/lib-esm/Util/Constants.d.ts +3 -1
- package/lib-esm/Util/Constants.js +3 -1
- package/lib-esm/Util/Constants.js.map +1 -1
- package/lib-esm/Util/Reachability.js +5 -3
- package/lib-esm/Util/Reachability.js.map +1 -1
- package/lib-esm/Util/Retry.js +2 -2
- package/lib-esm/Util/Retry.js.map +1 -1
- package/lib-esm/Util/StringUtils.d.ts +1 -0
- package/lib-esm/Util/StringUtils.js +11 -6
- package/lib-esm/Util/StringUtils.js.map +1 -1
- package/lib-esm/types/index.js +1 -0
- package/lib-esm/types/index.js.map +1 -1
- package/lib-esm/types/types.d.ts +26 -1
- package/lib-esm/types/types.js +5 -0
- package/lib-esm/types/types.js.map +1 -1
- package/package.json +2 -2
- package/src/Logger/ConsoleLogger.ts +45 -2
- package/src/Platform/version.ts +1 -1
- package/src/Providers/APIProvider/APILoggingProvider.ts +286 -0
- package/src/Providers/APIProvider/CloudWatchEventFormatter.ts +97 -0
- package/src/Providers/APIProvider/Fetch.ts +10 -0
- package/src/Providers/APIProvider/LoggerReachability/index.native.ts +4 -0
- package/src/Providers/APIProvider/LoggerReachability/index.ts +2 -0
- package/src/Providers/APIProvider/index.ts +1 -0
- package/src/Providers/APIProvider/loggerConnectivity.ts +49 -0
- package/src/Providers/index.ts +1 -0
- package/src/Util/Constants.ts +4 -0
- package/src/Util/Reachability.ts +9 -7
- package/src/Util/Retry.ts +2 -2
- package/src/Util/StringUtils.ts +15 -6
- package/src/types/types.ts +88 -62
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import Observable, { ZenObservable } from 'zen-observable-ts';
|
|
2
|
+
import { ReachabilityMonitor } from './LoggerReachability';
|
|
3
|
+
|
|
4
|
+
type ConnectionStatus = {
|
|
5
|
+
online: boolean;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
// TODO: refactor this to a singleton that supports numerous observers
|
|
9
|
+
export default class LoggerConnectivity {
|
|
10
|
+
private connectionStatus: ConnectionStatus;
|
|
11
|
+
private observer: ZenObservable.SubscriptionObserver<ConnectionStatus>;
|
|
12
|
+
private subscription: ZenObservable.Subscription;
|
|
13
|
+
private timeout: ReturnType<typeof setTimeout>;
|
|
14
|
+
constructor() {
|
|
15
|
+
this.connectionStatus = {
|
|
16
|
+
online: false,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
status(): Observable<ConnectionStatus> {
|
|
21
|
+
if (this.observer) {
|
|
22
|
+
throw new Error('Subscriber already exists');
|
|
23
|
+
}
|
|
24
|
+
return new Observable(observer => {
|
|
25
|
+
this.observer = observer;
|
|
26
|
+
|
|
27
|
+
this.subscription = ReachabilityMonitor.subscribe(({ online }) => {
|
|
28
|
+
this.connectionStatus.online = online;
|
|
29
|
+
|
|
30
|
+
const observerResult = { ...this.connectionStatus };
|
|
31
|
+
|
|
32
|
+
observer.next(observerResult);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
return () => {
|
|
36
|
+
clearTimeout(this.timeout);
|
|
37
|
+
this.unsubscribe();
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
unsubscribe() {
|
|
43
|
+
if (this.subscription) {
|
|
44
|
+
clearTimeout(this.timeout);
|
|
45
|
+
this.subscription.unsubscribe();
|
|
46
|
+
this.observer = undefined;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
package/src/Providers/index.ts
CHANGED
package/src/Util/Constants.ts
CHANGED
|
@@ -22,6 +22,8 @@ const RETRY_ERROR_CODES = [
|
|
|
22
22
|
'ResourceNotFoundException',
|
|
23
23
|
'InvalidSequenceTokenException',
|
|
24
24
|
];
|
|
25
|
+
const API_LOGGING_PROVIDER_NAME = 'API';
|
|
26
|
+
const API_LOGGING_PROVIDER_CATEGORY = 'Logging';
|
|
25
27
|
|
|
26
28
|
export {
|
|
27
29
|
AWS_CLOUDWATCH_BASE_BUFFER_SIZE,
|
|
@@ -31,4 +33,6 @@ export {
|
|
|
31
33
|
AWS_CLOUDWATCH_PROVIDER_NAME,
|
|
32
34
|
NO_CREDS_ERROR_STRING,
|
|
33
35
|
RETRY_ERROR_CODES,
|
|
36
|
+
API_LOGGING_PROVIDER_NAME,
|
|
37
|
+
API_LOGGING_PROVIDER_CATEGORY,
|
|
34
38
|
};
|
package/src/Util/Reachability.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { browserOrNode, isWebWorker } from '
|
|
1
|
+
import { browserOrNode, isWebWorker } from '../JS';
|
|
2
2
|
import Observable, { ZenObservable } from 'zen-observable-ts';
|
|
3
3
|
|
|
4
4
|
type NetworkStatus = {
|
|
@@ -32,9 +32,10 @@ export default class ReachabilityNavigator implements Reachability {
|
|
|
32
32
|
globalObj.removeEventListener('online', notifyOnline);
|
|
33
33
|
globalObj.removeEventListener('offline', notifyOffline);
|
|
34
34
|
|
|
35
|
-
ReachabilityNavigator._observers =
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
ReachabilityNavigator._observers =
|
|
36
|
+
ReachabilityNavigator._observers.filter(
|
|
37
|
+
_observer => _observer !== observer
|
|
38
|
+
);
|
|
38
39
|
};
|
|
39
40
|
});
|
|
40
41
|
}
|
|
@@ -43,9 +44,10 @@ export default class ReachabilityNavigator implements Reachability {
|
|
|
43
44
|
private static _observerOverride(status: NetworkStatus): void {
|
|
44
45
|
for (const observer of ReachabilityNavigator._observers) {
|
|
45
46
|
if (observer.closed) {
|
|
46
|
-
ReachabilityNavigator._observers =
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
ReachabilityNavigator._observers =
|
|
48
|
+
ReachabilityNavigator._observers.filter(
|
|
49
|
+
_observer => _observer !== observer
|
|
50
|
+
);
|
|
49
51
|
continue;
|
|
50
52
|
}
|
|
51
53
|
observer.next(status);
|
package/src/Util/Retry.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DelayFunction } from '../types';
|
|
2
2
|
import { ConsoleLogger as Logger } from '../Logger/ConsoleLogger';
|
|
3
|
-
const logger = new Logger('
|
|
3
|
+
const logger = new Logger('Retry');
|
|
4
4
|
|
|
5
5
|
export class NonRetryableError extends Error {
|
|
6
6
|
public readonly nonRetryable = true;
|
|
@@ -30,7 +30,7 @@ export async function retry(
|
|
|
30
30
|
logger.debug(
|
|
31
31
|
`${
|
|
32
32
|
functionToRetry.name
|
|
33
|
-
} attempt #${attempt} with
|
|
33
|
+
} attempt #${attempt} with these vars: ${JSON.stringify(args)}`
|
|
34
34
|
);
|
|
35
35
|
|
|
36
36
|
try {
|
package/src/Util/StringUtils.ts
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
|
+
import { browserOrNode } from '../../';
|
|
1
2
|
export function urlSafeEncode(str: string) {
|
|
2
3
|
return str
|
|
3
4
|
.split('')
|
|
4
|
-
.map(char =>
|
|
5
|
-
char
|
|
6
|
-
.charCodeAt(0)
|
|
7
|
-
.toString(16)
|
|
8
|
-
.padStart(2, '0')
|
|
9
|
-
)
|
|
5
|
+
.map(char => char.charCodeAt(0).toString(16).padStart(2, '0'))
|
|
10
6
|
.join('');
|
|
11
7
|
}
|
|
12
8
|
|
|
@@ -16,3 +12,16 @@ export function urlSafeDecode(hex: string) {
|
|
|
16
12
|
.map(char => String.fromCharCode(parseInt(char, 16)))
|
|
17
13
|
.join('');
|
|
18
14
|
}
|
|
15
|
+
export const getStringByteSize = (str: string): number => {
|
|
16
|
+
if (browserOrNode().isBrowser || Blob !== undefined) {
|
|
17
|
+
return new Blob([str]).size;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (Buffer !== undefined) {
|
|
21
|
+
return Buffer.byteLength(str, 'utf8');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
throw new Error(
|
|
25
|
+
'Cannot compute string length. Blob and Buffer are undefined'
|
|
26
|
+
);
|
|
27
|
+
};
|
package/src/types/types.ts
CHANGED
|
@@ -1,62 +1,88 @@
|
|
|
1
|
-
import { InputLogEvent, LogGroup } from '@aws-sdk/client-cloudwatch-logs';
|
|
2
|
-
import { Credentials } from '@aws-sdk/types';
|
|
3
|
-
|
|
4
|
-
export interface AmplifyConfig {
|
|
5
|
-
Analytics?: object;
|
|
6
|
-
Auth?: object;
|
|
7
|
-
API?: object;
|
|
8
|
-
Logging?: object;
|
|
9
|
-
Storage?: object;
|
|
10
|
-
Cache?: object;
|
|
11
|
-
Geo?: object;
|
|
12
|
-
ssr?: boolean;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface ICredentials {
|
|
16
|
-
accessKeyId: string;
|
|
17
|
-
sessionToken: string;
|
|
18
|
-
secretAccessKey: string;
|
|
19
|
-
identityId: string;
|
|
20
|
-
authenticated: boolean;
|
|
21
|
-
// Long term creds do not provide an expiration date
|
|
22
|
-
expiration?: Date;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* @private
|
|
27
|
-
* Internal use of Amplify only
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
|
-
export type DelayFunction = (
|
|
31
|
-
attempt: number,
|
|
32
|
-
args?: any[],
|
|
33
|
-
error?: Error
|
|
34
|
-
) => number | false;
|
|
35
|
-
|
|
36
|
-
export interface LoggingProvider {
|
|
37
|
-
// return the name of you provider
|
|
38
|
-
getProviderName(): string;
|
|
39
|
-
|
|
40
|
-
// return the name of you category
|
|
41
|
-
getCategoryName(): string;
|
|
42
|
-
|
|
43
|
-
// configure the plugin
|
|
44
|
-
configure(config?: object): object;
|
|
45
|
-
|
|
46
|
-
// take logs and push to provider
|
|
47
|
-
pushLogs(logs: InputLogEvent[]): void;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
1
|
+
import { InputLogEvent, LogGroup } from '@aws-sdk/client-cloudwatch-logs';
|
|
2
|
+
import { Credentials } from '@aws-sdk/types';
|
|
3
|
+
import { LOG_TYPE } from '../Logger/ConsoleLogger';
|
|
4
|
+
export interface AmplifyConfig {
|
|
5
|
+
Analytics?: object;
|
|
6
|
+
Auth?: object;
|
|
7
|
+
API?: object;
|
|
8
|
+
Logging?: object;
|
|
9
|
+
Storage?: object;
|
|
10
|
+
Cache?: object;
|
|
11
|
+
Geo?: object;
|
|
12
|
+
ssr?: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface ICredentials {
|
|
16
|
+
accessKeyId: string;
|
|
17
|
+
sessionToken: string;
|
|
18
|
+
secretAccessKey: string;
|
|
19
|
+
identityId: string;
|
|
20
|
+
authenticated: boolean;
|
|
21
|
+
// Long term creds do not provide an expiration date
|
|
22
|
+
expiration?: Date;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @private
|
|
27
|
+
* Internal use of Amplify only
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
export type DelayFunction = (
|
|
31
|
+
attempt: number,
|
|
32
|
+
args?: any[],
|
|
33
|
+
error?: Error
|
|
34
|
+
) => number | false;
|
|
35
|
+
|
|
36
|
+
export interface LoggingProvider {
|
|
37
|
+
// return the name of you provider
|
|
38
|
+
getProviderName(): string;
|
|
39
|
+
|
|
40
|
+
// return the name of you category
|
|
41
|
+
getCategoryName(): string;
|
|
42
|
+
|
|
43
|
+
// configure the plugin
|
|
44
|
+
configure(config?: object): object;
|
|
45
|
+
|
|
46
|
+
// take logs and push to provider
|
|
47
|
+
pushLogs?(logs: InputLogEvent[]): void;
|
|
48
|
+
|
|
49
|
+
// push a single log event
|
|
50
|
+
pushLog?(log: GenericLogEvent): void;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface AWSCloudWatchProviderOptions {
|
|
54
|
+
logGroupName?: string;
|
|
55
|
+
logStreamName?: string;
|
|
56
|
+
region?: string;
|
|
57
|
+
credentials?: Credentials;
|
|
58
|
+
endpoint?: string;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface CloudWatchDataTracker {
|
|
62
|
+
eventUploadInProgress: boolean;
|
|
63
|
+
logEvents: InputLogEvent[];
|
|
64
|
+
verifiedLogGroup?: LogGroup;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface APILoggingProviderOptions {
|
|
68
|
+
endpoint: string;
|
|
69
|
+
apiKey?: string;
|
|
70
|
+
enabled?: boolean;
|
|
71
|
+
level?: LOG_TYPE;
|
|
72
|
+
excludeClassList?: string[];
|
|
73
|
+
metadata?: { [key: string]: any };
|
|
74
|
+
eventFormat?: EVENT_FORMAT;
|
|
75
|
+
bufferInterval?: number;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export enum EVENT_FORMAT {
|
|
79
|
+
GENERIC = 'GENERIC',
|
|
80
|
+
CLOUDWATCH = 'CLOUDWATCH',
|
|
81
|
+
}
|
|
82
|
+
export interface GenericLogEvent {
|
|
83
|
+
level: string;
|
|
84
|
+
source: string;
|
|
85
|
+
timestamp: number;
|
|
86
|
+
message?: string;
|
|
87
|
+
data?: object;
|
|
88
|
+
}
|