@crimson-education/browser-logger 3.0.0 → 3.0.1
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/index.d.ts +12 -12
- package/lib/index.js +69 -69
- package/lib/logger/consoleTransport.d.ts +36 -36
- package/lib/logger/consoleTransport.js +80 -80
- package/lib/logger/datadogTransport.d.ts +7 -7
- package/lib/logger/datadogTransport.js +20 -20
- package/lib/logger/index.d.ts +15 -15
- package/lib/logger/index.js +147 -147
- package/lib/logger/index.test.d.ts +1 -1
- package/lib/logger/index.test.js +59 -59
- package/lib/logger/utils.d.ts +14 -14
- package/lib/logger/utils.js +31 -31
- package/lib/reporters/amplifyReporter.d.ts +83 -77
- package/lib/reporters/amplifyReporter.d.ts.map +1 -1
- package/lib/reporters/amplifyReporter.js +162 -150
- package/lib/reporters/amplifyReporter.js.map +1 -1
- package/lib/reporters/amplifyReporter.test.d.ts +1 -1
- package/lib/reporters/amplifyReporter.test.js +50 -50
- package/lib/reporters/datadogReporter.d.ts +76 -76
- package/lib/reporters/datadogReporter.js +122 -122
- package/lib/reporters/gtmReporter.d.ts +8 -8
- package/lib/reporters/gtmReporter.js +56 -56
- package/lib/reporters/index.d.ts +66 -66
- package/lib/reporters/index.js +212 -212
- package/lib/reporters/logReporter.d.ts +34 -34
- package/lib/reporters/logReporter.js +61 -61
- package/lib/types/index.d.ts +2 -2
- package/lib/types/index.js +18 -18
- package/lib/types/logger.d.ts +77 -77
- package/lib/types/logger.js +10 -10
- package/lib/types/reporter.d.ts +154 -154
- package/lib/types/reporter.js +2 -2
- package/lib/utils.d.ts +9 -9
- package/lib/utils.js +31 -31
- package/lib/utils.test.d.ts +1 -1
- package/lib/utils.test.js +31 -31
- package/package.json +1 -1
- package/src/reporters/amplifyReporter.ts +22 -1
package/lib/utils.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { IReporter, Metadata } from './types';
|
|
2
|
-
/**
|
|
3
|
-
* Recursively filter reporter metadata.
|
|
4
|
-
* @param metadata Deep Metadata to filter.
|
|
5
|
-
* @param reporter Reporter with filter config.
|
|
6
|
-
* @param prefix Prefix for recusring nested metadata.
|
|
7
|
-
* @returns Filtered metadata.
|
|
8
|
-
*/
|
|
9
|
-
export declare function filterReporterMetadata<TMetadata extends Metadata | undefined>(metadata: TMetadata, reporter: Pick<IReporter, 'ignoreMetadataPatterns'>, prefix?: string): TMetadata;
|
|
1
|
+
import { IReporter, Metadata } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Recursively filter reporter metadata.
|
|
4
|
+
* @param metadata Deep Metadata to filter.
|
|
5
|
+
* @param reporter Reporter with filter config.
|
|
6
|
+
* @param prefix Prefix for recusring nested metadata.
|
|
7
|
+
* @returns Filtered metadata.
|
|
8
|
+
*/
|
|
9
|
+
export declare function filterReporterMetadata<TMetadata extends Metadata | undefined>(metadata: TMetadata, reporter: Pick<IReporter, 'ignoreMetadataPatterns'>, prefix?: string): TMetadata;
|
|
10
10
|
//# sourceMappingURL=utils.d.ts.map
|
package/lib/utils.js
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.filterReporterMetadata = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Recursively filter reporter metadata.
|
|
6
|
-
* @param metadata Deep Metadata to filter.
|
|
7
|
-
* @param reporter Reporter with filter config.
|
|
8
|
-
* @param prefix Prefix for recusring nested metadata.
|
|
9
|
-
* @returns Filtered metadata.
|
|
10
|
-
*/
|
|
11
|
-
function filterReporterMetadata(metadata, reporter, prefix) {
|
|
12
|
-
const ignorePatterns = reporter.ignoreMetadataPatterns;
|
|
13
|
-
// No metadata, or no patterns.
|
|
14
|
-
if (metadata === undefined || !ignorePatterns) {
|
|
15
|
-
return metadata;
|
|
16
|
-
}
|
|
17
|
-
const entries = Object.entries(metadata);
|
|
18
|
-
return Object.fromEntries(entries
|
|
19
|
-
.filter(([key]) => {
|
|
20
|
-
const fullKey = prefix ? prefix + key : key;
|
|
21
|
-
return !ignorePatterns.some((pattern) => typeof pattern === 'string' ? pattern === fullKey : pattern.test(fullKey));
|
|
22
|
-
})
|
|
23
|
-
.map(([key, value]) => {
|
|
24
|
-
if (typeof value === 'object' && value !== null) {
|
|
25
|
-
const fullKey = prefix ? prefix + key : key;
|
|
26
|
-
return [key, filterReporterMetadata(value, reporter, `${fullKey}.`)];
|
|
27
|
-
}
|
|
28
|
-
return [key, value];
|
|
29
|
-
}));
|
|
30
|
-
}
|
|
31
|
-
exports.filterReporterMetadata = filterReporterMetadata;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.filterReporterMetadata = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Recursively filter reporter metadata.
|
|
6
|
+
* @param metadata Deep Metadata to filter.
|
|
7
|
+
* @param reporter Reporter with filter config.
|
|
8
|
+
* @param prefix Prefix for recusring nested metadata.
|
|
9
|
+
* @returns Filtered metadata.
|
|
10
|
+
*/
|
|
11
|
+
function filterReporterMetadata(metadata, reporter, prefix) {
|
|
12
|
+
const ignorePatterns = reporter.ignoreMetadataPatterns;
|
|
13
|
+
// No metadata, or no patterns.
|
|
14
|
+
if (metadata === undefined || !ignorePatterns) {
|
|
15
|
+
return metadata;
|
|
16
|
+
}
|
|
17
|
+
const entries = Object.entries(metadata);
|
|
18
|
+
return Object.fromEntries(entries
|
|
19
|
+
.filter(([key]) => {
|
|
20
|
+
const fullKey = prefix ? prefix + key : key;
|
|
21
|
+
return !ignorePatterns.some((pattern) => typeof pattern === 'string' ? pattern === fullKey : pattern.test(fullKey));
|
|
22
|
+
})
|
|
23
|
+
.map(([key, value]) => {
|
|
24
|
+
if (typeof value === 'object' && value !== null) {
|
|
25
|
+
const fullKey = prefix ? prefix + key : key;
|
|
26
|
+
return [key, filterReporterMetadata(value, reporter, `${fullKey}.`)];
|
|
27
|
+
}
|
|
28
|
+
return [key, value];
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
31
|
+
exports.filterReporterMetadata = filterReporterMetadata;
|
|
32
32
|
//# sourceMappingURL=utils.js.map
|
package/lib/utils.test.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
|
2
2
|
//# sourceMappingURL=utils.test.d.ts.map
|
package/lib/utils.test.js
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const utils_1 = require("./utils");
|
|
4
|
-
describe('utils', () => {
|
|
5
|
-
describe('filterReporterMetadata', () => {
|
|
6
|
-
it('should remove attributes which match the ignore patterns', () => {
|
|
7
|
-
const inputAttributeMap = {
|
|
8
|
-
includeme: '5',
|
|
9
|
-
excludeme: 'false',
|
|
10
|
-
differentProp: 'boo',
|
|
11
|
-
deep: {
|
|
12
|
-
includeme: '5',
|
|
13
|
-
excludeme: 'false',
|
|
14
|
-
deepExcludeStr: 'boo',
|
|
15
|
-
deepExcludeRegex: 'boo',
|
|
16
|
-
},
|
|
17
|
-
};
|
|
18
|
-
const filtered = (0, utils_1.filterReporterMetadata)(inputAttributeMap, {
|
|
19
|
-
ignoreMetadataPatterns: [/excludeme/g, /Prop/g, 'deep.deepExcludeStr', /deep\.deepExcludeRegex/g],
|
|
20
|
-
});
|
|
21
|
-
expect(filtered.includeme).toBeTruthy();
|
|
22
|
-
expect(filtered.excludeme).toBeFalsy();
|
|
23
|
-
expect(filtered.differentProp).toBeFalsy();
|
|
24
|
-
// deep
|
|
25
|
-
expect(filtered.deep.includeme).toBeTruthy();
|
|
26
|
-
expect(filtered.deep.excludeme).toBeFalsy();
|
|
27
|
-
expect(filtered.deep.deepExcludeStr).toBeFalsy();
|
|
28
|
-
expect(filtered.deep.deepExcludeRegex).toBeFalsy();
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
});
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const utils_1 = require("./utils");
|
|
4
|
+
describe('utils', () => {
|
|
5
|
+
describe('filterReporterMetadata', () => {
|
|
6
|
+
it('should remove attributes which match the ignore patterns', () => {
|
|
7
|
+
const inputAttributeMap = {
|
|
8
|
+
includeme: '5',
|
|
9
|
+
excludeme: 'false',
|
|
10
|
+
differentProp: 'boo',
|
|
11
|
+
deep: {
|
|
12
|
+
includeme: '5',
|
|
13
|
+
excludeme: 'false',
|
|
14
|
+
deepExcludeStr: 'boo',
|
|
15
|
+
deepExcludeRegex: 'boo',
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
const filtered = (0, utils_1.filterReporterMetadata)(inputAttributeMap, {
|
|
19
|
+
ignoreMetadataPatterns: [/excludeme/g, /Prop/g, 'deep.deepExcludeStr', /deep\.deepExcludeRegex/g],
|
|
20
|
+
});
|
|
21
|
+
expect(filtered.includeme).toBeTruthy();
|
|
22
|
+
expect(filtered.excludeme).toBeFalsy();
|
|
23
|
+
expect(filtered.differentProp).toBeFalsy();
|
|
24
|
+
// deep
|
|
25
|
+
expect(filtered.deep.includeme).toBeTruthy();
|
|
26
|
+
expect(filtered.deep.excludeme).toBeFalsy();
|
|
27
|
+
expect(filtered.deep.deepExcludeStr).toBeFalsy();
|
|
28
|
+
expect(filtered.deep.deepExcludeRegex).toBeFalsy();
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
32
|
//# sourceMappingURL=utils.test.js.map
|
package/package.json
CHANGED
|
@@ -14,6 +14,8 @@ import { logger } from '../logger';
|
|
|
14
14
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
15
15
|
type AttributeMap = Record<string, string[] | string | null>;
|
|
16
16
|
|
|
17
|
+
type AmplifyAutoTrackSource = 'pageView' | 'event' | 'session';
|
|
18
|
+
|
|
17
19
|
export interface AmplifyReporterConfig extends ReporterConfigBase {
|
|
18
20
|
/**
|
|
19
21
|
* AWS Region for Amplify.
|
|
@@ -54,6 +56,11 @@ export interface AmplifyReporterConfig extends ReporterConfigBase {
|
|
|
54
56
|
* To keep it simple we define that the web session is active when the page is not hidden and inactive when the page is hidden.
|
|
55
57
|
*/
|
|
56
58
|
autoTrackSessions?: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Optional function to run before autotracked analytics events are sent out.
|
|
61
|
+
* The returned metadata is attached to the event.
|
|
62
|
+
*/
|
|
63
|
+
beforeAutoTrack?(source: AmplifyAutoTrackSource): Metadata | undefined;
|
|
57
64
|
|
|
58
65
|
/**
|
|
59
66
|
* The data tag prefix to use for attributing HTML elements. Defaults to data-analytics-
|
|
@@ -92,6 +99,11 @@ export function amplifyReporter(info: ServiceInfo, config: AmplifyReporterConfig
|
|
|
92
99
|
});
|
|
93
100
|
}
|
|
94
101
|
|
|
102
|
+
const wrapAutoTrackMiddleware = (source: AmplifyAutoTrackSource) => {
|
|
103
|
+
const { beforeAutoTrack } = config;
|
|
104
|
+
return typeof beforeAutoTrack === 'function' ? () => beforeAutoTrack(source) ?? {} : undefined;
|
|
105
|
+
};
|
|
106
|
+
|
|
95
107
|
const allMetadata = asAttributeMap({
|
|
96
108
|
appName: info.service,
|
|
97
109
|
service: info.service,
|
|
@@ -103,19 +115,27 @@ export function amplifyReporter(info: ServiceInfo, config: AmplifyReporterConfig
|
|
|
103
115
|
Analytics.configure({
|
|
104
116
|
region: config.region,
|
|
105
117
|
appId: config.analyticsAppId,
|
|
106
|
-
autoSessionRecord: config.autoTrackSessions,
|
|
107
118
|
endpoint: {
|
|
108
119
|
attributes: allMetadata,
|
|
109
120
|
},
|
|
110
121
|
...config.buffering,
|
|
111
122
|
});
|
|
112
123
|
|
|
124
|
+
// Session autotracking is enabled by default for backwards compatibility reasons, so we _must_
|
|
125
|
+
// call this unconditionally to ensure we opt out of session tracking when `autoTrackSessions` isn't set
|
|
126
|
+
// See: https://docs.amplify.aws/lib/analytics/autotrack/q/platform/js/#session-tracking
|
|
127
|
+
Analytics.autoTrack('session', {
|
|
128
|
+
enable: config.autoTrackSessions === true,
|
|
129
|
+
attributes: wrapAutoTrackMiddleware('session'),
|
|
130
|
+
});
|
|
131
|
+
|
|
113
132
|
if (config.autoTrackPageViews) {
|
|
114
133
|
Analytics.autoTrack('pageView', {
|
|
115
134
|
enable: true,
|
|
116
135
|
eventName: 'pageView',
|
|
117
136
|
type: 'SPA',
|
|
118
137
|
provider: 'AWSPinpoint',
|
|
138
|
+
attributes: wrapAutoTrackMiddleware('pageView'),
|
|
119
139
|
});
|
|
120
140
|
}
|
|
121
141
|
|
|
@@ -123,6 +143,7 @@ export function amplifyReporter(info: ServiceInfo, config: AmplifyReporterConfig
|
|
|
123
143
|
Analytics.autoTrack('event', {
|
|
124
144
|
enable: true,
|
|
125
145
|
selectorPrefix: config.selectorPrefix ?? 'data-analytics-',
|
|
146
|
+
attributes: wrapAutoTrackMiddleware('event'),
|
|
126
147
|
});
|
|
127
148
|
}
|
|
128
149
|
|