@shiva004/surveys 0.5.0 → 0.7.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.
package/LICENSE ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 shiva004
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Logs + Feedback POC
2
2
 
3
- Standalone proof of concept with two modules: a **Log Viewer** (with a guided tour) and a **Feedback** popup (4-step star-rating survey preview). All data is mock and lives in memory.
3
+ Standalone proof of concept with two modules: a **Log Viewer** (with a guided tour) and a **Feedback** popup (4-step star-rating survey that opens automatically). All data is mock and lives in memory.
4
4
 
5
5
  ## Use as a package
6
6
 
@@ -20,6 +20,14 @@ export default function Page() {
20
20
  `LogsApp` accepts `autoStart` (default `true`) to open the tutorial once on first load.
21
21
  `LogsFeedbackApp` renders both modules behind tabs.
22
22
 
23
+ `FeedbackApp` opens its popup automatically on mount (no button). The popup header and footer stay pinned, and the middle scrolls on short screens. Props:
24
+
25
+ | Prop | Default | Description |
26
+ | --- | --- | --- |
27
+ | `autoOpen` | `true` | Open the popup when the component mounts |
28
+ | `onClose` | – | Called after the popup is closed (X, Cancel, Done, Esc, backdrop) |
29
+ | `onSubmit` | – | Called with `{ rating, topics, otherTopic, comment, email, contactOk, submittedAt }` when the person submits |
30
+
23
31
  ### Walkthrough tour + analytics
24
32
 
25
33
  ```tsx
@@ -40,3 +48,122 @@ npm run build # production build + type declarations
40
48
 
41
49
  - Removed: Survey and User Journey modules (`SurveyApp`, `JourneyApp`, `SurveyJourneyApp`, NPS helpers, journey analytics, types, `UserJourneyDocs`).
42
50
  - Added: `LogsApp`, `FeedbackApp`, `LogsFeedbackApp`.
51
+
52
+ ## What changed in 0.7.0
53
+
54
+ - New **Live Events** page (`IngestionApp`): real-time event ingestion from your own app (throughput, success rate, ack latency, by-source bars, live table with filters and payload details).
55
+ - New pipeline in `events/`: `trackEvent`, queue + batching, retries with backoff, client rate limit, optional HTTP `endpoint` or custom `transport`.
56
+ - Auto-capture: page views, clicks, JS errors, `fetch` calls, tab visibility, and logger lines (`log_error`, `log_warn`).
57
+ - New exports: `startEventCapture`, `trackEvent`, `ingestRemote`, `identify`, `configureIngestion`, `useIngestion`, `getIngestionSnapshot`.
58
+ - New "Live Events" tab in `LogsFeedbackApp`.
59
+
60
+ ```tsx
61
+ import { startEventCapture, trackEvent, identify, ingestRemote, IngestionApp } from '@shiva004/surveys';
62
+ import '@shiva004/surveys/style.css';
63
+
64
+ // once, at your app root (local in-app sink by default)
65
+ startEventCapture({
66
+ // endpoint: 'https://api.yourapp.com/events', // POST { events: [...] }
67
+ // headers: { Authorization: 'Bearer ...' },
68
+ // capture: { logs: { levels: ['ERROR', 'WARN', 'INFO'] } },
69
+ });
70
+
71
+ trackEvent('checkout_started', { cart_value: 49.9 }); // custom event
72
+ identify(user.id); // attach a user id
73
+ socket.onmessage = (m) => ingestRemote(JSON.parse(m.data)); // server-pushed events
74
+
75
+ <IngestionApp /> // the live viewer
76
+ ```
77
+
78
+ Notes: click text (first 60 characters) is recorded, add `data-ei-ignore` to skip an element. Log messages and URLs can contain private data, so check them before sending to a real backend. Events live in memory and reset on reload.
79
+
80
+ ## What changed in 0.6.1
81
+
82
+ - Fixed the Log Viewer tutorial (no more state updates inside state updaters) and the highlight box near screen edges.
83
+ - `EnvPanel` rebuilt; environment capture now survives hot reload, ignores out-of-order network refreshes, and detects browsers that hide the LAN IP.
84
+ - New exports: `refreshNetwork`, `setPublicLookup`, `isPublicLookupEnabled`.
85
+ - `HeatmapApp`, `startHeatmapCapture`, `createLogger` and `logger` are now in the published build (0.6.0 shipped without them).
86
+
87
+ ```tsx
88
+ import { HeatmapApp, startHeatmapCapture } from '@shiva004/surveys';
89
+ startHeatmapCapture(); // once, records mouse / clicks / scroll on every page
90
+ <HeatmapApp /> // the viewer
91
+ ```
92
+
93
+ ## What changed in 0.6.0
94
+
95
+ - `FeedbackApp` no longer shows a "Preview Feedback" button; the popup auto-opens. New optional props `autoOpen` and `onClose`.
96
+ - Removed dead legacy source (`journey/`, `survey/`, `docs/`, `types.ts`) so `tsc` type-checks cleanly.
97
+ - Added `license`, `keywords`, `publishConfig` to `package.json`.
98
+
99
+ - New fields: "Something else" reveals a required text box, optional email (validated) with a "you can contact me" checkbox, comment counter (500 max). New `onSubmit` prop and `FeedbackResponse` type.
100
+ - New look: pinned header/footer so Back/Next are never cut off, 2-column topic chips, glow and focus rings.
101
+
102
+ ## Logger for your own app code
103
+
104
+ ```ts
105
+ import { createLogger } from '@shiva004/surveys';
106
+
107
+ const log = createLogger('login'); // adds a live "login.logger.log" file to the Log Viewer
108
+ log.info('Login request received', { email });
109
+ log.warn('Password attempt 2 of 3');
110
+ log.error('Authentication failed', err); // Error objects keep their stack trace
111
+ ```
112
+
113
+ Every call prints to the browser console and appears live in the Log Viewer with the real time.
114
+ `import { logger } from '@shiva004/surveys'` gives a default app-wide logger (source `app`).
115
+
116
+ ## Environment capture (network, IP, local time, storage)
117
+
118
+ The Log Viewer records the tester's environment automatically, in the same way as `RouteRecorderWatcher`:
119
+
120
+ - Date/time from the laptop's own clock, with timezone offset (`2026-11-10 14:32:05.123 (UTC+05:30)`)
121
+ - Network: online/offline, connection type, speed class, downlink, RTT
122
+ - Public IP, ISP and location, plus local (LAN) IP via WebRTC
123
+ - Wi-Fi name: browsers cannot read it, so the tester types it once in the Environment panel (remembered, logged)
124
+ - localStorage and sessionStorage: a snapshot at start, then every add / update / remove / clear (sensitive keys masked as `***`)
125
+
126
+ Lines appear live in `network.logger.log` and `storage.logger.log`, and in `console.log`. A collapsible Environment panel shows the current values.
127
+
128
+ ## Logging inside your own functions
129
+
130
+ ```ts
131
+ import { createLogger } from '@shiva004/surveys';
132
+ const log = createLogger('login');
133
+
134
+ // 1) Wrap: start / success + duration / failure are logged for you (sync or async)
135
+ export const login = log.wrap('login', async (email: string, password: string) => {
136
+ const res = await api.post('/login', { email, password });
137
+ return res.data;
138
+ });
139
+
140
+ // 2) Manual: log only the steps you care about
141
+ export async function checkout(cart) {
142
+ log.info('Checkout started', { items: cart.length });
143
+ try {
144
+ const order = await api.post('/orders', cart);
145
+ log.info('Order created', { id: order.id });
146
+ return order;
147
+ } catch (err) {
148
+ log.error('Checkout failed', err);
149
+ throw err;
150
+ }
151
+ }
152
+ ```
153
+
154
+ Arguments and results are not logged unless you pass `{ logArgs: true }` / `{ logResult: true }`. Never enable them for passwords or tokens.
155
+
156
+ ## Heatmap (mouse, clicks, scroll, time per section)
157
+
158
+ ```tsx
159
+ import { HeatmapApp, startHeatmapCapture } from '@shiva004/surveys';
160
+
161
+ startHeatmapCapture(); // call once at app start, so every page is recorded
162
+ <HeatmapApp /> // the report: heatmap, scroll time per page part, most hovered elements
163
+ ```
164
+
165
+ Recorded per page (route): where the mouse rests (20px grid, time in ms), where people click, scroll depth,
166
+ which tenth of the page is in the middle of the screen the longest, and the elements the mouse hovers longest.
167
+ Time only counts while the tab is visible and active (5s idle stops the clock). Typed input values are never recorded.
168
+ Data is kept in localStorage (`pulseLogs.heatmap.v1`) and a summary line per page goes to `heatmap.logger.log`.
169
+ The viewer shows one tile map of the page (each square coloured by mouse time or clicks, strongest spots numbered 1-3) with Mouse time / Clicks buttons and a Details panel.
package/dist/App.d.ts CHANGED
@@ -1,2 +1,11 @@
1
1
  import React from 'react';
2
- export declare const App: React.FC;
2
+ export declare const MODULES: {
3
+ id: string;
4
+ label: string;
5
+ }[];
6
+ export interface AppProps {
7
+ /** Optional controlled mode: pass the active tab (e.g. from the URL) and a change handler. */
8
+ module?: string;
9
+ onModuleChange?: (id: string) => void;
10
+ }
11
+ export declare const App: React.FC<AppProps>;
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ import './ingestion.css';
3
+ export declare const IngestionApp: React.FC;
@@ -0,0 +1,99 @@
1
+ import { type Level } from '../logs/data';
2
+ export type IngestStatus = 'accepted' | 'queued' | 'failed' | 'dropped';
3
+ export declare const STATUSES: IngestStatus[];
4
+ export type Source = string;
5
+ /** What is actually sent over the wire (one item of the batch). */
6
+ export interface WireEvent {
7
+ id: string;
8
+ name: string;
9
+ timestamp: string;
10
+ source: Source;
11
+ user_id: string;
12
+ session_id: string;
13
+ properties: Record<string, unknown>;
14
+ }
15
+ export interface IngestEvent {
16
+ id: string;
17
+ ts: number;
18
+ name: string;
19
+ source: Source;
20
+ status: IngestStatus;
21
+ latencyMs: number | null;
22
+ sizeBytes: number;
23
+ userId: string;
24
+ page: string;
25
+ attempts: number;
26
+ reason?: string;
27
+ payload: WireEvent;
28
+ }
29
+ export interface Point {
30
+ t: number;
31
+ rate: number;
32
+ failed: number;
33
+ }
34
+ export interface Snapshot {
35
+ events: IngestEvent[];
36
+ history: Point[];
37
+ paused: boolean;
38
+ capturing: boolean;
39
+ mode: 'local' | 'endpoint' | 'custom';
40
+ target: string;
41
+ total: number;
42
+ byStatus: Record<IngestStatus, number>;
43
+ bySource: Record<string, number>;
44
+ currentRate: number;
45
+ peakRate: number;
46
+ p50: number | null;
47
+ p95: number | null;
48
+ }
49
+ export interface IngestionConfig {
50
+ /** POST target. Body: { events: WireEvent[] }. Omit to use the in-app local sink. */
51
+ endpoint?: string;
52
+ headers?: Record<string, string>;
53
+ /** Full control over delivery. Throw (or reject) to mark the batch as failed. */
54
+ transport?: (batch: WireEvent[]) => Promise<void> | void;
55
+ batchSize?: number;
56
+ flushMs?: number;
57
+ maxPerSecond?: number;
58
+ maxRetries?: number;
59
+ source?: Source;
60
+ }
61
+ export interface CaptureOptions {
62
+ pageViews?: boolean;
63
+ clicks?: boolean;
64
+ errors?: boolean;
65
+ network?: boolean;
66
+ visibility?: boolean;
67
+ /** Forward logger lines (console.* and logger.*) as events. Default: ERROR + WARN only. */
68
+ logs?: boolean | {
69
+ levels?: Level[];
70
+ };
71
+ }
72
+ export interface RemoteEvent {
73
+ id?: string;
74
+ name: string;
75
+ ts?: number | string;
76
+ source?: Source;
77
+ userId?: string;
78
+ properties?: Record<string, unknown>;
79
+ }
80
+ export declare const configureIngestion: (c: IngestionConfig) => void;
81
+ export declare const identify: (id: string) => void;
82
+ /** Send one event into the pipeline. Returns the event id. */
83
+ export declare const trackEvent: (name: string, properties?: Record<string, unknown>, opts?: {
84
+ source?: Source;
85
+ }) => string;
86
+ /** Push an event that was produced elsewhere (e.g. from your WebSocket / SSE handler). */
87
+ export declare const ingestRemote: (r: RemoteEvent) => void;
88
+ /**
89
+ * Start capturing real events from this app. Call once at the app root; returns a stop function.
90
+ * Captures: page_view, click, js_error / unhandled_rejection, api_request (fetch), app_hidden / app_visible,
91
+ * and logger lines as log_error / log_warn (/ log_info / log_debug if enabled via capture.logs.levels).
92
+ */
93
+ export declare const startEventCapture: (config?: IngestionConfig & {
94
+ capture?: CaptureOptions;
95
+ }) => (() => void);
96
+ export declare const useIngestion: () => Snapshot;
97
+ export declare const getIngestionSnapshot: () => Snapshot;
98
+ export declare const setPaused: (p: boolean) => void;
99
+ export declare const resetIngestion: () => void;
@@ -1,3 +1,22 @@
1
1
  import React from 'react';
2
2
  import './feedback.css';
3
- export declare const FeedbackApp: React.FC;
3
+ export interface FeedbackResponse {
4
+ rating: number;
5
+ topics: string[];
6
+ /** Text typed when "Something else" is selected. */
7
+ otherTopic: string;
8
+ comment: string;
9
+ email: string;
10
+ /** True if the person agreed to be contacted about their feedback. */
11
+ contactOk: boolean;
12
+ submittedAt: string;
13
+ }
14
+ export interface FeedbackAppProps {
15
+ /** Open the popup as soon as the component mounts. Default: true. */
16
+ autoOpen?: boolean;
17
+ /** Called after the popup is closed. */
18
+ onClose?: () => void;
19
+ /** Called once with the answers when the person submits. */
20
+ onSubmit?: (response: FeedbackResponse) => void;
21
+ }
22
+ export declare const FeedbackApp: React.FC<FeedbackAppProps>;
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ import '../logs/logs.css';
3
+ import './heatmap.css';
4
+ export declare const HeatmapApp: React.FC;
@@ -0,0 +1,33 @@
1
+ export declare const CELL = 20;
2
+ export declare const BANDS = 10;
3
+ export interface ElementStat {
4
+ ms: number;
5
+ text: string;
6
+ }
7
+ export interface PageData {
8
+ path: string;
9
+ visits: number;
10
+ activeMs: number;
11
+ docW: number;
12
+ docH: number;
13
+ maxScrollPct: number;
14
+ cells: Record<string, number>;
15
+ clicks: Record<string, number>;
16
+ clickCount: number;
17
+ bands: number[];
18
+ bandReach: number[];
19
+ elements: Record<string, ElementStat>;
20
+ updatedAt: number;
21
+ }
22
+ export type HeatStore = Record<string, PageData>;
23
+ export declare const getHeatmapData: () => HeatStore;
24
+ export declare const clearHeatmap: () => void;
25
+ export declare const useHeatmapData: () => HeatStore;
26
+ /** The heatmap viewer pauses recording while it is open, so looking at the report is not counted as page time. */
27
+ export declare const setHeatmapPaused: (v: boolean) => void;
28
+ declare global {
29
+ interface Window {
30
+ __pulseHeatmap?: boolean;
31
+ }
32
+ }
33
+ export declare function startHeatmapCapture(): void;
@@ -0,0 +1,17 @@
1
+ import { type PageData } from './capture';
2
+ /** One tile = 2x2 capture cells (40px of the page). Tiles are less noisy than single cells. */
3
+ export declare const TILE: number;
4
+ export interface Hotspot {
5
+ x: number;
6
+ y: number;
7
+ v: number;
8
+ }
9
+ export declare function buildTiles(page: PageData, metric: 'time' | 'clicks'): {
10
+ tiles: Map<string, number>;
11
+ max: number;
12
+ top: Hotspot[];
13
+ };
14
+ export declare const LEGEND_GRADIENT: string;
15
+ /** Tile map: the page is cut into squares, each coloured by how much time / how many clicks it got.
16
+ * The three strongest spots are numbered 1, 2, 3. */
17
+ export declare function drawTiles(canvas: HTMLCanvasElement, page: PageData, metric: 'time' | 'clicks', scale: number): void;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,17 @@
1
1
  import './styles.css';
2
2
  export { App as LogsFeedbackApp } from './App';
3
3
  export { LogsApp } from './logs/LogsApp';
4
+ export { createLogger, logger } from './logs/data';
5
+ export type { Logger, WrapOptions } from './logs/data';
4
6
  export { FeedbackApp } from './feedback/FeedbackApp';
7
+ export type { FeedbackAppProps, FeedbackResponse } from './feedback/FeedbackApp';
5
8
  export * from './walkthrough';
9
+ export { getNetworkInfo, setNetworkName, refreshNetwork, setPublicLookup, isPublicLookupEnabled, formatLocalTime, } from './logs/environment';
10
+ export { HeatmapApp } from './heatmap/HeatmapApp';
11
+ export { IngestionApp } from './events/IngestionApp';
12
+ export { startEventCapture, trackEvent, ingestRemote, identify, configureIngestion, useIngestion, getIngestionSnapshot, } from './events/data';
13
+ export type { IngestionConfig, CaptureOptions, RemoteEvent, WireEvent, IngestEvent, IngestStatus } from './events/data';
14
+ export { startHeatmapCapture, clearHeatmap, getHeatmapData } from './heatmap/capture';
15
+ export { RouteRecorderWatcher } from './recorder/RouteRecorderWatcher';
16
+ export type { RouteRecorderWatcherProps } from './recorder/RouteRecorderWatcher';
17
+ export type { AppProps } from './App';