cfg-kit-posthog
Version:
PostHog plugin for cfg-kit - Define PostHog feature flags as configuration
336 lines (331 loc) • 16.1 kB
TypeScript
import * as cfg_kit from 'cfg-kit';
import { Plugin } from 'cfg-kit';
import { PostHog } from 'posthog-node';
import { z } from 'zod';
declare const PostHogFeatureFlagSchema: z.ZodObject<{
key: z.ZodString;
name: z.ZodString;
description: z.ZodOptional<z.ZodString>;
active: z.ZodDefault<z.ZodBoolean>;
filters: z.ZodDefault<z.ZodObject<{
groups: z.ZodDefault<z.ZodArray<z.ZodObject<{
properties: z.ZodDefault<z.ZodArray<z.ZodObject<{
key: z.ZodString;
operator: z.ZodOptional<z.ZodEnum<["exact", "is_not", "icontains", "not_icontains", "regex", "not_regex", "gt", "gte", "lt", "lte", "is_set", "is_not_set"]>>;
value: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodString, "many">, z.ZodArray<z.ZodNumber, "many">]>>;
type: z.ZodOptional<z.ZodEnum<["person", "event", "element", "static-cohort", "behavioral"]>>;
}, "strip", z.ZodTypeAny, {
key: string;
value?: string | number | boolean | string[] | number[] | undefined;
type?: "person" | "event" | "element" | "static-cohort" | "behavioral" | undefined;
operator?: "exact" | "is_not" | "icontains" | "not_icontains" | "regex" | "not_regex" | "gt" | "gte" | "lt" | "lte" | "is_set" | "is_not_set" | undefined;
}, {
key: string;
value?: string | number | boolean | string[] | number[] | undefined;
type?: "person" | "event" | "element" | "static-cohort" | "behavioral" | undefined;
operator?: "exact" | "is_not" | "icontains" | "not_icontains" | "regex" | "not_regex" | "gt" | "gte" | "lt" | "lte" | "is_set" | "is_not_set" | undefined;
}>, "many">>;
rollout_percentage: z.ZodDefault<z.ZodNumber>;
variant: z.ZodOptional<z.ZodString>;
}, "strip", z.ZodTypeAny, {
properties: {
key: string;
value?: string | number | boolean | string[] | number[] | undefined;
type?: "person" | "event" | "element" | "static-cohort" | "behavioral" | undefined;
operator?: "exact" | "is_not" | "icontains" | "not_icontains" | "regex" | "not_regex" | "gt" | "gte" | "lt" | "lte" | "is_set" | "is_not_set" | undefined;
}[];
rollout_percentage: number;
variant?: string | undefined;
}, {
properties?: {
key: string;
value?: string | number | boolean | string[] | number[] | undefined;
type?: "person" | "event" | "element" | "static-cohort" | "behavioral" | undefined;
operator?: "exact" | "is_not" | "icontains" | "not_icontains" | "regex" | "not_regex" | "gt" | "gte" | "lt" | "lte" | "is_set" | "is_not_set" | undefined;
}[] | undefined;
rollout_percentage?: number | undefined;
variant?: string | undefined;
}>, "many">>;
}, "strip", z.ZodTypeAny, {
groups: {
properties: {
key: string;
value?: string | number | boolean | string[] | number[] | undefined;
type?: "person" | "event" | "element" | "static-cohort" | "behavioral" | undefined;
operator?: "exact" | "is_not" | "icontains" | "not_icontains" | "regex" | "not_regex" | "gt" | "gte" | "lt" | "lte" | "is_set" | "is_not_set" | undefined;
}[];
rollout_percentage: number;
variant?: string | undefined;
}[];
}, {
groups?: {
properties?: {
key: string;
value?: string | number | boolean | string[] | number[] | undefined;
type?: "person" | "event" | "element" | "static-cohort" | "behavioral" | undefined;
operator?: "exact" | "is_not" | "icontains" | "not_icontains" | "regex" | "not_regex" | "gt" | "gte" | "lt" | "lte" | "is_set" | "is_not_set" | undefined;
}[] | undefined;
rollout_percentage?: number | undefined;
variant?: string | undefined;
}[] | undefined;
}>>;
variants: z.ZodOptional<z.ZodArray<z.ZodObject<{
key: z.ZodString;
name: z.ZodOptional<z.ZodString>;
rollout_percentage: z.ZodNumber;
}, "strip", z.ZodTypeAny, {
key: string;
rollout_percentage: number;
name?: string | undefined;
}, {
key: string;
rollout_percentage: number;
name?: string | undefined;
}>, "many">>;
tags: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
}, "strip", z.ZodTypeAny, {
key: string;
name: string;
active: boolean;
filters: {
groups: {
properties: {
key: string;
value?: string | number | boolean | string[] | number[] | undefined;
type?: "person" | "event" | "element" | "static-cohort" | "behavioral" | undefined;
operator?: "exact" | "is_not" | "icontains" | "not_icontains" | "regex" | "not_regex" | "gt" | "gte" | "lt" | "lte" | "is_set" | "is_not_set" | undefined;
}[];
rollout_percentage: number;
variant?: string | undefined;
}[];
};
tags: string[];
description?: string | undefined;
variants?: {
key: string;
rollout_percentage: number;
name?: string | undefined;
}[] | undefined;
}, {
key: string;
name: string;
description?: string | undefined;
active?: boolean | undefined;
filters?: {
groups?: {
properties?: {
key: string;
value?: string | number | boolean | string[] | number[] | undefined;
type?: "person" | "event" | "element" | "static-cohort" | "behavioral" | undefined;
operator?: "exact" | "is_not" | "icontains" | "not_icontains" | "regex" | "not_regex" | "gt" | "gte" | "lt" | "lte" | "is_set" | "is_not_set" | undefined;
}[] | undefined;
rollout_percentage?: number | undefined;
variant?: string | undefined;
}[] | undefined;
} | undefined;
variants?: {
key: string;
rollout_percentage: number;
name?: string | undefined;
}[] | undefined;
tags?: string[] | undefined;
}>;
declare const PostHogConfigSchema: z.ZodObject<{
featureFlags: z.ZodDefault<z.ZodArray<z.ZodObject<{
key: z.ZodString;
name: z.ZodString;
description: z.ZodOptional<z.ZodString>;
active: z.ZodDefault<z.ZodBoolean>;
filters: z.ZodDefault<z.ZodObject<{
groups: z.ZodDefault<z.ZodArray<z.ZodObject<{
properties: z.ZodDefault<z.ZodArray<z.ZodObject<{
key: z.ZodString;
operator: z.ZodOptional<z.ZodEnum<["exact", "is_not", "icontains", "not_icontains", "regex", "not_regex", "gt", "gte", "lt", "lte", "is_set", "is_not_set"]>>;
value: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodString, "many">, z.ZodArray<z.ZodNumber, "many">]>>;
type: z.ZodOptional<z.ZodEnum<["person", "event", "element", "static-cohort", "behavioral"]>>;
}, "strip", z.ZodTypeAny, {
key: string;
value?: string | number | boolean | string[] | number[] | undefined;
type?: "person" | "event" | "element" | "static-cohort" | "behavioral" | undefined;
operator?: "exact" | "is_not" | "icontains" | "not_icontains" | "regex" | "not_regex" | "gt" | "gte" | "lt" | "lte" | "is_set" | "is_not_set" | undefined;
}, {
key: string;
value?: string | number | boolean | string[] | number[] | undefined;
type?: "person" | "event" | "element" | "static-cohort" | "behavioral" | undefined;
operator?: "exact" | "is_not" | "icontains" | "not_icontains" | "regex" | "not_regex" | "gt" | "gte" | "lt" | "lte" | "is_set" | "is_not_set" | undefined;
}>, "many">>;
rollout_percentage: z.ZodDefault<z.ZodNumber>;
variant: z.ZodOptional<z.ZodString>;
}, "strip", z.ZodTypeAny, {
properties: {
key: string;
value?: string | number | boolean | string[] | number[] | undefined;
type?: "person" | "event" | "element" | "static-cohort" | "behavioral" | undefined;
operator?: "exact" | "is_not" | "icontains" | "not_icontains" | "regex" | "not_regex" | "gt" | "gte" | "lt" | "lte" | "is_set" | "is_not_set" | undefined;
}[];
rollout_percentage: number;
variant?: string | undefined;
}, {
properties?: {
key: string;
value?: string | number | boolean | string[] | number[] | undefined;
type?: "person" | "event" | "element" | "static-cohort" | "behavioral" | undefined;
operator?: "exact" | "is_not" | "icontains" | "not_icontains" | "regex" | "not_regex" | "gt" | "gte" | "lt" | "lte" | "is_set" | "is_not_set" | undefined;
}[] | undefined;
rollout_percentage?: number | undefined;
variant?: string | undefined;
}>, "many">>;
}, "strip", z.ZodTypeAny, {
groups: {
properties: {
key: string;
value?: string | number | boolean | string[] | number[] | undefined;
type?: "person" | "event" | "element" | "static-cohort" | "behavioral" | undefined;
operator?: "exact" | "is_not" | "icontains" | "not_icontains" | "regex" | "not_regex" | "gt" | "gte" | "lt" | "lte" | "is_set" | "is_not_set" | undefined;
}[];
rollout_percentage: number;
variant?: string | undefined;
}[];
}, {
groups?: {
properties?: {
key: string;
value?: string | number | boolean | string[] | number[] | undefined;
type?: "person" | "event" | "element" | "static-cohort" | "behavioral" | undefined;
operator?: "exact" | "is_not" | "icontains" | "not_icontains" | "regex" | "not_regex" | "gt" | "gte" | "lt" | "lte" | "is_set" | "is_not_set" | undefined;
}[] | undefined;
rollout_percentage?: number | undefined;
variant?: string | undefined;
}[] | undefined;
}>>;
variants: z.ZodOptional<z.ZodArray<z.ZodObject<{
key: z.ZodString;
name: z.ZodOptional<z.ZodString>;
rollout_percentage: z.ZodNumber;
}, "strip", z.ZodTypeAny, {
key: string;
rollout_percentage: number;
name?: string | undefined;
}, {
key: string;
rollout_percentage: number;
name?: string | undefined;
}>, "many">>;
tags: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
}, "strip", z.ZodTypeAny, {
key: string;
name: string;
active: boolean;
filters: {
groups: {
properties: {
key: string;
value?: string | number | boolean | string[] | number[] | undefined;
type?: "person" | "event" | "element" | "static-cohort" | "behavioral" | undefined;
operator?: "exact" | "is_not" | "icontains" | "not_icontains" | "regex" | "not_regex" | "gt" | "gte" | "lt" | "lte" | "is_set" | "is_not_set" | undefined;
}[];
rollout_percentage: number;
variant?: string | undefined;
}[];
};
tags: string[];
description?: string | undefined;
variants?: {
key: string;
rollout_percentage: number;
name?: string | undefined;
}[] | undefined;
}, {
key: string;
name: string;
description?: string | undefined;
active?: boolean | undefined;
filters?: {
groups?: {
properties?: {
key: string;
value?: string | number | boolean | string[] | number[] | undefined;
type?: "person" | "event" | "element" | "static-cohort" | "behavioral" | undefined;
operator?: "exact" | "is_not" | "icontains" | "not_icontains" | "regex" | "not_regex" | "gt" | "gte" | "lt" | "lte" | "is_set" | "is_not_set" | undefined;
}[] | undefined;
rollout_percentage?: number | undefined;
variant?: string | undefined;
}[] | undefined;
} | undefined;
variants?: {
key: string;
rollout_percentage: number;
name?: string | undefined;
}[] | undefined;
tags?: string[] | undefined;
}>, "many">>;
}, "strip", z.ZodTypeAny, {
featureFlags: {
key: string;
name: string;
active: boolean;
filters: {
groups: {
properties: {
key: string;
value?: string | number | boolean | string[] | number[] | undefined;
type?: "person" | "event" | "element" | "static-cohort" | "behavioral" | undefined;
operator?: "exact" | "is_not" | "icontains" | "not_icontains" | "regex" | "not_regex" | "gt" | "gte" | "lt" | "lte" | "is_set" | "is_not_set" | undefined;
}[];
rollout_percentage: number;
variant?: string | undefined;
}[];
};
tags: string[];
description?: string | undefined;
variants?: {
key: string;
rollout_percentage: number;
name?: string | undefined;
}[] | undefined;
}[];
}, {
featureFlags?: {
key: string;
name: string;
description?: string | undefined;
active?: boolean | undefined;
filters?: {
groups?: {
properties?: {
key: string;
value?: string | number | boolean | string[] | number[] | undefined;
type?: "person" | "event" | "element" | "static-cohort" | "behavioral" | undefined;
operator?: "exact" | "is_not" | "icontains" | "not_icontains" | "regex" | "not_regex" | "gt" | "gte" | "lt" | "lte" | "is_set" | "is_not_set" | undefined;
}[] | undefined;
rollout_percentage?: number | undefined;
variant?: string | undefined;
}[] | undefined;
} | undefined;
variants?: {
key: string;
rollout_percentage: number;
name?: string | undefined;
}[] | undefined;
tags?: string[] | undefined;
}[] | undefined;
}>;
type PostHogFeatureFlag = z.infer<typeof PostHogFeatureFlagSchema>;
type PostHogConfig = z.infer<typeof PostHogConfigSchema>;
interface PostHogPluginOptions {
posthog?: PostHog;
apiKey: string;
host?: string;
projectId: string;
}
type PostHogPluginConfig = z.infer<typeof PostHogConfigSchema>;
declare class PostHogPlugin extends Plugin {
private posthog;
private config;
private projectId;
constructor(config: PostHogPluginConfig, options: PostHogPluginOptions);
build(): Promise<cfg_kit.PluginConfig>;
}
declare function definePostHogFeatureFlag(featureFlag: PostHogFeatureFlag): PostHogFeatureFlag;
declare function definePostHogConfig(config: PostHogConfig): PostHogConfig;
export { type PostHogConfig, PostHogConfigSchema, type PostHogFeatureFlag, PostHogFeatureFlagSchema, PostHogPlugin, type PostHogPluginOptions, PostHogPlugin as default, definePostHogConfig, definePostHogFeatureFlag };