@posthog/browser-common 0.5.1 → 0.5.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/dist/config.js +1 -1
- package/dist/config.mjs +1 -1
- package/dist/types/surveys.d.ts +2 -15
- package/dist/utils/property-utils.d.ts +3 -10
- package/dist/utils/property-utils.js +4 -34
- package/dist/utils/property-utils.mjs +1 -31
- package/dist/utils/regex-utils.d.ts +1 -2
- package/dist/utils/regex-utils.js +3 -18
- package/dist/utils/regex-utils.mjs +1 -16
- package/package.json +3 -3
package/dist/config.js
CHANGED
|
@@ -26,7 +26,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
26
26
|
__webpack_require__.d(__webpack_exports__, {
|
|
27
27
|
default: ()=>__WEBPACK_DEFAULT_EXPORT__
|
|
28
28
|
});
|
|
29
|
-
const packageVersion = "0.5.
|
|
29
|
+
const packageVersion = "0.5.2";
|
|
30
30
|
const Config = {
|
|
31
31
|
DEBUG: false,
|
|
32
32
|
LIB_VERSION: packageVersion,
|
package/dist/config.mjs
CHANGED
package/dist/types/surveys.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { SurveyAppearance as CoreSurveyAppearance, SurveyQuestionTranslation, SurveyTranslation, SurveyValidationRule } from '@posthog/core';
|
|
1
|
+
import type { PropertyMatchType, SurveyAppearance as CoreSurveyAppearance, SurveyEventWithFilters, SurveyQuestionTranslation, SurveyTranslation, SurveyValidationRule } from '@posthog/core';
|
|
2
|
+
export type { PropertyFilters, PropertyMatchType, PropertyOperator, SurveyEventWithFilters } from '@posthog/core';
|
|
2
3
|
export declare const SurveyEventType: {
|
|
3
4
|
readonly Activation: "events";
|
|
4
5
|
readonly Cancellation: "cancelEvents";
|
|
@@ -85,19 +86,6 @@ export declare const DisplaySurveyType: {
|
|
|
85
86
|
readonly Inline: "inline";
|
|
86
87
|
};
|
|
87
88
|
export type DisplaySurveyType = (typeof DisplaySurveyType)[keyof typeof DisplaySurveyType];
|
|
88
|
-
export type PropertyMatchType = 'regex' | 'not_regex' | 'exact' | 'is_not' | 'icontains' | 'not_icontains';
|
|
89
|
-
/** Extended survey operator type with numeric comparisons. */
|
|
90
|
-
export type PropertyOperator = PropertyMatchType | 'gt' | 'lt';
|
|
91
|
-
export type PropertyFilters = {
|
|
92
|
-
[propertyName: string]: {
|
|
93
|
-
values: string[];
|
|
94
|
-
operator: PropertyOperator;
|
|
95
|
-
};
|
|
96
|
-
};
|
|
97
|
-
export interface SurveyEventWithFilters {
|
|
98
|
-
name: string;
|
|
99
|
-
propertyFilters?: PropertyFilters;
|
|
100
|
-
}
|
|
101
89
|
export type SurveyQuestionDescriptionContentType = 'html' | 'text';
|
|
102
90
|
/** Browser survey appearance, including browser-only placement and rendering options. */
|
|
103
91
|
export interface SurveyAppearance extends Omit<CoreSurveyAppearance, 'position' | 'widgetType'> {
|
|
@@ -240,4 +228,3 @@ export interface ActionStepType {
|
|
|
240
228
|
type?: string;
|
|
241
229
|
}[];
|
|
242
230
|
}
|
|
243
|
-
export {};
|
|
@@ -1,12 +1,7 @@
|
|
|
1
|
+
import type { PropertyOperator } from '@posthog/core';
|
|
1
2
|
import type { Properties } from '@posthog/types';
|
|
2
|
-
export type
|
|
3
|
-
export
|
|
4
|
-
export type PropertyFilters = {
|
|
5
|
-
[propertyName: string]: {
|
|
6
|
-
values: string[];
|
|
7
|
-
operator: PropertyOperator;
|
|
8
|
-
};
|
|
9
|
-
};
|
|
3
|
+
export type { PropertyFilters, PropertyMatchType, PropertyOperator } from '@posthog/core';
|
|
4
|
+
export { matchPropertyFilters, propertyComparisons } from '@posthog/core/surveys';
|
|
10
5
|
export interface SessionRecordingTriggerPropertyFilter {
|
|
11
6
|
key: string;
|
|
12
7
|
value?: string | number | boolean | (string | number | boolean)[] | null;
|
|
@@ -14,10 +9,8 @@ export interface SessionRecordingTriggerPropertyFilter {
|
|
|
14
9
|
type?: string | null;
|
|
15
10
|
}
|
|
16
11
|
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
12
|
/**
|
|
19
13
|
* Evaluate trigger property filters (WHERE clauses) against event and person properties.
|
|
20
14
|
* All filters must match (implicit AND). Returns true if no filters are present.
|
|
21
15
|
*/
|
|
22
16
|
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;
|
|
@@ -24,14 +24,14 @@ var __webpack_require__ = {};
|
|
|
24
24
|
var __webpack_exports__ = {};
|
|
25
25
|
__webpack_require__.r(__webpack_exports__);
|
|
26
26
|
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
-
matchPropertyFilters: ()=>matchPropertyFilters,
|
|
28
|
-
propertyComparisons: ()=>propertyComparisons,
|
|
27
|
+
matchPropertyFilters: ()=>surveys_namespaceObject.matchPropertyFilters,
|
|
28
|
+
propertyComparisons: ()=>surveys_namespaceObject.propertyComparisons,
|
|
29
29
|
getPersonPropertiesHash: ()=>getPersonPropertiesHash,
|
|
30
30
|
matchTriggerPropertyFilters: ()=>matchTriggerPropertyFilters
|
|
31
31
|
});
|
|
32
32
|
const core_namespaceObject = require("@posthog/core");
|
|
33
|
+
const surveys_namespaceObject = require("@posthog/core/surveys");
|
|
33
34
|
const external_request_utils_js_namespaceObject = require("./request-utils.js");
|
|
34
|
-
const external_regex_utils_js_namespaceObject = require("./regex-utils.js");
|
|
35
35
|
function getPersonPropertiesHash(distinct_id, userPropertiesToSet, userPropertiesToSetOnce) {
|
|
36
36
|
return (0, external_request_utils_js_namespaceObject.jsonStringify)({
|
|
37
37
|
distinct_id,
|
|
@@ -39,23 +39,6 @@ function getPersonPropertiesHash(distinct_id, userPropertiesToSet, userPropertie
|
|
|
39
39
|
userPropertiesToSetOnce
|
|
40
40
|
});
|
|
41
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
42
|
const NEGATIVE_OPERATORS = new Set([
|
|
60
43
|
'is_not',
|
|
61
44
|
'not_icontains',
|
|
@@ -68,7 +51,7 @@ function matchTriggerPropertyFilters(filters, eventProperties, personProperties)
|
|
|
68
51
|
const propertyValue = source?.[filter.key];
|
|
69
52
|
const operator = filter.operator || 'exact';
|
|
70
53
|
if ((0, core_namespaceObject.isUndefined)(propertyValue) || (0, core_namespaceObject.isNull)(propertyValue)) return NEGATIVE_OPERATORS.has(operator);
|
|
71
|
-
const comparisonFunction = propertyComparisons[operator];
|
|
54
|
+
const comparisonFunction = surveys_namespaceObject.propertyComparisons[operator];
|
|
72
55
|
if (!comparisonFunction) return false;
|
|
73
56
|
if ((0, core_namespaceObject.isUndefined)(filter.value) || (0, core_namespaceObject.isNull)(filter.value)) return false;
|
|
74
57
|
const targetValues = (0, core_namespaceObject.isArray)(filter.value) ? filter.value.map(String) : [
|
|
@@ -80,19 +63,6 @@ function matchTriggerPropertyFilters(filters, eventProperties, personProperties)
|
|
|
80
63
|
return comparisonFunction(targetValues, actualValues);
|
|
81
64
|
});
|
|
82
65
|
}
|
|
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
66
|
exports.getPersonPropertiesHash = __webpack_exports__.getPersonPropertiesHash;
|
|
97
67
|
exports.matchPropertyFilters = __webpack_exports__.matchPropertyFilters;
|
|
98
68
|
exports.matchTriggerPropertyFilters = __webpack_exports__.matchTriggerPropertyFilters;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isArray, isNull, isUndefined } from "@posthog/core";
|
|
2
|
+
import { matchPropertyFilters, propertyComparisons } from "@posthog/core/surveys";
|
|
2
3
|
import { jsonStringify } from "./request-utils.mjs";
|
|
3
|
-
import { isMatchingRegex } from "./regex-utils.mjs";
|
|
4
4
|
function getPersonPropertiesHash(distinct_id, userPropertiesToSet, userPropertiesToSetOnce) {
|
|
5
5
|
return jsonStringify({
|
|
6
6
|
distinct_id,
|
|
@@ -8,23 +8,6 @@ function getPersonPropertiesHash(distinct_id, userPropertiesToSet, userPropertie
|
|
|
8
8
|
userPropertiesToSetOnce
|
|
9
9
|
});
|
|
10
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
11
|
const NEGATIVE_OPERATORS = new Set([
|
|
29
12
|
'is_not',
|
|
30
13
|
'not_icontains',
|
|
@@ -49,17 +32,4 @@ function matchTriggerPropertyFilters(filters, eventProperties, personProperties)
|
|
|
49
32
|
return comparisonFunction(targetValues, actualValues);
|
|
50
33
|
});
|
|
51
34
|
}
|
|
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
35
|
export { getPersonPropertiesHash, matchPropertyFilters, matchTriggerPropertyFilters, propertyComparisons };
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
export declare const isMatchingRegex: (value: string, pattern: string) => boolean;
|
|
1
|
+
export { isMatchingRegex, isValidRegex } from '@posthog/core/surveys';
|
|
@@ -24,25 +24,10 @@ var __webpack_require__ = {};
|
|
|
24
24
|
var __webpack_exports__ = {};
|
|
25
25
|
__webpack_require__.r(__webpack_exports__);
|
|
26
26
|
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
-
isMatchingRegex: ()=>isMatchingRegex,
|
|
28
|
-
isValidRegex: ()=>isValidRegex
|
|
27
|
+
isMatchingRegex: ()=>surveys_namespaceObject.isMatchingRegex,
|
|
28
|
+
isValidRegex: ()=>surveys_namespaceObject.isValidRegex
|
|
29
29
|
});
|
|
30
|
-
const
|
|
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
|
-
};
|
|
30
|
+
const surveys_namespaceObject = require("@posthog/core/surveys");
|
|
46
31
|
exports.isMatchingRegex = __webpack_exports__.isMatchingRegex;
|
|
47
32
|
exports.isValidRegex = __webpack_exports__.isValidRegex;
|
|
48
33
|
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
@@ -1,17 +1,2 @@
|
|
|
1
|
-
|
|
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
|
-
};
|
|
1
|
+
import { isMatchingRegex, isValidRegex } from "@posthog/core/surveys";
|
|
17
2
|
export { isMatchingRegex, isValidRegex };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@posthog/browser-common",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"description": "Internal shared browser utilities and extension primitives for PostHog Browser SDKs",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -65,8 +65,8 @@
|
|
|
65
65
|
}
|
|
66
66
|
},
|
|
67
67
|
"dependencies": {
|
|
68
|
-
"@posthog/core": "^1.48.
|
|
69
|
-
"@posthog/types": "^1.405.
|
|
68
|
+
"@posthog/core": "^1.48.11",
|
|
69
|
+
"@posthog/types": "^1.405.3"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
72
|
"@rslib/core": "0.10.6",
|