@crimson-education/browser-logger 5.0.1 → 5.0.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.
- package/README.md +72 -94
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +23 -46
- package/lib/index.js.map +1 -1
- package/lib/logger/consoleTransport.d.ts +1 -1
- package/lib/logger/consoleTransport.d.ts.map +1 -1
- package/lib/logger/consoleTransport.js +16 -22
- package/lib/logger/consoleTransport.js.map +1 -1
- package/lib/logger/datadogTransport.d.ts +1 -1
- package/lib/logger/datadogTransport.d.ts.map +1 -1
- package/lib/logger/datadogTransport.js +4 -8
- package/lib/logger/datadogTransport.js.map +1 -1
- package/lib/logger/index.js +29 -49
- package/lib/logger/index.js.map +1 -1
- package/lib/logger/index.test.js +16 -18
- package/lib/logger/index.test.js.map +1 -1
- package/lib/logger/utils.js +4 -9
- package/lib/logger/utils.js.map +1 -1
- package/lib/reporters/datadogReporter.d.ts +13 -1
- package/lib/reporters/datadogReporter.d.ts.map +1 -1
- package/lib/reporters/datadogReporter.js +122 -49
- package/lib/reporters/datadogReporter.js.map +1 -1
- package/lib/reporters/gtmReporter.d.ts +1 -1
- package/lib/reporters/gtmReporter.d.ts.map +1 -1
- package/lib/reporters/gtmReporter.js +1 -5
- package/lib/reporters/gtmReporter.js.map +1 -1
- package/lib/reporters/index.js +46 -71
- package/lib/reporters/index.js.map +1 -1
- package/lib/reporters/logReporter.js +24 -34
- package/lib/reporters/logReporter.js.map +1 -1
- package/lib/reporters/posthogReporter.d.ts +1 -1
- package/lib/reporters/posthogReporter.d.ts.map +1 -1
- package/lib/reporters/posthogReporter.js +46 -55
- package/lib/reporters/posthogReporter.js.map +1 -1
- package/lib/reporters/posthogReporter.test.js +21 -23
- package/lib/reporters/posthogReporter.test.js.map +1 -1
- package/lib/types/index.js +2 -18
- package/lib/types/index.js.map +1 -1
- package/lib/types/logger.d.ts +3 -3
- package/lib/types/logger.d.ts.map +1 -1
- package/lib/types/logger.js +2 -5
- package/lib/types/logger.js.map +1 -1
- package/lib/types/reporter.d.ts +6 -12
- package/lib/types/reporter.d.ts.map +1 -1
- package/lib/types/reporter.js +1 -2
- package/lib/utils.js +1 -5
- package/lib/utils.js.map +1 -1
- package/lib/utils.test.js +2 -4
- package/lib/utils.test.js.map +1 -1
- package/package.json +16 -16
- package/src/index.ts +0 -6
- package/src/reporters/datadogReporter.ts +133 -22
- package/src/reporters/posthogReporter.test.ts +6 -1
- package/src/reporters/posthogReporter.ts +6 -1
- package/src/types/reporter.ts +0 -7
- package/lib/reporters/amplifyReporter.d.ts +0 -86
- package/lib/reporters/amplifyReporter.d.ts.map +0 -1
- package/lib/reporters/amplifyReporter.js +0 -225
- package/lib/reporters/amplifyReporter.js.map +0 -1
- package/lib/reporters/amplifyReporter.test.d.ts +0 -2
- package/lib/reporters/amplifyReporter.test.d.ts.map +0 -1
- package/lib/reporters/amplifyReporter.test.js +0 -51
- package/lib/reporters/amplifyReporter.test.js.map +0 -1
- package/src/reporters/amplifyReporter.test.ts +0 -61
- package/src/reporters/amplifyReporter.ts +0 -344
|
@@ -1,225 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildAttributeMap = exports.asAttributeMap = exports.amplifyReporter = void 0;
|
|
4
|
-
const auth_1 = require("@aws-amplify/auth");
|
|
5
|
-
const analytics_1 = require("@aws-amplify/analytics");
|
|
6
|
-
const protocol_http_1 = require("@aws-sdk/protocol-http");
|
|
7
|
-
const logger_1 = require("../logger");
|
|
8
|
-
function amplifyReporter(info, config) {
|
|
9
|
-
var _a;
|
|
10
|
-
if (config.identityPoolId !== false) {
|
|
11
|
-
auth_1.Auth.configure({
|
|
12
|
-
region: config.region,
|
|
13
|
-
identityPoolId: config.identityPoolId,
|
|
14
|
-
userPoolId: config.userPoolId,
|
|
15
|
-
userPoolWebClientId: config.userPoolWebClientId,
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
const wrapAutoTrackMiddleware = (source) => {
|
|
19
|
-
const { beforeAutoTrack } = config;
|
|
20
|
-
return typeof beforeAutoTrack === 'function' ? () => { var _a; return (_a = beforeAutoTrack(source)) !== null && _a !== void 0 ? _a : {}; } : undefined;
|
|
21
|
-
};
|
|
22
|
-
const allMetadata = asAttributeMap({
|
|
23
|
-
appName: info.service,
|
|
24
|
-
service: info.service,
|
|
25
|
-
domain: window.location.host,
|
|
26
|
-
environment: info.environment,
|
|
27
|
-
version: info.version,
|
|
28
|
-
});
|
|
29
|
-
analytics_1.Analytics.configure({
|
|
30
|
-
region: config.region,
|
|
31
|
-
appId: config.analyticsAppId,
|
|
32
|
-
endpoint: {
|
|
33
|
-
attributes: allMetadata,
|
|
34
|
-
},
|
|
35
|
-
...config.buffering,
|
|
36
|
-
});
|
|
37
|
-
// Session autotracking is enabled by default for backwards compatibility reasons, so we _must_
|
|
38
|
-
// call this unconditionally to ensure we opt out of session tracking when `autoTrackSessions` isn't set
|
|
39
|
-
// See: https://docs.amplify.aws/lib/analytics/autotrack/q/platform/js/#session-tracking
|
|
40
|
-
analytics_1.Analytics.autoTrack('session', {
|
|
41
|
-
enable: config.autoTrackSessions === true,
|
|
42
|
-
attributes: wrapAutoTrackMiddleware('session'),
|
|
43
|
-
});
|
|
44
|
-
if (config.autoTrackPageViews) {
|
|
45
|
-
analytics_1.Analytics.autoTrack('pageView', {
|
|
46
|
-
enable: true,
|
|
47
|
-
eventName: 'pageView',
|
|
48
|
-
type: 'SPA',
|
|
49
|
-
provider: 'AWSPinpoint',
|
|
50
|
-
attributes: wrapAutoTrackMiddleware('pageView'),
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
if (config.autoTrackEvents) {
|
|
54
|
-
analytics_1.Analytics.autoTrack('event', {
|
|
55
|
-
enable: true,
|
|
56
|
-
selectorPrefix: (_a = config.selectorPrefix) !== null && _a !== void 0 ? _a : 'data-analytics-',
|
|
57
|
-
attributes: wrapAutoTrackMiddleware('event'),
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
if (config.proxyUrl) {
|
|
61
|
-
installPinpointProxy(new URL(config.proxyUrl));
|
|
62
|
-
}
|
|
63
|
-
const reporter = {
|
|
64
|
-
trackEvent: function (event) {
|
|
65
|
-
analytics_1.Analytics.record({
|
|
66
|
-
name: event.message,
|
|
67
|
-
attributes: asAttributeMap({
|
|
68
|
-
...event.metadata,
|
|
69
|
-
...event.tags,
|
|
70
|
-
}, false),
|
|
71
|
-
metrics: event.metrics,
|
|
72
|
-
}).catch(() => {
|
|
73
|
-
// Swallow; see: https://crimsonhq.slack.com/archives/G4UN6Q4KF/p1648599302847539
|
|
74
|
-
});
|
|
75
|
-
},
|
|
76
|
-
addBreadcrumb: function (breadcrumb) {
|
|
77
|
-
reporter.trackEvent({
|
|
78
|
-
message: breadcrumb.message,
|
|
79
|
-
metadata: {
|
|
80
|
-
category: breadcrumb.category,
|
|
81
|
-
...breadcrumb.metadata,
|
|
82
|
-
},
|
|
83
|
-
});
|
|
84
|
-
},
|
|
85
|
-
addMetadata: function (metadata) {
|
|
86
|
-
Object.assign(allMetadata, asAttributeMap(metadata, true));
|
|
87
|
-
analytics_1.Analytics.updateEndpoint({
|
|
88
|
-
attributes: allMetadata,
|
|
89
|
-
}).catch(() => {
|
|
90
|
-
// Swallow; see: https://crimsonhq.slack.com/archives/G4UN6Q4KF/p1648599302847539
|
|
91
|
-
});
|
|
92
|
-
},
|
|
93
|
-
setUser: function (user) {
|
|
94
|
-
var _a, _b;
|
|
95
|
-
const userMetadata = user
|
|
96
|
-
? asAttributeMap({
|
|
97
|
-
userId: user.id,
|
|
98
|
-
})
|
|
99
|
-
: {};
|
|
100
|
-
Object.assign(allMetadata, asAttributeMap(userMetadata, true));
|
|
101
|
-
analytics_1.Analytics.updateEndpoint({
|
|
102
|
-
userId: (_a = user === null || user === void 0 ? void 0 : user.id) !== null && _a !== void 0 ? _a : '',
|
|
103
|
-
attributes: allMetadata,
|
|
104
|
-
userAttributes: user
|
|
105
|
-
? asAttributeMap({
|
|
106
|
-
id: user.id,
|
|
107
|
-
email: user.email,
|
|
108
|
-
name: (_b = user.name) !== null && _b !== void 0 ? _b : user.email,
|
|
109
|
-
username: user.username,
|
|
110
|
-
})
|
|
111
|
-
: {},
|
|
112
|
-
}).catch(() => {
|
|
113
|
-
// Swallow; see: https://crimsonhq.slack.com/archives/G4UN6Q4KF/p1648599302847539
|
|
114
|
-
});
|
|
115
|
-
},
|
|
116
|
-
setRouteName: function (routeName) {
|
|
117
|
-
reporter.addMetadata({ routeName });
|
|
118
|
-
},
|
|
119
|
-
setPageName: function (pageName) {
|
|
120
|
-
reporter.addMetadata({ pageName });
|
|
121
|
-
},
|
|
122
|
-
};
|
|
123
|
-
return reporter;
|
|
124
|
-
}
|
|
125
|
-
exports.amplifyReporter = amplifyReporter;
|
|
126
|
-
/**
|
|
127
|
-
* Pinpoint has strict attribute name and value length limits
|
|
128
|
-
*/
|
|
129
|
-
function asAttributeMap(values, groupValues = true) {
|
|
130
|
-
const attributeMap = buildAttributeMap(values, undefined, groupValues);
|
|
131
|
-
const checkedEntries = Object.entries(attributeMap).map(([key, value]) => {
|
|
132
|
-
var _a, _b;
|
|
133
|
-
const truncatedKey = key.length > 50 ? `___${key.slice(-47)}` : key;
|
|
134
|
-
const truncatedValue = Array.isArray(value)
|
|
135
|
-
? (_a = value === null || value === void 0 ? void 0 : value.map((val) => val.slice(0, 100))) !== null && _a !== void 0 ? _a : null
|
|
136
|
-
: (_b = value === null || value === void 0 ? void 0 : value.slice(0, 100)) !== null && _b !== void 0 ? _b : null;
|
|
137
|
-
return [truncatedKey, truncatedValue];
|
|
138
|
-
});
|
|
139
|
-
// Pinpoint only accepts 40 attributes
|
|
140
|
-
if (checkedEntries.length > 40) {
|
|
141
|
-
logger_1.logger.error(`Amplify only allows 40 attributes per event, truncating to 40 attributes`, {
|
|
142
|
-
attributes: checkedEntries,
|
|
143
|
-
});
|
|
144
|
-
checkedEntries.length = 40;
|
|
145
|
-
}
|
|
146
|
-
return Object.fromEntries(checkedEntries);
|
|
147
|
-
}
|
|
148
|
-
exports.asAttributeMap = asAttributeMap;
|
|
149
|
-
/**
|
|
150
|
-
* Pinpoint expects `endpoint.attributes` and `endpoint.userAttributes` to have
|
|
151
|
-
* values which are string arrays. This function takes in an object and ensures
|
|
152
|
-
* all of its values are of type `string[]` to appease Pinpoint.
|
|
153
|
-
*/
|
|
154
|
-
function buildAttributeMap(values, parentKey = undefined, groupValues = true) {
|
|
155
|
-
const valuesWithStringArrays = {};
|
|
156
|
-
Object.entries(values).forEach(([key, value]) => {
|
|
157
|
-
const combinedKey = parentKey ? [parentKey, key].join('.') : key;
|
|
158
|
-
if (!value) {
|
|
159
|
-
valuesWithStringArrays[combinedKey] = null;
|
|
160
|
-
}
|
|
161
|
-
else if (groupValues && Array.isArray(value)) {
|
|
162
|
-
valuesWithStringArrays[combinedKey] = value.map((element) => typeof element === 'string' ? element : JSON.stringify(element));
|
|
163
|
-
}
|
|
164
|
-
else if (typeof value === 'object') {
|
|
165
|
-
const flattenedAttribute = buildAttributeMap(value, combinedKey, groupValues);
|
|
166
|
-
Object.assign(valuesWithStringArrays, flattenedAttribute);
|
|
167
|
-
}
|
|
168
|
-
else {
|
|
169
|
-
const stringValue = typeof value === 'string' ? value : JSON.stringify(value);
|
|
170
|
-
valuesWithStringArrays[combinedKey] = groupValues ? [stringValue] : stringValue;
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
return valuesWithStringArrays;
|
|
174
|
-
}
|
|
175
|
-
exports.buildAttributeMap = buildAttributeMap;
|
|
176
|
-
function installPinpointProxy(proxyUrl) {
|
|
177
|
-
// No public API for overriding where the Pinpoint client sends events to... 🤮
|
|
178
|
-
// In theory you can pass in an `endpoint` to the Pinpoint client's constructor like any other AWS
|
|
179
|
-
// client, but Amplify's analytics doesn't expose anything we can use to get an endpoint threaded
|
|
180
|
-
// down to the Pinpoint client's constructor.
|
|
181
|
-
//
|
|
182
|
-
// The Pinpoint client _also_ isn't available synchronously because it is instantiated when events
|
|
183
|
-
// get sent out, and then reconfigured whenever the API credentials change. We need to hook `_initClients`
|
|
184
|
-
// to ensure that the Pinpoint client being used is always patched with our custom endpoint.
|
|
185
|
-
const provider = analytics_1.Analytics.getPluggable('AWSPinpoint');
|
|
186
|
-
if (!provider || typeof provider._initClients !== 'function') {
|
|
187
|
-
logger_1.logger.error('Installation of the Pinpoint proxy failed. This likely means the internals of the @aws-amplify/analytics package have changed.');
|
|
188
|
-
return;
|
|
189
|
-
}
|
|
190
|
-
const originalInitClients = provider._initClients;
|
|
191
|
-
const requestMiddleware = (next) => async (args) => {
|
|
192
|
-
const pinpointClient = provider.pinpointClient;
|
|
193
|
-
if (pinpointClient && proxyUrl.pathname !== '/' && protocol_http_1.HttpRequest.isInstance(args.request)) {
|
|
194
|
-
// Add proxyUrl.pathname to final request url if it was provided
|
|
195
|
-
const shouldStripSlash = proxyUrl.pathname.endsWith('/');
|
|
196
|
-
args.request.path = `${proxyUrl.pathname}${args.request.path.slice(shouldStripSlash ? 1 : 0)}`;
|
|
197
|
-
// Wrap request body so the proxy has signing info
|
|
198
|
-
if (typeof args.request.body === 'string') {
|
|
199
|
-
const credentials = await pinpointClient.config.credentials();
|
|
200
|
-
args.request.body = JSON.stringify({
|
|
201
|
-
credentials,
|
|
202
|
-
data: JSON.parse(args.request.body),
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
return next(args);
|
|
207
|
-
};
|
|
208
|
-
provider._initClients = async (credentials) => {
|
|
209
|
-
const result = await originalInitClients.call(provider, credentials);
|
|
210
|
-
const pinpointClient = provider.pinpointClient;
|
|
211
|
-
if (pinpointClient) {
|
|
212
|
-
pinpointClient.config.endpoint = () => Promise.resolve({
|
|
213
|
-
hostname: proxyUrl.hostname,
|
|
214
|
-
// Passing proxyUrl.pathname here doesn't work; it gets overridden
|
|
215
|
-
path: '/',
|
|
216
|
-
port: undefined,
|
|
217
|
-
protocol: proxyUrl.protocol,
|
|
218
|
-
});
|
|
219
|
-
pinpointClient.middlewareStack.remove(requestMiddleware);
|
|
220
|
-
pinpointClient.middlewareStack.add(requestMiddleware, { step: 'finalizeRequest' });
|
|
221
|
-
}
|
|
222
|
-
return result;
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
//# sourceMappingURL=amplifyReporter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"amplifyReporter.js","sourceRoot":"","sources":["../../src/reporters/amplifyReporter.ts"],"names":[],"mappings":";;;AAAA,4CAAyC;AACzC,sDAAmD;AAEnD,0DAAqD;AAYrD,sCAAmC;AAkFnC,SAAgB,eAAe,CAAC,IAAiB,EAAE,MAA6B;;IAC9E,IAAI,MAAM,CAAC,cAAc,KAAK,KAAK,EAAE;QACnC,WAAI,CAAC,SAAS,CAAC;YACb,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,cAAc,EAAE,MAAM,CAAC,cAAc;YACrC,UAAU,EAAE,MAAM,CAAC,UAAU;YAC7B,mBAAmB,EAAE,MAAM,CAAC,mBAAmB;SAChD,CAAC,CAAC;KACJ;IAED,MAAM,uBAAuB,GAAG,CAAC,MAA8B,EAAE,EAAE;QACjE,MAAM,EAAE,eAAe,EAAE,GAAG,MAAM,CAAC;QACnC,OAAO,OAAO,eAAe,KAAK,UAAU,CAAC,CAAC,CAAC,GAAG,EAAE,WAAC,OAAA,MAAA,eAAe,CAAC,MAAM,CAAC,mCAAI,EAAE,CAAA,EAAA,CAAC,CAAC,CAAC,SAAS,CAAC;IACjG,CAAC,CAAC;IAEF,MAAM,WAAW,GAAG,cAAc,CAAC;QACjC,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,IAAI;QAC5B,WAAW,EAAE,IAAI,CAAC,WAAW;QAC7B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CAAC;SACpF;QACD,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"amplifyReporter.test.d.ts","sourceRoot":"","sources":["../../src/reporters/amplifyReporter.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const amplifyReporter_1 = require("./amplifyReporter");
|
|
4
|
-
describe('amplifyReporter', () => {
|
|
5
|
-
it('should convert all attribute values to arrays of strings', () => {
|
|
6
|
-
const testMetadata = { a: 'a', d: ['e', 'f'] };
|
|
7
|
-
const attributeMap = (0, amplifyReporter_1.asAttributeMap)(testMetadata);
|
|
8
|
-
expect(attributeMap.a).toEqual(['a']);
|
|
9
|
-
expect(attributeMap.d).toEqual(['e', 'f']);
|
|
10
|
-
});
|
|
11
|
-
it('should handle undefined / null attributes', () => {
|
|
12
|
-
const testMetadata = { a: null, d: undefined };
|
|
13
|
-
const attributeMap = (0, amplifyReporter_1.asAttributeMap)(testMetadata);
|
|
14
|
-
expect(attributeMap.a).toBeNull();
|
|
15
|
-
expect(attributeMap.d).toBeNull();
|
|
16
|
-
});
|
|
17
|
-
it('should flatten hierarchies', () => {
|
|
18
|
-
const testMetadata = { foo: { bar: 'baz' } };
|
|
19
|
-
const attributeMap = (0, amplifyReporter_1.asAttributeMap)(testMetadata);
|
|
20
|
-
expect(attributeMap['foo.bar']).toEqual(['baz']);
|
|
21
|
-
});
|
|
22
|
-
it('should stringify non-string array members', () => {
|
|
23
|
-
var _a;
|
|
24
|
-
const testMetadata = { foo: 5, bar: [{ baz: 'maz' }] };
|
|
25
|
-
const attributeMap = (0, amplifyReporter_1.asAttributeMap)(testMetadata);
|
|
26
|
-
expect(attributeMap.foo).toEqual(['5']);
|
|
27
|
-
expect(typeof ((_a = attributeMap.bar) === null || _a === void 0 ? void 0 : _a[0])).toEqual('string');
|
|
28
|
-
});
|
|
29
|
-
it('should truncate attribute names', () => {
|
|
30
|
-
const testMetadata = { thisIsAVeryVeryLongAttributeNameThatNeedsToBeTruncated: 5 };
|
|
31
|
-
const attributeMap = (0, amplifyReporter_1.asAttributeMap)(testMetadata);
|
|
32
|
-
expect(attributeMap.___VeryVeryLongAttributeNameThatNeedsToBeTruncated).toEqual(['5']);
|
|
33
|
-
});
|
|
34
|
-
it('should truncate attribute values', () => {
|
|
35
|
-
const testMetadata = {
|
|
36
|
-
a: 'ThisIsAVeryLongStringThatNeedsToBeTruncatedTo100CharsOrElseThereWillBeAProblemWithSendingTheBeautifulDataToPinpoint',
|
|
37
|
-
};
|
|
38
|
-
const attributeMap = (0, amplifyReporter_1.asAttributeMap)(testMetadata);
|
|
39
|
-
expect(attributeMap.a).toEqual([
|
|
40
|
-
'ThisIsAVeryLongStringThatNeedsToBeTruncatedTo100CharsOrElseThereWillBeAProblemWithSendingTheBeautifu',
|
|
41
|
-
]);
|
|
42
|
-
});
|
|
43
|
-
it('should not group values into arrays when groupValues===false', () => {
|
|
44
|
-
const testMetadata = {
|
|
45
|
-
a: '5',
|
|
46
|
-
};
|
|
47
|
-
const attributeMap = (0, amplifyReporter_1.asAttributeMap)(testMetadata, false);
|
|
48
|
-
expect(attributeMap.a).toEqual('5');
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
//# 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,uDAAmD;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,M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,CAAC,CAAC,CAAC;QACxC,MAAM,CAAC,OAAO,CAAA,MAAA,YAAY,CAAC,GAAG,0CAAG,CAAC,CAAC,CAAA,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACzD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,iCAAiC,EAAE,GAAG,EAAE;QACzC,MAAM,YAAY,GAAG,EAAE,sDAAsD,EAAE,CAAC,EAAE,CAAC;QACnF,MAAM,YAAY,GAAG,IAAA,gCAAc,EAAC,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,IAAA,gCAAc,EAAC,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,IAAA,gCAAc,EAAC,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
|
-
});
|