@crimson-education/browser-logger 2.0.2-cognito.2 → 3.0.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/README.md +289 -18
- package/lib/index.d.ts +10 -24
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +45 -116
- package/lib/index.js.map +1 -1
- package/lib/logger/consoleTransport.d.ts +37 -0
- package/lib/logger/consoleTransport.d.ts.map +1 -0
- package/lib/logger/consoleTransport.js +81 -0
- package/lib/logger/consoleTransport.js.map +1 -0
- package/lib/logger/datadogTransport.d.ts +8 -0
- package/lib/logger/datadogTransport.d.ts.map +1 -0
- package/lib/logger/datadogTransport.js +21 -0
- package/lib/logger/datadogTransport.js.map +1 -0
- package/lib/logger/index.d.ts +16 -0
- package/lib/logger/index.d.ts.map +1 -0
- package/lib/logger/index.js +148 -0
- package/lib/logger/index.js.map +1 -0
- package/lib/logger/index.test.d.ts +2 -0
- package/lib/logger/index.test.d.ts.map +1 -0
- package/lib/logger/index.test.js +60 -0
- package/lib/logger/index.test.js.map +1 -0
- package/lib/logger/utils.d.ts +15 -0
- package/lib/logger/utils.d.ts.map +1 -0
- package/lib/logger/utils.js +32 -0
- package/lib/logger/utils.js.map +1 -0
- package/lib/reporters/amplifyReporter.d.ts +40 -14
- package/lib/reporters/amplifyReporter.d.ts.map +1 -1
- package/lib/reporters/amplifyReporter.js +15 -23
- package/lib/reporters/amplifyReporter.js.map +1 -1
- package/lib/reporters/amplifyReporter.test.js +0 -11
- package/lib/reporters/amplifyReporter.test.js.map +1 -1
- package/lib/reporters/datadogReporter.d.ts +64 -14
- package/lib/reporters/datadogReporter.d.ts.map +1 -1
- package/lib/reporters/datadogReporter.js +46 -101
- package/lib/reporters/datadogReporter.js.map +1 -1
- package/lib/reporters/gtmReporter.d.ts +3 -2
- package/lib/reporters/gtmReporter.d.ts.map +1 -1
- package/lib/reporters/gtmReporter.js +20 -6
- package/lib/reporters/gtmReporter.js.map +1 -1
- package/lib/reporters/index.d.ts +66 -28
- package/lib/reporters/index.d.ts.map +1 -1
- package/lib/reporters/index.js +210 -0
- package/lib/reporters/index.js.map +1 -1
- package/lib/reporters/logReporter.d.ts +35 -0
- package/lib/reporters/logReporter.d.ts.map +1 -0
- package/lib/reporters/logReporter.js +62 -0
- package/lib/reporters/logReporter.js.map +1 -0
- package/lib/types/index.d.ts +3 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js +19 -0
- package/lib/types/index.js.map +1 -0
- package/lib/types/logger.d.ts +78 -0
- package/lib/types/logger.d.ts.map +1 -0
- package/lib/{types.js → types/logger.js} +1 -1
- package/lib/types/logger.js.map +1 -0
- package/lib/types/reporter.d.ts +155 -0
- package/lib/types/reporter.d.ts.map +1 -0
- package/lib/types/reporter.js +3 -0
- package/lib/types/reporter.js.map +1 -0
- package/lib/utils.d.ts +9 -4
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js +28 -43
- package/lib/utils.js.map +1 -1
- package/lib/utils.test.d.ts +2 -0
- package/lib/utils.test.d.ts.map +1 -0
- package/lib/utils.test.js +32 -0
- package/lib/utils.test.js.map +1 -0
- package/package.json +5 -4
- package/src/index.ts +41 -120
- package/src/logger/consoleTransport.ts +101 -0
- package/src/logger/datadogTransport.ts +20 -0
- package/src/logger/index.test.ts +68 -0
- package/src/logger/index.ts +139 -0
- package/src/logger/utils.ts +28 -0
- package/src/reporters/amplifyReporter.test.ts +1 -14
- package/src/reporters/amplifyReporter.ts +65 -36
- package/src/reporters/datadogReporter.ts +123 -115
- package/src/reporters/gtmReporter.ts +35 -8
- package/src/reporters/index.ts +208 -24
- package/src/reporters/logReporter.ts +86 -0
- package/src/types/index.ts +2 -0
- package/src/types/logger.ts +85 -0
- package/src/types/reporter.ts +167 -0
- package/src/utils.test.ts +32 -0
- package/src/utils.ts +39 -49
- package/lib/types.d.ts +0 -48
- package/lib/types.d.ts.map +0 -1
- package/lib/types.js.map +0 -1
- package/src/types.ts +0 -50
package/lib/reporters/index.js
CHANGED
|
@@ -1,3 +1,213 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.recordSessionStop = exports.recordSession = exports.reportError = exports.setPageName = exports.setRouteName = exports.setUser = exports.addMetadata = exports.addBreadcrumb = exports.getLastTrackedEvent = exports.trackEventSinceLastAction = exports.trackEvent = exports.setEventLevel = exports.globalEventLevel = exports.reporters = void 0;
|
|
4
|
+
const utils_1 = require("../logger/utils");
|
|
5
|
+
const utils_2 = require("../utils");
|
|
6
|
+
exports.reporters = {};
|
|
7
|
+
/**
|
|
8
|
+
* Sets the global event level.
|
|
9
|
+
*/
|
|
10
|
+
function setEventLevel(level) {
|
|
11
|
+
exports.globalEventLevel = level !== null && level !== void 0 ? level : undefined;
|
|
12
|
+
}
|
|
13
|
+
exports.setEventLevel = setEventLevel;
|
|
14
|
+
/**
|
|
15
|
+
* Gets reporters, optionally with filters.
|
|
16
|
+
* @param filters Filters to remove or specify specific reporters.
|
|
17
|
+
* @returns Selected reporters, or all registered reporters.
|
|
18
|
+
*/
|
|
19
|
+
function getReporters(filters) {
|
|
20
|
+
let result = Object.entries(exports.reporters);
|
|
21
|
+
if (filters === null || filters === void 0 ? void 0 : filters.excludeReporters) {
|
|
22
|
+
result = result.filter(([key]) => { var _a; return !((_a = filters === null || filters === void 0 ? void 0 : filters.excludeReporters) === null || _a === void 0 ? void 0 : _a.includes(key)); });
|
|
23
|
+
}
|
|
24
|
+
if (filters === null || filters === void 0 ? void 0 : filters.toReporters) {
|
|
25
|
+
result = result.filter(([key]) => { var _a; return (_a = filters === null || filters === void 0 ? void 0 : filters.toReporters) === null || _a === void 0 ? void 0 : _a.includes(key); });
|
|
26
|
+
}
|
|
27
|
+
return result.map(([, reporter]) => reporter);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Tracks an Analytics event.
|
|
31
|
+
*/
|
|
32
|
+
function trackEvent(event) {
|
|
33
|
+
var _a;
|
|
34
|
+
if (exports.globalEventLevel && event.level && !(0, utils_1.isAboveLevel)(event.level, exports.globalEventLevel)) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
for (const reporter of getReporters(event)) {
|
|
38
|
+
if (((_a = reporter.endpoints) === null || _a === void 0 ? void 0 : _a.trackEvent) === false) {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
else if (reporter.eventLevel && event.level && !(0, utils_1.isAboveLevel)(event.level, reporter.eventLevel)) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const reporterEvent = { ...event };
|
|
45
|
+
reporterEvent.metadata = (0, utils_2.filterReporterMetadata)(event.metadata, reporter);
|
|
46
|
+
reporterEvent.metrics = (0, utils_2.filterReporterMetadata)(event.metrics, reporter);
|
|
47
|
+
reporterEvent.tags = (0, utils_2.filterReporterMetadata)(event.tags, reporter);
|
|
48
|
+
reporter.trackEvent(reporterEvent);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.trackEvent = trackEvent;
|
|
52
|
+
/**
|
|
53
|
+
* Tracks an Analytics event, recording the time since the last event, if available.
|
|
54
|
+
*/
|
|
55
|
+
function trackEventSinceLastAction(event) {
|
|
56
|
+
if (exports.globalEventLevel && event.level && !(0, utils_1.isAboveLevel)(event.level, exports.globalEventLevel)) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const lastEvent = getLastTrackedEvent();
|
|
60
|
+
if (lastEvent) {
|
|
61
|
+
const duration = new Date().getTime() - lastEvent.occurred.getTime();
|
|
62
|
+
trackEvent({
|
|
63
|
+
...event,
|
|
64
|
+
metadata: {
|
|
65
|
+
...event.metadata,
|
|
66
|
+
lastEventName: lastEvent.message,
|
|
67
|
+
timeSinceLastEvent: duration,
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
trackEvent(event);
|
|
73
|
+
}
|
|
74
|
+
sessionStorage.setItem('loggerLastEvent', JSON.stringify({ ...event, occurred: new Date() }));
|
|
75
|
+
}
|
|
76
|
+
exports.trackEventSinceLastAction = trackEventSinceLastAction;
|
|
77
|
+
/**
|
|
78
|
+
* Gets the last tracked event, if available.
|
|
79
|
+
*/
|
|
80
|
+
function getLastTrackedEvent() {
|
|
81
|
+
const eventStr = sessionStorage.getItem('loggerLastEvent');
|
|
82
|
+
if (!eventStr)
|
|
83
|
+
return null;
|
|
84
|
+
const event = JSON.parse(eventStr);
|
|
85
|
+
event.occurred = new Date(event.occurred);
|
|
86
|
+
return event;
|
|
87
|
+
}
|
|
88
|
+
exports.getLastTrackedEvent = getLastTrackedEvent;
|
|
89
|
+
/**
|
|
90
|
+
* Breadcrumbs to create a trail of events that happened prior to an issue.
|
|
91
|
+
* These events are very similar to traditional logs, but can record more rich structured data.
|
|
92
|
+
*/
|
|
93
|
+
function addBreadcrumb(breadcrumb) {
|
|
94
|
+
var _a, _b;
|
|
95
|
+
for (const reporter of getReporters(breadcrumb)) {
|
|
96
|
+
if (((_a = reporter.endpoints) === null || _a === void 0 ? void 0 : _a.addBreadcrumb) === false) {
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
else if (breadcrumb.category && ((_b = reporter.ignoreBreadcrumbCategories) === null || _b === void 0 ? void 0 : _b.includes(breadcrumb.category))) {
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
const reporterBreadcrumb = { ...breadcrumb };
|
|
103
|
+
reporterBreadcrumb.metadata = (0, utils_2.filterReporterMetadata)(breadcrumb.metadata, reporter);
|
|
104
|
+
reporter.addBreadcrumb(reporterBreadcrumb);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
exports.addBreadcrumb = addBreadcrumb;
|
|
108
|
+
/**
|
|
109
|
+
* Adds global metadata to all events and logs.
|
|
110
|
+
* @param metadata Metadata to add.
|
|
111
|
+
* @param filters Optional filters to specify which reporters to add metadata to.
|
|
112
|
+
*/
|
|
113
|
+
function addMetadata(metadata, filters) {
|
|
114
|
+
var _a;
|
|
115
|
+
for (const reporter of getReporters(filters)) {
|
|
116
|
+
if (((_a = reporter.endpoints) === null || _a === void 0 ? void 0 : _a.addMetadata) === false) {
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
reporter.addMetadata((0, utils_2.filterReporterMetadata)(metadata, reporter));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
exports.addMetadata = addMetadata;
|
|
123
|
+
/**
|
|
124
|
+
* Sets the user information in Analytics.
|
|
125
|
+
* @param user User information, or null to clear.
|
|
126
|
+
* @param filters Optional filters to specify which reporters to set the user for.
|
|
127
|
+
*/
|
|
128
|
+
function setUser(user, filters) {
|
|
129
|
+
var _a;
|
|
130
|
+
for (const reporter of getReporters(filters)) {
|
|
131
|
+
if (((_a = reporter.endpoints) === null || _a === void 0 ? void 0 : _a.setUser) === false) {
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
reporter.setUser(user);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
exports.setUser = setUser;
|
|
138
|
+
/**
|
|
139
|
+
* Sets the route name in Analytics.
|
|
140
|
+
* Some Analytics services use this differentiate SPA Route vs Page changes.
|
|
141
|
+
* @param routeName Name of the Route.
|
|
142
|
+
* @param filters Optional filters to specify which reporters to set the route name for.
|
|
143
|
+
*/
|
|
144
|
+
function setRouteName(routeName, filters) {
|
|
145
|
+
var _a;
|
|
146
|
+
for (const reporter of getReporters(filters)) {
|
|
147
|
+
if (((_a = reporter.endpoints) === null || _a === void 0 ? void 0 : _a.setRouteName) === false) {
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
reporter.setRouteName(routeName);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
exports.setRouteName = setRouteName;
|
|
154
|
+
/**
|
|
155
|
+
* Sets the page name in Analytics.
|
|
156
|
+
* @param pageName Name of the Page.
|
|
157
|
+
* @param filters Optional filters to specify which reporters to set the page name for.
|
|
158
|
+
*/
|
|
159
|
+
function setPageName(pageName, filters) {
|
|
160
|
+
var _a;
|
|
161
|
+
for (const reporter of getReporters(filters)) {
|
|
162
|
+
if (((_a = reporter.endpoints) === null || _a === void 0 ? void 0 : _a.setPageName) === false) {
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
reporter.setPageName(pageName);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
exports.setPageName = setPageName;
|
|
169
|
+
/**
|
|
170
|
+
* Reports an Error in Reporters that support error tracking.
|
|
171
|
+
* @param error Error data.
|
|
172
|
+
* @param metadata Metadata to add to the error.
|
|
173
|
+
* @param filters Optional filters to specify which reporters to report the error to.
|
|
174
|
+
*/
|
|
175
|
+
function reportError(error, metadata, filters) {
|
|
176
|
+
var _a, _b;
|
|
177
|
+
for (const reporter of getReporters(filters)) {
|
|
178
|
+
if (((_a = reporter.endpoints) === null || _a === void 0 ? void 0 : _a.reportError) === false) {
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
(_b = reporter.reportError) === null || _b === void 0 ? void 0 : _b.call(reporter, error, (0, utils_2.filterReporterMetadata)(metadata, reporter));
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
exports.reportError = reportError;
|
|
185
|
+
/**
|
|
186
|
+
* Starts a session recording in Analytics, e.g. RUM Session Replay
|
|
187
|
+
* @param filters Optional filters to specify which reporters to start a session recording for.
|
|
188
|
+
*/
|
|
189
|
+
function recordSession(filters) {
|
|
190
|
+
var _a, _b;
|
|
191
|
+
for (const reporter of getReporters(filters)) {
|
|
192
|
+
if (((_a = reporter.endpoints) === null || _a === void 0 ? void 0 : _a.recordSession) === false) {
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
(_b = reporter.recordSession) === null || _b === void 0 ? void 0 : _b.call(reporter);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
exports.recordSession = recordSession;
|
|
199
|
+
/**
|
|
200
|
+
* Stops a session recording in Analytics, e.g. RUM Session Replay
|
|
201
|
+
* @param filters Optional filters to specify which reporters to stop a session recording for.
|
|
202
|
+
*/
|
|
203
|
+
function recordSessionStop(filters) {
|
|
204
|
+
var _a, _b;
|
|
205
|
+
for (const reporter of getReporters(filters)) {
|
|
206
|
+
if (((_a = reporter.endpoints) === null || _a === void 0 ? void 0 : _a.recordSessionStop) === false) {
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
(_b = reporter.recordSessionStop) === null || _b === void 0 ? void 0 : _b.call(reporter);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
exports.recordSessionStop = recordSessionStop;
|
|
3
213
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/reporters/index.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/reporters/index.ts"],"names":[],"mappings":";;;AAAA,2CAA+C;AAa/C,oCAAkD;AAErC,QAAA,SAAS,GAA6C,EAAE,CAAC;AAGtE;;GAEG;AACH,SAAgB,aAAa,CAAC,KAAsB;IAClD,wBAAgB,GAAG,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,SAAS,CAAC;AACxC,CAAC;AAFD,sCAEC;AAED;;;;GAIG;AACH,SAAS,YAAY,CAAC,OAAyB;IAC7C,IAAI,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,iBAAS,CAAC,CAAC;IACvC,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,gBAAgB,EAAE;QAC7B,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,WAAC,OAAA,CAAC,CAAA,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,gBAAgB,0CAAE,QAAQ,CAAC,GAAmB,CAAC,CAAA,CAAA,EAAA,CAAC,CAAC;KAC9F;IACD,IAAI,OAAO,aAAP,OAAO,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AE;QAC5C,IAAI,CAAA,MAAA,QAAQ,CAAC,SAAS,0CAAE,iBAAiB,MAAK,KAAK,EAAE;YACnD,SAAS;SACV;QACD,MAAA,QAAQ,CAAC,iBAAiB,wDAAI,CAAC;KAChC;AACH,CAAC;AAPD,8CAOC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { IReporter, LogLevel, ReporterConfigBase, ServiceInfo } from '../types';
|
|
2
|
+
export interface LogReporterConfig extends ReporterConfigBase {
|
|
3
|
+
/**
|
|
4
|
+
* The fallback log level to apply to all trackEvent calls (if the event's level is not set).
|
|
5
|
+
* Defaults to info.
|
|
6
|
+
*/
|
|
7
|
+
trackEventDefaultLevel?: LogLevel;
|
|
8
|
+
/**
|
|
9
|
+
* The log level to apply to all addBreadcrumb calls.
|
|
10
|
+
* Defaults to info.
|
|
11
|
+
*/
|
|
12
|
+
addBreadcrumbLevel?: LogLevel;
|
|
13
|
+
/**
|
|
14
|
+
* The log level to apply to all setRouteName calls.
|
|
15
|
+
* Defaults to debug.
|
|
16
|
+
*/
|
|
17
|
+
setRouteNameLevel?: LogLevel;
|
|
18
|
+
/**
|
|
19
|
+
* The log level to apply to all setPageName calls.
|
|
20
|
+
* Defaults to debug.
|
|
21
|
+
*/
|
|
22
|
+
setPageNameLevel?: LogLevel;
|
|
23
|
+
/**
|
|
24
|
+
* The log level to apply to all recordSession calls.
|
|
25
|
+
* Defaults to debug.
|
|
26
|
+
*/
|
|
27
|
+
recordSessionLevel?: LogLevel;
|
|
28
|
+
/**
|
|
29
|
+
* The log level to apply to all recordSessionStop calls.
|
|
30
|
+
* Defaults to debug.
|
|
31
|
+
*/
|
|
32
|
+
recordSessionStopLevel?: LogLevel;
|
|
33
|
+
}
|
|
34
|
+
export declare function logReporter(info: ServiceInfo, config: LogReporterConfig): IReporter;
|
|
35
|
+
//# sourceMappingURL=logReporter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logReporter.d.ts","sourceRoot":"","sources":["../../src/reporters/logReporter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEhF,MAAM,WAAW,iBAAkB,SAAQ,kBAAkB;IAC3D;;;OAGG;IACH,sBAAsB,CAAC,EAAE,QAAQ,CAAC;IAClC;;;OAGG;IACH,kBAAkB,CAAC,EAAE,QAAQ,CAAC;IAC9B;;;OAGG;IACH,iBAAiB,CAAC,EAAE,QAAQ,CAAC;IAC7B;;;OAGG;IACH,gBAAgB,CAAC,EAAE,QAAQ,CAAC;IAC5B;;;OAGG;IACH,kBAAkB,CAAC,EAAE,QAAQ,CAAC;IAC9B;;;OAGG;IACH,sBAAsB,CAAC,EAAE,QAAQ,CAAC;CACnC;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,iBAAiB,aAiDvE"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.logReporter = void 0;
|
|
4
|
+
const logger_1 = require("../logger");
|
|
5
|
+
const types_1 = require("../types");
|
|
6
|
+
function logReporter(info, config) {
|
|
7
|
+
const reporter = {
|
|
8
|
+
...config,
|
|
9
|
+
trackEvent(event) {
|
|
10
|
+
var _a, _b, _c, _d, _e;
|
|
11
|
+
// config.trackEventLevel and config.level overrides event.level here, as it is an override, while config.trackEventDefaultLevel is a fallback.
|
|
12
|
+
const level = (_b = (_a = event.level) !== null && _a !== void 0 ? _a : config.trackEventDefaultLevel) !== null && _b !== void 0 ? _b : types_1.LogLevel.Info;
|
|
13
|
+
logger_1.logger.log(level, event.message, {
|
|
14
|
+
...((_c = event.metadata) !== null && _c !== void 0 ? _c : {}),
|
|
15
|
+
...((_d = event.metrics) !== null && _d !== void 0 ? _d : {}),
|
|
16
|
+
...((_e = event.tags) !== null && _e !== void 0 ? _e : {}),
|
|
17
|
+
});
|
|
18
|
+
},
|
|
19
|
+
addBreadcrumb(breadcrumb) {
|
|
20
|
+
var _a, _b;
|
|
21
|
+
const level = (_a = config.addBreadcrumbLevel) !== null && _a !== void 0 ? _a : types_1.LogLevel.Info;
|
|
22
|
+
logger_1.logger.log(level, breadcrumb.message, {
|
|
23
|
+
...((_b = breadcrumb.metadata) !== null && _b !== void 0 ? _b : {}),
|
|
24
|
+
category: breadcrumb.category,
|
|
25
|
+
});
|
|
26
|
+
},
|
|
27
|
+
addMetadata(metadata) {
|
|
28
|
+
Object.assign(logger_1.globalMetadata, metadata);
|
|
29
|
+
},
|
|
30
|
+
setUser(user) {
|
|
31
|
+
Object.assign(logger_1.globalMetadata, { user });
|
|
32
|
+
},
|
|
33
|
+
setRouteName(routeName) {
|
|
34
|
+
var _a;
|
|
35
|
+
Object.assign(logger_1.globalMetadata, { routeName });
|
|
36
|
+
const level = (_a = config.setRouteNameLevel) !== null && _a !== void 0 ? _a : types_1.LogLevel.Debug;
|
|
37
|
+
logger_1.logger.log(level, `Route changed to ${routeName}`);
|
|
38
|
+
},
|
|
39
|
+
setPageName(pageName) {
|
|
40
|
+
var _a;
|
|
41
|
+
Object.assign(logger_1.globalMetadata, { pageName });
|
|
42
|
+
const level = (_a = config.setPageNameLevel) !== null && _a !== void 0 ? _a : types_1.LogLevel.Debug;
|
|
43
|
+
logger_1.logger.log(level, `Page changed to ${pageName}`);
|
|
44
|
+
},
|
|
45
|
+
reportError(error, metadata) {
|
|
46
|
+
logger_1.logger.error(typeof error === 'string' ? error : error.message, { ...metadata, error });
|
|
47
|
+
},
|
|
48
|
+
recordSession() {
|
|
49
|
+
var _a;
|
|
50
|
+
const level = (_a = config.recordSessionLevel) !== null && _a !== void 0 ? _a : types_1.LogLevel.Debug;
|
|
51
|
+
logger_1.logger.log(level, 'Recording Session');
|
|
52
|
+
},
|
|
53
|
+
recordSessionStop() {
|
|
54
|
+
var _a;
|
|
55
|
+
const level = (_a = config.recordSessionStopLevel) !== null && _a !== void 0 ? _a : types_1.LogLevel.Debug;
|
|
56
|
+
logger_1.logger.log(level, 'Recording Session Stopping');
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
return reporter;
|
|
60
|
+
}
|
|
61
|
+
exports.logReporter = logReporter;
|
|
62
|
+
//# sourceMappingURL=logReporter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logReporter.js","sourceRoot":"","sources":["../../src/reporters/logReporter.ts"],"names":[],"mappings":";;;AAAA,sCAAwE;AACxE,oCAAgF;AAmChF,SAAgB,WAAW,CAAC,IAAiB,EAAE,MAAyB;IACtE,MAAM,QAAQ,GAAc;QAC1B,GAAG,MAAM;QACT,UAAU,CAAC,KAAK;;YACd,+IAA+I;YAC/I,MAAM,KAAK,GAAG,MAAA,MAAA,KAAK,CAAC,KAAK,mCAAI,MAAM,CAAC,sBAAsB,mCAAI,gBAAQ,CAAC,IAAI,CAAC;YAC5E,eAAM,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,OAAO,EAAE;gBAC/B,GAAG,CAAC,MAAA,KAAK,CAAC,QAAQ,mCAAI,EAAE,CAAC;gBACzB,GAAG,CAAC,MAAA,KAAK,CAAC,OAAO,mCAAI,EAAE,CAAC;gBACxB,GAAG,CAAC,MAAA,KAAK,CAAC,IAAI,mCAAI,EAAE,CAAC;aACtB,CAAC,CAAC;QACL,CAAC;QACD,aAAa,CAAC,UAAU;;YACtB,MAAM,KAAK,GAAG,MAAA,MAAM,CAAC,kBAAkB,mCAAI,gBAAQ,CAAC,IAAI,CAAC;YACzD,eAAM,CAAC,GAAG,CAAC,KAAK,EAAE,UAAU,CAAC,OAAO,EAAE;gBACpC,GAAG,CAAC,MAAA,UAAU,CAAC,QAAQ,mCAAI,EAAE,CAAC;gBAC9B,QAAQ,EAAE,UAAU,CAAC,QAAQ;aAC9B,CAAC,CAAC;QACL,CAAC;QACD,WAAW,CAAC,QAAQ;YAClB,MAAM,CAA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C,KAAK,EAAE,4BAA4B,CAAC,CAAC;QAClD,CAAC;KACF,CAAC;IAEF,OAAO,QAAQ,CAAC;AAClB,CAAC;AAjDD,kCAiDC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./logger"), exports);
|
|
18
|
+
__exportStar(require("./reporter"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,6CAA2B"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
export declare type Metadata = Record<string, any>;
|
|
2
|
+
/**
|
|
3
|
+
* Options to Customize the Logger
|
|
4
|
+
*/
|
|
5
|
+
export declare type LoggerOptions = {
|
|
6
|
+
/**
|
|
7
|
+
* The min log level for events to be sent to the logger.
|
|
8
|
+
*/
|
|
9
|
+
logLevel?: LogLevel;
|
|
10
|
+
/**
|
|
11
|
+
* Metadata to add to all logs.
|
|
12
|
+
*/
|
|
13
|
+
metadata?: Metadata;
|
|
14
|
+
};
|
|
15
|
+
export declare enum LogLevel {
|
|
16
|
+
Debug = "debug",
|
|
17
|
+
Info = "info",
|
|
18
|
+
Warn = "warn",
|
|
19
|
+
Error = "error"
|
|
20
|
+
}
|
|
21
|
+
export interface LogLevelMethod {
|
|
22
|
+
(message: string, metadata?: Metadata): ILogger;
|
|
23
|
+
(message: string, ...meta: any[]): ILogger;
|
|
24
|
+
(message: any): ILogger;
|
|
25
|
+
}
|
|
26
|
+
export interface LogMethod {
|
|
27
|
+
(level: LogLevel, message: string, metadata?: Metadata): ILogger;
|
|
28
|
+
(level: LogLevel, message: string, ...meta: any[]): ILogger;
|
|
29
|
+
(level: LogLevel, message: any): ILogger;
|
|
30
|
+
(message: Record<string, any>): ILogger;
|
|
31
|
+
}
|
|
32
|
+
export interface Profiler {
|
|
33
|
+
logger: ILogger;
|
|
34
|
+
done(info?: {
|
|
35
|
+
message?: string;
|
|
36
|
+
level?: LogLevel;
|
|
37
|
+
metadata?: Metadata;
|
|
38
|
+
}): boolean;
|
|
39
|
+
}
|
|
40
|
+
export declare type StructuredLog = {
|
|
41
|
+
level: LogLevel;
|
|
42
|
+
message: any;
|
|
43
|
+
[key: string]: any;
|
|
44
|
+
};
|
|
45
|
+
export interface LogTransportConfigBase {
|
|
46
|
+
/**
|
|
47
|
+
* The min log level for logs to be sent.
|
|
48
|
+
*/
|
|
49
|
+
logLevel?: LogLevel;
|
|
50
|
+
/**
|
|
51
|
+
* Ignore specific metadata keys from being sent.
|
|
52
|
+
* This can be a regular expression, or a string to exact match.
|
|
53
|
+
* This is useful to prevent data of no use for the logger, or if the data keys are too long.
|
|
54
|
+
*/
|
|
55
|
+
ignoreMetadataPatterns?: (string | RegExp)[];
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* A logger interface that is used to transport logs to a destination
|
|
59
|
+
*/
|
|
60
|
+
export interface ILogTransport extends LogTransportConfigBase {
|
|
61
|
+
/**
|
|
62
|
+
* Inbound log event to transport.
|
|
63
|
+
*/
|
|
64
|
+
log: (logInfo: StructuredLog) => void;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* A Logger is a service that can receive log messages.
|
|
68
|
+
*/
|
|
69
|
+
export interface ILogger {
|
|
70
|
+
startTimer(): Profiler;
|
|
71
|
+
child(metadata?: Metadata, name?: string): ILogger;
|
|
72
|
+
log: LogMethod;
|
|
73
|
+
debug: LogLevelMethod;
|
|
74
|
+
info: LogLevelMethod;
|
|
75
|
+
warn: LogLevelMethod;
|
|
76
|
+
error: LogLevelMethod;
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/types/logger.ts"],"names":[],"mappings":"AAAA,oBAAY,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAE3C;;GAEG;AACH,oBAAY,aAAa,GAAG;IAC1B;;OAEG;IACH,QAAQ,CAAC,EAAE,QAAQ,CAAC;IAEpB;;OAEG;IACH,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB,CAAC;AAEF,oBAAY,QAAQ;IAClB,KAAK,UAAU;IACf,IAAI,SAAS;IACb,IAAI,SAAS;IACb,KAAK,UAAU;CAChB;AAED,MAAM,WAAW,cAAc;IAC7B,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC;IAChD,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC;IAC3C,CAAC,O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AAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IAEnD,GAAG,EAAE,SAAS,CAAC;IACf,KAAK,EAAE,cAAc,CAAC;IACtB,IAAI,EAAE,cAAc,CAAC;IACrB,IAAI,EAAE,cAAc,CAAC;IACrB,KAAK,EAAE,cAAc,CAAC;CACvB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/types/logger.ts"],"names":[],"mappings":";;;AAiBA,IAAY,QAKX;AALD,WAAY,QAAQ;IAClB,2BAAe,CAAA;IACf,yBAAa,CAAA;IACb,yBAAa,CAAA;IACb,2BAAe,CAAA;AACjB,CAAC,EALW,QAAQ,GAAR,gBAAQ,KAAR,gBAAQ,QAKnB"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { AmplifyReporterConfig } from '../reporters/amplifyReporter';
|
|
2
|
+
import { DatadogReporterConfig } from '../reporters/datadogReporter';
|
|
3
|
+
import { GTMReporterConfig } from '../reporters/gtmReporter';
|
|
4
|
+
import { LogReporterConfig } from '../reporters/logReporter';
|
|
5
|
+
import { LogLevel, Metadata } from './logger';
|
|
6
|
+
export declare type ReporterConfigurations = {
|
|
7
|
+
/**
|
|
8
|
+
* Log reporter configuration.
|
|
9
|
+
* If not set, it will default to everything enabled.
|
|
10
|
+
*/
|
|
11
|
+
log?: boolean | LogReporterConfig;
|
|
12
|
+
/**
|
|
13
|
+
* Datadog reporter configuration.
|
|
14
|
+
* If not set, the datadog reporter will not be used.
|
|
15
|
+
*/
|
|
16
|
+
datadog?: DatadogReporterConfig;
|
|
17
|
+
/**
|
|
18
|
+
* Amplify/Pinpoint reporter configuration.
|
|
19
|
+
* If not set, the amplify reporter will not be used.
|
|
20
|
+
*/
|
|
21
|
+
amplify?: AmplifyReporterConfig;
|
|
22
|
+
/**
|
|
23
|
+
* Google Tag Manager reporter configuration.
|
|
24
|
+
* If not set, the gtm reporter will not be used.
|
|
25
|
+
*/
|
|
26
|
+
gtm?: true | GTMReporterConfig;
|
|
27
|
+
};
|
|
28
|
+
export declare type ReporterType = keyof ReporterConfigurations;
|
|
29
|
+
export declare type Metrics = Record<string, number>;
|
|
30
|
+
export declare type ServiceInfo = {
|
|
31
|
+
/** The Application's name. */
|
|
32
|
+
service: string;
|
|
33
|
+
/** The Application's Environment */
|
|
34
|
+
environment: string;
|
|
35
|
+
/** The Application's Version. */
|
|
36
|
+
version: string;
|
|
37
|
+
/**
|
|
38
|
+
* Default metadata to add to Reporter events.
|
|
39
|
+
*/
|
|
40
|
+
defaultMetadata?: Metadata;
|
|
41
|
+
/**
|
|
42
|
+
* The min log level for logs to be sent to the logger.
|
|
43
|
+
*/
|
|
44
|
+
logLevel?: LogLevel;
|
|
45
|
+
/**
|
|
46
|
+
* The min event level for events to be sent to reporters.
|
|
47
|
+
*/
|
|
48
|
+
eventLevel?: LogLevel;
|
|
49
|
+
};
|
|
50
|
+
export declare type ReportUser = {
|
|
51
|
+
id: string;
|
|
52
|
+
email?: string;
|
|
53
|
+
username?: string;
|
|
54
|
+
name?: string;
|
|
55
|
+
};
|
|
56
|
+
export declare type ReportError = Error | string;
|
|
57
|
+
export interface ReporterFilters {
|
|
58
|
+
/**
|
|
59
|
+
* Send only to these Reporters.
|
|
60
|
+
*/
|
|
61
|
+
toReporters?: ReporterType[];
|
|
62
|
+
/**
|
|
63
|
+
* Don't send to these Reporters.
|
|
64
|
+
*/
|
|
65
|
+
excludeReporters?: ReporterType[];
|
|
66
|
+
}
|
|
67
|
+
export interface ReporterEvent extends ReporterFilters {
|
|
68
|
+
/**
|
|
69
|
+
* The Severity of this event.
|
|
70
|
+
*/
|
|
71
|
+
level?: LogLevel;
|
|
72
|
+
/**
|
|
73
|
+
* The event message/name.
|
|
74
|
+
*/
|
|
75
|
+
message: string;
|
|
76
|
+
/**
|
|
77
|
+
* Event metadata.
|
|
78
|
+
*/
|
|
79
|
+
metadata?: Metadata | undefined;
|
|
80
|
+
/**
|
|
81
|
+
* Event tags, if supported by the Reporter. (Otherwise, they will be added to metadata)
|
|
82
|
+
*/
|
|
83
|
+
tags?: Metadata | undefined;
|
|
84
|
+
/**
|
|
85
|
+
* Event metrics, if supported by the Reporter. (Otherwise, they will be added to metadata)
|
|
86
|
+
* Metrics are numbers, and are used for aggregations.
|
|
87
|
+
*/
|
|
88
|
+
metrics?: Metrics | undefined;
|
|
89
|
+
}
|
|
90
|
+
export interface TrackedReporterEvent extends ReporterEvent {
|
|
91
|
+
/**
|
|
92
|
+
* The time this event was created.
|
|
93
|
+
*/
|
|
94
|
+
occurred: Date;
|
|
95
|
+
}
|
|
96
|
+
export interface ReporterBreadcrumb extends ReporterFilters {
|
|
97
|
+
/**
|
|
98
|
+
* The breadcrumb event message/name.
|
|
99
|
+
*/
|
|
100
|
+
message: string;
|
|
101
|
+
/**
|
|
102
|
+
* The category of this breadcrumb (Useful for filtering out in specific reporters).
|
|
103
|
+
*/
|
|
104
|
+
category?: string | undefined;
|
|
105
|
+
/**
|
|
106
|
+
* Breadcrumb metadata.
|
|
107
|
+
*/
|
|
108
|
+
metadata?: Metadata | undefined;
|
|
109
|
+
}
|
|
110
|
+
export interface ReporterConfigBase {
|
|
111
|
+
/**
|
|
112
|
+
* Enable/Disable reporter endpoints from being called.
|
|
113
|
+
*/
|
|
114
|
+
endpoints?: {
|
|
115
|
+
trackEvent?: boolean;
|
|
116
|
+
addMetadata?: boolean;
|
|
117
|
+
addBreadcrumb?: boolean;
|
|
118
|
+
setUser?: boolean;
|
|
119
|
+
setRouteName?: boolean;
|
|
120
|
+
setPageName?: boolean;
|
|
121
|
+
reportError?: boolean;
|
|
122
|
+
recordSession?: boolean;
|
|
123
|
+
recordSessionStop?: boolean;
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* The min event level for events to be sent to the reporter.
|
|
127
|
+
*/
|
|
128
|
+
eventLevel?: LogLevel;
|
|
129
|
+
/**
|
|
130
|
+
* Categories of breadcrumbs to ignore sending to the reporter.
|
|
131
|
+
* This is useful to prevent data of no use for that reporter.
|
|
132
|
+
*/
|
|
133
|
+
ignoreBreadcrumbCategories?: string[];
|
|
134
|
+
/**
|
|
135
|
+
* Ignore specific metadata keys from being sent to the reporter.
|
|
136
|
+
* This can be a regular expression, or a string to exact match.
|
|
137
|
+
* This is useful to prevent data of no use for the reporter, or if the data keys are too long.
|
|
138
|
+
*/
|
|
139
|
+
ignoreMetadataPatterns?: (string | RegExp)[];
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* A Reporter is a service that can receive Analytics data.
|
|
143
|
+
*/
|
|
144
|
+
export interface IReporter extends ReporterConfigBase {
|
|
145
|
+
trackEvent(event: ReporterEvent): void;
|
|
146
|
+
addBreadcrumb(breadcrumb: ReporterBreadcrumb): void;
|
|
147
|
+
addMetadata(metadata: Metadata): void;
|
|
148
|
+
setUser(user: ReportUser | null): void;
|
|
149
|
+
setRouteName(routeName: string): void;
|
|
150
|
+
setPageName(pageName: string): void;
|
|
151
|
+
reportError?(error: ReportError, metadata?: Metadata): void;
|
|
152
|
+
recordSession?(): void;
|
|
153
|
+
recordSessionStop?(): void;
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=reporter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reporter.d.ts","sourceRoot":"","sources":["../../src/types/reporter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAE9C,oBAAY,sBAAsB,GAAG;IACnC;;;OAGG;IACH,GAAG,CAAC,EAAE,OAAO,GAAG,iBAAiB,CAAC;IAElC;;;O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AI,GAAG,IAAI,CAAC;IACvC,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACtC,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,WAAW,CAAC,CAAC,KAAK,EAAE,WAAW,EAAE,QAAQ,CAAC,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC5D,aAAa,CAAC,IAAI,IAAI,CAAC;IACvB,iBAAiB,CAAC,IAAI,IAAI,CAAC;CAC5B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reporter.js","sourceRoot":"","sources":["../../src/types/reporter.ts"],"names":[],"mappings":""}
|
package/lib/utils.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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;
|
|
5
10
|
//# sourceMappingURL=utils.d.ts.map
|
package/lib/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE9C;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,SAAS,SAAS,QAAQ,GAAG,SAAS,EAC3E,QAAQ,EAAE,SAAS,EACnB,QAAQ,EAAE,IAAI,CAAC,SAAS,EAAE,wBAAwB,CAAC,EACnD,MAAM,CAAC,EAAE,MAAM,GACd,SAAS,CA0BX"}
|