@workleap/logrocket 1.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/CHANGELOG.md +14 -0
- package/LICENSE +201 -0
- package/README.md +13 -0
- package/dist/HasExecutedGuard.d.ts +6 -0
- package/dist/HasExecutedGuard.js +21 -0
- package/dist/HasExecutedGuard.js.map +1 -0
- package/dist/applyTransformers.d.ts +9 -0
- package/dist/applyTransformers.js +10 -0
- package/dist/applyTransformers.js.map +1 -0
- package/dist/assertions.d.ts +1 -0
- package/dist/assertions.js +9 -0
- package/dist/assertions.js.map +1 -0
- package/dist/createDefaultUserTraits.d.ts +109 -0
- package/dist/createDefaultUserTraits.js +102 -0
- package/dist/createDefaultUserTraits.js.map +1 -0
- package/dist/createRequestSanitizer.d.ts +3 -0
- package/dist/createRequestSanitizer.js +18 -0
- package/dist/createRequestSanitizer.js.map +1 -0
- package/dist/createResponseSanitizer.d.ts +3 -0
- package/dist/createResponseSanitizer.js +15 -0
- package/dist/createResponseSanitizer.js.map +1 -0
- package/dist/createUrlSanitizer.d.ts +1 -0
- package/dist/createUrlSanitizer.js +15 -0
- package/dist/createUrlSanitizer.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/logRocketTypes.d.ts +24 -0
- package/dist/logRocketTypes.js +7 -0
- package/dist/logRocketTypes.js.map +1 -0
- package/dist/registerLogRocketInstrumentation.d.ts +20 -0
- package/dist/registerLogRocketInstrumentation.js +146 -0
- package/dist/registerLogRocketInstrumentation.js.map +1 -0
- package/package.json +55 -0
- package/src/HasExecutedGuard.ts +19 -0
- package/src/applyTransformers.ts +17 -0
- package/src/assertions.ts +3 -0
- package/src/createDefaultUserTraits.ts +151 -0
- package/src/createRequestSanitizer.ts +19 -0
- package/src/createResponseSanitizer.ts +15 -0
- package/src/createUrlSanitizer.ts +11 -0
- package/src/index.ts +5 -0
- package/src/logRocketTypes.ts +30 -0
- package/src/registerLogRocketInstrumentation.ts +152 -0
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { getBootstrappingStore, getTelemetryContext } from "@workleap/telemetry";
|
|
2
|
+
import LogRocket from "logrocket";
|
|
3
|
+
import LogrocketFuzzySanitizer from "logrocket-fuzzy-search-sanitizer";
|
|
4
|
+
import { applyTransformers, type LogRocketSdkOptionsTransformer } from "./applyTransformers.ts";
|
|
5
|
+
import { DeviceIdTrait, TelemetryIdTrait } from "./createDefaultUserTraits.ts";
|
|
6
|
+
import { createRequestSanitizer } from "./createRequestSanitizer.ts";
|
|
7
|
+
import { createResponseSanitizer } from "./createResponseSanitizer.ts";
|
|
8
|
+
import { createUrlSanitizer } from "./createUrlSanitizer.ts";
|
|
9
|
+
import { HasExecutedGuard } from "./HasExecutedGuard.ts";
|
|
10
|
+
import type { LogRocketSdkOptions } from "./logRocketTypes.ts";
|
|
11
|
+
|
|
12
|
+
export const IsRegisteredFunctionName = "__WLP_LOGROCKET_INSTRUMENTATION_IS_REGISTERED__";
|
|
13
|
+
export const RegisterGetSessionUrlFunctionName = "__WLP_LOGROCKET_INSTRUMENTATION_REGISTER_GET_SESSION_URL_LISTENER__";
|
|
14
|
+
|
|
15
|
+
const DefaultPrivateFieldNames = [
|
|
16
|
+
"email",
|
|
17
|
+
"personalEmail",
|
|
18
|
+
"phoneNumber",
|
|
19
|
+
"password",
|
|
20
|
+
"firstName",
|
|
21
|
+
"lastName",
|
|
22
|
+
"givenName",
|
|
23
|
+
"fullName",
|
|
24
|
+
"gender",
|
|
25
|
+
"timeZone",
|
|
26
|
+
"birthday"
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
const DefaultPrivateQueryParameterNames = [
|
|
30
|
+
"token",
|
|
31
|
+
"email",
|
|
32
|
+
"password"
|
|
33
|
+
];
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @see https://workleap.github.io/wl-telemetry
|
|
37
|
+
*/
|
|
38
|
+
export interface RegisterLogRocketInstrumentationOptions {
|
|
39
|
+
// Set to capture traffic from all subdomains under one session: https://docs.logrocket.com/reference/roothostname.
|
|
40
|
+
rootHostname?: LogRocketSdkOptions["rootHostname"];
|
|
41
|
+
privateFieldNames?: string[];
|
|
42
|
+
privateQueryParameterNames?: string[];
|
|
43
|
+
verbose?: boolean;
|
|
44
|
+
transformers?: LogRocketSdkOptionsTransformer[];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// The function return type is mandatory, otherwise we got an error TS4058.
|
|
48
|
+
export function getLogRocketSdkOptions(options: RegisterLogRocketInstrumentationOptions): LogRocketSdkOptions {
|
|
49
|
+
const {
|
|
50
|
+
rootHostname = "workleap.com",
|
|
51
|
+
privateFieldNames = [],
|
|
52
|
+
privateQueryParameterNames = [],
|
|
53
|
+
verbose = false,
|
|
54
|
+
transformers = []
|
|
55
|
+
} = options;
|
|
56
|
+
|
|
57
|
+
const mergedPrivateFieldNames = DefaultPrivateFieldNames.concat(privateFieldNames);
|
|
58
|
+
const mergedPrivateQueryParameterNames = DefaultPrivateQueryParameterNames.concat(privateQueryParameterNames);
|
|
59
|
+
|
|
60
|
+
// The "LogrocketFuzzySearch.setup" code is awkward. For now, we prefer to play it safe and call it once here, then forward the sanitize functions
|
|
61
|
+
// to the appropriate factories.
|
|
62
|
+
// No clue why the "setup" method is not available. This package is shady.
|
|
63
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
64
|
+
// @ts-ignore
|
|
65
|
+
const { requestSanitizer: fuzzyRequestSanitizer, responseSanitizer: fuzzyResponseSanitizer } = LogrocketFuzzySanitizer.setup(mergedPrivateFieldNames);
|
|
66
|
+
|
|
67
|
+
const sdkOptions = {
|
|
68
|
+
console: {
|
|
69
|
+
isEnabled: false
|
|
70
|
+
},
|
|
71
|
+
rootHostname,
|
|
72
|
+
dom: {
|
|
73
|
+
textSanitizer: true,
|
|
74
|
+
inputSanitizer: true
|
|
75
|
+
},
|
|
76
|
+
network: {
|
|
77
|
+
requestSanitizer: createRequestSanitizer(fuzzyRequestSanitizer),
|
|
78
|
+
responseSanitizer: createResponseSanitizer(fuzzyResponseSanitizer)
|
|
79
|
+
},
|
|
80
|
+
browser: {
|
|
81
|
+
urlSanitizer: createUrlSanitizer(mergedPrivateQueryParameterNames)
|
|
82
|
+
},
|
|
83
|
+
shouldDebugLog: verbose
|
|
84
|
+
} satisfies LogRocketSdkOptions;
|
|
85
|
+
|
|
86
|
+
return applyTransformers(sdkOptions, transformers, {
|
|
87
|
+
verbose
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const registrationGuard = new HasExecutedGuard();
|
|
92
|
+
|
|
93
|
+
// This function should only be used by tests.
|
|
94
|
+
export function __resetRegistrationGuard() {
|
|
95
|
+
registrationGuard.reset();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* @see https://workleap.github.io/wl-telemetry
|
|
100
|
+
*/
|
|
101
|
+
export function registerLogRocketInstrumentation(appId: string, options: RegisterLogRocketInstrumentationOptions = {}) {
|
|
102
|
+
const {
|
|
103
|
+
verbose = false
|
|
104
|
+
} = options;
|
|
105
|
+
|
|
106
|
+
registrationGuard.throw("[logrocket] The LogRocket instrumentation has already been registered. Did you call the \"registerLogRocketInstrumentation\" function twice?");
|
|
107
|
+
|
|
108
|
+
const sdkOptions = getLogRocketSdkOptions(options);
|
|
109
|
+
|
|
110
|
+
// Session starts anonymously when LogRocket.init() is called.
|
|
111
|
+
LogRocket.init(appId, sdkOptions);
|
|
112
|
+
|
|
113
|
+
const telemetryContext = getTelemetryContext({ verbose });
|
|
114
|
+
|
|
115
|
+
// LogRocket maintains the same session even if the user starts as anonymous and later becomes identified via LogRocket.identify().
|
|
116
|
+
// If LogRocket.identify is called multiple times during a recording, you can search for any of the identified users in the session.
|
|
117
|
+
LogRocket.identify(telemetryContext.deviceId, {
|
|
118
|
+
[DeviceIdTrait]: telemetryContext.deviceId,
|
|
119
|
+
[TelemetryIdTrait]: telemetryContext.telemetryId
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
if (verbose) {
|
|
123
|
+
LogRocket.getSessionURL(url => {
|
|
124
|
+
console.log("[logrocket] Session replay URL is now available:", url);
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Indicates to the host applications that logrocket has been initialized.
|
|
129
|
+
// It's useful in cases where an "add-on", like the platform widgets needs
|
|
130
|
+
// to know whether or not the host application is using LogRocket.
|
|
131
|
+
// While there are ways that the host application could tell to an "add-on" if
|
|
132
|
+
// it's using LogRocket or not, doing it this way is transparent for the consumer,
|
|
133
|
+
// which is great for DX.
|
|
134
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
135
|
+
// @ts-ignore
|
|
136
|
+
globalThis[IsRegisteredFunctionName] = true;
|
|
137
|
+
|
|
138
|
+
// While consumers could directly call LogRocket.getSessionURL, by doing it this way,
|
|
139
|
+
// it allow consumers to not take a direct dependency on the "logrocket" package.
|
|
140
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
141
|
+
// @ts-ignore
|
|
142
|
+
globalThis[RegisterGetSessionUrlFunctionName] = listener => {
|
|
143
|
+
LogRocket.getSessionURL(listener);
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
// Let the other telemetry libraries know that LogRocket instrumentation is ready.
|
|
147
|
+
getBootstrappingStore().dispatch({ type: "logrocket-ready" });
|
|
148
|
+
|
|
149
|
+
if (verbose) {
|
|
150
|
+
console.log("[logrocket] LogRocket instrumentation is registered.");
|
|
151
|
+
}
|
|
152
|
+
}
|