@shiva004/surveys 0.8.0 → 0.10.0

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.
@@ -0,0 +1,30 @@
1
+ export interface RecNet {
2
+ at: number;
3
+ method: string;
4
+ url: string;
5
+ status: number;
6
+ ok: boolean;
7
+ ms: number;
8
+ body?: string;
9
+ error?: string;
10
+ }
11
+ export interface RecStore {
12
+ at: number;
13
+ area: 'local' | 'session';
14
+ op: 'set' | 'remove' | 'clear';
15
+ key?: string;
16
+ value?: string;
17
+ }
18
+ export interface RecForm {
19
+ at: number;
20
+ form: string;
21
+ method: string;
22
+ action: string;
23
+ fields: Record<string, string>;
24
+ }
25
+ export interface CaptureSink {
26
+ net: RecNet[];
27
+ storage: RecStore[];
28
+ forms: RecForm[];
29
+ }
30
+ export declare function startCapture(now: () => number, sink: CaptureSink): () => void;
@@ -0,0 +1,6 @@
1
+ import type { RecMeta } from './recorder';
2
+ export declare function listMeta(): Promise<RecMeta[]>;
3
+ export declare function saveRecording(meta: RecMeta, blob: Blob): Promise<void>;
4
+ export declare function getVideo(id: string): Promise<Blob | undefined>;
5
+ export declare function removeRecording(id: string): Promise<void>;
6
+ export declare function clearRecordings(): Promise<void>;
@@ -0,0 +1,45 @@
1
+ import { type Level } from '../logs/data';
2
+ import { type RecForm, type RecNet, type RecStore } from './capture';
3
+ export interface RecLog {
4
+ at: number;
5
+ l: Level;
6
+ m: string;
7
+ src?: string;
8
+ }
9
+ export type { RecForm, RecNet, RecStore };
10
+ export interface RecPage {
11
+ at: number;
12
+ label: string;
13
+ }
14
+ export interface RecMeta {
15
+ id: string;
16
+ name: string;
17
+ startedAt: number;
18
+ durationMs: number;
19
+ size: number;
20
+ mime: string;
21
+ pages: RecPage[];
22
+ logs: RecLog[];
23
+ network?: RecNet[];
24
+ storage?: RecStore[];
25
+ forms?: RecForm[];
26
+ }
27
+ export type RecStatus = 'idle' | 'starting' | 'recording';
28
+ export interface RecSnapshot {
29
+ status: RecStatus;
30
+ elapsedMs: number;
31
+ error: string;
32
+ recordings: RecMeta[];
33
+ loaded: boolean;
34
+ }
35
+ export declare const getRecorderState: () => RecSnapshot;
36
+ export declare const useRecorder: () => RecSnapshot;
37
+ export declare const refreshRecordings: () => Promise<void>;
38
+ export declare const deleteRecording: (id: string) => Promise<void>;
39
+ export declare const deleteAllRecordings: () => Promise<void>;
40
+ /** The app calls this when the visible module / tab changes so the video gets a page marker. */
41
+ export declare const setRecorderPage: (label: string) => void;
42
+ export declare function startRecording(): Promise<void>;
43
+ export declare function stopRecording(): void;
44
+ export declare const start: typeof startRecording;
45
+ export declare const stop: typeof stopRecording;
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ import '../logs/logs.css';
3
+ import './releases.css';
4
+ export interface ReleasesAppProps {
5
+ environment?: string;
6
+ /** Called by the "Open Error Tracking" / "Open Live Events" links in the details panel. */
7
+ onOpenErrors?: () => void;
8
+ onOpenEvents?: () => void;
9
+ }
10
+ export declare const ReleasesApp: React.FC<ReleasesAppProps>;
@@ -0,0 +1,107 @@
1
+ import { type Issue } from '../errortracking/data';
2
+ import { type LinkStatus } from '../store';
3
+ export type ReleaseStatus = 'deployed' | 'rolled_back';
4
+ export declare const RELEASE_STATUSES: ReleaseStatus[];
5
+ export type Health = 'new' | 'healthy' | 'degraded' | 'unhealthy';
6
+ /** What was recorded while the release was live. */
7
+ export interface ReleaseStats {
8
+ /** Events ingested (page views, clicks, API calls, logs ...), without the release_* markers themselves. */
9
+ events: number;
10
+ /** js_error, unhandled_rejection, log_error and failed API calls (network error or 5xx). */
11
+ errors: number;
12
+ /** log_warn events. */
13
+ warnings: number;
14
+ requests: number;
15
+ failedRequests: number;
16
+ }
17
+ export interface ReleaseError {
18
+ ts: number;
19
+ name: string;
20
+ message: string;
21
+ page: string;
22
+ traceId?: string;
23
+ }
24
+ export interface Release {
25
+ id: string;
26
+ version: string;
27
+ environment: string;
28
+ deployedAt: number;
29
+ status: ReleaseStatus;
30
+ rolledBackAt?: number;
31
+ notes?: string;
32
+ commit?: string;
33
+ author?: string;
34
+ stats: ReleaseStats;
35
+ /** Latest errors seen while this release was live, newest first (this browser only). */
36
+ recent: ReleaseError[];
37
+ /** True for releases loaded from your backend. */
38
+ remote?: boolean;
39
+ /** Issues first seen on this release, when the backend reports them. */
40
+ newIssues?: number;
41
+ }
42
+ export interface ReleaseInput {
43
+ version: string;
44
+ environment?: string;
45
+ notes?: string;
46
+ commit?: string;
47
+ author?: string;
48
+ ts?: number;
49
+ }
50
+ export interface ReleasesConfig {
51
+ /** Version of this running app. Default: VITE_APP_RELEASE. It is also stamped on new Error Tracking issues. */
52
+ release?: string;
53
+ environment?: string;
54
+ /** localStorage key. Default "rel_releases_v1". */
55
+ storageKey?: string;
56
+ /** Releases kept in memory. Default 50. */
57
+ max?: number;
58
+ /** Called after every status change (rollback / redeploy), also for releases from your backend. */
59
+ onStatusChange?: (release: Release, status: ReleaseStatus) => void;
60
+ /** Called when a release goes live (first sight of the configured version, trackRelease(), or a new release from your backend). */
61
+ onRelease?: (release: Release) => void;
62
+ }
63
+ export declare const useReleases: () => {
64
+ releases: Release[];
65
+ link: LinkStatus;
66
+ };
67
+ export declare const getReleases: () => Release[];
68
+ export declare const getRelease: (id: string) => Release | undefined;
69
+ export declare const getReleaseEnvironment: (override?: string) => string;
70
+ /** Errors per 100 events. null until the release has seen anything. */
71
+ export declare const errorRate: (s: ReleaseStats) => number | null;
72
+ /** Fewer than 20 events is not enough to judge. Under 1 % errors is healthy, under 5 % degraded. */
73
+ export declare const healthOf: (s: ReleaseStats) => Health;
74
+ /** The release currently live in an environment: the newest one that was not rolled back. */
75
+ export declare const currentOf: (releases: Release[], environment: string) => Release;
76
+ export declare const isCurrent: (releases: Release[], r: Release) => boolean;
77
+ /** The release deployed just before this one in the same environment. */
78
+ export declare const previousOf: (releases: Release[], r: Release) => Release;
79
+ /** Issues Error Tracking stamped with this release version. */
80
+ export declare const issuesOf: (r: Release, issues?: Issue[]) => Issue[];
81
+ export declare const newIssueCount: (r: Release, issues?: Issue[]) => number;
82
+ /** Set once at app start. Every field is optional. */
83
+ export declare const configureReleases: (c?: ReleasesConfig) => void;
84
+ /** Mark a release as deployed now. Events, errors and new issues recorded from here on count against it. Also writes a log line and a `release_deployed` event. */
85
+ export declare const trackRelease: (i: ReleaseInput) => Release | null;
86
+ export declare const setReleaseStatus: (id: string, status: ReleaseStatus) => void;
87
+ export declare const rollBackRelease: (id: string) => void;
88
+ export declare const redeployRelease: (id: string) => void;
89
+ export declare const deleteRelease: (id: string) => void;
90
+ /** Forget the releases recorded in this browser. Releases from your backend stay. */
91
+ export declare const clearReleases: () => void;
92
+ /** Count this app's events against the live release, and register the configured version the first time it is seen. Safe to call twice. */
93
+ export declare const startLocalReleases: () => (() => void);
94
+ /** Turn one release from a backend into a Release. Accepts the usual names (version/tag/name, deployed_at/created_at, sha/commit ...). */
95
+ export declare const toRemoteRelease: (raw: unknown) => Release | null;
96
+ export interface ReleasesConnection {
97
+ /** JSON endpoint: an array of releases, or `{ "releases": [] }`. */
98
+ url: string;
99
+ pollMs?: number;
100
+ headers?: Record<string, string>;
101
+ /** How rollback / redeploy reach your backend. PATCH sends `{ status }` to `url/<id>`; PUT and POST send `{ id, status }` to `url`. Default "none": the backend stays read-only. */
102
+ statusMethod?: 'PATCH' | 'PUT' | 'POST' | 'none';
103
+ }
104
+ /** Load releases from your backend every few seconds. Returns a function that disconnects. */
105
+ export declare const connectReleases: (o: ReleasesConnection) => (() => void);
106
+ /** Pull the backend now (the Refresh button). */
107
+ export declare const refreshReleases: () => void | undefined;
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ import { type Session } from './data';
3
+ import '../logs/logs.css';
4
+ import './sessions.css';
5
+ export interface SessionsAppProps {
6
+ environment?: string;
7
+ /** Called when the user presses Replay. Open your own player here. If omitted a built-in timeline preview plays. */
8
+ onReplay?: (s: Session) => void;
9
+ }
10
+ export declare const SessionsApp: React.FC<SessionsAppProps>;
@@ -0,0 +1,64 @@
1
+ import { type LinkStatus } from '../store';
2
+ export type Device = 'desktop' | 'mobile' | 'tablet';
3
+ export declare const DEVICES: Device[];
4
+ export type SessionEventKind = 'page' | 'click' | 'rage' | 'dead' | 'error' | 'input';
5
+ export interface SessionEvent {
6
+ at: number;
7
+ kind: SessionEventKind;
8
+ text: string;
9
+ }
10
+ export interface Session {
11
+ id: string;
12
+ user: {
13
+ name: string;
14
+ id: string;
15
+ };
16
+ startedAt: number;
17
+ durationSec: number;
18
+ pages: number;
19
+ events: number;
20
+ browser: string;
21
+ os: string;
22
+ device: Device;
23
+ saved: boolean;
24
+ rageClicks: number;
25
+ deadClicks: number;
26
+ errors: number;
27
+ /** Seconds from session start. */
28
+ timeline: SessionEvent[];
29
+ }
30
+ export interface SessionsConfig {
31
+ environment?: string;
32
+ /** Called when the user presses Refresh instead of re-polling the connected API. */
33
+ onRefresh?: () => void;
34
+ onChange?: (sessions: Session[]) => void;
35
+ }
36
+ interface State {
37
+ local: Session | null;
38
+ remote: Session[];
39
+ list: Session[];
40
+ link: LinkStatus;
41
+ at: number;
42
+ }
43
+ export declare const configureSessions: (c?: SessionsConfig) => void;
44
+ export declare const getSessionsEnvironment: (override?: string) => string;
45
+ export declare const useSessions: () => Session[];
46
+ /** Connection status and the time of the last update. */
47
+ export declare const useSessionsStatus: () => State;
48
+ /** Replace the sessions that come from your backend. The local browser session is kept. */
49
+ export declare const setSessions: (remote: Session[]) => void;
50
+ /** Build this browser's session from captured events (including those already captured). Safe to call twice. */
51
+ export declare const startLocalSession: () => (() => void);
52
+ /** Turn one JSON object from a backend into a Session (camelCase or snake_case fields). Returns null without an id. */
53
+ export declare const toSession: (raw: unknown) => Session | null;
54
+ export interface SessionsConnection {
55
+ url: string;
56
+ headers?: Record<string, string>;
57
+ pollMs?: number;
58
+ }
59
+ /** Load real sessions from your backend (JSON array, or { sessions: [] }) now and every pollMs. Returns a function that disconnects. */
60
+ export declare const connectSessions: (o: SessionsConnection) => (() => void);
61
+ export declare const refreshSessions: () => void;
62
+ export declare const toggleSaved: (id: string) => void;
63
+ export declare const deleteSession: (id: string) => void;
64
+ export {};
@@ -0,0 +1,43 @@
1
+ /** Tiny external store. Replaces the listeners / subscribe / useSyncExternalStore code each module used to repeat. */
2
+ export declare const createStore: <T>(initial: T) => {
3
+ get: () => T;
4
+ set: (next: T | ((prev: T) => T)) => void;
5
+ subscribe: (cb: () => void) => () => void;
6
+ use: <S = T>(select?: (s: T) => S) => S;
7
+ };
8
+ export type LinkState = 'off' | 'connecting' | 'live' | 'error';
9
+ export interface LinkStatus {
10
+ state: LinkState;
11
+ at: number;
12
+ error: string;
13
+ url: string;
14
+ }
15
+ export declare const LINK_OFF: LinkStatus;
16
+ export interface Poller {
17
+ stop: () => void;
18
+ refresh: () => void;
19
+ }
20
+ export interface PollOptions {
21
+ url: string;
22
+ headers?: Record<string, string>;
23
+ pollMs?: number;
24
+ onData: (body: unknown) => void;
25
+ onStatus: (s: LinkStatus) => void;
26
+ }
27
+ /** GET a JSON endpoint now and then every pollMs (0 = once). */
28
+ export declare const pollJson: ({ url, headers, pollMs, onData, onStatus }: PollOptions) => Poller;
29
+ /** WebSocket (ws:// wss://) or Server-Sent Events (http:// https://). Reconnects with backoff. Each message is JSON-parsed when possible. */
30
+ export declare const openStream: (url: string, onMessage: (data: unknown) => void, onStatus: (s: LinkStatus) => void) => (() => void);
31
+ export declare const isObj: (v: unknown) => v is Record<string, unknown>;
32
+ export declare const num: (v: unknown, fallback?: number) => number;
33
+ export declare const str: (v: unknown, fallback?: string) => string;
34
+ /** Epoch ms from a number (seconds or ms) or an ISO string. */
35
+ export declare const toMs: (v: unknown, fallback?: number) => number;
36
+ /** First value present under any of these keys (for APIs that name the same field differently). */
37
+ export declare const pick: (o: Record<string, unknown>, ...keys: string[]) => {} | undefined;
38
+ /** The array inside a response: the body itself, or body[key]. */
39
+ export declare const listOf: (body: unknown, key: string) => unknown[];
40
+ /** Label under each page title. Defaults to the host the app runs on, or VITE_ENV_NAME. */
41
+ export declare const environmentName: (override?: string) => string;
42
+ export declare const dur: (s: number) => string;
43
+ export declare const fmtStamp: (ts: number) => string;