Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

posthog-node

Package Overview
Dependencies
Maintainers
6
Versions
67
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

posthog-node - npm Package Compare versions

Comparing version 2.1.0 to 2.2.0

5

CHANGELOG.md

@@ -0,1 +1,6 @@

# 2.2.0 - 2022-11-18
1. Add support for variant overrides for feature flag local evaluation.
2. Add support for date operators in feature flag local evaluation.
# 2.1.0 - 2022-09-08

@@ -2,0 +7,0 @@

@@ -9,2 +9,7 @@ /// <reference types="node" />

preloadFeatureFlags?: boolean;
bootstrap?: {
distinctId?: string;
isIdentifiedId?: boolean;
featureFlags?: Record<string, boolean | string>;
};
fetchRetryCount?: number;

@@ -11,0 +16,0 @@ fetchRetryDelay?: number;

2

lib/posthog-core/src/index.d.ts

@@ -29,2 +29,3 @@ import { PostHogFetchOptions, PostHogFetchResponse, PostHogAutocaptureElement, PostHogDecideResponse, PosthogCoreOptions, PostHogEventProperties, PostHogPersistedProperty } from './types';

protected getCommonEventProperties(): any;
protected setupBootstrap(options?: Partial<PosthogCoreOptions>): void;
private get props();

@@ -80,2 +81,3 @@ private set props(value);

private _decideAsync;
private setKnownFeatureFlags;
getFeatureFlag(key: string): boolean | string | undefined;

@@ -82,0 +84,0 @@ getFeatureFlags(): PostHogDecideResponse['featureFlags'] | undefined;

@@ -9,2 +9,7 @@ /// <reference types="node" />

preloadFeatureFlags?: boolean;
bootstrap?: {
distinctId?: string;
isIdentifiedId?: boolean;
featureFlags?: Record<string, boolean | string>;
};
fetchRetryCount?: number;

@@ -11,0 +16,0 @@ fetchRetryDelay?: number;

@@ -23,2 +23,3 @@ export interface IdentifyMessageV1 {

rollout_percentage?: number;
variant?: string;
};

@@ -25,0 +26,0 @@ export declare type PostHogFeatureFlag = {

4

package.json
{
"name": "posthog-node",
"version": "2.1.0",
"version": "2.2.0",
"description": "PostHog Node.js integration",
"repository": "PostHog/posthog-node",
"scripts": {
"prepublish": "cd .. && yarn build"
"prepublishOnly": "cd .. && yarn build"
},

@@ -9,0 +9,0 @@ "engines": {

@@ -193,6 +193,30 @@ import { createHash } from 'crypto'

flagConditions.forEach((condition) => {
// # Stable sort conditions with variant overrides to the top. This ensures that if overrides are present, they are
// # evaluated first, and the variant override is applied to the first matching condition.
const sortedFlagConditions = [...flagConditions].sort((conditionA, conditionB) => {
const AHasVariantOverride = !!conditionA.variant
const BHasVariantOverride = !!conditionB.variant
if (AHasVariantOverride && BHasVariantOverride) {
return 0
} else if (AHasVariantOverride) {
return -1
} else if (BHasVariantOverride) {
return 1
} else {
return 0
}
})
for (const condition of sortedFlagConditions) {
try {
if (this.isConditionMatch(flag, distinctId, condition, properties)) {
result = this.getMatchingVariant(flag, distinctId) || true
const variantOverride = condition.variant
const flagVariants = flagFilters.multivariate?.variants || []
if (variantOverride && flagVariants.some((variant) => variant.key === variantOverride)) {
result = variantOverride
} else {
result = this.getMatchingVariant(flag, distinctId) || true
}
break
}

@@ -206,3 +230,3 @@ } catch (e) {

}
})
}

@@ -399,2 +423,10 @@ if (result !== undefined) {

return typeof overrideValue == typeof value && overrideValue <= value
case 'is_date_after':
case 'is_date_before':
const parsedDate = convertToDateTime(value)
const overrideDate = convertToDateTime(overrideValue)
if (operator === 'is_date_before') {
return overrideDate < parsedDate
}
return overrideDate > parsedDate
default:

@@ -415,2 +447,16 @@ console.error(`Unknown operator: ${operator}`)

function convertToDateTime(value: string | number | (string | number)[] | Date): Date {
if (value instanceof Date) {
return value
} else if (typeof value === 'string' || typeof value === 'number') {
const date = new Date(value)
if (!isNaN(date.valueOf())) {
return date
}
throw new InconclusiveMatchError(`${value} is in an invalid date format`)
} else {
throw new InconclusiveMatchError(`The date provided ${value} must be a string, number, or date object`)
}
}
export { FeatureFlagsPoller, matchProperty, InconclusiveMatchError, ClientError }

@@ -26,2 +26,3 @@ export interface IdentifyMessageV1 {

rollout_percentage?: number
variant?: string
}

@@ -28,0 +29,0 @@

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc