@statsig/web-analytics 3.24.0 → 3.24.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@statsig/web-analytics",
3
- "version": "3.24.0",
3
+ "version": "3.24.2",
4
4
  "license": "ISC",
5
5
  "homepage": "https://github.com/statsig-io/js-client-monorepo",
6
6
  "repository": {
@@ -9,8 +9,8 @@
9
9
  "directory": "packages/web-analytics"
10
10
  },
11
11
  "dependencies": {
12
- "@statsig/client-core": "3.24.0",
13
- "@statsig/js-client": "3.24.0",
12
+ "@statsig/client-core": "3.24.2",
13
+ "@statsig/js-client": "3.24.2",
14
14
  "web-vitals": "5.0.3"
15
15
  },
16
16
  "jsdelivr": "./build/statsig-web-analytics.min.js",
@@ -56,7 +56,7 @@ class ConsoleLogManager {
56
56
  return;
57
57
  const original = console[level].bind(console);
58
58
  let inStack = false;
59
- const restore = (0, commonUtils_1.patch)(console, level, (originalFn) => {
59
+ const restore = (0, commonUtils_1.wrapFunctionWithRestore)(console, level, (originalFn) => {
60
60
  return (...args) => {
61
61
  originalFn(...args);
62
62
  if (inStack)
@@ -18,5 +18,5 @@ export declare function _getSafeTimezoneOffset(): number | null;
18
18
  export declare function _getAnchorNodeInHierarchy(node: Element | null): Element | null;
19
19
  export declare function _sanitizeString(maybeString: string | null | undefined): string | null;
20
20
  export declare function throttle<T extends (...args: unknown[]) => void>(fn: T, limit: number): T;
21
- export declare function patch(source: Record<string, unknown>, name: string, replacement: (original: (...args: unknown[]) => void) => (...args: unknown[]) => void): () => void;
21
+ export declare function wrapFunctionWithRestore(targetObject: Record<string, unknown>, functionName: string, wrapperFactory: (original: (...args: unknown[]) => unknown) => (...args: unknown[]) => unknown): () => void;
22
22
  export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.patch = exports.throttle = exports._sanitizeString = exports._getAnchorNodeInHierarchy = exports._getSafeTimezoneOffset = exports._getSafeTimezone = exports._getSafeNetworkInformation = exports._registerEventHandler = exports._getSanitizedPageUrl = exports._getSafeUrlString = exports._getSafeUrl = exports._shouldLogEvent = exports._getTargetNode = exports._stripEmptyValues = exports.interactiveElements = void 0;
3
+ exports.wrapFunctionWithRestore = exports.throttle = exports._sanitizeString = exports._getAnchorNodeInHierarchy = exports._getSafeTimezoneOffset = exports._getSafeTimezone = exports._getSafeNetworkInformation = exports._registerEventHandler = exports._getSanitizedPageUrl = exports._getSafeUrlString = exports._getSafeUrl = exports._shouldLogEvent = exports._getTargetNode = exports._stripEmptyValues = exports.interactiveElements = void 0;
4
4
  const client_core_1 = require("@statsig/client-core");
5
5
  const coreCCPattern = `(4[0-9]{12}(?:[0-9]{3})?)|(5[1-5][0-9]{14})|(6(?:011|5[0-9]{2})[0-9]{12})|(3[47][0-9]{13})|(3(?:0[0-5]|[68][0-9])[0-9]{11})|((?:2131|1800|35[0-9]{3})[0-9]{11})`;
6
6
  const CC_REGEX = new RegExp(`^(?:${coreCCPattern})$`);
@@ -186,38 +186,29 @@ function throttle(fn, limit) {
186
186
  };
187
187
  }
188
188
  exports.throttle = throttle;
189
- // copy from https://github.com/getsentry/sentry-javascript/blob/b2109071975af8bf0316d3b5b38f519bdaf5dc15/packages/utils/src/object.ts
190
- function patch(source, name, replacement) {
189
+ function wrapFunctionWithRestore(targetObject, functionName, wrapperFactory) {
190
+ const originalFunction = targetObject[functionName];
191
+ if (typeof originalFunction !== 'function') {
192
+ return () => {
193
+ // noop
194
+ };
195
+ }
191
196
  try {
192
- if (!source[name])
193
- return () => {
194
- // noop
195
- };
196
- const original = source[name];
197
- const wrapped = replacement(original);
198
- // Make sure it's a function first, as we need to attach an empty prototype for `defineProperties` to work
199
- // otherwise it'll throw "TypeError: Object.defineProperties called on non-object"
200
- if (typeof wrapped === 'function') {
201
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
202
- wrapped.prototype = wrapped.prototype || {};
203
- Object.defineProperties(wrapped, {
204
- __statsig_original__: {
205
- enumerable: false,
206
- value: original,
207
- },
208
- });
209
- }
210
- source[name] = wrapped;
197
+ const wrappedFunction = wrapperFactory(originalFunction);
198
+ Object.defineProperty(wrappedFunction, '__statsig_original__', {
199
+ enumerable: false,
200
+ value: originalFunction,
201
+ });
202
+ targetObject[functionName] = wrappedFunction;
203
+ // Restore function
211
204
  return () => {
212
- source[name] = original;
205
+ targetObject[functionName] = originalFunction;
213
206
  };
214
207
  }
215
- catch (err) {
208
+ catch (_a) {
216
209
  return () => {
217
210
  // noop
218
211
  };
219
- // This can throw if multiple fill happens on a global object like XMLHttpRequest
220
- // Fixes https://github.com/getsentry/sentry-javascript/issues/2043
221
212
  }
222
213
  }
223
- exports.patch = patch;
214
+ exports.wrapFunctionWithRestore = wrapFunctionWithRestore;