@posthog/browser-common 0.1.0 → 0.2.1
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/README.md +23 -8
- package/dist/config.d.ts +9 -0
- package/dist/config.js +43 -0
- package/dist/config.mjs +9 -0
- package/dist/constants.d.ts +3 -0
- package/dist/constants.js +44 -0
- package/dist/constants.mjs +4 -0
- package/dist/token.d.ts +13 -12
- package/dist/utils/array-at-polyfill.d.ts +1 -0
- package/dist/utils/array-at-polyfill.js +16 -0
- package/dist/utils/array-at-polyfill.mjs +11 -0
- package/dist/utils/autocapture-utils.d.ts +23 -0
- package/dist/utils/autocapture-utils.js +479 -0
- package/dist/utils/autocapture-utils.mjs +385 -0
- package/dist/utils/blocked-uas.d.ts +17 -0
- package/dist/utils/blocked-uas.js +54 -0
- package/dist/utils/blocked-uas.mjs +14 -0
- package/dist/utils/cookie-utils.d.ts +1 -0
- package/dist/utils/cookie-utils.js +49 -0
- package/dist/utils/cookie-utils.mjs +15 -0
- package/dist/utils/device-model-utils.d.ts +8 -0
- package/dist/utils/device-model-utils.js +52 -0
- package/dist/utils/device-model-utils.mjs +18 -0
- package/dist/utils/element-utils.d.ts +5 -0
- package/dist/utils/element-utils.js +67 -0
- package/dist/utils/element-utils.mjs +21 -0
- package/dist/utils/elements-chain-utils.d.ts +4 -0
- package/dist/utils/elements-chain-utils.js +79 -0
- package/dist/utils/elements-chain-utils.mjs +36 -0
- package/dist/utils/encode-utils.d.ts +8 -0
- package/dist/utils/encode-utils.js +39 -0
- package/dist/utils/encode-utils.mjs +5 -0
- package/dist/utils/event-utils.d.ts +24 -0
- package/dist/utils/event-utils.js +344 -0
- package/dist/utils/event-utils.mjs +246 -0
- package/dist/utils/general-utils.d.ts +30 -0
- package/dist/utils/general-utils.js +191 -0
- package/dist/utils/general-utils.mjs +118 -0
- package/dist/utils/globals.d.ts +25 -0
- package/dist/utils/globals.js +75 -0
- package/dist/utils/globals.mjs +14 -0
- package/dist/utils/logger.d.ts +16 -0
- package/dist/utils/logger.js +83 -0
- package/dist/utils/logger.mjs +36 -0
- package/dist/utils/matcher-utils.d.ts +3 -0
- package/dist/utils/matcher-utils.js +63 -0
- package/dist/utils/matcher-utils.mjs +26 -0
- package/dist/utils/property-utils.d.ts +23 -0
- package/dist/utils/property-utils.js +108 -0
- package/dist/utils/property-utils.mjs +65 -0
- package/dist/utils/prototype-utils.d.ts +7 -0
- package/dist/utils/prototype-utils.js +64 -0
- package/dist/utils/prototype-utils.mjs +27 -0
- package/dist/utils/regex-utils.d.ts +2 -0
- package/dist/utils/regex-utils.js +54 -0
- package/dist/utils/regex-utils.mjs +17 -0
- package/dist/utils/request-utils.d.ts +15 -0
- package/dist/utils/request-utils.js +153 -0
- package/dist/utils/request-utils.mjs +95 -0
- package/dist/utils/simple-event-emitter.d.ts +5 -0
- package/dist/utils/simple-event-emitter.js +51 -0
- package/dist/utils/simple-event-emitter.mjs +17 -0
- package/dist/utils/stylesheet-loader.d.ts +7 -0
- package/dist/utils/stylesheet-loader.js +53 -0
- package/dist/utils/stylesheet-loader.mjs +19 -0
- package/dist/utils/type-utils.d.ts +2 -0
- package/dist/utils/type-utils.js +41 -0
- package/dist/utils/type-utils.mjs +4 -0
- package/dist/utils/url-targeting-utils.d.ts +28 -0
- package/dist/utils/url-targeting-utils.js +56 -0
- package/dist/utils/url-targeting-utils.mjs +19 -0
- package/dist/utils/uuidv7.d.ts +43 -0
- package/dist/utils/uuidv7.js +172 -0
- package/dist/utils/uuidv7.js.LICENSE.txt +9 -0
- package/dist/utils/uuidv7.mjs +132 -0
- package/dist/utils/uuidv7.mjs.LICENSE.txt +9 -0
- package/package.json +37 -3
- package/LICENSE +0 -353
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const win = 'undefined' != typeof window ? window : void 0;
|
|
2
|
+
const global = 'undefined' != typeof globalThis ? globalThis : win;
|
|
3
|
+
const globals_navigator = global?.navigator;
|
|
4
|
+
const globals_document = global?.document;
|
|
5
|
+
const globals_location = global?.location;
|
|
6
|
+
const fetch = global?.fetch;
|
|
7
|
+
const XMLHttpRequest = global?.XMLHttpRequest && 'withCredentials' in new global.XMLHttpRequest() ? global.XMLHttpRequest : void 0;
|
|
8
|
+
const AbortController = global?.AbortController;
|
|
9
|
+
const CompressionStream = global?.CompressionStream;
|
|
10
|
+
const userAgent = globals_navigator?.userAgent;
|
|
11
|
+
function isBrowserOnline() {
|
|
12
|
+
return !!(win && false !== win.navigator.onLine);
|
|
13
|
+
}
|
|
14
|
+
export { AbortController, CompressionStream, XMLHttpRequest, globals_document as document, fetch, isBrowserOnline, globals_location as location, globals_navigator as navigator, userAgent, win as window };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Logger } from '@posthog/types';
|
|
2
|
+
export type CreateLoggerOptions = {
|
|
3
|
+
debugEnabled?: boolean;
|
|
4
|
+
};
|
|
5
|
+
export type PosthogJsLogger = Omit<Logger, 'createLogger' | 'debug' | 'info' | 'warn' | 'error' | 'trace' | 'fatal'> & {
|
|
6
|
+
_log: (level: 'debug' | 'log' | 'warn' | 'error', ...args: any[]) => void;
|
|
7
|
+
debug: (...args: any[]) => void;
|
|
8
|
+
info: (...args: any[]) => void;
|
|
9
|
+
warn: (...args: any[]) => void;
|
|
10
|
+
error: (...args: any[]) => void;
|
|
11
|
+
critical: (...args: any[]) => void;
|
|
12
|
+
uninitializedWarning: (methodName: string) => void;
|
|
13
|
+
createLogger: (prefix: string, options?: CreateLoggerOptions) => PosthogJsLogger;
|
|
14
|
+
};
|
|
15
|
+
export declare const logger: PosthogJsLogger;
|
|
16
|
+
export declare const createLogger: (prefix: string, options?: CreateLoggerOptions) => PosthogJsLogger;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.n = (module)=>{
|
|
5
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
+
__webpack_require__.d(getter, {
|
|
7
|
+
a: getter
|
|
8
|
+
});
|
|
9
|
+
return getter;
|
|
10
|
+
};
|
|
11
|
+
})();
|
|
12
|
+
(()=>{
|
|
13
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
14
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: definition[key]
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
})();
|
|
20
|
+
(()=>{
|
|
21
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
22
|
+
})();
|
|
23
|
+
(()=>{
|
|
24
|
+
__webpack_require__.r = (exports1)=>{
|
|
25
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
26
|
+
value: 'Module'
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
29
|
+
value: true
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
})();
|
|
33
|
+
var __webpack_exports__ = {};
|
|
34
|
+
__webpack_require__.r(__webpack_exports__);
|
|
35
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
+
logger: ()=>logger_logger,
|
|
37
|
+
createLogger: ()=>createLogger
|
|
38
|
+
});
|
|
39
|
+
const external_config_js_namespaceObject = require("../config.js");
|
|
40
|
+
var external_config_js_default = /*#__PURE__*/ __webpack_require__.n(external_config_js_namespaceObject);
|
|
41
|
+
const core_namespaceObject = require("@posthog/core");
|
|
42
|
+
const external_globals_js_namespaceObject = require("./globals.js");
|
|
43
|
+
const _createLogger = (prefix, { debugEnabled } = {})=>{
|
|
44
|
+
const logger = {
|
|
45
|
+
_log: (level, ...args)=>{
|
|
46
|
+
if (external_globals_js_namespaceObject.window && (external_config_js_default().DEBUG || external_globals_js_namespaceObject.window.POSTHOG_DEBUG || debugEnabled) && !(0, core_namespaceObject.isUndefined)(external_globals_js_namespaceObject.window.console) && external_globals_js_namespaceObject.window.console) {
|
|
47
|
+
const consoleLog = '__rrweb_original__' in external_globals_js_namespaceObject.window.console[level] ? external_globals_js_namespaceObject.window.console[level]['__rrweb_original__'] : external_globals_js_namespaceObject.window.console[level];
|
|
48
|
+
consoleLog(prefix, ...args);
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
debug: (...args)=>{
|
|
52
|
+
logger._log('debug', ...args);
|
|
53
|
+
},
|
|
54
|
+
info: (...args)=>{
|
|
55
|
+
logger._log('log', ...args);
|
|
56
|
+
},
|
|
57
|
+
warn: (...args)=>{
|
|
58
|
+
logger._log('warn', ...args);
|
|
59
|
+
},
|
|
60
|
+
error: (...args)=>{
|
|
61
|
+
logger._log('error', ...args);
|
|
62
|
+
},
|
|
63
|
+
critical: (...args)=>{
|
|
64
|
+
console.error(prefix, ...args);
|
|
65
|
+
},
|
|
66
|
+
uninitializedWarning: (methodName)=>{
|
|
67
|
+
logger.error(`You must initialize PostHog before calling ${methodName}`);
|
|
68
|
+
},
|
|
69
|
+
createLogger: (additionalPrefix, options)=>_createLogger(`${prefix} ${additionalPrefix}`, options)
|
|
70
|
+
};
|
|
71
|
+
return logger;
|
|
72
|
+
};
|
|
73
|
+
const logger_logger = _createLogger('[PostHog.js]');
|
|
74
|
+
const createLogger = logger_logger.createLogger;
|
|
75
|
+
exports.createLogger = __webpack_exports__.createLogger;
|
|
76
|
+
exports.logger = __webpack_exports__.logger;
|
|
77
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
78
|
+
"createLogger",
|
|
79
|
+
"logger"
|
|
80
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
81
|
+
Object.defineProperty(exports, '__esModule', {
|
|
82
|
+
value: true
|
|
83
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import config from "../config.mjs";
|
|
2
|
+
import { isUndefined } from "@posthog/core";
|
|
3
|
+
import { window as external_globals_mjs_window } from "./globals.mjs";
|
|
4
|
+
const _createLogger = (prefix, { debugEnabled } = {})=>{
|
|
5
|
+
const logger = {
|
|
6
|
+
_log: (level, ...args)=>{
|
|
7
|
+
if (external_globals_mjs_window && (config.DEBUG || external_globals_mjs_window.POSTHOG_DEBUG || debugEnabled) && !isUndefined(external_globals_mjs_window.console) && external_globals_mjs_window.console) {
|
|
8
|
+
const consoleLog = '__rrweb_original__' in external_globals_mjs_window.console[level] ? external_globals_mjs_window.console[level]['__rrweb_original__'] : external_globals_mjs_window.console[level];
|
|
9
|
+
consoleLog(prefix, ...args);
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
debug: (...args)=>{
|
|
13
|
+
logger._log('debug', ...args);
|
|
14
|
+
},
|
|
15
|
+
info: (...args)=>{
|
|
16
|
+
logger._log('log', ...args);
|
|
17
|
+
},
|
|
18
|
+
warn: (...args)=>{
|
|
19
|
+
logger._log('warn', ...args);
|
|
20
|
+
},
|
|
21
|
+
error: (...args)=>{
|
|
22
|
+
logger._log('error', ...args);
|
|
23
|
+
},
|
|
24
|
+
critical: (...args)=>{
|
|
25
|
+
console.error(prefix, ...args);
|
|
26
|
+
},
|
|
27
|
+
uninitializedWarning: (methodName)=>{
|
|
28
|
+
logger.error(`You must initialize PostHog before calling ${methodName}`);
|
|
29
|
+
},
|
|
30
|
+
createLogger: (additionalPrefix, options)=>_createLogger(`${prefix} ${additionalPrefix}`, options)
|
|
31
|
+
};
|
|
32
|
+
return logger;
|
|
33
|
+
};
|
|
34
|
+
const logger_logger = _createLogger('[PostHog.js]');
|
|
35
|
+
const createLogger = logger_logger.createLogger;
|
|
36
|
+
export { createLogger, logger_logger as logger };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type PropertyMatchType } from './property-utils';
|
|
2
|
+
export declare function doesDeviceTypeMatch(deviceTypes?: string[], matchType?: PropertyMatchType): boolean;
|
|
3
|
+
export declare function hasPeriodPassed(periodDays?: number, lastSeenDate?: string | Date | null): boolean;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
hasPeriodPassed: ()=>hasPeriodPassed,
|
|
28
|
+
doesDeviceTypeMatch: ()=>doesDeviceTypeMatch
|
|
29
|
+
});
|
|
30
|
+
const core_namespaceObject = require("@posthog/core");
|
|
31
|
+
const external_globals_js_namespaceObject = require("./globals.js");
|
|
32
|
+
const external_property_utils_js_namespaceObject = require("./property-utils.js");
|
|
33
|
+
function doesDeviceTypeMatch(deviceTypes, matchType) {
|
|
34
|
+
if (!deviceTypes || 0 === deviceTypes.length) return true;
|
|
35
|
+
if (!external_globals_js_namespaceObject.userAgent) return false;
|
|
36
|
+
const deviceType = (0, core_namespaceObject.detectDeviceType)(external_globals_js_namespaceObject.userAgent, {
|
|
37
|
+
userAgentDataPlatform: external_globals_js_namespaceObject.navigator?.userAgentData?.platform,
|
|
38
|
+
maxTouchPoints: external_globals_js_namespaceObject.navigator?.maxTouchPoints,
|
|
39
|
+
screenWidth: external_globals_js_namespaceObject.window?.screen?.width,
|
|
40
|
+
screenHeight: external_globals_js_namespaceObject.window?.screen?.height,
|
|
41
|
+
devicePixelRatio: external_globals_js_namespaceObject.window?.devicePixelRatio
|
|
42
|
+
});
|
|
43
|
+
return external_property_utils_js_namespaceObject.propertyComparisons[matchType ?? 'icontains'](deviceTypes, [
|
|
44
|
+
deviceType
|
|
45
|
+
]);
|
|
46
|
+
}
|
|
47
|
+
function hasPeriodPassed(periodDays, lastSeenDate) {
|
|
48
|
+
if (!periodDays || !lastSeenDate) return true;
|
|
49
|
+
const date = 'string' == typeof lastSeenDate ? new Date(lastSeenDate) : lastSeenDate;
|
|
50
|
+
const now = new Date();
|
|
51
|
+
const diffMs = Math.abs(now.getTime() - date.getTime());
|
|
52
|
+
const diffDays = Math.ceil(diffMs / 86400000);
|
|
53
|
+
return diffDays > periodDays;
|
|
54
|
+
}
|
|
55
|
+
exports.doesDeviceTypeMatch = __webpack_exports__.doesDeviceTypeMatch;
|
|
56
|
+
exports.hasPeriodPassed = __webpack_exports__.hasPeriodPassed;
|
|
57
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
58
|
+
"doesDeviceTypeMatch",
|
|
59
|
+
"hasPeriodPassed"
|
|
60
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
61
|
+
Object.defineProperty(exports, '__esModule', {
|
|
62
|
+
value: true
|
|
63
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { detectDeviceType } from "@posthog/core";
|
|
2
|
+
import { navigator as external_globals_mjs_navigator, userAgent, window as external_globals_mjs_window } from "./globals.mjs";
|
|
3
|
+
import { propertyComparisons } from "./property-utils.mjs";
|
|
4
|
+
function doesDeviceTypeMatch(deviceTypes, matchType) {
|
|
5
|
+
if (!deviceTypes || 0 === deviceTypes.length) return true;
|
|
6
|
+
if (!userAgent) return false;
|
|
7
|
+
const deviceType = detectDeviceType(userAgent, {
|
|
8
|
+
userAgentDataPlatform: external_globals_mjs_navigator?.userAgentData?.platform,
|
|
9
|
+
maxTouchPoints: external_globals_mjs_navigator?.maxTouchPoints,
|
|
10
|
+
screenWidth: external_globals_mjs_window?.screen?.width,
|
|
11
|
+
screenHeight: external_globals_mjs_window?.screen?.height,
|
|
12
|
+
devicePixelRatio: external_globals_mjs_window?.devicePixelRatio
|
|
13
|
+
});
|
|
14
|
+
return propertyComparisons[matchType ?? 'icontains'](deviceTypes, [
|
|
15
|
+
deviceType
|
|
16
|
+
]);
|
|
17
|
+
}
|
|
18
|
+
function hasPeriodPassed(periodDays, lastSeenDate) {
|
|
19
|
+
if (!periodDays || !lastSeenDate) return true;
|
|
20
|
+
const date = 'string' == typeof lastSeenDate ? new Date(lastSeenDate) : lastSeenDate;
|
|
21
|
+
const now = new Date();
|
|
22
|
+
const diffMs = Math.abs(now.getTime() - date.getTime());
|
|
23
|
+
const diffDays = Math.ceil(diffMs / 86400000);
|
|
24
|
+
return diffDays > periodDays;
|
|
25
|
+
}
|
|
26
|
+
export { doesDeviceTypeMatch, hasPeriodPassed };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Properties } from '@posthog/types';
|
|
2
|
+
export type PropertyMatchType = 'exact' | 'is_not' | 'regex' | 'not_regex' | 'icontains' | 'not_icontains';
|
|
3
|
+
export type PropertyOperator = PropertyMatchType | 'gt' | 'lt';
|
|
4
|
+
export type PropertyFilters = {
|
|
5
|
+
[propertyName: string]: {
|
|
6
|
+
values: string[];
|
|
7
|
+
operator: PropertyOperator;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
export interface SessionRecordingTriggerPropertyFilter {
|
|
11
|
+
key: string;
|
|
12
|
+
value?: string | number | boolean | (string | number | boolean)[] | null;
|
|
13
|
+
operator?: PropertyOperator | null;
|
|
14
|
+
type?: string | null;
|
|
15
|
+
}
|
|
16
|
+
export declare function getPersonPropertiesHash(distinct_id: string, userPropertiesToSet?: Properties, userPropertiesToSetOnce?: Properties): string;
|
|
17
|
+
export declare const propertyComparisons: Record<PropertyOperator, (targets: string[], values: string[]) => boolean>;
|
|
18
|
+
/**
|
|
19
|
+
* Evaluate trigger property filters (WHERE clauses) against event and person properties.
|
|
20
|
+
* All filters must match (implicit AND). Returns true if no filters are present.
|
|
21
|
+
*/
|
|
22
|
+
export declare function matchTriggerPropertyFilters(filters: SessionRecordingTriggerPropertyFilter[] | undefined, eventProperties: Properties | undefined, personProperties: Properties | undefined): boolean;
|
|
23
|
+
export declare function matchPropertyFilters(propertyFilters: PropertyFilters | undefined, eventProperties: Properties | undefined): boolean;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
matchPropertyFilters: ()=>matchPropertyFilters,
|
|
28
|
+
propertyComparisons: ()=>propertyComparisons,
|
|
29
|
+
getPersonPropertiesHash: ()=>getPersonPropertiesHash,
|
|
30
|
+
matchTriggerPropertyFilters: ()=>matchTriggerPropertyFilters
|
|
31
|
+
});
|
|
32
|
+
const core_namespaceObject = require("@posthog/core");
|
|
33
|
+
const external_request_utils_js_namespaceObject = require("./request-utils.js");
|
|
34
|
+
const external_regex_utils_js_namespaceObject = require("./regex-utils.js");
|
|
35
|
+
function getPersonPropertiesHash(distinct_id, userPropertiesToSet, userPropertiesToSetOnce) {
|
|
36
|
+
return (0, external_request_utils_js_namespaceObject.jsonStringify)({
|
|
37
|
+
distinct_id,
|
|
38
|
+
userPropertiesToSet,
|
|
39
|
+
userPropertiesToSetOnce
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
const propertyComparisons = {
|
|
43
|
+
exact: (targets, values)=>values.some((value)=>targets.some((target)=>value === target)),
|
|
44
|
+
is_not: (targets, values)=>values.every((value)=>targets.every((target)=>value !== target)),
|
|
45
|
+
regex: (targets, values)=>values.some((value)=>targets.some((target)=>(0, external_regex_utils_js_namespaceObject.isMatchingRegex)(value, target))),
|
|
46
|
+
not_regex: (targets, values)=>values.every((value)=>targets.every((target)=>!(0, external_regex_utils_js_namespaceObject.isMatchingRegex)(value, target))),
|
|
47
|
+
icontains: (targets, values)=>values.map(toLowerCase).some((value)=>targets.map(toLowerCase).some((target)=>value.includes(target))),
|
|
48
|
+
not_icontains: (targets, values)=>values.map(toLowerCase).every((value)=>targets.map(toLowerCase).every((target)=>!value.includes(target))),
|
|
49
|
+
gt: (targets, values)=>values.some((value)=>{
|
|
50
|
+
const numValue = parseFloat(value);
|
|
51
|
+
return !isNaN(numValue) && targets.some((t)=>numValue > parseFloat(t));
|
|
52
|
+
}),
|
|
53
|
+
lt: (targets, values)=>values.some((value)=>{
|
|
54
|
+
const numValue = parseFloat(value);
|
|
55
|
+
return !isNaN(numValue) && targets.some((t)=>numValue < parseFloat(t));
|
|
56
|
+
})
|
|
57
|
+
};
|
|
58
|
+
const toLowerCase = (v)=>v.toLowerCase();
|
|
59
|
+
const NEGATIVE_OPERATORS = new Set([
|
|
60
|
+
'is_not',
|
|
61
|
+
'not_icontains',
|
|
62
|
+
'not_regex'
|
|
63
|
+
]);
|
|
64
|
+
function matchTriggerPropertyFilters(filters, eventProperties, personProperties) {
|
|
65
|
+
if (!filters || 0 === filters.length) return true;
|
|
66
|
+
return filters.every((filter)=>{
|
|
67
|
+
const source = 'person' === filter.type ? personProperties : eventProperties;
|
|
68
|
+
const propertyValue = source?.[filter.key];
|
|
69
|
+
const operator = filter.operator || 'exact';
|
|
70
|
+
if ((0, core_namespaceObject.isUndefined)(propertyValue) || (0, core_namespaceObject.isNull)(propertyValue)) return NEGATIVE_OPERATORS.has(operator);
|
|
71
|
+
const comparisonFunction = propertyComparisons[operator];
|
|
72
|
+
if (!comparisonFunction) return false;
|
|
73
|
+
if ((0, core_namespaceObject.isUndefined)(filter.value) || (0, core_namespaceObject.isNull)(filter.value)) return false;
|
|
74
|
+
const targetValues = (0, core_namespaceObject.isArray)(filter.value) ? filter.value.map(String) : [
|
|
75
|
+
String(filter.value)
|
|
76
|
+
];
|
|
77
|
+
const actualValues = (0, core_namespaceObject.isArray)(propertyValue) ? propertyValue.map(String) : [
|
|
78
|
+
String(propertyValue)
|
|
79
|
+
];
|
|
80
|
+
return comparisonFunction(targetValues, actualValues);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
function matchPropertyFilters(propertyFilters, eventProperties) {
|
|
84
|
+
if (!propertyFilters) return true;
|
|
85
|
+
return Object.entries(propertyFilters).every(([propertyName, filter])=>{
|
|
86
|
+
const eventPropertyValue = eventProperties?.[propertyName];
|
|
87
|
+
if ((0, core_namespaceObject.isUndefined)(eventPropertyValue) || (0, core_namespaceObject.isNull)(eventPropertyValue)) return false;
|
|
88
|
+
const eventValues = [
|
|
89
|
+
String(eventPropertyValue)
|
|
90
|
+
];
|
|
91
|
+
const comparisonFunction = propertyComparisons[filter.operator];
|
|
92
|
+
if (!comparisonFunction) return false;
|
|
93
|
+
return comparisonFunction(filter.values, eventValues);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
exports.getPersonPropertiesHash = __webpack_exports__.getPersonPropertiesHash;
|
|
97
|
+
exports.matchPropertyFilters = __webpack_exports__.matchPropertyFilters;
|
|
98
|
+
exports.matchTriggerPropertyFilters = __webpack_exports__.matchTriggerPropertyFilters;
|
|
99
|
+
exports.propertyComparisons = __webpack_exports__.propertyComparisons;
|
|
100
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
101
|
+
"getPersonPropertiesHash",
|
|
102
|
+
"matchPropertyFilters",
|
|
103
|
+
"matchTriggerPropertyFilters",
|
|
104
|
+
"propertyComparisons"
|
|
105
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
106
|
+
Object.defineProperty(exports, '__esModule', {
|
|
107
|
+
value: true
|
|
108
|
+
});
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { isArray, isNull, isUndefined } from "@posthog/core";
|
|
2
|
+
import { jsonStringify } from "./request-utils.mjs";
|
|
3
|
+
import { isMatchingRegex } from "./regex-utils.mjs";
|
|
4
|
+
function getPersonPropertiesHash(distinct_id, userPropertiesToSet, userPropertiesToSetOnce) {
|
|
5
|
+
return jsonStringify({
|
|
6
|
+
distinct_id,
|
|
7
|
+
userPropertiesToSet,
|
|
8
|
+
userPropertiesToSetOnce
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
const propertyComparisons = {
|
|
12
|
+
exact: (targets, values)=>values.some((value)=>targets.some((target)=>value === target)),
|
|
13
|
+
is_not: (targets, values)=>values.every((value)=>targets.every((target)=>value !== target)),
|
|
14
|
+
regex: (targets, values)=>values.some((value)=>targets.some((target)=>isMatchingRegex(value, target))),
|
|
15
|
+
not_regex: (targets, values)=>values.every((value)=>targets.every((target)=>!isMatchingRegex(value, target))),
|
|
16
|
+
icontains: (targets, values)=>values.map(toLowerCase).some((value)=>targets.map(toLowerCase).some((target)=>value.includes(target))),
|
|
17
|
+
not_icontains: (targets, values)=>values.map(toLowerCase).every((value)=>targets.map(toLowerCase).every((target)=>!value.includes(target))),
|
|
18
|
+
gt: (targets, values)=>values.some((value)=>{
|
|
19
|
+
const numValue = parseFloat(value);
|
|
20
|
+
return !isNaN(numValue) && targets.some((t)=>numValue > parseFloat(t));
|
|
21
|
+
}),
|
|
22
|
+
lt: (targets, values)=>values.some((value)=>{
|
|
23
|
+
const numValue = parseFloat(value);
|
|
24
|
+
return !isNaN(numValue) && targets.some((t)=>numValue < parseFloat(t));
|
|
25
|
+
})
|
|
26
|
+
};
|
|
27
|
+
const toLowerCase = (v)=>v.toLowerCase();
|
|
28
|
+
const NEGATIVE_OPERATORS = new Set([
|
|
29
|
+
'is_not',
|
|
30
|
+
'not_icontains',
|
|
31
|
+
'not_regex'
|
|
32
|
+
]);
|
|
33
|
+
function matchTriggerPropertyFilters(filters, eventProperties, personProperties) {
|
|
34
|
+
if (!filters || 0 === filters.length) return true;
|
|
35
|
+
return filters.every((filter)=>{
|
|
36
|
+
const source = 'person' === filter.type ? personProperties : eventProperties;
|
|
37
|
+
const propertyValue = source?.[filter.key];
|
|
38
|
+
const operator = filter.operator || 'exact';
|
|
39
|
+
if (isUndefined(propertyValue) || isNull(propertyValue)) return NEGATIVE_OPERATORS.has(operator);
|
|
40
|
+
const comparisonFunction = propertyComparisons[operator];
|
|
41
|
+
if (!comparisonFunction) return false;
|
|
42
|
+
if (isUndefined(filter.value) || isNull(filter.value)) return false;
|
|
43
|
+
const targetValues = isArray(filter.value) ? filter.value.map(String) : [
|
|
44
|
+
String(filter.value)
|
|
45
|
+
];
|
|
46
|
+
const actualValues = isArray(propertyValue) ? propertyValue.map(String) : [
|
|
47
|
+
String(propertyValue)
|
|
48
|
+
];
|
|
49
|
+
return comparisonFunction(targetValues, actualValues);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
function matchPropertyFilters(propertyFilters, eventProperties) {
|
|
53
|
+
if (!propertyFilters) return true;
|
|
54
|
+
return Object.entries(propertyFilters).every(([propertyName, filter])=>{
|
|
55
|
+
const eventPropertyValue = eventProperties?.[propertyName];
|
|
56
|
+
if (isUndefined(eventPropertyValue) || isNull(eventPropertyValue)) return false;
|
|
57
|
+
const eventValues = [
|
|
58
|
+
String(eventPropertyValue)
|
|
59
|
+
];
|
|
60
|
+
const comparisonFunction = propertyComparisons[filter.operator];
|
|
61
|
+
if (!comparisonFunction) return false;
|
|
62
|
+
return comparisonFunction(filter.values, eventValues);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
export { getPersonPropertiesHash, matchPropertyFilters, matchTriggerPropertyFilters, propertyComparisons };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
interface NativeImplementationsCache {
|
|
2
|
+
MutationObserver: typeof MutationObserver;
|
|
3
|
+
}
|
|
4
|
+
type BrowserWindow = Window & typeof globalThis;
|
|
5
|
+
export declare function getNativeImplementation<T extends keyof NativeImplementationsCache>(name: T, assignableWindow: BrowserWindow): NativeImplementationsCache[T];
|
|
6
|
+
export declare function getNativeMutationObserverImplementation(assignableWindow: BrowserWindow): typeof MutationObserver;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
getNativeImplementation: ()=>getNativeImplementation,
|
|
28
|
+
getNativeMutationObserverImplementation: ()=>getNativeMutationObserverImplementation
|
|
29
|
+
});
|
|
30
|
+
const core_namespaceObject = require("@posthog/core");
|
|
31
|
+
const external_logger_js_namespaceObject = require("./logger.js");
|
|
32
|
+
const external_type_utils_js_namespaceObject = require("./type-utils.js");
|
|
33
|
+
const cachedImplementations = {};
|
|
34
|
+
function getNativeImplementation(name, assignableWindow) {
|
|
35
|
+
const cached = cachedImplementations[name];
|
|
36
|
+
if (cached) return cached;
|
|
37
|
+
let impl = assignableWindow[name];
|
|
38
|
+
if ((0, core_namespaceObject.isNativeFunction)(impl) && !(0, external_type_utils_js_namespaceObject.isAngularZonePresent)()) return cachedImplementations[name] = impl.bind(assignableWindow);
|
|
39
|
+
const document = assignableWindow.document;
|
|
40
|
+
if (document && (0, core_namespaceObject.isFunction)(document.createElement)) try {
|
|
41
|
+
const sandbox = document.createElement('iframe');
|
|
42
|
+
sandbox.hidden = true;
|
|
43
|
+
document.head.appendChild(sandbox);
|
|
44
|
+
const contentWindow = sandbox.contentWindow;
|
|
45
|
+
if (contentWindow && contentWindow[name]) impl = contentWindow[name];
|
|
46
|
+
document.head.removeChild(sandbox);
|
|
47
|
+
} catch (e) {
|
|
48
|
+
external_logger_js_namespaceObject.logger.warn(`Could not create sandbox iframe for ${name} check, bailing to assignableWindow.${name}: `, e);
|
|
49
|
+
}
|
|
50
|
+
if (!impl || !(0, core_namespaceObject.isFunction)(impl)) return impl;
|
|
51
|
+
return cachedImplementations[name] = impl.bind(assignableWindow);
|
|
52
|
+
}
|
|
53
|
+
function getNativeMutationObserverImplementation(assignableWindow) {
|
|
54
|
+
return getNativeImplementation('MutationObserver', assignableWindow);
|
|
55
|
+
}
|
|
56
|
+
exports.getNativeImplementation = __webpack_exports__.getNativeImplementation;
|
|
57
|
+
exports.getNativeMutationObserverImplementation = __webpack_exports__.getNativeMutationObserverImplementation;
|
|
58
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
59
|
+
"getNativeImplementation",
|
|
60
|
+
"getNativeMutationObserverImplementation"
|
|
61
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
62
|
+
Object.defineProperty(exports, '__esModule', {
|
|
63
|
+
value: true
|
|
64
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { isFunction, isNativeFunction } from "@posthog/core";
|
|
2
|
+
import { logger } from "./logger.mjs";
|
|
3
|
+
import { isAngularZonePresent } from "./type-utils.mjs";
|
|
4
|
+
const cachedImplementations = {};
|
|
5
|
+
function getNativeImplementation(name, assignableWindow) {
|
|
6
|
+
const cached = cachedImplementations[name];
|
|
7
|
+
if (cached) return cached;
|
|
8
|
+
let impl = assignableWindow[name];
|
|
9
|
+
if (isNativeFunction(impl) && !isAngularZonePresent()) return cachedImplementations[name] = impl.bind(assignableWindow);
|
|
10
|
+
const document = assignableWindow.document;
|
|
11
|
+
if (document && isFunction(document.createElement)) try {
|
|
12
|
+
const sandbox = document.createElement('iframe');
|
|
13
|
+
sandbox.hidden = true;
|
|
14
|
+
document.head.appendChild(sandbox);
|
|
15
|
+
const contentWindow = sandbox.contentWindow;
|
|
16
|
+
if (contentWindow && contentWindow[name]) impl = contentWindow[name];
|
|
17
|
+
document.head.removeChild(sandbox);
|
|
18
|
+
} catch (e) {
|
|
19
|
+
logger.warn(`Could not create sandbox iframe for ${name} check, bailing to assignableWindow.${name}: `, e);
|
|
20
|
+
}
|
|
21
|
+
if (!impl || !isFunction(impl)) return impl;
|
|
22
|
+
return cachedImplementations[name] = impl.bind(assignableWindow);
|
|
23
|
+
}
|
|
24
|
+
function getNativeMutationObserverImplementation(assignableWindow) {
|
|
25
|
+
return getNativeImplementation('MutationObserver', assignableWindow);
|
|
26
|
+
}
|
|
27
|
+
export { getNativeImplementation, getNativeMutationObserverImplementation };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
isMatchingRegex: ()=>isMatchingRegex,
|
|
28
|
+
isValidRegex: ()=>isValidRegex
|
|
29
|
+
});
|
|
30
|
+
const isValidRegex = function(str) {
|
|
31
|
+
try {
|
|
32
|
+
new RegExp(str);
|
|
33
|
+
} catch {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
return true;
|
|
37
|
+
};
|
|
38
|
+
const isMatchingRegex = function(value, pattern) {
|
|
39
|
+
if (!isValidRegex(pattern)) return false;
|
|
40
|
+
try {
|
|
41
|
+
return new RegExp(pattern).test(value);
|
|
42
|
+
} catch {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
exports.isMatchingRegex = __webpack_exports__.isMatchingRegex;
|
|
47
|
+
exports.isValidRegex = __webpack_exports__.isValidRegex;
|
|
48
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
49
|
+
"isMatchingRegex",
|
|
50
|
+
"isValidRegex"
|
|
51
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
52
|
+
Object.defineProperty(exports, '__esModule', {
|
|
53
|
+
value: true
|
|
54
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const isValidRegex = function(str) {
|
|
2
|
+
try {
|
|
3
|
+
new RegExp(str);
|
|
4
|
+
} catch {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
return true;
|
|
8
|
+
};
|
|
9
|
+
const isMatchingRegex = function(value, pattern) {
|
|
10
|
+
if (!isValidRegex(pattern)) return false;
|
|
11
|
+
try {
|
|
12
|
+
return new RegExp(pattern).test(value);
|
|
13
|
+
} catch {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
export { isMatchingRegex, isValidRegex };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const jsonStringify: (data: any, space?: string | number) => string;
|
|
2
|
+
/**
|
|
3
|
+
* IE11 doesn't support `new URL`
|
|
4
|
+
* so we can create an anchor element and use that to parse the URL
|
|
5
|
+
* there's a lot of overlap between HTMLHyperlinkElementUtils and URL
|
|
6
|
+
* meaning useful properties like `pathname` are available on both
|
|
7
|
+
*/
|
|
8
|
+
export declare const convertToURL: (url: string) => HTMLAnchorElement | null;
|
|
9
|
+
export declare const formDataToQuery: (formdata: Record<string, any> | FormData, arg_separator?: string) => string;
|
|
10
|
+
export declare const getQueryParam: (url: string, param: string) => string;
|
|
11
|
+
export declare const maskQueryParams: <T extends string | undefined>(url: T, maskedParams: string[] | undefined, mask: string) => T extends string ? string : undefined;
|
|
12
|
+
export declare const _getHashParam: (hash: string, param: string) => string | null;
|
|
13
|
+
export declare const isLocalhost: () => boolean;
|
|
14
|
+
export declare const isStatusZeroFailureCircuitBreakerTripped: (consecutiveStatusZeroFailures: number, maxConsecutiveStatusZeroFailures: number) => boolean;
|
|
15
|
+
export declare const updateStatusZeroFailureCount: (statusCode: number, consecutiveStatusZeroFailures: number, maxConsecutiveStatusZeroFailures: number, onCircuitBreakerTripped: () => void) => number;
|