@alwaysmeticulous/recorder-loader 2.97.0 → 2.98.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/dist/index.d.ts +38 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +52 -1
- package/dist/index.js.map +1 -1
- package/dist/module.js +52 -2
- package/dist/module.js.map +1 -1
- package/package.json +3 -2
package/dist/index.d.ts
CHANGED
|
@@ -33,5 +33,43 @@ export const tryLoadAndStartRecorder: (options: LoaderOptions) => Promise<void>;
|
|
|
33
33
|
* Load and start the Meticulous Recorder
|
|
34
34
|
*/
|
|
35
35
|
export const loadAndStartRecorder: ({ projectId, uploadIntervalMs, snapshotLinkedStylesheets, commitHash, maxMsToBlockFor: maxMsToBlockFor_, snippetsBaseUrl, forceRecording, responseSanitizers, isProduction, }: LoaderOptions) => Promise<void>;
|
|
36
|
+
interface Interceptor {
|
|
37
|
+
startRecordingSession: (options: LoaderOptions) => Promise<void>;
|
|
38
|
+
stopIntercepting: () => Promise<void>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Stores a copy of network requests and responses in memory, but doesn't send them to the
|
|
42
|
+
* server, until the the main recorder is initialised.
|
|
43
|
+
*
|
|
44
|
+
* This is useful if you only want to record sessions for certain users with certain attributes. In
|
|
45
|
+
* this case you have an issue: you need to wait for the user information to load before you know whether
|
|
46
|
+
* you can enable the recorder, but if you enable the recorder after the user information has loaded
|
|
47
|
+
* then the recorder won't be able to capture the initial request & response to load the user information,
|
|
48
|
+
* or other early network responses.
|
|
49
|
+
*
|
|
50
|
+
* The early network recorder solves this: load the early network recorder for all sessions,
|
|
51
|
+
* but only load the main recorder for sessions that you want to record. If when you load the user data
|
|
52
|
+
* you find out you don't want to record the session then you can call the stopRecording() method returned
|
|
53
|
+
* by this method.
|
|
54
|
+
*
|
|
55
|
+
* Example usage:
|
|
56
|
+
*
|
|
57
|
+
* ```
|
|
58
|
+
* // The below call should happen before your app makes any network requests,
|
|
59
|
+
* // or executes any methods that may store a reference to window.fetch or XMLHttpRequest.
|
|
60
|
+
* const interceptor = await tryInstallMeticulousIntercepts();
|
|
61
|
+
*
|
|
62
|
+
* // Later, when you have loaded user data...
|
|
63
|
+
* const userData = await loadUserInfo();
|
|
64
|
+
* if (shouldRecord(userData)) {
|
|
65
|
+
* await interceptor.startRecordingSession({ ... });
|
|
66
|
+
* } else {
|
|
67
|
+
* interceptor.stopIntercepting();
|
|
68
|
+
* }
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export const tryInstallMeticulousIntercepts: (options?: {
|
|
72
|
+
maxMsToBlockFor: number;
|
|
73
|
+
}) => Promise<Interceptor>;
|
|
36
74
|
|
|
37
75
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";
|
|
1
|
+
{"mappings":";ACEA;IACE,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,yBAAyB,CAAC,EAAE,OAAO,CAAC;IACpC,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB,YAAY,CAAC,EAAE,OAAO,CAAC;IAEvB;;;;;;;;;OASG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IAEzB;;OAEG;IACH,kBAAkB,CAAC,EAAE,wBAAwB,EAAE,CAAC;CACjD;ACxBD;;GAEG;AACH,OAAO,MAAM,mCACF,aAAa,KACrB,QAAQ,IAAI,CAKd,CAAC;AA0FF;;;;GAIG;AACH,OAAO,MAAM,sMAnFV,aAAa,KAAG,QAAQ,IAAI,CAmF+B,CAAC;AClG/D;IACE,qBAAqB,EAAE,CAAC,OAAO,EAAE,aAAa,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACjE,gBAAgB,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACvC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,OAAO,MAAM,2CACF;IAAE,eAAe,EAAE,MAAM,CAAA;CAAE,KACnC,QAAQ,WAAW,CAsDrB,CAAC","sources":["packages/recorder-loader/src/src/constants.ts","packages/recorder-loader/src/src/loader.types.ts","packages/recorder-loader/src/src/loader.ts","packages/recorder-loader/src/src/install-meticulous-intercepts.ts","packages/recorder-loader/src/src/index.ts","packages/recorder-loader/src/index.ts"],"sourcesContent":[null,null,null,null,null,"export { loadAndStartRecorder, tryLoadAndStartRecorder } from \"./loader\";\nexport { tryInstallMeticulousIntercepts } from \"./install-meticulous-intercepts\";\n"],"names":[],"version":3,"file":"index.d.ts.map"}
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,10 @@ function $parcel$export(e, n, v, s) {
|
|
|
4
4
|
|
|
5
5
|
$parcel$export(module.exports, "loadAndStartRecorder", () => $c97024bcb09807fa$export$9da0cde53b499187);
|
|
6
6
|
$parcel$export(module.exports, "tryLoadAndStartRecorder", () => $c97024bcb09807fa$export$f80553af9d70f9fd);
|
|
7
|
+
$parcel$export(module.exports, "tryInstallMeticulousIntercepts", () => $f8da777fb815521f$export$c0c9d1ed5ecb2675);
|
|
8
|
+
const $d2f90b927d91d104$export$d16af6ab0c202bae = "https://snippet.meticulous.ai";
|
|
9
|
+
|
|
10
|
+
|
|
7
11
|
const $c97024bcb09807fa$var$DEFAULT_MAX_MS_TO_BLOCK_FOR = 2000;
|
|
8
12
|
const $c97024bcb09807fa$export$f80553af9d70f9fd = async (options)=>{
|
|
9
13
|
// Try to load the recorder and silence any initialisation error.
|
|
@@ -21,7 +25,7 @@ const $c97024bcb09807fa$var$unsafeLoadAndStartRecorder = ({ projectId: projectId
|
|
|
21
25
|
}, maxMsToBlockFor);
|
|
22
26
|
const script = document.createElement("script");
|
|
23
27
|
script.type = "text/javascript";
|
|
24
|
-
const baseSnippetsUrl = snippetsBaseUrl ||
|
|
28
|
+
const baseSnippetsUrl = snippetsBaseUrl || (0, $d2f90b927d91d104$export$d16af6ab0c202bae);
|
|
25
29
|
script.src = new URL("v1/meticulous-manual-init.js", baseSnippetsUrl).href;
|
|
26
30
|
// Setup configuration
|
|
27
31
|
const typedWindow = window;
|
|
@@ -61,4 +65,51 @@ const $c97024bcb09807fa$export$9da0cde53b499187 = $c97024bcb09807fa$var$unsafeLo
|
|
|
61
65
|
|
|
62
66
|
|
|
63
67
|
|
|
68
|
+
const $f8da777fb815521f$export$c0c9d1ed5ecb2675 = async (options = {
|
|
69
|
+
maxMsToBlockFor: 2000
|
|
70
|
+
})=>{
|
|
71
|
+
let requestedToStopIntercepting = false;
|
|
72
|
+
let disposedEarlyNetworkRecorder = false;
|
|
73
|
+
const stopIntercepting = async ()=>{
|
|
74
|
+
requestedToStopIntercepting = true;
|
|
75
|
+
const disposeFunction = window?.__meticulous?.earlyNetworkRecorder?.dispose;
|
|
76
|
+
if (disposeFunction && !disposedEarlyNetworkRecorder) {
|
|
77
|
+
await disposeFunction();
|
|
78
|
+
disposedEarlyNetworkRecorder = true;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
const startRecordingSession = (0, $c97024bcb09807fa$export$f80553af9d70f9fd);
|
|
82
|
+
const interceptor = {
|
|
83
|
+
startRecordingSession: startRecordingSession,
|
|
84
|
+
stopIntercepting: stopIntercepting
|
|
85
|
+
};
|
|
86
|
+
const promise = new Promise((resolve, reject)=>{
|
|
87
|
+
const timeout = options.maxMsToBlockFor > 0 ? setTimeout(()=>{
|
|
88
|
+
resolve(interceptor);
|
|
89
|
+
}, options.maxMsToBlockFor) : null;
|
|
90
|
+
const script = document.createElement("script");
|
|
91
|
+
script.type = "text/javascript";
|
|
92
|
+
script.src = `${0, $d2f90b927d91d104$export$d16af6ab0c202bae}/record/v1/network-recorder.bundle.js`;
|
|
93
|
+
script.onload = function() {
|
|
94
|
+
if (timeout) window.clearTimeout(timeout);
|
|
95
|
+
resolve(interceptor);
|
|
96
|
+
};
|
|
97
|
+
script.onerror = ()=>{
|
|
98
|
+
if (timeout) window.clearTimeout(timeout);
|
|
99
|
+
reject("Meticulous early network recorder failed to initialise.");
|
|
100
|
+
};
|
|
101
|
+
document.head.appendChild(script);
|
|
102
|
+
});
|
|
103
|
+
// Try to load the early network recorder and silence any initialisation error.
|
|
104
|
+
return promise.catch((error)=>{
|
|
105
|
+
console.error(error);
|
|
106
|
+
return interceptor;
|
|
107
|
+
}).finally(()=>{
|
|
108
|
+
if (requestedToStopIntercepting) stopIntercepting();
|
|
109
|
+
});
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
|
|
64
115
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;;;;;AEAO,MAAM,4CAAoB;;ADAjC;AAGA,MAAM,oDAA8B;AAK7B,MAAM,4CAA0B,OACrC,UACkB;IAClB,iEAAiE;IACjE,MAAM,iDAA2B,SAAS,KAAK,CAAC,CAAC,QAAU;QACzD,QAAQ,KAAK,CAAC;IAChB;AACF;AAEA,MAAM,mDAA6B,CAAC,aAClC,UAAS,oBACT,iBAAgB,6BAChB,0BAAyB,cACzB,WAAU,EACV,iBAAiB,iBAAgB,mBACjC,gBAAe,kBACf,eAAc,sBACd,mBAAkB,gBAClB,aAAY,EACE,GAAoB;IAClC,IAAI,YAAY,KAAK;IAErB,OAAO,IAAI,QAAc,CAAC,SAAS,SAAW;QAC5C,MAAM,kBAAkB,oBAAoB;QAE5C,IAAI,kBAAkB,GACpB,WAAW,IAAM;YACf,YAAY,IAAI;YAChB;QACF,GAAG;QAGL,MAAM,SAAS,SAAS,aAAa,CAAC;QACtC,OAAO,IAAI,GAAG;QACd,MAAM,kBAAkB,mBAAmB,CAAA,GAAA,yCAAiB,AAAD;QAC3D,OAAO,GAAG,GAAG,IAAI,IAAI,gC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AS,SAAW;QAC5D,MAAM,UACJ,QAAQ,eAAe,GAAG,IACtB,WAAW,IAAM;YACf,QAAQ;QACV,GAAG,QAAQ,eAAe,IAC1B,IAAI;QAEV,MAAM,SAAS,SAAS,aAAa,CAAC;QACtC,OAAO,IAAI,GAAG;QACd,OAAO,GAAG,GAAG,CAAC,EAAE,GAAA,yCAAiB,CAAC,qCAAqC,CAAC;QAExE,OAAO,MAAM,GAAG,WAAY;YAC1B,IAAI,SACF,OAAO,YAAY,CAAC;YAEtB,QAAQ;QACV;QACA,OAAO,OAAO,GAAG,IAAM;YACrB,IAAI,SACF,OAAO,YAAY,CAAC;YAEtB,OAAO;QACT;QAEA,SAAS,IAAI,CAAC,WAAW,CAAC;IAC5B;IAEA,+EAA+E;IAC/E,OAAO,QACJ,KAAK,CAAC,CAAC,QAAU;QAChB,QAAQ,KAAK,CAAC;QACd,OAAO;IACT,GACC,OAAO,CAAC,IAAM;QACb,IAAI,6BACF;IAEJ;AACJ;","sources":["packages/recorder-loader/src/index.ts","packages/recorder-loader/src/loader.ts","packages/recorder-loader/src/constants.ts","packages/recorder-loader/src/install-meticulous-intercepts.ts"],"sourcesContent":["export { loadAndStartRecorder, tryLoadAndStartRecorder } from \"./loader\";\nexport { tryInstallMeticulousIntercepts } from \"./install-meticulous-intercepts\";\n","import { SNIPPETS_BASE_URL } from \"./constants\";\nimport { LoaderOptions } from \"./loader.types\";\n\nconst DEFAULT_MAX_MS_TO_BLOCK_FOR = 2_000;\n\n/**\n * Load and start the Meticulous Recorder\n */\nexport const tryLoadAndStartRecorder = async (\n options: LoaderOptions\n): Promise<void> => {\n // Try to load the recorder and silence any initialisation error.\n await unsafeLoadAndStartRecorder(options).catch((error) => {\n console.error(error);\n });\n};\n\nconst unsafeLoadAndStartRecorder = ({\n projectId,\n uploadIntervalMs,\n snapshotLinkedStylesheets,\n commitHash,\n maxMsToBlockFor: maxMsToBlockFor_,\n snippetsBaseUrl,\n forceRecording,\n responseSanitizers,\n isProduction,\n}: LoaderOptions): Promise<void> => {\n let abandoned = false;\n\n return new Promise<void>((resolve, reject) => {\n const maxMsToBlockFor = maxMsToBlockFor_ ?? DEFAULT_MAX_MS_TO_BLOCK_FOR;\n\n if (maxMsToBlockFor > 0) {\n setTimeout(() => {\n abandoned = true;\n resolve();\n }, maxMsToBlockFor);\n }\n\n const script = document.createElement(\"script\");\n script.type = \"text/javascript\";\n const baseSnippetsUrl = snippetsBaseUrl || SNIPPETS_BASE_URL;\n script.src = new URL(\"v1/meticulous-manual-init.js\", baseSnippetsUrl).href;\n\n // Setup configuration\n const typedWindow = window;\n typedWindow.METICULOUS_RECORDING_TOKEN = projectId;\n\n if (uploadIntervalMs !== undefined) {\n typedWindow.METICULOUS_UPLOAD_INTERVAL_MS = uploadIntervalMs;\n }\n\n if (commitHash !== undefined) {\n typedWindow.METICULOUS_APP_COMMIT_HASH = commitHash;\n }\n\n if (snapshotLinkedStylesheets !== undefined) {\n typedWindow.METICULOUS_SNAPSHOT_LINKED_STYLESHEETS =\n snapshotLinkedStylesheets;\n }\n\n if (forceRecording !== undefined) {\n typedWindow.METICULOUS_FORCE_RECORDING = forceRecording;\n }\n\n if (isProduction !== undefined) {\n typedWindow.METICULOUS_IS_PRODUCTION_ENVIRONMENT = isProduction;\n }\n\n if (responseSanitizers != null && responseSanitizers.length > 0) {\n typedWindow.METICULOUS_NETWORK_RESPONSE_SANITIZERS = responseSanitizers;\n }\n\n script.onload = function () {\n if (abandoned) {\n console.debug(\n \"Meticulous snippet abandoned due to max blocking time reached.\"\n );\n // At this point the promise has already resolved.\n return;\n }\n\n const initialiseRecorder = window.__meticulous?.initialiseRecorder;\n if (typeof initialiseRecorder !== \"function\") {\n reject(\"Meticulous recorder failed to initialise.\");\n return;\n }\n\n try {\n initialiseRecorder();\n } catch (error) {\n reject(error);\n }\n\n resolve();\n };\n script.onerror = () => {\n reject(\"Meticulous recorder failed to initialise.\");\n };\n\n document.head.appendChild(script);\n });\n};\n\n/**\n * @deprecated Use `tryLoadAndStartRecorder` instead.\n *\n * Load and start the Meticulous Recorder\n */\nexport const loadAndStartRecorder = unsafeLoadAndStartRecorder;\n","export const SNIPPETS_BASE_URL = \"https://snippet.meticulous.ai\";\n","import { SNIPPETS_BASE_URL } from \"./constants\";\nimport { tryLoadAndStartRecorder } from \"./loader\";\nimport { LoaderOptions } from \"./loader.types\";\n\ninterface EarlyNetworkRecorderWindow {\n __meticulous?: {\n earlyNetworkRecorder?: {\n dispose?: () => Promise<void>;\n };\n };\n}\n\nexport interface Interceptor {\n startRecordingSession: (options: LoaderOptions) => Promise<void>;\n stopIntercepting: () => Promise<void>;\n}\n\n/**\n * Stores a copy of network requests and responses in memory, but doesn't send them to the\n * server, until the the main recorder is initialised.\n *\n * This is useful if you only want to record sessions for certain users with certain attributes. In\n * this case you have an issue: you need to wait for the user information to load before you know whether\n * you can enable the recorder, but if you enable the recorder after the user information has loaded\n * then the recorder won't be able to capture the initial request & response to load the user information,\n * or other early network responses.\n *\n * The early network recorder solves this: load the early network recorder for all sessions,\n * but only load the main recorder for sessions that you want to record. If when you load the user data\n * you find out you don't want to record the session then you can call the stopRecording() method returned\n * by this method.\n *\n * Example usage:\n *\n * ```\n * // The below call should happen before your app makes any network requests,\n * // or executes any methods that may store a reference to window.fetch or XMLHttpRequest.\n * const interceptor = await tryInstallMeticulousIntercepts();\n *\n * // Later, when you have loaded user data...\n * const userData = await loadUserInfo();\n * if (shouldRecord(userData)) {\n * await interceptor.startRecordingSession({ ... });\n * } else {\n * interceptor.stopIntercepting();\n * }\n * ```\n */\nexport const tryInstallMeticulousIntercepts = async (\n options: { maxMsToBlockFor: number } = { maxMsToBlockFor: 2000 }\n): Promise<Interceptor> => {\n let requestedToStopIntercepting = false;\n let disposedEarlyNetworkRecorder = false;\n const stopIntercepting = async () => {\n requestedToStopIntercepting = true;\n const disposeFunction = (window as EarlyNetworkRecorderWindow)?.__meticulous\n ?.earlyNetworkRecorder?.dispose;\n if (disposeFunction && !disposedEarlyNetworkRecorder) {\n await disposeFunction();\n disposedEarlyNetworkRecorder = true;\n }\n };\n const startRecordingSession = tryLoadAndStartRecorder;\n const interceptor = { startRecordingSession, stopIntercepting };\n\n const promise = new Promise<Interceptor>((resolve, reject) => {\n const timeout =\n options.maxMsToBlockFor > 0\n ? setTimeout(() => {\n resolve(interceptor);\n }, options.maxMsToBlockFor)\n : null;\n\n const script = document.createElement(\"script\");\n script.type = \"text/javascript\";\n script.src = `${SNIPPETS_BASE_URL}/record/v1/network-recorder.bundle.js`;\n\n script.onload = function () {\n if (timeout) {\n window.clearTimeout(timeout);\n }\n resolve(interceptor);\n };\n script.onerror = () => {\n if (timeout) {\n window.clearTimeout(timeout);\n }\n reject(\"Meticulous early network recorder failed to initialise.\");\n };\n\n document.head.appendChild(script);\n });\n\n // Try to load the early network recorder and silence any initialisation error.\n return promise\n .catch((error) => {\n console.error(error);\n return interceptor;\n })\n .finally(() => {\n if (requestedToStopIntercepting) {\n stopIntercepting();\n }\n });\n};\n"],"names":[],"version":3,"file":"index.js.map"}
|
package/dist/module.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
const $7d7683134fbb8fec$export$d16af6ab0c202bae = "https://snippet.meticulous.ai";
|
|
2
|
+
|
|
3
|
+
|
|
1
4
|
const $5d774bdb3a883001$var$DEFAULT_MAX_MS_TO_BLOCK_FOR = 2000;
|
|
2
5
|
const $5d774bdb3a883001$export$f80553af9d70f9fd = async (options)=>{
|
|
3
6
|
// Try to load the recorder and silence any initialisation error.
|
|
@@ -15,7 +18,7 @@ const $5d774bdb3a883001$var$unsafeLoadAndStartRecorder = ({ projectId: projectId
|
|
|
15
18
|
}, maxMsToBlockFor);
|
|
16
19
|
const script = document.createElement("script");
|
|
17
20
|
script.type = "text/javascript";
|
|
18
|
-
const baseSnippetsUrl = snippetsBaseUrl ||
|
|
21
|
+
const baseSnippetsUrl = snippetsBaseUrl || (0, $7d7683134fbb8fec$export$d16af6ab0c202bae);
|
|
19
22
|
script.src = new URL("v1/meticulous-manual-init.js", baseSnippetsUrl).href;
|
|
20
23
|
// Setup configuration
|
|
21
24
|
const typedWindow = window;
|
|
@@ -55,5 +58,52 @@ const $5d774bdb3a883001$export$9da0cde53b499187 = $5d774bdb3a883001$var$unsafeLo
|
|
|
55
58
|
|
|
56
59
|
|
|
57
60
|
|
|
58
|
-
|
|
61
|
+
const $d91c442ec5d010f4$export$c0c9d1ed5ecb2675 = async (options = {
|
|
62
|
+
maxMsToBlockFor: 2000
|
|
63
|
+
})=>{
|
|
64
|
+
let requestedToStopIntercepting = false;
|
|
65
|
+
let disposedEarlyNetworkRecorder = false;
|
|
66
|
+
const stopIntercepting = async ()=>{
|
|
67
|
+
requestedToStopIntercepting = true;
|
|
68
|
+
const disposeFunction = window?.__meticulous?.earlyNetworkRecorder?.dispose;
|
|
69
|
+
if (disposeFunction && !disposedEarlyNetworkRecorder) {
|
|
70
|
+
await disposeFunction();
|
|
71
|
+
disposedEarlyNetworkRecorder = true;
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
const startRecordingSession = (0, $5d774bdb3a883001$export$f80553af9d70f9fd);
|
|
75
|
+
const interceptor = {
|
|
76
|
+
startRecordingSession: startRecordingSession,
|
|
77
|
+
stopIntercepting: stopIntercepting
|
|
78
|
+
};
|
|
79
|
+
const promise = new Promise((resolve, reject)=>{
|
|
80
|
+
const timeout = options.maxMsToBlockFor > 0 ? setTimeout(()=>{
|
|
81
|
+
resolve(interceptor);
|
|
82
|
+
}, options.maxMsToBlockFor) : null;
|
|
83
|
+
const script = document.createElement("script");
|
|
84
|
+
script.type = "text/javascript";
|
|
85
|
+
script.src = `${0, $7d7683134fbb8fec$export$d16af6ab0c202bae}/record/v1/network-recorder.bundle.js`;
|
|
86
|
+
script.onload = function() {
|
|
87
|
+
if (timeout) window.clearTimeout(timeout);
|
|
88
|
+
resolve(interceptor);
|
|
89
|
+
};
|
|
90
|
+
script.onerror = ()=>{
|
|
91
|
+
if (timeout) window.clearTimeout(timeout);
|
|
92
|
+
reject("Meticulous early network recorder failed to initialise.");
|
|
93
|
+
};
|
|
94
|
+
document.head.appendChild(script);
|
|
95
|
+
});
|
|
96
|
+
// Try to load the early network recorder and silence any initialisation error.
|
|
97
|
+
return promise.catch((error)=>{
|
|
98
|
+
console.error(error);
|
|
99
|
+
return interceptor;
|
|
100
|
+
}).finally(()=>{
|
|
101
|
+
if (requestedToStopIntercepting) stopIntercepting();
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
export {$5d774bdb3a883001$export$9da0cde53b499187 as loadAndStartRecorder, $5d774bdb3a883001$export$f80553af9d70f9fd as tryLoadAndStartRecorder, $d91c442ec5d010f4$export$c0c9d1ed5ecb2675 as tryInstallMeticulousIntercepts};
|
|
59
109
|
//# sourceMappingURL=module.js.map
|
package/dist/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":"AEAO,MAAM,4CAAoB;;ADAjC;AAGA,MAAM,oDAA8B;AAK7B,MAAM,4CAA0B,OACrC,UACkB;IAClB,iEAAiE;IACjE,MAAM,iDAA2B,SAAS,KAAK,CAAC,CAAC,QAAU;QACzD,QAAQ,KAAK,CAAC;IAChB;AACF;AAEA,MAAM,mDAA6B,CAAC,aAClC,UAAS,oBACT,iBAAgB,6BAChB,0BAAyB,cACzB,WAAU,EACV,iBAAiB,iBAAgB,mBACjC,gBAAe,kBACf,eAAc,sBACd,mBAAkB,gBAClB,aAAY,EACE,GAAoB;IAClC,IAAI,YAAY,KAAK;IAErB,OAAO,IAAI,QAAc,CAAC,SAAS,SAAW;QAC5C,MAAM,kBAAkB,oBAAoB;QAE5C,IAAI,kBAAkB,GACpB,WAAW,IAAM;YACf,YAAY,IAAI;YAChB;QACF,GAAG;QAGL,MAAM,SAAS,SAAS,aAAa,CAAC;QACtC,OAAO,IAAI,GAAG;QACd,MAAM,kBAAkB,mBAAmB,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c;+BAAE;0BAAuB;IAAiB;IAE9D,MAAM,UAAU,IAAI,QAAqB,CAAC,SAAS,SAAW;QAC5D,MAAM,UACJ,QAAQ,eAAe,GAAG,IACtB,WAAW,IAAM;YACf,QAAQ;QACV,GAAG,QAAQ,eAAe,IAC1B,IAAI;QAEV,MAAM,SAAS,SAAS,aAAa,CAAC;QACtC,OAAO,IAAI,GAAG;QACd,OAAO,GAAG,GAAG,CAAC,EAAE,GAAA,yCAAiB,CAAC,qCAAqC,CAAC;QAExE,OAAO,MAAM,GAAG,WAAY;YAC1B,IAAI,SACF,OAAO,YAAY,CAAC;YAEtB,QAAQ;QACV;QACA,OAAO,OAAO,GAAG,IAAM;YACrB,IAAI,SACF,OAAO,YAAY,CAAC;YAEtB,OAAO;QACT;QAEA,SAAS,IAAI,CAAC,WAAW,CAAC;IAC5B;IAEA,+EAA+E;IAC/E,OAAO,QACJ,KAAK,CAAC,CAAC,QAAU;QAChB,QAAQ,KAAK,CAAC;QACd,OAAO;IACT,GACC,OAAO,CAAC,IAAM;QACb,IAAI,6BACF;IAEJ;AACJ;","sources":["packages/recorder-loader/src/index.ts","packages/recorder-loader/src/loader.ts","packages/recorder-loader/src/constants.ts","packages/recorder-loader/src/install-meticulous-intercepts.ts"],"sourcesContent":["export { loadAndStartRecorder, tryLoadAndStartRecorder } from \"./loader\";\nexport { tryInstallMeticulousIntercepts } from \"./install-meticulous-intercepts\";\n","import { SNIPPETS_BASE_URL } from \"./constants\";\nimport { LoaderOptions } from \"./loader.types\";\n\nconst DEFAULT_MAX_MS_TO_BLOCK_FOR = 2_000;\n\n/**\n * Load and start the Meticulous Recorder\n */\nexport const tryLoadAndStartRecorder = async (\n options: LoaderOptions\n): Promise<void> => {\n // Try to load the recorder and silence any initialisation error.\n await unsafeLoadAndStartRecorder(options).catch((error) => {\n console.error(error);\n });\n};\n\nconst unsafeLoadAndStartRecorder = ({\n projectId,\n uploadIntervalMs,\n snapshotLinkedStylesheets,\n commitHash,\n maxMsToBlockFor: maxMsToBlockFor_,\n snippetsBaseUrl,\n forceRecording,\n responseSanitizers,\n isProduction,\n}: LoaderOptions): Promise<void> => {\n let abandoned = false;\n\n return new Promise<void>((resolve, reject) => {\n const maxMsToBlockFor = maxMsToBlockFor_ ?? DEFAULT_MAX_MS_TO_BLOCK_FOR;\n\n if (maxMsToBlockFor > 0) {\n setTimeout(() => {\n abandoned = true;\n resolve();\n }, maxMsToBlockFor);\n }\n\n const script = document.createElement(\"script\");\n script.type = \"text/javascript\";\n const baseSnippetsUrl = snippetsBaseUrl || SNIPPETS_BASE_URL;\n script.src = new URL(\"v1/meticulous-manual-init.js\", baseSnippetsUrl).href;\n\n // Setup configuration\n const typedWindow = window;\n typedWindow.METICULOUS_RECORDING_TOKEN = projectId;\n\n if (uploadIntervalMs !== undefined) {\n typedWindow.METICULOUS_UPLOAD_INTERVAL_MS = uploadIntervalMs;\n }\n\n if (commitHash !== undefined) {\n typedWindow.METICULOUS_APP_COMMIT_HASH = commitHash;\n }\n\n if (snapshotLinkedStylesheets !== undefined) {\n typedWindow.METICULOUS_SNAPSHOT_LINKED_STYLESHEETS =\n snapshotLinkedStylesheets;\n }\n\n if (forceRecording !== undefined) {\n typedWindow.METICULOUS_FORCE_RECORDING = forceRecording;\n }\n\n if (isProduction !== undefined) {\n typedWindow.METICULOUS_IS_PRODUCTION_ENVIRONMENT = isProduction;\n }\n\n if (responseSanitizers != null && responseSanitizers.length > 0) {\n typedWindow.METICULOUS_NETWORK_RESPONSE_SANITIZERS = responseSanitizers;\n }\n\n script.onload = function () {\n if (abandoned) {\n console.debug(\n \"Meticulous snippet abandoned due to max blocking time reached.\"\n );\n // At this point the promise has already resolved.\n return;\n }\n\n const initialiseRecorder = window.__meticulous?.initialiseRecorder;\n if (typeof initialiseRecorder !== \"function\") {\n reject(\"Meticulous recorder failed to initialise.\");\n return;\n }\n\n try {\n initialiseRecorder();\n } catch (error) {\n reject(error);\n }\n\n resolve();\n };\n script.onerror = () => {\n reject(\"Meticulous recorder failed to initialise.\");\n };\n\n document.head.appendChild(script);\n });\n};\n\n/**\n * @deprecated Use `tryLoadAndStartRecorder` instead.\n *\n * Load and start the Meticulous Recorder\n */\nexport const loadAndStartRecorder = unsafeLoadAndStartRecorder;\n","export const SNIPPETS_BASE_URL = \"https://snippet.meticulous.ai\";\n","import { SNIPPETS_BASE_URL } from \"./constants\";\nimport { tryLoadAndStartRecorder } from \"./loader\";\nimport { LoaderOptions } from \"./loader.types\";\n\ninterface EarlyNetworkRecorderWindow {\n __meticulous?: {\n earlyNetworkRecorder?: {\n dispose?: () => Promise<void>;\n };\n };\n}\n\nexport interface Interceptor {\n startRecordingSession: (options: LoaderOptions) => Promise<void>;\n stopIntercepting: () => Promise<void>;\n}\n\n/**\n * Stores a copy of network requests and responses in memory, but doesn't send them to the\n * server, until the the main recorder is initialised.\n *\n * This is useful if you only want to record sessions for certain users with certain attributes. In\n * this case you have an issue: you need to wait for the user information to load before you know whether\n * you can enable the recorder, but if you enable the recorder after the user information has loaded\n * then the recorder won't be able to capture the initial request & response to load the user information,\n * or other early network responses.\n *\n * The early network recorder solves this: load the early network recorder for all sessions,\n * but only load the main recorder for sessions that you want to record. If when you load the user data\n * you find out you don't want to record the session then you can call the stopRecording() method returned\n * by this method.\n *\n * Example usage:\n *\n * ```\n * // The below call should happen before your app makes any network requests,\n * // or executes any methods that may store a reference to window.fetch or XMLHttpRequest.\n * const interceptor = await tryInstallMeticulousIntercepts();\n *\n * // Later, when you have loaded user data...\n * const userData = await loadUserInfo();\n * if (shouldRecord(userData)) {\n * await interceptor.startRecordingSession({ ... });\n * } else {\n * interceptor.stopIntercepting();\n * }\n * ```\n */\nexport const tryInstallMeticulousIntercepts = async (\n options: { maxMsToBlockFor: number } = { maxMsToBlockFor: 2000 }\n): Promise<Interceptor> => {\n let requestedToStopIntercepting = false;\n let disposedEarlyNetworkRecorder = false;\n const stopIntercepting = async () => {\n requestedToStopIntercepting = true;\n const disposeFunction = (window as EarlyNetworkRecorderWindow)?.__meticulous\n ?.earlyNetworkRecorder?.dispose;\n if (disposeFunction && !disposedEarlyNetworkRecorder) {\n await disposeFunction();\n disposedEarlyNetworkRecorder = true;\n }\n };\n const startRecordingSession = tryLoadAndStartRecorder;\n const interceptor = { startRecordingSession, stopIntercepting };\n\n const promise = new Promise<Interceptor>((resolve, reject) => {\n const timeout =\n options.maxMsToBlockFor > 0\n ? setTimeout(() => {\n resolve(interceptor);\n }, options.maxMsToBlockFor)\n : null;\n\n const script = document.createElement(\"script\");\n script.type = \"text/javascript\";\n script.src = `${SNIPPETS_BASE_URL}/record/v1/network-recorder.bundle.js`;\n\n script.onload = function () {\n if (timeout) {\n window.clearTimeout(timeout);\n }\n resolve(interceptor);\n };\n script.onerror = () => {\n if (timeout) {\n window.clearTimeout(timeout);\n }\n reject(\"Meticulous early network recorder failed to initialise.\");\n };\n\n document.head.appendChild(script);\n });\n\n // Try to load the early network recorder and silence any initialisation error.\n return promise\n .catch((error) => {\n console.error(error);\n return interceptor;\n })\n .finally(() => {\n if (requestedToStopIntercepting) {\n stopIntercepting();\n }\n });\n};\n"],"names":[],"version":3,"file":"module.js.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alwaysmeticulous/recorder-loader",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.98.0",
|
|
4
4
|
"license": "ISC",
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
"files": [
|
|
10
10
|
"dist"
|
|
11
11
|
],
|
|
12
|
+
"sideEffects": false,
|
|
12
13
|
"scripts": {
|
|
13
14
|
"clean": "rimraf dist tsconfig.tsbuildinfo",
|
|
14
15
|
"dev": "parcel watch",
|
|
@@ -36,5 +37,5 @@
|
|
|
36
37
|
"bugs": {
|
|
37
38
|
"url": "https://github.com/alwaysmeticulous/meticulous-sdk/issues"
|
|
38
39
|
},
|
|
39
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "6876d5f7c284320a132ab96cbee2d2a3d74da83d"
|
|
40
41
|
}
|