@shiva004/surveys 0.11.1 → 0.11.3

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.
@@ -1,129 +0,0 @@
1
- export type ExperimentStatus = 'draft' | 'running' | 'paused' | 'completed';
2
- export declare const EXPERIMENT_STATUSES: ExperimentStatus[];
3
- export interface Variant {
4
- key: string;
5
- name: string;
6
- weight: number;
7
- }
8
- export interface Assignment {
9
- variant: string;
10
- at: number;
11
- converted: boolean;
12
- value: number;
13
- convertedAt?: number;
14
- }
15
- export interface Experiment {
16
- id: string;
17
- key: string;
18
- name: string;
19
- hypothesis?: string;
20
- status: ExperimentStatus;
21
- /** First variant is the control. Weights add up to 100. */
22
- variants: Variant[];
23
- /** Name of the event that counts as a conversion. */
24
- goal: string;
25
- /** Percent of users that take part (the rest get null from getVariant and see your default). */
26
- traffic: number;
27
- createdAt: number;
28
- startedAt?: number;
29
- endedAt?: number;
30
- /** Variant shipped to everyone once the experiment is completed. */
31
- winner?: string;
32
- /** user id -> what that user saw and did. */
33
- assigned: Record<string, Assignment>;
34
- }
35
- export interface ExperimentInput {
36
- key: string;
37
- name: string;
38
- hypothesis?: string;
39
- goal: string;
40
- traffic?: number;
41
- /** Default: control 50 / treatment 50. */
42
- variants?: {
43
- key: string;
44
- name?: string;
45
- weight: number;
46
- }[];
47
- }
48
- export interface ExperimentsConfig {
49
- /** localStorage key. Default "exp_experiments_v1". */
50
- storageKey?: string;
51
- /** Who is the current user. Default: the id of Live Events (identify()). */
52
- userId?: () => string;
53
- /** Users needed in every variant before a verdict is given. Default 100. */
54
- minSample?: number;
55
- /** Confidence for the significance test. Default 0.95. */
56
- confidence?: number;
57
- /** Users kept per experiment. Beyond it users still get a variant but are not counted. Default 5000. */
58
- maxUsers?: number;
59
- onExposure?: (e: Experiment, variant: string, userId: string) => void;
60
- onConversion?: (e: Experiment, variant: string, userId: string, value: number) => void;
61
- onStatusChange?: (e: Experiment, status: ExperimentStatus) => void;
62
- }
63
- export type Outcome<T> = {
64
- ok: true;
65
- value: T;
66
- } | {
67
- ok: false;
68
- error: string;
69
- };
70
- export declare const EXPERIMENT_KEY_RE: RegExp;
71
- export declare const VARIANT_KEY_RE: RegExp;
72
- export declare const useExperiments: () => {
73
- experiments: Experiment[];
74
- };
75
- export declare const getExperiments: () => Experiment[];
76
- export declare const getExperiment: (key: string) => Experiment | undefined;
77
- export declare const configureExperiments: (c: ExperimentsConfig) => void;
78
- /** A stable number in [0, 100) for this experiment, user and purpose. */
79
- export declare const experimentBucket: (key: string, userId: string, salt: "traffic" | "variant") => number;
80
- /** Which variant would this user get? Records nothing, safe to call while rendering. */
81
- export declare const peekVariant: (key: string, userId?: string) => string | null;
82
- /** The variant for this user. The first call per user also records the exposure. Returns null when the user is not in the experiment. */
83
- export declare const getVariant: (key: string, userId?: string) => string | null;
84
- /** React hook: the variant for the current user, recording the exposure after render. */
85
- export declare const useVariant: (key: string, userId?: string) => string | null;
86
- /** Count a conversion for a user who saw the experiment. A user converts once; later calls only add to the value (revenue). */
87
- export declare const trackConversion: (key: string, value?: number, userId?: string) => boolean;
88
- /** Turns events named like an experiment's goal into conversions. Call once at start-up. Returns a stop function. */
89
- export declare const startLocalExperiments: () => (() => void);
90
- export declare const createExperiment: (input: ExperimentInput) => Outcome<Experiment>;
91
- export declare const startExperiment: (key: string) => boolean;
92
- export declare const pauseExperiment: (key: string) => boolean;
93
- /** Ends the experiment. With a winner, getVariant() returns that variant to everyone from now on (ship it). */
94
- export declare const stopExperiment: (key: string, winner?: string) => boolean;
95
- /** Forget every user and conversion. Only for a draft or paused experiment. */
96
- export declare const resetExperimentResults: (key: string) => boolean;
97
- export declare const deleteExperiment: (key: string) => void;
98
- export declare const clearExperiments: () => void;
99
- /** Two-sided p-value of "these two conversion rates are really different" (pooled two-proportion z-test). null when it cannot be computed. */
100
- export declare const twoProportionP: (c1: number, n1: number, c2: number, n2: number) => number | null;
101
- export interface VariantResult {
102
- key: string;
103
- name: string;
104
- control: boolean;
105
- weight: number;
106
- exposures: number;
107
- conversions: number;
108
- value: number;
109
- /** Conversions per exposed user, 0 to 1. null before the first exposure. */
110
- rate: number | null;
111
- /** Relative change of the rate against the control, 0.1 = 10 % better. null for the control or without data. */
112
- lift: number | null;
113
- pValue: number | null;
114
- /** The difference to the control is real (p below 1 - confidence, corrected for the number of variants). */
115
- significant: boolean;
116
- }
117
- export type Verdict = 'no_data' | 'collecting' | 'winner' | 'control_better' | 'inconclusive';
118
- export interface ExperimentResults {
119
- variants: VariantResult[];
120
- exposures: number;
121
- conversions: number;
122
- verdict: Verdict;
123
- /** The variant the data supports shipping, when the verdict is winner / control_better. */
124
- suggested?: string;
125
- message: string;
126
- /** Users still missing in the smallest variant before a verdict. */
127
- missing: number;
128
- }
129
- export declare const resultsOf: (e: Experiment) => ExperimentResults;
@@ -1,8 +0,0 @@
1
- import React from 'react';
2
- import '../logs/logs.css';
3
- import './monitoring.css';
4
- export interface MonitoringAppProps {
5
- /** Called by the "Open Live Logs" link in the details panel. */
6
- onOpenLogs?: () => void;
7
- }
8
- export declare const MonitoringApp: React.FC<MonitoringAppProps>;
@@ -1,108 +0,0 @@
1
- export type CheckMethod = 'GET' | 'HEAD';
2
- export type CheckMode = 'cors' | 'no-cors';
3
- export type CheckStatus = 'unknown' | 'up' | 'degraded' | 'down' | 'paused';
4
- export interface CheckResult {
5
- ts: number;
6
- ok: boolean;
7
- /** HTTP status. null for a "no-cors" check (opaque answer) or when nothing came back. */
8
- status: number | null;
9
- /** Time until the response headers arrived. */
10
- latencyMs: number;
11
- /** Answered, but slower than the check's maxLatencyMs. */
12
- slow?: boolean;
13
- error?: string;
14
- }
15
- export interface Check {
16
- id: string;
17
- name: string;
18
- url: string;
19
- method: CheckMethod;
20
- mode: CheckMode;
21
- intervalSec: number;
22
- timeoutMs: number;
23
- /** Exact status that counts as healthy. null: any 2xx. */
24
- expectStatus: number | null;
25
- /** Slower than this is "degraded". null: no limit. */
26
- maxLatencyMs: number | null;
27
- /** The body must contain this text (GET and "cors" only). */
28
- contains?: string;
29
- enabled: boolean;
30
- createdAt: number;
31
- /** Newest first. */
32
- results: CheckResult[];
33
- /** Failures in a row. */
34
- failures: number;
35
- }
36
- export interface Incident {
37
- id: string;
38
- checkId: string;
39
- checkName: string;
40
- url: string;
41
- startedAt: number;
42
- resolvedAt?: number;
43
- reason: string;
44
- }
45
- export interface CheckInput {
46
- name: string;
47
- url: string;
48
- method?: CheckMethod;
49
- mode?: CheckMode;
50
- intervalSec?: number;
51
- timeoutMs?: number;
52
- expectStatus?: number | null;
53
- maxLatencyMs?: number | null;
54
- contains?: string;
55
- enabled?: boolean;
56
- }
57
- export interface MonitoringConfig {
58
- /** localStorage key. Default "mon_checks_v1". */
59
- storageKey?: string;
60
- /** Results kept per check. Default 100. */
61
- maxResults?: number;
62
- /** Failures in a row before an incident opens. Default 2. */
63
- failAfter?: number;
64
- onResult?: (c: Check, r: CheckResult) => void;
65
- onDown?: (c: Check, i: Incident) => void;
66
- onRecover?: (c: Check, i: Incident) => void;
67
- }
68
- export type Outcome<T> = {
69
- ok: true;
70
- value: T;
71
- } | {
72
- ok: false;
73
- error: string;
74
- };
75
- export declare const useMonitoring: () => {
76
- checks: Check[];
77
- incidents: Incident[];
78
- online: boolean;
79
- };
80
- export declare const getChecks: () => Check[];
81
- export declare const getCheck: (id: string) => Check | undefined;
82
- export declare const getIncidents: () => Incident[];
83
- export declare const configureMonitoring: (c: MonitoringConfig) => void;
84
- export declare const statusOf: (c: Check) => CheckStatus;
85
- export interface CheckStats {
86
- total: number;
87
- uptime: number | null;
88
- avgMs: number | null;
89
- p95Ms: number | null;
90
- last?: CheckResult;
91
- }
92
- /** Uptime and latency over the results kept for this check. Latency counts only answered requests. */
93
- export declare const statsOf: (c: Check) => CheckStats;
94
- export declare const openIncident: (checkId: string) => Incident | undefined;
95
- export type ProbeOptions = Pick<Check, 'url'> & Partial<Pick<Check, 'method' | 'mode' | 'timeoutMs' | 'expectStatus' | 'maxLatencyMs' | 'contains'>>;
96
- /** One request, no store involved. Uses the browser's own fetch, so it is not counted as app traffic by Live Events, Rate Limit or Mock API. */
97
- export declare const probe: (o: ProbeOptions) => Promise<CheckResult>;
98
- /** Run one check now and record the result. Returns null when the check does not exist or is already running. */
99
- export declare const runCheck: (id: string) => Promise<CheckResult | null>;
100
- export declare const runAllChecks: () => Promise<(CheckResult | null)[]>;
101
- export declare const addCheck: (input: CheckInput) => Outcome<Check>;
102
- export declare const updateCheck: (id: string, input: CheckInput) => Outcome<Check>;
103
- export declare const toggleCheck: (id: string) => void;
104
- export declare const removeCheck: (id: string) => void;
105
- export declare const clearCheckHistory: (id: string) => void;
106
- export declare const clearChecks: () => void;
107
- /** Runs every enabled check at its interval while the page is open, and tracks the browser's online state. Call once at start-up. Returns a stop function. */
108
- export declare const startLocalMonitoring: () => (() => void);