@alwaysmeticulous/recorder-loader 2.293.0 → 2.294.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 +18 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/module.js +4 -3
- package/dist/module.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -57,6 +57,23 @@ interface BaseLoaderOptions {
|
|
|
57
57
|
* This is particularly useful if you can't allow the script to create an iframe to meticulous.ai to track the session.
|
|
58
58
|
*/
|
|
59
59
|
disableTrackerId?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Maximum size in bytes of a single session payload upload.
|
|
62
|
+
*
|
|
63
|
+
* Without a cap, long or network-heavy sessions can produce payloads large enough
|
|
64
|
+
* to exceed V8's maximum string length (~512 MB), which will crash any Node.js
|
|
65
|
+
* process that buffers the upload body. Set this when running the recorder inside
|
|
66
|
+
* an environment where outgoing HTTP request bodies are captured in-process
|
|
67
|
+
* (e.g. Playwright with tracing, HAR recording, or any `page.route()` handler).
|
|
68
|
+
*
|
|
69
|
+
* ```typescript
|
|
70
|
+
* await tryLoadAndStartRecorder({
|
|
71
|
+
* recordingToken: '...',
|
|
72
|
+
* maxPayloadSize: 50 * 1024 * 1024, // 50 MB
|
|
73
|
+
* });
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
maxPayloadSize?: number;
|
|
60
77
|
}
|
|
61
78
|
/**
|
|
62
79
|
* Options for loading a specific version of the Meticulous recorder.
|
|
@@ -103,7 +120,7 @@ export const tryLoadAndStartRecorder: (options: LoaderOptions) => Promise<Record
|
|
|
103
120
|
*
|
|
104
121
|
* Load and start the Meticulous Recorder
|
|
105
122
|
*/
|
|
106
|
-
export const loadAndStartRecorder: ({ projectId, recordingToken, uploadIntervalMs, snapshotLinkedStylesheets, commitHash, maxMsToBlockFor: maxMsToBlockFor_, snippetsBaseUrl, forceRecording, middleware, responseSanitizers, isProduction, version, integrity, nonce, disableErrorReporting, disableTrackerId, }: LoaderOptions) => Promise<Recorder>;
|
|
123
|
+
export const loadAndStartRecorder: ({ projectId, recordingToken, uploadIntervalMs, snapshotLinkedStylesheets, commitHash, maxMsToBlockFor: maxMsToBlockFor_, snippetsBaseUrl, forceRecording, middleware, responseSanitizers, isProduction, version, integrity, nonce, disableErrorReporting, disableTrackerId, maxPayloadSize, }: LoaderOptions) => Promise<Recorder>;
|
|
107
124
|
interface Interceptor {
|
|
108
125
|
startRecordingSession: (options: LoaderOptions) => Promise<Recorder>;
|
|
109
126
|
stopIntercepting: () => Promise<void>;
|
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;IAEzB;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,wBAAwB,EAAE,CAAC;IAEhD;;;;;OAKG;IACH,UAAU,CAAC,EAAE,kBAAkB,EAAE,CAAC;IAElC;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;;OAGG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAEhC;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;
|
|
1
|
+
{"mappings":";AEKA;IACE;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,c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,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,iCACX,SAAS,kBAAkB,KAC1B,OAAO,CAAC,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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
3
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="934b333a-8aaf-5956-9340-933ff04d643d")}catch(e){}}();
|
|
4
4
|
function $parcel$export(e, n, v, s) {
|
|
5
5
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
6
6
|
}
|
|
@@ -38,7 +38,7 @@ const $c97024bcb09807fa$export$f80553af9d70f9fd = async (options)=>{
|
|
|
38
38
|
};
|
|
39
39
|
});
|
|
40
40
|
};
|
|
41
|
-
const $c97024bcb09807fa$var$unsafeLoadAndStartRecorder = ({ projectId: projectId, recordingToken: recordingToken, uploadIntervalMs: uploadIntervalMs, snapshotLinkedStylesheets: snapshotLinkedStylesheets, commitHash: commitHash, maxMsToBlockFor: maxMsToBlockFor_, snippetsBaseUrl: snippetsBaseUrl, forceRecording: forceRecording, middleware: middleware, responseSanitizers: responseSanitizers, isProduction: isProduction, version: version, integrity: integrity, nonce: nonce, disableErrorReporting: disableErrorReporting, disableTrackerId: disableTrackerId })=>{
|
|
41
|
+
const $c97024bcb09807fa$var$unsafeLoadAndStartRecorder = ({ projectId: projectId, recordingToken: recordingToken, uploadIntervalMs: uploadIntervalMs, snapshotLinkedStylesheets: snapshotLinkedStylesheets, commitHash: commitHash, maxMsToBlockFor: maxMsToBlockFor_, snippetsBaseUrl: snippetsBaseUrl, forceRecording: forceRecording, middleware: middleware, responseSanitizers: responseSanitizers, isProduction: isProduction, version: version, integrity: integrity, nonce: nonce, disableErrorReporting: disableErrorReporting, disableTrackerId: disableTrackerId, maxPayloadSize: maxPayloadSize })=>{
|
|
42
42
|
let abandoned = false;
|
|
43
43
|
return new Promise((resolve, reject)=>{
|
|
44
44
|
const maxMsToBlockFor = maxMsToBlockFor_ ?? $c97024bcb09807fa$var$DEFAULT_MAX_MS_TO_BLOCK_FOR;
|
|
@@ -75,6 +75,7 @@ const $c97024bcb09807fa$var$unsafeLoadAndStartRecorder = ({ projectId: projectId
|
|
|
75
75
|
if (middleware != null && middleware.length > 0) typedWindow.METICULOUS_RECORDER_MIDDLEWARE_V1 = middleware;
|
|
76
76
|
if (disableErrorReporting != null) typedWindow.METICULOUS_DISABLE_ERROR_REPORTING = disableErrorReporting;
|
|
77
77
|
if (disableTrackerId != null) typedWindow.METICULOUS_DISABLE_TRACKER_ID = disableTrackerId;
|
|
78
|
+
if (maxPayloadSize !== undefined) typedWindow.METICULOUS_MAX_PAYLOAD_SIZE = maxPayloadSize;
|
|
78
79
|
script.onload = function() {
|
|
79
80
|
if (abandoned) {
|
|
80
81
|
console.debug("Meticulous snippet abandoned due to max blocking time reached.");
|
|
@@ -166,4 +167,4 @@ const $6795f29cc093eb86$export$e592d04d772ce0ec = async ()=>{
|
|
|
166
167
|
|
|
167
168
|
//# sourceMappingURL=index.js.map
|
|
168
169
|
|
|
169
|
-
//# debugId=
|
|
170
|
+
//# debugId=934b333a-8aaf-5956-9340-933ff04d643d
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js.map","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":[],"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,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I,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","debugId":"d63b8d97-beb3-5fad-8e3a-7100125b8965"}
|
|
1
|
+
{"version":3,"file":"index.js.map","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 maxPayloadSize,\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 if (maxPayloadSize !== undefined) {\n typedWindow.METICULOUS_MAX_PAYLOAD_SIZE = maxPayloadSize;\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":[],"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,kBAChB,cAAc,EACA;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,SAA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C,OAAO,CAAC;QACP,IAAI,6BACG;IAET;AACJ;;;AClHO,MAAM,4CAAmB;IAC9B,MAAM,kBAAmB,QAA6B,cAClD,sBAAsB;IAC1B,IAAI,iBACF,MAAM;AAEV","debugId":"934b333a-8aaf-5956-9340-933ff04d643d"}
|
package/dist/module.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="1f1a8331-9aa6-54b5-b736-cc806b1aef31")}catch(e){}}();
|
|
3
3
|
const $7d7683134fbb8fec$export$d16af6ab0c202bae = "https://snippet.meticulous.ai";
|
|
4
4
|
|
|
5
5
|
|
|
@@ -29,7 +29,7 @@ const $5d774bdb3a883001$export$f80553af9d70f9fd = async (options)=>{
|
|
|
29
29
|
};
|
|
30
30
|
});
|
|
31
31
|
};
|
|
32
|
-
const $5d774bdb3a883001$var$unsafeLoadAndStartRecorder = ({ projectId: projectId, recordingToken: recordingToken, uploadIntervalMs: uploadIntervalMs, snapshotLinkedStylesheets: snapshotLinkedStylesheets, commitHash: commitHash, maxMsToBlockFor: maxMsToBlockFor_, snippetsBaseUrl: snippetsBaseUrl, forceRecording: forceRecording, middleware: middleware, responseSanitizers: responseSanitizers, isProduction: isProduction, version: version, integrity: integrity, nonce: nonce, disableErrorReporting: disableErrorReporting, disableTrackerId: disableTrackerId })=>{
|
|
32
|
+
const $5d774bdb3a883001$var$unsafeLoadAndStartRecorder = ({ projectId: projectId, recordingToken: recordingToken, uploadIntervalMs: uploadIntervalMs, snapshotLinkedStylesheets: snapshotLinkedStylesheets, commitHash: commitHash, maxMsToBlockFor: maxMsToBlockFor_, snippetsBaseUrl: snippetsBaseUrl, forceRecording: forceRecording, middleware: middleware, responseSanitizers: responseSanitizers, isProduction: isProduction, version: version, integrity: integrity, nonce: nonce, disableErrorReporting: disableErrorReporting, disableTrackerId: disableTrackerId, maxPayloadSize: maxPayloadSize })=>{
|
|
33
33
|
let abandoned = false;
|
|
34
34
|
return new Promise((resolve, reject)=>{
|
|
35
35
|
const maxMsToBlockFor = maxMsToBlockFor_ ?? $5d774bdb3a883001$var$DEFAULT_MAX_MS_TO_BLOCK_FOR;
|
|
@@ -66,6 +66,7 @@ const $5d774bdb3a883001$var$unsafeLoadAndStartRecorder = ({ projectId: projectId
|
|
|
66
66
|
if (middleware != null && middleware.length > 0) typedWindow.METICULOUS_RECORDER_MIDDLEWARE_V1 = middleware;
|
|
67
67
|
if (disableErrorReporting != null) typedWindow.METICULOUS_DISABLE_ERROR_REPORTING = disableErrorReporting;
|
|
68
68
|
if (disableTrackerId != null) typedWindow.METICULOUS_DISABLE_TRACKER_ID = disableTrackerId;
|
|
69
|
+
if (maxPayloadSize !== undefined) typedWindow.METICULOUS_MAX_PAYLOAD_SIZE = maxPayloadSize;
|
|
69
70
|
script.onload = function() {
|
|
70
71
|
if (abandoned) {
|
|
71
72
|
console.debug("Meticulous snippet abandoned due to max blocking time reached.");
|
|
@@ -158,4 +159,4 @@ const $57efbd113493cb78$export$e592d04d772ce0ec = async ()=>{
|
|
|
158
159
|
export {$5d774bdb3a883001$export$9da0cde53b499187 as loadAndStartRecorder, $5d774bdb3a883001$export$f80553af9d70f9fd as tryLoadAndStartRecorder, $d91c442ec5d010f4$export$c0c9d1ed5ecb2675 as tryInstallMeticulousIntercepts, $57efbd113493cb78$export$e592d04d772ce0ec as stopIntercepting};
|
|
159
160
|
//# sourceMappingURL=module.js.map
|
|
160
161
|
|
|
161
|
-
//# debugId=
|
|
162
|
+
//# debugId=1f1a8331-9aa6-54b5-b736-cc806b1aef31
|
package/dist/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.js.map","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":[],"mappings":";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;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","debugId":"91e84d6e-2df3-5f3c-955a-470c913c37a3"}
|
|
1
|
+
{"version":3,"file":"module.js.map","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 maxPayloadSize,\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 if (maxPayloadSize !== undefined) {\n typedWindow.METICULOUS_MAX_PAYLOAD_SIZE = maxPayloadSize;\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":[],"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,UAA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+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","debugId":"1f1a8331-9aa6-54b5-b736-cc806b1aef31"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alwaysmeticulous/recorder-loader",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.294.0",
|
|
4
4
|
"license": "ISC",
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
],
|
|
12
12
|
"sideEffects": false,
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@alwaysmeticulous/sdk-bundles-api": "2.
|
|
14
|
+
"@alwaysmeticulous/sdk-bundles-api": "2.294.0"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
17
|
"parcel": "^2.15.2"
|