New:Socket for Asana Is Now Available.Learn more
Get Started

@posthog/browser-common

Package Overview
Dependencies
Maintainers
21
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@posthog/browser-common - npm Package Compare versions

Comparing version
0.5.1
to
0.5.2
+1
-1
dist/config.js

@@ -29,3 +29,3 @@ "use strict";

});
const packageVersion = "0.5.1";
const packageVersion = "0.5.2";
const Config = {

@@ -32,0 +32,0 @@ DEBUG: false,

@@ -1,2 +0,2 @@

const packageVersion = "0.5.1";
const packageVersion = "0.5.2";
const Config = {

@@ -3,0 +3,0 @@ DEBUG: false,

@@ -1,2 +0,3 @@

import type { SurveyAppearance as CoreSurveyAppearance, SurveyQuestionTranslation, SurveyTranslation, SurveyValidationRule } from '@posthog/core';
import type { PropertyMatchType, SurveyAppearance as CoreSurveyAppearance, SurveyEventWithFilters, SurveyQuestionTranslation, SurveyTranslation, SurveyValidationRule } from '@posthog/core';
export type { PropertyFilters, PropertyMatchType, PropertyOperator, SurveyEventWithFilters } from '@posthog/core';
export declare const SurveyEventType: {

@@ -88,15 +89,2 @@ readonly Activation: "events";

export type DisplaySurveyType = (typeof DisplaySurveyType)[keyof typeof DisplaySurveyType];
export type PropertyMatchType = 'regex' | 'not_regex' | 'exact' | 'is_not' | 'icontains' | 'not_icontains';
/** Extended survey operator type with numeric comparisons. */
export type PropertyOperator = PropertyMatchType | 'gt' | 'lt';
export type PropertyFilters = {
[propertyName: string]: {
values: string[];
operator: PropertyOperator;
};
};
export interface SurveyEventWithFilters {
name: string;
propertyFilters?: PropertyFilters;
}
export type SurveyQuestionDescriptionContentType = 'html' | 'text';

@@ -244,2 +232,1 @@ /** Browser survey appearance, including browser-only placement and rendering options. */

}
export {};

@@ -0,10 +1,5 @@

import type { PropertyOperator } from '@posthog/core';
import type { Properties } from '@posthog/types';
export type PropertyMatchType = 'exact' | 'is_not' | 'regex' | 'not_regex' | 'icontains' | 'not_icontains';
export type PropertyOperator = PropertyMatchType | 'gt' | 'lt';
export type PropertyFilters = {
[propertyName: string]: {
values: string[];
operator: PropertyOperator;
};
};
export type { PropertyFilters, PropertyMatchType, PropertyOperator } from '@posthog/core';
export { matchPropertyFilters, propertyComparisons } from '@posthog/core/surveys';
export interface SessionRecordingTriggerPropertyFilter {

@@ -17,3 +12,2 @@ key: string;

export declare function getPersonPropertiesHash(distinct_id: string, userPropertiesToSet?: Properties, userPropertiesToSetOnce?: Properties): string;
export declare const propertyComparisons: Record<PropertyOperator, (targets: string[], values: string[]) => boolean>;
/**

@@ -24,2 +18,1 @@ * Evaluate trigger property filters (WHERE clauses) against event and person properties.

export declare function matchTriggerPropertyFilters(filters: SessionRecordingTriggerPropertyFilter[] | undefined, eventProperties: Properties | undefined, personProperties: Properties | undefined): boolean;
export declare function matchPropertyFilters(propertyFilters: PropertyFilters | undefined, eventProperties: Properties | undefined): boolean;

@@ -27,4 +27,4 @@ "use strict";

__webpack_require__.d(__webpack_exports__, {
matchPropertyFilters: ()=>matchPropertyFilters,
propertyComparisons: ()=>propertyComparisons,
matchPropertyFilters: ()=>surveys_namespaceObject.matchPropertyFilters,
propertyComparisons: ()=>surveys_namespaceObject.propertyComparisons,
getPersonPropertiesHash: ()=>getPersonPropertiesHash,

@@ -34,4 +34,4 @@ matchTriggerPropertyFilters: ()=>matchTriggerPropertyFilters

const core_namespaceObject = require("@posthog/core");
const surveys_namespaceObject = require("@posthog/core/surveys");
const external_request_utils_js_namespaceObject = require("./request-utils.js");
const external_regex_utils_js_namespaceObject = require("./regex-utils.js");
function getPersonPropertiesHash(distinct_id, userPropertiesToSet, userPropertiesToSetOnce) {

@@ -44,19 +44,2 @@ return (0, external_request_utils_js_namespaceObject.jsonStringify)({

}
const propertyComparisons = {
exact: (targets, values)=>values.some((value)=>targets.some((target)=>value === target)),
is_not: (targets, values)=>values.every((value)=>targets.every((target)=>value !== target)),
regex: (targets, values)=>values.some((value)=>targets.some((target)=>(0, external_regex_utils_js_namespaceObject.isMatchingRegex)(value, target))),
not_regex: (targets, values)=>values.every((value)=>targets.every((target)=>!(0, external_regex_utils_js_namespaceObject.isMatchingRegex)(value, target))),
icontains: (targets, values)=>values.map(toLowerCase).some((value)=>targets.map(toLowerCase).some((target)=>value.includes(target))),
not_icontains: (targets, values)=>values.map(toLowerCase).every((value)=>targets.map(toLowerCase).every((target)=>!value.includes(target))),
gt: (targets, values)=>values.some((value)=>{
const numValue = parseFloat(value);
return !isNaN(numValue) && targets.some((t)=>numValue > parseFloat(t));
}),
lt: (targets, values)=>values.some((value)=>{
const numValue = parseFloat(value);
return !isNaN(numValue) && targets.some((t)=>numValue < parseFloat(t));
})
};
const toLowerCase = (v)=>v.toLowerCase();
const NEGATIVE_OPERATORS = new Set([

@@ -74,3 +57,3 @@ 'is_not',

if ((0, core_namespaceObject.isUndefined)(propertyValue) || (0, core_namespaceObject.isNull)(propertyValue)) return NEGATIVE_OPERATORS.has(operator);
const comparisonFunction = propertyComparisons[operator];
const comparisonFunction = surveys_namespaceObject.propertyComparisons[operator];
if (!comparisonFunction) return false;

@@ -87,15 +70,2 @@ if ((0, core_namespaceObject.isUndefined)(filter.value) || (0, core_namespaceObject.isNull)(filter.value)) return false;

}
function matchPropertyFilters(propertyFilters, eventProperties) {
if (!propertyFilters) return true;
return Object.entries(propertyFilters).every(([propertyName, filter])=>{
const eventPropertyValue = eventProperties?.[propertyName];
if ((0, core_namespaceObject.isUndefined)(eventPropertyValue) || (0, core_namespaceObject.isNull)(eventPropertyValue)) return false;
const eventValues = [
String(eventPropertyValue)
];
const comparisonFunction = propertyComparisons[filter.operator];
if (!comparisonFunction) return false;
return comparisonFunction(filter.values, eventValues);
});
}
exports.getPersonPropertiesHash = __webpack_exports__.getPersonPropertiesHash;

@@ -102,0 +72,0 @@ exports.matchPropertyFilters = __webpack_exports__.matchPropertyFilters;

import { isArray, isNull, isUndefined } from "@posthog/core";
import { matchPropertyFilters, propertyComparisons } from "@posthog/core/surveys";
import { jsonStringify } from "./request-utils.mjs";
import { isMatchingRegex } from "./regex-utils.mjs";
function getPersonPropertiesHash(distinct_id, userPropertiesToSet, userPropertiesToSetOnce) {

@@ -11,19 +11,2 @@ return jsonStringify({

}
const propertyComparisons = {
exact: (targets, values)=>values.some((value)=>targets.some((target)=>value === target)),
is_not: (targets, values)=>values.every((value)=>targets.every((target)=>value !== target)),
regex: (targets, values)=>values.some((value)=>targets.some((target)=>isMatchingRegex(value, target))),
not_regex: (targets, values)=>values.every((value)=>targets.every((target)=>!isMatchingRegex(value, target))),
icontains: (targets, values)=>values.map(toLowerCase).some((value)=>targets.map(toLowerCase).some((target)=>value.includes(target))),
not_icontains: (targets, values)=>values.map(toLowerCase).every((value)=>targets.map(toLowerCase).every((target)=>!value.includes(target))),
gt: (targets, values)=>values.some((value)=>{
const numValue = parseFloat(value);
return !isNaN(numValue) && targets.some((t)=>numValue > parseFloat(t));
}),
lt: (targets, values)=>values.some((value)=>{
const numValue = parseFloat(value);
return !isNaN(numValue) && targets.some((t)=>numValue < parseFloat(t));
})
};
const toLowerCase = (v)=>v.toLowerCase();
const NEGATIVE_OPERATORS = new Set([

@@ -53,15 +36,2 @@ 'is_not',

}
function matchPropertyFilters(propertyFilters, eventProperties) {
if (!propertyFilters) return true;
return Object.entries(propertyFilters).every(([propertyName, filter])=>{
const eventPropertyValue = eventProperties?.[propertyName];
if (isUndefined(eventPropertyValue) || isNull(eventPropertyValue)) return false;
const eventValues = [
String(eventPropertyValue)
];
const comparisonFunction = propertyComparisons[filter.operator];
if (!comparisonFunction) return false;
return comparisonFunction(filter.values, eventValues);
});
}
export { getPersonPropertiesHash, matchPropertyFilters, matchTriggerPropertyFilters, propertyComparisons };

@@ -1,2 +0,1 @@

export declare const isValidRegex: (str: string) => boolean;
export declare const isMatchingRegex: (value: string, pattern: string) => boolean;
export { isMatchingRegex, isValidRegex } from '@posthog/core/surveys';

@@ -27,21 +27,6 @@ "use strict";

__webpack_require__.d(__webpack_exports__, {
isMatchingRegex: ()=>isMatchingRegex,
isValidRegex: ()=>isValidRegex
isMatchingRegex: ()=>surveys_namespaceObject.isMatchingRegex,
isValidRegex: ()=>surveys_namespaceObject.isValidRegex
});
const isValidRegex = function(str) {
try {
new RegExp(str);
} catch {
return false;
}
return true;
};
const isMatchingRegex = function(value, pattern) {
if (!isValidRegex(pattern)) return false;
try {
return new RegExp(pattern).test(value);
} catch {
return false;
}
};
const surveys_namespaceObject = require("@posthog/core/surveys");
exports.isMatchingRegex = __webpack_exports__.isMatchingRegex;

@@ -48,0 +33,0 @@ exports.isValidRegex = __webpack_exports__.isValidRegex;

@@ -1,17 +0,2 @@

const isValidRegex = function(str) {
try {
new RegExp(str);
} catch {
return false;
}
return true;
};
const isMatchingRegex = function(value, pattern) {
if (!isValidRegex(pattern)) return false;
try {
return new RegExp(pattern).test(value);
} catch {
return false;
}
};
import { isMatchingRegex, isValidRegex } from "@posthog/core/surveys";
export { isMatchingRegex, isValidRegex };
{
"name": "@posthog/browser-common",
"version": "0.5.1",
"version": "0.5.2",
"description": "Internal shared browser utilities and extension primitives for PostHog Browser SDKs",

@@ -68,4 +68,4 @@ "license": "MIT",

"dependencies": {
"@posthog/core": "^1.48.10",
"@posthog/types": "^1.405.2"
"@posthog/core": "^1.48.11",
"@posthog/types": "^1.405.3"
},

@@ -72,0 +72,0 @@ "devDependencies": {