@crimson-education/browser-logger 5.0.1-beta.1 → 5.0.1-beta.3

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.
@@ -1,322 +0,0 @@
1
- import { identifyUser, record } from '@aws-amplify/analytics';
2
- import { logger } from '../logger';
3
- // Note: fetchAuthSession was previously imported but unused; removing to satisfy linter
4
- import { Amplify } from '@aws-amplify/core';
5
- // Auto-tracking implementation for Gen2
6
- class AmplifyAutoTracker {
7
- config;
8
- allMetadata;
9
- currentUser = null;
10
- sessionStartTime = Date.now();
11
- pageViewCount = 0;
12
- lastPageUrl = window.location.href;
13
- isPageVisible = !document.hidden;
14
- constructor(config, allMetadata) {
15
- this.config = config;
16
- this.allMetadata = allMetadata;
17
- this.setupEventListeners();
18
- }
19
- setupEventListeners() {
20
- // Page visibility tracking
21
- document.addEventListener('visibilitychange', () => {
22
- this.isPageVisible = !document.hidden;
23
- if (this.config.autoTrackSessions) {
24
- this.trackSessionState();
25
- }
26
- });
27
- // Page view tracking
28
- if (this.config.autoTrackPageViews) {
29
- // Delay initial page view to ensure Amplify is fully configured
30
- // Using setTimeout(0) to defer to the next event loop tick
31
- setTimeout(() => {
32
- this.trackPageView();
33
- }, 0);
34
- // Track route changes for SPAs
35
- let currentUrl = window.location.href;
36
- const observer = new MutationObserver(() => {
37
- if (window.location.href !== currentUrl) {
38
- currentUrl = window.location.href;
39
- this.trackPageView();
40
- }
41
- });
42
- observer.observe(document.body, { childList: true, subtree: true });
43
- }
44
- // User interaction tracking
45
- if (this.config.autoTrackEvents) {
46
- this.setupInteractionTracking();
47
- }
48
- }
49
- trackPageView() {
50
- this.pageViewCount++;
51
- const pageViewEvent = {
52
- message: 'Page View',
53
- metadata: {
54
- url: window.location.href,
55
- title: document.title,
56
- referrer: document.referrer,
57
- pageViewCount: this.pageViewCount,
58
- ...this.getAutoTrackMetadata('pageView'),
59
- },
60
- };
61
- record({
62
- name: pageViewEvent.message,
63
- attributes: asAttributeMap({
64
- ...this.allMetadata,
65
- ...pageViewEvent.metadata,
66
- }, false),
67
- });
68
- }
69
- trackSessionState() {
70
- const sessionDuration = Date.now() - this.sessionStartTime;
71
- const sessionEvent = {
72
- message: this.isPageVisible ? 'Session Active' : 'Session Inactive',
73
- metadata: {
74
- sessionDuration,
75
- isVisible: this.isPageVisible,
76
- ...this.getAutoTrackMetadata('session'),
77
- },
78
- };
79
- record({
80
- name: sessionEvent.message,
81
- attributes: asAttributeMap({
82
- ...this.allMetadata,
83
- ...sessionEvent.metadata,
84
- }, false),
85
- });
86
- }
87
- setupInteractionTracking() {
88
- const selectorPrefix = this.config.selectorPrefix ?? 'data-analytics-';
89
- document.addEventListener('click', (event) => {
90
- const target = event.target;
91
- if (!target)
92
- return;
93
- // Find the closest element with analytics attributes
94
- const analyticsElement = target.closest(`[${selectorPrefix}name]`);
95
- if (!analyticsElement)
96
- return;
97
- const analyticsName = analyticsElement.getAttribute(`${selectorPrefix}name`);
98
- if (!analyticsName)
99
- return;
100
- const interactionEvent = {
101
- message: 'User Interaction',
102
- metadata: {
103
- elementName: analyticsName,
104
- elementType: target.tagName.toLowerCase(),
105
- elementText: target.textContent?.slice(0, 100),
106
- interactionType: 'click',
107
- ...this.getAutoTrackMetadata('event'),
108
- },
109
- };
110
- record({
111
- name: interactionEvent.message,
112
- attributes: asAttributeMap({
113
- ...this.allMetadata,
114
- ...interactionEvent.metadata,
115
- }, false),
116
- });
117
- });
118
- }
119
- getAutoTrackMetadata(source) {
120
- const { beforeAutoTrack } = this.config;
121
- return typeof beforeAutoTrack === 'function' ? (beforeAutoTrack(source) ?? {}) : {};
122
- }
123
- setUser(user) {
124
- this.currentUser = user;
125
- }
126
- updateMetadata(metadata) {
127
- Object.assign(this.allMetadata, metadata);
128
- }
129
- }
130
- export function amplifyReporter(info, config) {
131
- Amplify.configure({
132
- Auth: {
133
- Cognito: {
134
- identityPoolId: config.identityPoolId,
135
- allowGuestAccess: true,
136
- },
137
- },
138
- Analytics: {
139
- Pinpoint: {
140
- appId: config.analyticsAppId,
141
- region: config.region,
142
- ...config.buffering,
143
- },
144
- },
145
- });
146
- const allMetadata = asAttributeMap({
147
- appName: info.service,
148
- service: info.service,
149
- domain: window.location.host,
150
- environment: info.environment,
151
- version: info.version,
152
- });
153
- // Initialize auto-tracker for Gen2
154
- const autoTracker = new AmplifyAutoTracker(config, allMetadata);
155
- if (config.proxyUrl) {
156
- // installPinpointProxy(new URL(config.proxyUrl));
157
- }
158
- const reporter = {
159
- trackEvent: function (event) {
160
- record({
161
- name: event.message,
162
- attributes: asAttributeMap({
163
- ...allMetadata,
164
- ...event.metadata,
165
- ...event.tags,
166
- }, false),
167
- metrics: event.metrics,
168
- });
169
- },
170
- addBreadcrumb: function (breadcrumb) {
171
- reporter.trackEvent({
172
- message: breadcrumb.message,
173
- metadata: {
174
- category: breadcrumb.category,
175
- ...breadcrumb.metadata,
176
- },
177
- });
178
- },
179
- addMetadata: function (metadata) {
180
- Object.assign(allMetadata, asAttributeMap(metadata, true));
181
- autoTracker.updateMetadata(asAttributeMap(metadata, true));
182
- // Note: updateEndpoint is not available in Amplify v7
183
- // Metadata updates would need to be handled differently
184
- },
185
- setUser: function (user) {
186
- const userMetadata = user
187
- ? asAttributeMap({
188
- userId: user.id,
189
- })
190
- : {};
191
- Object.assign(allMetadata, asAttributeMap(userMetadata, true));
192
- autoTracker.setUser(user);
193
- // Only call identifyUser when we have a valid user ID
194
- // Calling with empty string can cause issues with Pinpoint USER_ID
195
- if (user?.id) {
196
- identifyUser({
197
- userId: user.id,
198
- userProfile: {
199
- email: user.email,
200
- },
201
- }).catch((error) => {
202
- // Credentials may not be ready yet, log warning and continue
203
- // The userId is still stored in allMetadata for event tracking
204
- logger.warn('Failed to identify user in Pinpoint', { error });
205
- });
206
- }
207
- },
208
- setRouteName: function (routeName) {
209
- reporter.addMetadata({ routeName });
210
- },
211
- setPageName: function (pageName) {
212
- reporter.addMetadata({ pageName });
213
- },
214
- };
215
- return reporter;
216
- }
217
- /**
218
- * Pinpoint has strict attribute name and value length limits
219
- */
220
- export function asAttributeMap(values, groupValues = true) {
221
- const attributeMap = buildAttributeMap(values, undefined, groupValues);
222
- const checkedEntries = Object.entries(attributeMap).map(([key, value]) => {
223
- const truncatedKey = key.length > 50 ? `___${key.slice(-47)}` : key;
224
- const truncatedValue = Array.isArray(value)
225
- ? (value?.map((val) => val.slice(0, 100)) ?? null)
226
- : (value?.slice(0, 100) ?? null);
227
- return [truncatedKey, truncatedValue];
228
- });
229
- // Pinpoint only accepts 40 attributes
230
- if (checkedEntries.length > 40) {
231
- logger.error(`Amplify only allows 40 attributes per event, truncating to 40 attributes`, {
232
- attributes: checkedEntries,
233
- });
234
- checkedEntries.length = 40;
235
- }
236
- return Object.fromEntries(checkedEntries);
237
- }
238
- /**
239
- * Pinpoint expects `endpoint.attributes` and `endpoint.userAttributes` to have
240
- * values which are string arrays. This function takes in an object and ensures
241
- * all of its values are of type `string[]` to appease Pinpoint.
242
- */
243
- export function buildAttributeMap(values, parentKey = undefined, groupValues = true) {
244
- const valuesWithStringArrays = {};
245
- Object.entries(values).forEach(([key, value]) => {
246
- const combinedKey = parentKey ? [parentKey, key].join('.') : key;
247
- // Only treat undefined or null as empty; avoid converting falsy values like ''/0/false to null
248
- if (value === undefined || value === null) {
249
- // For event attributes (groupValues === false), Pinpoint rejects null values.
250
- // In that case we omit the key entirely to avoid "Event attribute value can not be null".
251
- if (groupValues) {
252
- valuesWithStringArrays[combinedKey] = null;
253
- }
254
- }
255
- else if (groupValues && Array.isArray(value)) {
256
- valuesWithStringArrays[combinedKey] = value.map((element) => typeof element === 'string' ? element : JSON.stringify(element));
257
- }
258
- else if (typeof value === 'object') {
259
- const flattenedAttribute = buildAttributeMap(value, combinedKey, groupValues);
260
- Object.assign(valuesWithStringArrays, flattenedAttribute);
261
- }
262
- else {
263
- const stringValue = typeof value === 'string' ? value : JSON.stringify(value);
264
- valuesWithStringArrays[combinedKey] = groupValues ? [stringValue] : stringValue;
265
- }
266
- });
267
- return valuesWithStringArrays;
268
- }
269
- // function installPinpointProxy(proxyUrl: URL) {
270
- // // No public API for overriding where the Pinpoint client sends events to... 🤮
271
- // // In theory you can pass in an `endpoint` to the Pinpoint client's constructor like any other AWS
272
- // // client, but Amplify's analytics doesn't expose anything we can use to get an endpoint threaded
273
- // // down to the Pinpoint client's constructor.
274
- // //
275
- // // The Pinpoint client _also_ isn't available synchronously because it is instantiated when events
276
- // // get sent out, and then reconfigured whenever the API credentials change. We need to hook `_initClients`
277
- // // to ensure that the Pinpoint client being used is always patched with our custom endpoint.
278
- // const provider = (globalThis as any).Analytics?.getPluggable?.('AWSPinpoint') as any;
279
- // if (!provider || typeof provider._initClients !== 'function') {
280
- // logger.error(
281
- // 'Installation of the Pinpoint proxy failed. This likely means the internals of the @aws-amplify/analytics package have changed.',
282
- // );
283
- // return;
284
- // }
285
- // const originalInitClients = provider._initClients;
286
- // const requestMiddleware: FinalizeRequestMiddleware<ServiceInputTypes, ServiceOutputTypes> =
287
- // (next) => async (args) => {
288
- // const pinpointClient = provider.pinpointClient as PinpointClient | undefined;
289
- // if (pinpointClient && proxyUrl.pathname !== '/' && HttpRequest.isInstance(args.request)) {
290
- // // Add proxyUrl.pathname to final request url if it was provided
291
- // const shouldStripSlash = proxyUrl.pathname.endsWith('/');
292
- // args.request.path = `${proxyUrl.pathname}${args.request.path.slice(shouldStripSlash ? 1 : 0)}`;
293
- // // Wrap request body so the proxy has signing info
294
- // if (typeof args.request.body === 'string') {
295
- // const credentials = await pinpointClient.config.credentials();
296
- // args.request.body = JSON.stringify({
297
- // credentials,
298
- // data: JSON.parse(args.request.body),
299
- // });
300
- // }
301
- // }
302
- // return next(args);
303
- // };
304
- // provider._initClients = async (credentials: unknown) => {
305
- // const result = await originalInitClients.call(provider, credentials);
306
- // const pinpointClient = provider.pinpointClient as PinpointClient | undefined;
307
- // if (pinpointClient) {
308
- // pinpointClient.config.endpoint = (): Promise<Endpoint> =>
309
- // Promise.resolve({
310
- // hostname: proxyUrl.hostname,
311
- // // Passing proxyUrl.pathname here doesn't work; it gets overridden
312
- // path: '/',
313
- // port: undefined,
314
- // protocol: proxyUrl.protocol,
315
- // });
316
- // pinpointClient.middlewareStack.remove(requestMiddleware);
317
- // pinpointClient.middlewareStack.add(requestMiddleware, { step: 'finalizeRequest' });
318
- // }
319
- // return result;
320
- // };
321
- // }
322
- //# sourceMappingURL=amplifyReporter.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"amplifyReporter.js","sourceRoot":"","sources":["../../src/reporters/amplifyReporter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAc9D,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,wFAAwF;AACxF,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAO5C,wCAAwC;AACxC,MAAM,kBAAkB;IACd,MAAM,CAAwB;IAC9B,WAAW,CAAe;IAC1B,WAAW,GAAsB,IAAI,CAAC;IACtC,gBAAgB,GAAW,IAAI,CAAC,GAAG,EAAE,CAAC;IACtC,aAAa,GAAW,CAAC,CAAC;IAC1B,WAAW,GAAW,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC;IAC3C,aAAa,GAAY,CAAC,QAAQ,CAAC,MAAM,CAAC;IAElD,YAAY,MAA6B,EAAE,WAAyB;QAClE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,mBAAmB,EAAE,CAAC;IAC7B,CAAC;IAEO,mBAAmB;QACzB,2BAA2B;QAC3B,QAAQ,CAAC,gBAAgB,CAAC,kBAAkB,EAAE,GAAG,EAAE;YACjD,IAAI,CAAC,aAAa,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC;YACtC,IAAI,IAAI,CAAC,MAAM,CAAC,iBAAiB,EAAE;gBACjC,IAAI,CAAC,i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AAgG;AAChG,kCAAkC;AAClC,sFAAsF;AAEtF,mGAAmG;AACnG,2EAA2E;AAC3E,oEAAoE;AACpE,0GAA0G;AAE1G,6DAA6D;AAC7D,uDAAuD;AACvD,2EAA2E;AAC3E,iDAAiD;AACjD,2BAA2B;AAC3B,mDAAmD;AACnD,gBAAgB;AAChB,YAAY;AACZ,UAAU;AAEV,2BAA2B;AAC3B,SAAS;AAET,8DAA8D;AAC9D,4EAA4E;AAC5E,oFAAoF;AAEpF,4BAA4B;AAC5B,kEAAkE;AAClE,4BAA4B;AAC5B,yCAAyC;AACzC,+EAA+E;AAC/E,uBAAuB;AACvB,6BAA6B;AAC7B,yCAAyC;AACzC,cAAc;AAEd,kEAAkE;AAClE,4FAA4F;AAC5F,QAAQ;AACR,qBAAqB;AACrB,OAAO;AACP,IAAI"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=amplifyReporter.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"amplifyReporter.test.d.ts","sourceRoot":"","sources":["../../src/reporters/amplifyReporter.test.ts"],"names":[],"mappings":""}
@@ -1,48 +0,0 @@
1
- import { asAttributeMap } from './amplifyReporter';
2
- describe('amplifyReporter', () => {
3
- it('should convert all attribute values to arrays of strings', () => {
4
- const testMetadata = { a: 'a', d: ['e', 'f'] };
5
- const attributeMap = asAttributeMap(testMetadata);
6
- expect(attributeMap.a).toEqual(['a']);
7
- expect(attributeMap.d).toEqual(['e', 'f']);
8
- });
9
- it('should handle undefined / null attributes', () => {
10
- const testMetadata = { a: null, d: undefined };
11
- const attributeMap = asAttributeMap(testMetadata);
12
- expect(attributeMap.a).toBeNull();
13
- expect(attributeMap.d).toBeNull();
14
- });
15
- it('should flatten hierarchies', () => {
16
- const testMetadata = { foo: { bar: 'baz' } };
17
- const attributeMap = asAttributeMap(testMetadata);
18
- expect(attributeMap['foo.bar']).toEqual(['baz']);
19
- });
20
- it('should stringify non-string array members', () => {
21
- const testMetadata = { foo: 5, bar: [{ baz: 'maz' }] };
22
- const attributeMap = asAttributeMap(testMetadata);
23
- expect(attributeMap.foo).toEqual(['5']);
24
- expect(typeof attributeMap.bar?.[0]).toEqual('string');
25
- });
26
- it('should truncate attribute names', () => {
27
- const testMetadata = { thisIsAVeryVeryLongAttributeNameThatNeedsToBeTruncated: 5 };
28
- const attributeMap = asAttributeMap(testMetadata);
29
- expect(attributeMap.___VeryVeryLongAttributeNameThatNeedsToBeTruncated).toEqual(['5']);
30
- });
31
- it('should truncate attribute values', () => {
32
- const testMetadata = {
33
- a: 'ThisIsAVeryLongStringThatNeedsToBeTruncatedTo100CharsOrElseThereWillBeAProblemWithSendingTheBeautifulDataToPinpoint',
34
- };
35
- const attributeMap = asAttributeMap(testMetadata);
36
- expect(attributeMap.a).toEqual([
37
- 'ThisIsAVeryLongStringThatNeedsToBeTruncatedTo100CharsOrElseThereWillBeAProblemWithSendingTheBeautifu',
38
- ]);
39
- });
40
- it('should not group values into arrays when groupValues===false', () => {
41
- const testMetadata = {
42
- a: '5',
43
- };
44
- const attributeMap = asAttributeMap(testMetadata, false);
45
- expect(attributeMap.a).toEqual('5');
46
- });
47
- });
48
- //# sourceMappingURL=amplifyReporter.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"amplifyReporter.test.js","sourceRoot":"","sources":["../../src/reporters/amplifyReporter.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,EAAE,CAAC,0DAA0D,EAAE,GAAG,EAAE;QAClE,MAAM,YAAY,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC;QAC/C,MAAM,YAAY,GAAG,cAAc,CAAC,YAAY,CAAC,CAAC;QAElD,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,CAA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IAEH,EAAE,CAAC,iCAAiC,EAAE,GAAG,EAAE;QACzC,MAAM,YAAY,GAAG,EAAE,sDAAsD,EAAE,CAAC,EAAE,CAAC;QACnF,MAAM,YAAY,GAAG,cAAc,CAAC,YAAY,CAAC,CAAC;QAElD,MAAM,CAAC,YAAY,CAAC,kDAAkD,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IACzF,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,kCAAkC,EAAE,GAAG,EAAE;QAC1C,MAAM,YAAY,GAAG;YACnB,CAAC,EAAE,qHAAqH;SACzH,CAAC;QACF,MAAM,YAAY,GAAG,cAAc,CAAC,YAAY,CAAC,CAAC;QAElD,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;YAC7B,sGAAsG;SACvG,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,8DAA8D,EAAE,GAAG,EAAE;QACtE,MAAM,YAAY,GAAG;YACnB,CAAC,EAAE,GAAG;SACP,CAAC;QAEF,MAAM,YAAY,GAAG,cAAc,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;QACzD,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1,61 +0,0 @@
1
- import { asAttributeMap } from './amplifyReporter';
2
-
3
- describe('amplifyReporter', () => {
4
- it('should convert all attribute values to arrays of strings', () => {
5
- const testMetadata = { a: 'a', d: ['e', 'f'] };
6
- const attributeMap = asAttributeMap(testMetadata);
7
-
8
- expect(attributeMap.a).toEqual(['a']);
9
- expect(attributeMap.d).toEqual(['e', 'f']);
10
- });
11
-
12
- it('should handle undefined / null attributes', () => {
13
- const testMetadata = { a: null, d: undefined };
14
- const attributeMap = asAttributeMap(testMetadata);
15
-
16
- expect(attributeMap.a).toBeNull();
17
- expect(attributeMap.d).toBeNull();
18
- });
19
-
20
- it('should flatten hierarchies', () => {
21
- const testMetadata = { foo: { bar: 'baz' } };
22
- const attributeMap = asAttributeMap(testMetadata);
23
-
24
- expect(attributeMap['foo.bar']).toEqual(['baz']);
25
- });
26
-
27
- it('should stringify non-string array members', () => {
28
- const testMetadata = { foo: 5, bar: [{ baz: 'maz' }] };
29
- const attributeMap = asAttributeMap(testMetadata);
30
-
31
- expect(attributeMap.foo).toEqual(['5']);
32
- expect(typeof attributeMap.bar?.[0]).toEqual('string');
33
- });
34
-
35
- it('should truncate attribute names', () => {
36
- const testMetadata = { thisIsAVeryVeryLongAttributeNameThatNeedsToBeTruncated: 5 };
37
- const attributeMap = asAttributeMap(testMetadata);
38
-
39
- expect(attributeMap.___VeryVeryLongAttributeNameThatNeedsToBeTruncated).toEqual(['5']);
40
- });
41
-
42
- it('should truncate attribute values', () => {
43
- const testMetadata = {
44
- a: 'ThisIsAVeryLongStringThatNeedsToBeTruncatedTo100CharsOrElseThereWillBeAProblemWithSendingTheBeautifulDataToPinpoint',
45
- };
46
- const attributeMap = asAttributeMap(testMetadata);
47
-
48
- expect(attributeMap.a).toEqual([
49
- 'ThisIsAVeryLongStringThatNeedsToBeTruncatedTo100CharsOrElseThereWillBeAProblemWithSendingTheBeautifu',
50
- ]);
51
- });
52
-
53
- it('should not group values into arrays when groupValues===false', () => {
54
- const testMetadata = {
55
- a: '5',
56
- };
57
-
58
- const attributeMap = asAttributeMap(testMetadata, false);
59
- expect(attributeMap.a).toEqual('5');
60
- });
61
- });