@alwaysmeticulous/recorder-loader 2.244.4 → 2.245.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 +28 -15
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/module.js +1 -0
- package/dist/module.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NetworkResponseSanitizer, RecorderMiddleware } from "@alwaysmeticulous/sdk-bundles-api";
|
|
2
|
-
interface
|
|
2
|
+
interface BaseLoaderOptions {
|
|
3
3
|
/**
|
|
4
4
|
* @deprecated Renamed to recordingToken. Please use the same value but pass it as the recordingToken instead.
|
|
5
5
|
*/
|
|
@@ -43,20 +43,6 @@ interface LoaderOptions {
|
|
|
43
43
|
* Please see JSDoc on {@link RecorderMiddleware} before implementing custom middleware.
|
|
44
44
|
*/
|
|
45
45
|
middleware?: RecorderMiddleware[];
|
|
46
|
-
/**
|
|
47
|
-
* Load a specific fixed version of the snippet. If not set will load the
|
|
48
|
-
* latest minor/patch version of the recorder. Bumping to a new major
|
|
49
|
-
* version requires a bump of your @alwaysmeticulous/recorder-loader
|
|
50
|
-
* dependency.
|
|
51
|
-
*
|
|
52
|
-
* Recommendation: leave this unset
|
|
53
|
-
*/
|
|
54
|
-
version?: string;
|
|
55
|
-
/**
|
|
56
|
-
* If set, we will use this integrity attribute on the script tag we create. This is useful if you have
|
|
57
|
-
* pinned the version above, and additionally want to ensure that the snippet is not corrupted.
|
|
58
|
-
*/
|
|
59
|
-
integrity?: string;
|
|
60
46
|
/**
|
|
61
47
|
* If set, we will use this nonce attribute on the script tag we create.
|
|
62
48
|
*/
|
|
@@ -72,6 +58,33 @@ interface LoaderOptions {
|
|
|
72
58
|
*/
|
|
73
59
|
disableTrackerId?: boolean;
|
|
74
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Options for loading a specific version of the Meticulous recorder.
|
|
63
|
+
* The `integrity` parameter can only be provided when `version` is also specified.
|
|
64
|
+
*/
|
|
65
|
+
type VersioningLoaderOptions = {
|
|
66
|
+
/**
|
|
67
|
+
* Load a specific fixed version of the snippet. If not set will load the
|
|
68
|
+
* latest minor/patch version of the recorder. Bumping to a new major
|
|
69
|
+
* version requires a bump of your @alwaysmeticulous/recorder-loader
|
|
70
|
+
* dependency.
|
|
71
|
+
*
|
|
72
|
+
* Recommendation: leave this unset
|
|
73
|
+
*/
|
|
74
|
+
version: string;
|
|
75
|
+
/**
|
|
76
|
+
* If set, we will use this integrity attribute on the script tag we create. This is useful if you have
|
|
77
|
+
* pinned the version above, and additionally want to ensure that the snippet is not corrupted.
|
|
78
|
+
*/
|
|
79
|
+
integrity?: string;
|
|
80
|
+
} | {
|
|
81
|
+
version?: undefined;
|
|
82
|
+
integrity?: undefined;
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Options for loading the Meticulous recorder.
|
|
86
|
+
*/
|
|
87
|
+
type LoaderOptions = BaseLoaderOptions & VersioningLoaderOptions;
|
|
75
88
|
interface Recorder {
|
|
76
89
|
/**
|
|
77
90
|
* Disables the recorder for the rest of the user session, and stops sending data to the Meticulous
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";AEKA;IACE;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IAEvB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,yBAAyB,CAAC,EAAE,OAAO,CAAC;IACpC,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;;;;;OAOG;IACH,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;IA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AqBlB,CAAC;AAkJF;;;;GAIG;AACH,OAAO,MAAM,sSApIV,aAAa,KAAG,QAAQ,QAAQ,CAoI2B,CAAC;AC5L/D;IACE,qBAAqB,EAAE,CAAC,OAAO,EAAE,aAAa,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;IACrE,gBAAgB,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACvC;AAED;IACE;;;;;;;OAOG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB;;;;;;;OAOG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAID;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,OAAO,MAAM,0CACF,kBAAkB,KAC1B,QAAQ,WAAW,CA4DrB,CAAC;AC9HF;;;;;;;;;;;GAWG;AACH,OAAO,MAAM,qCAMZ,CAAC","sources":["packages/recorder-loader/src/src/constants.ts","packages/recorder-loader/src/src/get-snippet-version-folder.ts","packages/recorder-loader/src/src/loader.types.ts","packages/recorder-loader/src/src/private-window-api.ts","packages/recorder-loader/src/src/loader.ts","packages/recorder-loader/src/src/install-meticulous-intercepts.ts","packages/recorder-loader/src/src/early-network-recorder.ts","packages/recorder-loader/src/src/index.ts","packages/recorder-loader/src/index.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,"export { loadAndStartRecorder, tryLoadAndStartRecorder } from \"./loader\";\nexport { tryInstallMeticulousIntercepts } from \"./install-meticulous-intercepts\";\nexport { stopIntercepting } from \"./early-network-recorder\";\n"],"names":[],"version":3,"file":"index.d.ts.map"}
|
package/dist/index.js
CHANGED
|
@@ -50,6 +50,7 @@ const $c97024bcb09807fa$var$unsafeLoadAndStartRecorder = ({ projectId: projectId
|
|
|
50
50
|
}, maxMsToBlockFor);
|
|
51
51
|
const script = document.createElement("script");
|
|
52
52
|
if (integrity) {
|
|
53
|
+
if (!version) throw new Error("Meticulous failed to initialise: integrity can only be provided when version is also provided");
|
|
53
54
|
script.integrity = integrity;
|
|
54
55
|
// We need to set the crossOrigin to anonymous to avoid CORS issues. Without this we get a failure like:
|
|
55
56
|
// "... has an integrity attribute, but the resource requires the request to be CORS enabled to check the
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;AEAO,MAAM,4CAAoB;;;ACA1B,MAAM,4CAA0B,CAAC;IACtC,IAAI,WAAW,MACb,OAAO;IAET,OAAO,CAAC,EAAE,EAAE,SAAS;AACvB;;;AFAA,MAAM,oDAA8B;AAe7B,MAAM,4CAA0B,OACrC;IAEA,IAAI,OAAO,UAAU,EAAE,iBAAiB;QACtC,QAAQ,KAAK,CACX;QAEF,OAAO;YACL,eAAe;YACb,QAAQ;YACV;QACF;IACF;IAEA,iEAAiE;IACjE,OAAO,MAAM,iDAA2B,SAAS,KAAK,CAAC,CAAC;QACtD,QAAQ,KAAK,CAAC;QACd,OAAO;YACL,eAAe;YACb,QAAQ;YACV;QACF;IACF;AACF;AAEA,MAAM,mDAA6B,CAAC,aAClC,SAAS,kBACT,cAAc,oBACd,gBAAgB,6BAChB,yBAAyB,cACzB,UAAU,EACV,iBAAiB,gBAAgB,mBACjC,eAAe,kBACf,cAAc,cACd,UAAU,sBACV,kBAAkB,gBAClB,YAAY,WACZ,OAAO,aACP,SAAS,SACT,KAAK,yBACL,qBAAqB,oBACrB,gBAAgB,EACF;IACd,IAAI,YAAY;IAEhB,OAAO,IAAI,QAAkB,CAAC,SAAS;QACrC,MAAM,kBAAkB,oBAAoB;QAE5C,IAAI,kBAAkB,GACpB,WAAW;YACT,YAAY;YACZ,QAAQ;gBACN,eAAe;gBACb,oCAAoC;gBACtC;YACF;QACF,GAAG;QAGL,MAAM,SAAS,SAAS,aAAa,CAAC;QACtC,IAAI,WAAW;YACb,OAAO,SAAS,GAAG;YACnB,wGAAwG;YACxG,yGAAyG;YACzG,qGAAqG;YACrG,OAAO,WAAW,GAAG;QACvB;QACA,IAAI,OACF,OAAO,KAAK,GAAG;QAEjB,O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C;IAC5B;AACF;AAOO,MAAM,4CAAuB;;;;;;AG5JpC,MAAM,oDAA8B;AAiC7B,MAAM,4CAAiC,OAC5C;IAEA,IAAI,8BAA8B;IAClC,IAAI,+BAA+B;IACnC,MAAM,mBAAmB;QACvB,8BAA8B;QAC9B,MAAM,kBAAmB,QAA6B,cAClD,sBAAsB;QAC1B,IAAI,mBAAmB,CAAC,8BAA8B;YACpD,MAAM;YACN,+BAA+B;QACjC;IACF;IACA,MAAM,cAAc;QAClB,uBAAuB,CAAA,GAAA,yCAAsB;0BAC7C;IACF;IAEA,MAAM,kBACJ,QAAQ,eAAe,IAAI;IAC7B,MAAM,UAAU,IAAI,QAAqB,CAAC,SAAS;QACjD,MAAM,UACJ,kBAAkB,IACd,WAAW;YACT,QAAQ;QACV,GAAG,mBACH;QAEN,MAAM,SAAS,SAAS,aAAa,CAAC;QACtC,OAAO,IAAI,GAAG;QACd,OAAO,GAAG,GAAG,GAAG,GAAA,0CAAkB,QAAQ,EAAE,CAAA,GAAA,yCAAsB,EAChE,QAAQ,OAAO,IAAI,MACnB,2BAA2B,CAAC;QAE9B,OAAO,MAAM,GAAG;YACd,IAAI,SACF,OAAO,YAAY,CAAC;YAEtB,QAAQ;QACV;QACA,OAAO,OAAO,GAAG;YACf,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;QACN,QAAQ,KAAK,CAAC;QACd,OAAO;IACT,GACC,OAAO,CAAC;QACP,IAAI,6BACG;IAET;AACJ;;;AClHO,MAAM,4CAAmB;IAC9B,MAAM,kBAAmB,QAA6B,cAClD,sBAAsB;IAC1B,IAAI,iBACF,MAAM;AAEV;","sources":["packages/recorder-loader/src/index.ts","packages/recorder-loader/src/loader.ts","packages/recorder-loader/src/constants.ts","packages/recorder-loader/src/get-snippet-version-folder.ts","packages/recorder-loader/src/install-meticulous-intercepts.ts","packages/recorder-loader/src/early-network-recorder.ts"],"sourcesContent":["export { loadAndStartRecorder, tryLoadAndStartRecorder } from \"./loader\";\nexport { tryInstallMeticulousIntercepts } from \"./install-meticulous-intercepts\";\nexport { stopIntercepting } from \"./early-network-recorder\";\n","import { SNIPPETS_BASE_URL } from \"./constants\";\nimport { getSnippetVersionFolder } from \"./get-snippet-version-folder\";\nimport { LoaderOptions } from \"./loader.types\";\nimport { PrivateWindowApi } from \"./private-window-api\";\n\nconst DEFAULT_MAX_MS_TO_BLOCK_FOR = 2_000;\n\nexport interface Recorder {\n /**\n * Disables the recorder for the rest of the user session, and stops sending data to the Meticulous\n * servers.\n *\n * Once this method is called the recorder cannot be restarted (unless the page is reloaded).\n */\n stopRecording: () => Promise<void>;\n}\n\n/**\n * Load and start the Meticulous Recorder\n */\nexport const tryLoadAndStartRecorder = async (\n options: LoaderOptions,\n): Promise<Recorder> => {\n if (window.Meticulous?.isRunningAsTest) {\n console.debug(\n \"Running as part of a Meticulous test case, so skipping loading the Meticulous recorder.\",\n );\n return {\n stopRecording: async () => {\n // No op\n },\n };\n }\n\n // Try to load the recorder and silence any initialisation error.\n return await unsafeLoadAndStartRecorder(options).catch((error) => {\n console.error(error);\n return {\n stopRecording: async () => {\n // No op\n },\n };\n });\n};\n\nconst unsafeLoadAndStartRecorder = ({\n projectId,\n recordingToken,\n uploadIntervalMs,\n snapshotLinkedStylesheets,\n commitHash,\n maxMsToBlockFor: maxMsToBlockFor_,\n snippetsBaseUrl,\n forceRecording,\n middleware,\n responseSanitizers,\n isProduction,\n version,\n integrity,\n nonce,\n disableErrorReporting,\n disableTrackerId,\n}: LoaderOptions): Promise<Recorder> => {\n let abandoned = false;\n\n return new Promise<Recorder>((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 stopRecording: async () => {\n // No op: we never started recording\n },\n });\n }, maxMsToBlockFor);\n }\n\n const script = document.createElement(\"script\");\n if (integrity) {\n script.integrity = integrity;\n // We need to set the crossOrigin to anonymous to avoid CORS issues. Without this we get a failure like:\n // \"... has an integrity attribute, but the resource requires the request to be CORS enabled to check the\n // integrity, and it is not. The resource has been blocked because the integrity cannot be enforced.\"\n script.crossOrigin = \"anonymous\";\n }\n if (nonce) {\n script.nonce = nonce;\n }\n script.type = \"text/javascript\";\n const baseSnippetsUrl = snippetsBaseUrl || SNIPPETS_BASE_URL;\n script.src = new URL(\n `${version != null ? \"record/\" : \"\"}${getSnippetVersionFolder(\n version ?? null,\n )}/meticulous-manual-init.js`,\n baseSnippetsUrl,\n ).href;\n\n // Setup configuration\n const typedWindow = window;\n typedWindow.METICULOUS_RECORDING_TOKEN = recordingToken ?? 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 if (middleware != null && middleware.length > 0) {\n typedWindow.METICULOUS_RECORDER_MIDDLEWARE_V1 = middleware;\n }\n\n if (disableErrorReporting != null) {\n typedWindow.METICULOUS_DISABLE_ERROR_REPORTING = disableErrorReporting;\n }\n\n if (disableTrackerId != null) {\n typedWindow.METICULOUS_DISABLE_TRACKER_ID = disableTrackerId;\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 as PrivateWindowApi).__meticulous\n ?.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 stopRecording: async () => {\n const stopRecording = (window as PrivateWindowApi).__meticulous\n ?.stopRecording;\n if (!stopRecording) {\n throw new Error(\n \"Recorder not initialised: window.__meticulous.stopRecording is not defined.\",\n );\n }\n await stopRecording();\n return;\n },\n });\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","export const getSnippetVersionFolder = (version: string | null) => {\n if (version == null) {\n return \"v1\";\n }\n return `v/${version}`;\n};\n","import { SNIPPETS_BASE_URL } from \"./constants\";\nimport { getSnippetVersionFolder } from \"./get-snippet-version-folder\";\nimport { Recorder, tryLoadAndStartRecorder } from \"./loader\";\nimport { LoaderOptions } from \"./loader.types\";\nimport { PrivateWindowApi } from \"./private-window-api\";\n\nexport interface Interceptor {\n startRecordingSession: (options: LoaderOptions) => Promise<Recorder>;\n stopIntercepting: () => Promise<void>;\n}\n\nexport interface InterceptorOptions {\n /**\n * If it takes more than the specified number of 'ms' to load the interceptor,\n * then the promise returned by tryInstallMeticulousIntercepts will return\n * immediately (thereby unblocking the load of the application, but preventing\n * Meticulous from recording a correct session, with all required network mocks).\n *\n * Defaults to 2000ms.\n */\n maxMsToBlockFor?: number;\n\n /**\n * Load a specific fixed version of the snippet. If not set will load the\n * latest minor/patch version of the recorder. Bumping to a new major\n * version requires a bump of your @alwaysmeticulous/recorder-loader\n * dependency.\n *\n * Recommendation: leave this unset\n */\n version?: string;\n}\n\nconst DEFAULT_MAX_MS_TO_BLOCK_FOR = 2000;\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: InterceptorOptions\n): Promise<Interceptor> => {\n let requestedToStopIntercepting = false;\n let disposedEarlyNetworkRecorder = false;\n const stopIntercepting = async () => {\n requestedToStopIntercepting = true;\n const disposeFunction = (window as PrivateWindowApi)?.__meticulous\n ?.earlyNetworkRecorder?.dispose;\n if (disposeFunction && !disposedEarlyNetworkRecorder) {\n await disposeFunction();\n disposedEarlyNetworkRecorder = true;\n }\n };\n const interceptor = {\n startRecordingSession: tryLoadAndStartRecorder,\n stopIntercepting,\n };\n\n const maxMsToBlockFor =\n options.maxMsToBlockFor ?? DEFAULT_MAX_MS_TO_BLOCK_FOR;\n const promise = new Promise<Interceptor>((resolve, reject) => {\n const timeout =\n maxMsToBlockFor > 0\n ? setTimeout(() => {\n resolve(interceptor);\n }, maxMsToBlockFor)\n : null;\n\n const script = document.createElement(\"script\");\n script.type = \"text/javascript\";\n script.src = `${SNIPPETS_BASE_URL}/record/${getSnippetVersionFolder(\n options.version ?? null\n )}/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 void stopIntercepting();\n }\n });\n};\n","import { PrivateWindowApi } from \"./private-window-api\";\n\n/**\n * If you add 'https://snippet.meticulous.ai/record/v1/network-recorder.bundle.js' as a script tag\n * then Meticulous will start off by recording any network requests in memory but not send the data to Meticulous’s\n * servers. Once you have the information to determine whether you want to record and persist the session\n * you can then call {@link tryLoadAndStartRecorder} if you do want to record, or this stopIntercepting method\n * if you do not want to record. When you call stopIntercepting any network requests/responses stored in memory\n * will be dropped and Meticulous will be deactivated. No data will be sent to Meticulous's servers.\n *\n * Please note that if you've already started recording and sending data to Meticulous's services i.e.\n * loaded the main meticulous recorder script or called tryLoadAndStartRecorder then this method will\n * not stop the recording. For that you need to call the stopRecording method returned by tryLoadAndStartRecorder.\n */\nexport const stopIntercepting = async () => {\n const disposeFunction = (window as PrivateWindowApi)?.__meticulous\n ?.earlyNetworkRecorder?.dispose;\n if (disposeFunction) {\n await disposeFunction();\n }\n};\n"],"names":[],"version":3,"file":"index.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;AEAO,MAAM,4CAAoB;;;ACA1B,MAAM,4CAA0B,CAAC;IACtC,IAAI,WAAW,MACb,OAAO;IAET,OAAO,CAAC,EAAE,EAAE,SAAS;AACvB;;;AFAA,MAAM,oDAA8B;AAe7B,MAAM,4CAA0B,OACrC;IAEA,IAAI,OAAO,UAAU,EAAE,iBAAiB;QACtC,QAAQ,KAAK,CACX;QAEF,OAAO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Ae,IAAI;IAC7B,MAAM,UAAU,IAAI,QAAqB,CAAC,SAAS;QACjD,MAAM,UACJ,kBAAkB,IACd,WAAW;YACT,QAAQ;QACV,GAAG,mBACH;QAEN,MAAM,SAAS,SAAS,aAAa,CAAC;QACtC,OAAO,IAAI,GAAG;QACd,OAAO,GAAG,GAAG,GAAG,GAAA,0CAAkB,QAAQ,EAAE,CAAA,GAAA,yCAAsB,EAChE,QAAQ,OAAO,IAAI,MACnB,2BAA2B,CAAC;QAE9B,OAAO,MAAM,GAAG;YACd,IAAI,SACF,OAAO,YAAY,CAAC;YAEtB,QAAQ;QACV;QACA,OAAO,OAAO,GAAG;YACf,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;QACN,QAAQ,KAAK,CAAC;QACd,OAAO;IACT,GACC,OAAO,CAAC;QACP,IAAI,6BACG;IAET;AACJ;;;AClHO,MAAM,4CAAmB;IAC9B,MAAM,kBAAmB,QAA6B,cAClD,sBAAsB;IAC1B,IAAI,iBACF,MAAM;AAEV;","sources":["packages/recorder-loader/src/index.ts","packages/recorder-loader/src/loader.ts","packages/recorder-loader/src/constants.ts","packages/recorder-loader/src/get-snippet-version-folder.ts","packages/recorder-loader/src/install-meticulous-intercepts.ts","packages/recorder-loader/src/early-network-recorder.ts"],"sourcesContent":["export { loadAndStartRecorder, tryLoadAndStartRecorder } from \"./loader\";\nexport { tryInstallMeticulousIntercepts } from \"./install-meticulous-intercepts\";\nexport { stopIntercepting } from \"./early-network-recorder\";\n","import { SNIPPETS_BASE_URL } from \"./constants\";\nimport { getSnippetVersionFolder } from \"./get-snippet-version-folder\";\nimport { LoaderOptions } from \"./loader.types\";\nimport { PrivateWindowApi } from \"./private-window-api\";\n\nconst DEFAULT_MAX_MS_TO_BLOCK_FOR = 2_000;\n\nexport interface Recorder {\n /**\n * Disables the recorder for the rest of the user session, and stops sending data to the Meticulous\n * servers.\n *\n * Once this method is called the recorder cannot be restarted (unless the page is reloaded).\n */\n stopRecording: () => Promise<void>;\n}\n\n/**\n * Load and start the Meticulous Recorder\n */\nexport const tryLoadAndStartRecorder = async (\n options: LoaderOptions,\n): Promise<Recorder> => {\n if (window.Meticulous?.isRunningAsTest) {\n console.debug(\n \"Running as part of a Meticulous test case, so skipping loading the Meticulous recorder.\",\n );\n return {\n stopRecording: async () => {\n // No op\n },\n };\n }\n\n // Try to load the recorder and silence any initialisation error.\n return await unsafeLoadAndStartRecorder(options).catch((error) => {\n console.error(error);\n return {\n stopRecording: async () => {\n // No op\n },\n };\n });\n};\n\nconst unsafeLoadAndStartRecorder = ({\n projectId,\n recordingToken,\n uploadIntervalMs,\n snapshotLinkedStylesheets,\n commitHash,\n maxMsToBlockFor: maxMsToBlockFor_,\n snippetsBaseUrl,\n forceRecording,\n middleware,\n responseSanitizers,\n isProduction,\n version,\n integrity,\n nonce,\n disableErrorReporting,\n disableTrackerId,\n}: LoaderOptions): Promise<Recorder> => {\n let abandoned = false;\n\n return new Promise<Recorder>((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 stopRecording: async () => {\n // No op: we never started recording\n },\n });\n }, maxMsToBlockFor);\n }\n\n const script = document.createElement(\"script\");\n if (integrity) {\n if (!version) {\n throw new Error(\n \"Meticulous failed to initialise: integrity can only be provided when version is also provided\",\n );\n }\n script.integrity = integrity;\n // We need to set the crossOrigin to anonymous to avoid CORS issues. Without this we get a failure like:\n // \"... has an integrity attribute, but the resource requires the request to be CORS enabled to check the\n // integrity, and it is not. The resource has been blocked because the integrity cannot be enforced.\"\n script.crossOrigin = \"anonymous\";\n }\n if (nonce) {\n script.nonce = nonce;\n }\n script.type = \"text/javascript\";\n const baseSnippetsUrl = snippetsBaseUrl || SNIPPETS_BASE_URL;\n script.src = new URL(\n `${version != null ? \"record/\" : \"\"}${getSnippetVersionFolder(\n version ?? null,\n )}/meticulous-manual-init.js`,\n baseSnippetsUrl,\n ).href;\n\n // Setup configuration\n const typedWindow = window;\n typedWindow.METICULOUS_RECORDING_TOKEN = recordingToken ?? 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 if (middleware != null && middleware.length > 0) {\n typedWindow.METICULOUS_RECORDER_MIDDLEWARE_V1 = middleware;\n }\n\n if (disableErrorReporting != null) {\n typedWindow.METICULOUS_DISABLE_ERROR_REPORTING = disableErrorReporting;\n }\n\n if (disableTrackerId != null) {\n typedWindow.METICULOUS_DISABLE_TRACKER_ID = disableTrackerId;\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 as PrivateWindowApi).__meticulous\n ?.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 stopRecording: async () => {\n const stopRecording = (window as PrivateWindowApi).__meticulous\n ?.stopRecording;\n if (!stopRecording) {\n throw new Error(\n \"Recorder not initialised: window.__meticulous.stopRecording is not defined.\",\n );\n }\n await stopRecording();\n return;\n },\n });\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","export const getSnippetVersionFolder = (version: string | null) => {\n if (version == null) {\n return \"v1\";\n }\n return `v/${version}`;\n};\n","import { SNIPPETS_BASE_URL } from \"./constants\";\nimport { getSnippetVersionFolder } from \"./get-snippet-version-folder\";\nimport { Recorder, tryLoadAndStartRecorder } from \"./loader\";\nimport { LoaderOptions } from \"./loader.types\";\nimport { PrivateWindowApi } from \"./private-window-api\";\n\nexport interface Interceptor {\n startRecordingSession: (options: LoaderOptions) => Promise<Recorder>;\n stopIntercepting: () => Promise<void>;\n}\n\nexport interface InterceptorOptions {\n /**\n * If it takes more than the specified number of 'ms' to load the interceptor,\n * then the promise returned by tryInstallMeticulousIntercepts will return\n * immediately (thereby unblocking the load of the application, but preventing\n * Meticulous from recording a correct session, with all required network mocks).\n *\n * Defaults to 2000ms.\n */\n maxMsToBlockFor?: number;\n\n /**\n * Load a specific fixed version of the snippet. If not set will load the\n * latest minor/patch version of the recorder. Bumping to a new major\n * version requires a bump of your @alwaysmeticulous/recorder-loader\n * dependency.\n *\n * Recommendation: leave this unset\n */\n version?: string;\n}\n\nconst DEFAULT_MAX_MS_TO_BLOCK_FOR = 2000;\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: InterceptorOptions\n): Promise<Interceptor> => {\n let requestedToStopIntercepting = false;\n let disposedEarlyNetworkRecorder = false;\n const stopIntercepting = async () => {\n requestedToStopIntercepting = true;\n const disposeFunction = (window as PrivateWindowApi)?.__meticulous\n ?.earlyNetworkRecorder?.dispose;\n if (disposeFunction && !disposedEarlyNetworkRecorder) {\n await disposeFunction();\n disposedEarlyNetworkRecorder = true;\n }\n };\n const interceptor = {\n startRecordingSession: tryLoadAndStartRecorder,\n stopIntercepting,\n };\n\n const maxMsToBlockFor =\n options.maxMsToBlockFor ?? DEFAULT_MAX_MS_TO_BLOCK_FOR;\n const promise = new Promise<Interceptor>((resolve, reject) => {\n const timeout =\n maxMsToBlockFor > 0\n ? setTimeout(() => {\n resolve(interceptor);\n }, maxMsToBlockFor)\n : null;\n\n const script = document.createElement(\"script\");\n script.type = \"text/javascript\";\n script.src = `${SNIPPETS_BASE_URL}/record/${getSnippetVersionFolder(\n options.version ?? null\n )}/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 void stopIntercepting();\n }\n });\n};\n","import { PrivateWindowApi } from \"./private-window-api\";\n\n/**\n * If you add 'https://snippet.meticulous.ai/record/v1/network-recorder.bundle.js' as a script tag\n * then Meticulous will start off by recording any network requests in memory but not send the data to Meticulous’s\n * servers. Once you have the information to determine whether you want to record and persist the session\n * you can then call {@link tryLoadAndStartRecorder} if you do want to record, or this stopIntercepting method\n * if you do not want to record. When you call stopIntercepting any network requests/responses stored in memory\n * will be dropped and Meticulous will be deactivated. No data will be sent to Meticulous's servers.\n *\n * Please note that if you've already started recording and sending data to Meticulous's services i.e.\n * loaded the main meticulous recorder script or called tryLoadAndStartRecorder then this method will\n * not stop the recording. For that you need to call the stopRecording method returned by tryLoadAndStartRecorder.\n */\nexport const stopIntercepting = async () => {\n const disposeFunction = (window as PrivateWindowApi)?.__meticulous\n ?.earlyNetworkRecorder?.dispose;\n if (disposeFunction) {\n await disposeFunction();\n }\n};\n"],"names":[],"version":3,"file":"index.js.map"}
|
package/dist/module.js
CHANGED
|
@@ -41,6 +41,7 @@ const $5d774bdb3a883001$var$unsafeLoadAndStartRecorder = ({ projectId: projectId
|
|
|
41
41
|
}, maxMsToBlockFor);
|
|
42
42
|
const script = document.createElement("script");
|
|
43
43
|
if (integrity) {
|
|
44
|
+
if (!version) throw new Error("Meticulous failed to initialise: integrity can only be provided when version is also provided");
|
|
44
45
|
script.integrity = integrity;
|
|
45
46
|
// We need to set the crossOrigin to anonymous to avoid CORS issues. Without this we get a failure like:
|
|
46
47
|
// "... has an integrity attribute, but the resource requires the request to be CORS enabled to check the
|
package/dist/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AEAO,MAAM,4CAAoB;;;ACA1B,MAAM,4CAA0B,CAAC;IACtC,IAAI,WAAW,MACb,OAAO;IAET,OAAO,CAAC,EAAE,EAAE,SAAS;AACvB;;;AFAA,MAAM,oDAA8B;AAe7B,MAAM,4CAA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0BAC7C;IACF;IAEA,MAAM,kBACJ,QAAQ,eAAe,IAAI;IAC7B,MAAM,UAAU,IAAI,QAAqB,CAAC,SAAS;QACjD,MAAM,UACJ,kBAAkB,IACd,WAAW;YACT,QAAQ;QACV,GAAG,mBACH;QAEN,MAAM,SAAS,SAAS,aAAa,CAAC;QACtC,OAAO,IAAI,GAAG;QACd,OAAO,GAAG,GAAG,GAAG,GAAA,0CAAkB,QAAQ,EAAE,CAAA,GAAA,yCAAsB,EAChE,QAAQ,OAAO,IAAI,MACnB,2BAA2B,CAAC;QAE9B,OAAO,MAAM,GAAG;YACd,IAAI,SACF,OAAO,YAAY,CAAC;YAEtB,QAAQ;QACV;QACA,OAAO,OAAO,GAAG;YACf,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;QACN,QAAQ,KAAK,CAAC;QACd,OAAO;IACT,GACC,OAAO,CAAC;QACP,IAAI,6BACG;IAET;AACJ;;;AClHO,MAAM,4CAAmB;IAC9B,MAAM,kBAAmB,QAA6B,cAClD,sBAAsB;IAC1B,IAAI,iBACF,MAAM;AAEV;","sources":["packages/recorder-loader/src/index.ts","packages/recorder-loader/src/loader.ts","packages/recorder-loader/src/constants.ts","packages/recorder-loader/src/get-snippet-version-folder.ts","packages/recorder-loader/src/install-meticulous-intercepts.ts","packages/recorder-loader/src/early-network-recorder.ts"],"sourcesContent":["export { loadAndStartRecorder, tryLoadAndStartRecorder } from \"./loader\";\nexport { tryInstallMeticulousIntercepts } from \"./install-meticulous-intercepts\";\nexport { stopIntercepting } from \"./early-network-recorder\";\n","import { SNIPPETS_BASE_URL } from \"./constants\";\nimport { getSnippetVersionFolder } from \"./get-snippet-version-folder\";\nimport { LoaderOptions } from \"./loader.types\";\nimport { PrivateWindowApi } from \"./private-window-api\";\n\nconst DEFAULT_MAX_MS_TO_BLOCK_FOR = 2_000;\n\nexport interface Recorder {\n /**\n * Disables the recorder for the rest of the user session, and stops sending data to the Meticulous\n * servers.\n *\n * Once this method is called the recorder cannot be restarted (unless the page is reloaded).\n */\n stopRecording: () => Promise<void>;\n}\n\n/**\n * Load and start the Meticulous Recorder\n */\nexport const tryLoadAndStartRecorder = async (\n options: LoaderOptions,\n): Promise<Recorder> => {\n if (window.Meticulous?.isRunningAsTest) {\n console.debug(\n \"Running as part of a Meticulous test case, so skipping loading the Meticulous recorder.\",\n );\n return {\n stopRecording: async () => {\n // No op\n },\n };\n }\n\n // Try to load the recorder and silence any initialisation error.\n return await unsafeLoadAndStartRecorder(options).catch((error) => {\n console.error(error);\n return {\n stopRecording: async () => {\n // No op\n },\n };\n });\n};\n\nconst unsafeLoadAndStartRecorder = ({\n projectId,\n recordingToken,\n uploadIntervalMs,\n snapshotLinkedStylesheets,\n commitHash,\n maxMsToBlockFor: maxMsToBlockFor_,\n snippetsBaseUrl,\n forceRecording,\n middleware,\n responseSanitizers,\n isProduction,\n version,\n integrity,\n nonce,\n disableErrorReporting,\n disableTrackerId,\n}: LoaderOptions): Promise<Recorder> => {\n let abandoned = false;\n\n return new Promise<Recorder>((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 stopRecording: async () => {\n // No op: we never started recording\n },\n });\n }, maxMsToBlockFor);\n }\n\n const script = document.createElement(\"script\");\n if (integrity) {\n script.integrity = integrity;\n // We need to set the crossOrigin to anonymous to avoid CORS issues. Without this we get a failure like:\n // \"... has an integrity attribute, but the resource requires the request to be CORS enabled to check the\n // integrity, and it is not. The resource has been blocked because the integrity cannot be enforced.\"\n script.crossOrigin = \"anonymous\";\n }\n if (nonce) {\n script.nonce = nonce;\n }\n script.type = \"text/javascript\";\n const baseSnippetsUrl = snippetsBaseUrl || SNIPPETS_BASE_URL;\n script.src = new URL(\n `${version != null ? \"record/\" : \"\"}${getSnippetVersionFolder(\n version ?? null,\n )}/meticulous-manual-init.js`,\n baseSnippetsUrl,\n ).href;\n\n // Setup configuration\n const typedWindow = window;\n typedWindow.METICULOUS_RECORDING_TOKEN = recordingToken ?? 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 if (middleware != null && middleware.length > 0) {\n typedWindow.METICULOUS_RECORDER_MIDDLEWARE_V1 = middleware;\n }\n\n if (disableErrorReporting != null) {\n typedWindow.METICULOUS_DISABLE_ERROR_REPORTING = disableErrorReporting;\n }\n\n if (disableTrackerId != null) {\n typedWindow.METICULOUS_DISABLE_TRACKER_ID = disableTrackerId;\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 as PrivateWindowApi).__meticulous\n ?.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 stopRecording: async () => {\n const stopRecording = (window as PrivateWindowApi).__meticulous\n ?.stopRecording;\n if (!stopRecording) {\n throw new Error(\n \"Recorder not initialised: window.__meticulous.stopRecording is not defined.\",\n );\n }\n await stopRecording();\n return;\n },\n });\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","export const getSnippetVersionFolder = (version: string | null) => {\n if (version == null) {\n return \"v1\";\n }\n return `v/${version}`;\n};\n","import { SNIPPETS_BASE_URL } from \"./constants\";\nimport { getSnippetVersionFolder } from \"./get-snippet-version-folder\";\nimport { Recorder, tryLoadAndStartRecorder } from \"./loader\";\nimport { LoaderOptions } from \"./loader.types\";\nimport { PrivateWindowApi } from \"./private-window-api\";\n\nexport interface Interceptor {\n startRecordingSession: (options: LoaderOptions) => Promise<Recorder>;\n stopIntercepting: () => Promise<void>;\n}\n\nexport interface InterceptorOptions {\n /**\n * If it takes more than the specified number of 'ms' to load the interceptor,\n * then the promise returned by tryInstallMeticulousIntercepts will return\n * immediately (thereby unblocking the load of the application, but preventing\n * Meticulous from recording a correct session, with all required network mocks).\n *\n * Defaults to 2000ms.\n */\n maxMsToBlockFor?: number;\n\n /**\n * Load a specific fixed version of the snippet. If not set will load the\n * latest minor/patch version of the recorder. Bumping to a new major\n * version requires a bump of your @alwaysmeticulous/recorder-loader\n * dependency.\n *\n * Recommendation: leave this unset\n */\n version?: string;\n}\n\nconst DEFAULT_MAX_MS_TO_BLOCK_FOR = 2000;\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: InterceptorOptions\n): Promise<Interceptor> => {\n let requestedToStopIntercepting = false;\n let disposedEarlyNetworkRecorder = false;\n const stopIntercepting = async () => {\n requestedToStopIntercepting = true;\n const disposeFunction = (window as PrivateWindowApi)?.__meticulous\n ?.earlyNetworkRecorder?.dispose;\n if (disposeFunction && !disposedEarlyNetworkRecorder) {\n await disposeFunction();\n disposedEarlyNetworkRecorder = true;\n }\n };\n const interceptor = {\n startRecordingSession: tryLoadAndStartRecorder,\n stopIntercepting,\n };\n\n const maxMsToBlockFor =\n options.maxMsToBlockFor ?? DEFAULT_MAX_MS_TO_BLOCK_FOR;\n const promise = new Promise<Interceptor>((resolve, reject) => {\n const timeout =\n maxMsToBlockFor > 0\n ? setTimeout(() => {\n resolve(interceptor);\n }, maxMsToBlockFor)\n : null;\n\n const script = document.createElement(\"script\");\n script.type = \"text/javascript\";\n script.src = `${SNIPPETS_BASE_URL}/record/${getSnippetVersionFolder(\n options.version ?? null\n )}/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 void stopIntercepting();\n }\n });\n};\n","import { PrivateWindowApi } from \"./private-window-api\";\n\n/**\n * If you add 'https://snippet.meticulous.ai/record/v1/network-recorder.bundle.js' as a script tag\n * then Meticulous will start off by recording any network requests in memory but not send the data to Meticulous’s\n * servers. Once you have the information to determine whether you want to record and persist the session\n * you can then call {@link tryLoadAndStartRecorder} if you do want to record, or this stopIntercepting method\n * if you do not want to record. When you call stopIntercepting any network requests/responses stored in memory\n * will be dropped and Meticulous will be deactivated. No data will be sent to Meticulous's servers.\n *\n * Please note that if you've already started recording and sending data to Meticulous's services i.e.\n * loaded the main meticulous recorder script or called tryLoadAndStartRecorder then this method will\n * not stop the recording. For that you need to call the stopRecording method returned by tryLoadAndStartRecorder.\n */\nexport const stopIntercepting = async () => {\n const disposeFunction = (window as PrivateWindowApi)?.__meticulous\n ?.earlyNetworkRecorder?.dispose;\n if (disposeFunction) {\n await disposeFunction();\n }\n};\n"],"names":[],"version":3,"file":"module.js.map"}
|
|
1
|
+
{"mappings":"AEAO,MAAM,4CAAoB;;;ACA1B,MAAM,4CAA0B,CAAC;IACtC,IAAI,WAAW,MACb,OAAO;IAET,OAAO,CAAC,EAAE,EAAE,SAAS;AACvB;;;AFAA,MAAM,oDAA8B;AAe7B,MAAM,4CAA0B,OACrC;IAEA,IAAI,OAAO,UAAU,EAAE,iBAAiB;QACtC,QAAQ,KAAK,CACX;QAEF,OAAO;YACL,eAAe;YACb,QAAQ;YACV;QACF;IACF;IAEA,iEAAiE;IACjE,OAAO,MAAM,iDAA2B,SAAS,KAAK,CAAC,CAAC;QACtD,QAAQ,KAAK,CAAC;QACd,OAAO;YACL,eAAe;YACb,QAAQ;YACV;QACF;IACF;AACF;AAEA,MAAM,mDAA6B,CAAC,aAClC,SAAS,kBACT,cAAc,oBACd,gBAAgB,6BAChB,yBAAyB,cACzB,UAAU,EACV,iBAAiB,gBAAgB,mBACjC,eAAe,kBACf,cAAc,cACd,UAAU,sBACV,kBAAkB,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AO,YAAY,CAAC;YAEtB,QAAQ;QACV;QACA,OAAO,OAAO,GAAG;YACf,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;QACN,QAAQ,KAAK,CAAC;QACd,OAAO;IACT,GACC,OAAO,CAAC;QACP,IAAI,6BACG;IAET;AACJ;;;AClHO,MAAM,4CAAmB;IAC9B,MAAM,kBAAmB,QAA6B,cAClD,sBAAsB;IAC1B,IAAI,iBACF,MAAM;AAEV;","sources":["packages/recorder-loader/src/index.ts","packages/recorder-loader/src/loader.ts","packages/recorder-loader/src/constants.ts","packages/recorder-loader/src/get-snippet-version-folder.ts","packages/recorder-loader/src/install-meticulous-intercepts.ts","packages/recorder-loader/src/early-network-recorder.ts"],"sourcesContent":["export { loadAndStartRecorder, tryLoadAndStartRecorder } from \"./loader\";\nexport { tryInstallMeticulousIntercepts } from \"./install-meticulous-intercepts\";\nexport { stopIntercepting } from \"./early-network-recorder\";\n","import { SNIPPETS_BASE_URL } from \"./constants\";\nimport { getSnippetVersionFolder } from \"./get-snippet-version-folder\";\nimport { LoaderOptions } from \"./loader.types\";\nimport { PrivateWindowApi } from \"./private-window-api\";\n\nconst DEFAULT_MAX_MS_TO_BLOCK_FOR = 2_000;\n\nexport interface Recorder {\n /**\n * Disables the recorder for the rest of the user session, and stops sending data to the Meticulous\n * servers.\n *\n * Once this method is called the recorder cannot be restarted (unless the page is reloaded).\n */\n stopRecording: () => Promise<void>;\n}\n\n/**\n * Load and start the Meticulous Recorder\n */\nexport const tryLoadAndStartRecorder = async (\n options: LoaderOptions,\n): Promise<Recorder> => {\n if (window.Meticulous?.isRunningAsTest) {\n console.debug(\n \"Running as part of a Meticulous test case, so skipping loading the Meticulous recorder.\",\n );\n return {\n stopRecording: async () => {\n // No op\n },\n };\n }\n\n // Try to load the recorder and silence any initialisation error.\n return await unsafeLoadAndStartRecorder(options).catch((error) => {\n console.error(error);\n return {\n stopRecording: async () => {\n // No op\n },\n };\n });\n};\n\nconst unsafeLoadAndStartRecorder = ({\n projectId,\n recordingToken,\n uploadIntervalMs,\n snapshotLinkedStylesheets,\n commitHash,\n maxMsToBlockFor: maxMsToBlockFor_,\n snippetsBaseUrl,\n forceRecording,\n middleware,\n responseSanitizers,\n isProduction,\n version,\n integrity,\n nonce,\n disableErrorReporting,\n disableTrackerId,\n}: LoaderOptions): Promise<Recorder> => {\n let abandoned = false;\n\n return new Promise<Recorder>((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 stopRecording: async () => {\n // No op: we never started recording\n },\n });\n }, maxMsToBlockFor);\n }\n\n const script = document.createElement(\"script\");\n if (integrity) {\n if (!version) {\n throw new Error(\n \"Meticulous failed to initialise: integrity can only be provided when version is also provided\",\n );\n }\n script.integrity = integrity;\n // We need to set the crossOrigin to anonymous to avoid CORS issues. Without this we get a failure like:\n // \"... has an integrity attribute, but the resource requires the request to be CORS enabled to check the\n // integrity, and it is not. The resource has been blocked because the integrity cannot be enforced.\"\n script.crossOrigin = \"anonymous\";\n }\n if (nonce) {\n script.nonce = nonce;\n }\n script.type = \"text/javascript\";\n const baseSnippetsUrl = snippetsBaseUrl || SNIPPETS_BASE_URL;\n script.src = new URL(\n `${version != null ? \"record/\" : \"\"}${getSnippetVersionFolder(\n version ?? null,\n )}/meticulous-manual-init.js`,\n baseSnippetsUrl,\n ).href;\n\n // Setup configuration\n const typedWindow = window;\n typedWindow.METICULOUS_RECORDING_TOKEN = recordingToken ?? 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 if (middleware != null && middleware.length > 0) {\n typedWindow.METICULOUS_RECORDER_MIDDLEWARE_V1 = middleware;\n }\n\n if (disableErrorReporting != null) {\n typedWindow.METICULOUS_DISABLE_ERROR_REPORTING = disableErrorReporting;\n }\n\n if (disableTrackerId != null) {\n typedWindow.METICULOUS_DISABLE_TRACKER_ID = disableTrackerId;\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 as PrivateWindowApi).__meticulous\n ?.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 stopRecording: async () => {\n const stopRecording = (window as PrivateWindowApi).__meticulous\n ?.stopRecording;\n if (!stopRecording) {\n throw new Error(\n \"Recorder not initialised: window.__meticulous.stopRecording is not defined.\",\n );\n }\n await stopRecording();\n return;\n },\n });\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","export const getSnippetVersionFolder = (version: string | null) => {\n if (version == null) {\n return \"v1\";\n }\n return `v/${version}`;\n};\n","import { SNIPPETS_BASE_URL } from \"./constants\";\nimport { getSnippetVersionFolder } from \"./get-snippet-version-folder\";\nimport { Recorder, tryLoadAndStartRecorder } from \"./loader\";\nimport { LoaderOptions } from \"./loader.types\";\nimport { PrivateWindowApi } from \"./private-window-api\";\n\nexport interface Interceptor {\n startRecordingSession: (options: LoaderOptions) => Promise<Recorder>;\n stopIntercepting: () => Promise<void>;\n}\n\nexport interface InterceptorOptions {\n /**\n * If it takes more than the specified number of 'ms' to load the interceptor,\n * then the promise returned by tryInstallMeticulousIntercepts will return\n * immediately (thereby unblocking the load of the application, but preventing\n * Meticulous from recording a correct session, with all required network mocks).\n *\n * Defaults to 2000ms.\n */\n maxMsToBlockFor?: number;\n\n /**\n * Load a specific fixed version of the snippet. If not set will load the\n * latest minor/patch version of the recorder. Bumping to a new major\n * version requires a bump of your @alwaysmeticulous/recorder-loader\n * dependency.\n *\n * Recommendation: leave this unset\n */\n version?: string;\n}\n\nconst DEFAULT_MAX_MS_TO_BLOCK_FOR = 2000;\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: InterceptorOptions\n): Promise<Interceptor> => {\n let requestedToStopIntercepting = false;\n let disposedEarlyNetworkRecorder = false;\n const stopIntercepting = async () => {\n requestedToStopIntercepting = true;\n const disposeFunction = (window as PrivateWindowApi)?.__meticulous\n ?.earlyNetworkRecorder?.dispose;\n if (disposeFunction && !disposedEarlyNetworkRecorder) {\n await disposeFunction();\n disposedEarlyNetworkRecorder = true;\n }\n };\n const interceptor = {\n startRecordingSession: tryLoadAndStartRecorder,\n stopIntercepting,\n };\n\n const maxMsToBlockFor =\n options.maxMsToBlockFor ?? DEFAULT_MAX_MS_TO_BLOCK_FOR;\n const promise = new Promise<Interceptor>((resolve, reject) => {\n const timeout =\n maxMsToBlockFor > 0\n ? setTimeout(() => {\n resolve(interceptor);\n }, maxMsToBlockFor)\n : null;\n\n const script = document.createElement(\"script\");\n script.type = \"text/javascript\";\n script.src = `${SNIPPETS_BASE_URL}/record/${getSnippetVersionFolder(\n options.version ?? null\n )}/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 void stopIntercepting();\n }\n });\n};\n","import { PrivateWindowApi } from \"./private-window-api\";\n\n/**\n * If you add 'https://snippet.meticulous.ai/record/v1/network-recorder.bundle.js' as a script tag\n * then Meticulous will start off by recording any network requests in memory but not send the data to Meticulous’s\n * servers. Once you have the information to determine whether you want to record and persist the session\n * you can then call {@link tryLoadAndStartRecorder} if you do want to record, or this stopIntercepting method\n * if you do not want to record. When you call stopIntercepting any network requests/responses stored in memory\n * will be dropped and Meticulous will be deactivated. No data will be sent to Meticulous's servers.\n *\n * Please note that if you've already started recording and sending data to Meticulous's services i.e.\n * loaded the main meticulous recorder script or called tryLoadAndStartRecorder then this method will\n * not stop the recording. For that you need to call the stopRecording method returned by tryLoadAndStartRecorder.\n */\nexport const stopIntercepting = async () => {\n const disposeFunction = (window as PrivateWindowApi)?.__meticulous\n ?.earlyNetworkRecorder?.dispose;\n if (disposeFunction) {\n await disposeFunction();\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.245.0",
|
|
4
4
|
"license": "ISC",
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"depcheck": "depcheck --ignore-patterns=dist"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@alwaysmeticulous/sdk-bundles-api": "^2.
|
|
24
|
+
"@alwaysmeticulous/sdk-bundles-api": "^2.245.0"
|
|
25
25
|
},
|
|
26
26
|
"author": {
|
|
27
27
|
"name": "The Meticulous Team",
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"bugs": {
|
|
38
38
|
"url": "https://github.com/alwaysmeticulous/meticulous-sdk/issues"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "6f1c11b95aa72962bf9aa2599f7ee0ebc44e6110"
|
|
41
41
|
}
|