@shiva004/surveys 0.4.0 → 0.6.1

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
- # Survey + User Journey POC
1
+ # Logs + Feedback POC
2
2
 
3
- A standalone proof of concept for the Survey and User Journey modules. No backend, no auth: all data is mock and lives in memory, so a page reload resets it.
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
 
@@ -9,82 +9,120 @@ npm install @shiva004/surveys
9
9
  ```
10
10
 
11
11
  ```tsx
12
- import { SurveyApp, JourneyApp, npsOf } from '@shiva004/surveys';
12
+ import { LogsApp, FeedbackApp } from '@shiva004/surveys';
13
13
  import '@shiva004/surveys/style.css';
14
14
 
15
15
  export default function Page() {
16
- return <SurveyApp />;
16
+ return <LogsApp />; // or <FeedbackApp />
17
17
  }
18
18
  ```
19
19
 
20
- ### Walkthrough tour + analytics (new in 0.4.0)
20
+ `LogsApp` accepts `autoStart` (default `true`) to open the tutorial once on first load.
21
+ `LogsFeedbackApp` renders both modules behind tabs.
21
22
 
22
- Replaces `UserJourneyDocs`. A React port of the Sonnaga walkthrough: spotlight tour, passive tracking (time, scroll depth, clicks, navigation, heatmap) and an optional event endpoint.
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:
23
24
 
24
- ```tsx
25
- import { JourneyProvider, useJourney, WalkthroughDemo } from '@shiva004/surveys';
26
- import '@shiva004/surveys/style.css';
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 |
27
30
 
28
- // Full sample site with tour and Insights panel
29
- <WalkthroughDemo />
31
+ ### Walkthrough tour + analytics
30
32
 
31
- // Or wrap your own app
32
- <JourneyProvider config={{ endpoint: '/api/journey/events', welcome: { title: 'Welcome', body: 'Quick tour?' } }}>
33
- <App />
34
- </JourneyProvider>
35
- // inside: const { start, setTheme, toggleHeat } = useJourney();
33
+ ```tsx
34
+ import { JourneyProvider, useJourney, WalkthroughDemo } from '@shiva004/surveys';
36
35
  ```
37
36
 
38
- Steps come from `config.steps`, else `data-sj-*` attributes, else the page's header, nav, sections and footer. `useJourneyStats()` returns live metrics. Needs `react` and `react-dom` 18+.
39
-
40
- Requires React 18 or newer. Also exported: `SurveyJourneyApp` (both modules with tabs), the NPS helpers, the journey analytics functions and all types.
37
+ Unchanged from 0.4.0. Needs `react` and `react-dom` 18+.
41
38
 
42
39
  ## Run the demo
43
40
 
44
41
  ```bash
45
42
  npm install
46
43
  npm run dev # http://localhost:5173
47
- npm run build # type-check + production build
44
+ npm run build # production build + type declarations
48
45
  ```
49
46
 
50
- ## What it proves
47
+ ## What changed in 0.5.0
51
48
 
52
- **Survey**
53
- - Create a survey with a question builder (nps, rating, multiple choice, open text) and validation
54
- - Change status (draft / active / paused / closed); only active surveys accept answers
55
- - Take a survey; each submission becomes a response
56
- - Results page: NPS (promoters 9-10 minus detractors 0-6), category split, responses table
57
- - Delete a survey and its responses
49
+ - Removed: Survey and User Journey modules (`SurveyApp`, `JourneyApp`, `SurveyJourneyApp`, NPS helpers, journey analytics, types, `UserJourneyDocs`).
50
+ - Added: `LogsApp`, `FeedbackApp`, `LogsFeedbackApp`.
58
51
 
59
- **User Journey**
60
- - A simulated page-view session stream (400 seeded sessions, "+ Simulate 50 sessions" adds more)
61
- - Navigation Analysis: views, share, bounce rate, exit rate per page
62
- - Paths: top 8 sequences (first 4 steps) with share reaching /signup
63
- - Userflows: where users go next from each page, as a percentage
64
- - Journey Maps: build stages with emotion and touchpoint pages; each stage's reach is computed from the same sessions
52
+ ## What changed in 0.6.0
65
53
 
66
- The point of the Journey half: one event stream feeds all four views, so adding more traffic updates every tab.
54
+ - `FeedbackApp` no longer shows a "Preview Feedback" button; the popup auto-opens. New optional props `autoOpen` and `onClose`.
55
+ - Removed dead legacy source (`journey/`, `survey/`, `docs/`, `types.ts`) so `tsc` type-checks cleanly.
56
+ - Added `license`, `keywords`, `publishConfig` to `package.json`.
67
57
 
68
- ## Layout
58
+ - 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.
59
+ - New look: pinned header/footer so Back/Next are never cut off, 2-column topic chips, glow and focus rings.
69
60
 
61
+ ## Logger for your own app code
62
+
63
+ ```ts
64
+ import { createLogger } from '@shiva004/surveys';
65
+
66
+ const log = createLogger('login'); // adds a live "login.logger.log" file to the Log Viewer
67
+ log.info('Login request received', { email });
68
+ log.warn('Password attempt 2 of 3');
69
+ log.error('Authentication failed', err); // Error objects keep their stack trace
70
70
  ```
71
- src/
72
- types.ts shared types (mirror survey.types.ts / journeys.types.ts)
73
- ui.tsx Stat, Tabs, Bar, Page + seeded rng
74
- survey/
75
- nps.ts NPS maths (pure functions)
76
- data.ts seed surveys and responses
77
- SurveyApp.tsx list, create, take, results
78
- journey/
79
- analytics.ts simulator + navigation / path / flow / reach calculations
80
- JourneyApp.tsx four views + map builder
71
+
72
+ Every call prints to the browser console and appears live in the Log Viewer with the real time.
73
+ `import { logger } from '@shiva004/surveys'` gives a default app-wide logger (source `app`).
74
+
75
+ ## Environment capture (network, IP, local time, storage)
76
+
77
+ The Log Viewer records the tester's environment automatically, in the same way as `RouteRecorderWatcher`:
78
+
79
+ - Date/time from the laptop's own clock, with timezone offset (`2026-11-10 14:32:05.123 (UTC+05:30)`)
80
+ - Network: online/offline, connection type, speed class, downlink, RTT
81
+ - Public IP, ISP and location, plus local (LAN) IP via WebRTC
82
+ - Wi-Fi name: browsers cannot read it, so the tester types it once in the Environment panel (remembered, logged)
83
+ - localStorage and sessionStorage: a snapshot at start, then every add / update / remove / clear (sensitive keys masked as `***`)
84
+
85
+ Lines appear live in `network.logger.log` and `storage.logger.log`, and in `console.log`. A collapsible Environment panel shows the current values.
86
+
87
+ ## Logging inside your own functions
88
+
89
+ ```ts
90
+ import { createLogger } from '@shiva004/surveys';
91
+ const log = createLogger('login');
92
+
93
+ // 1) Wrap: start / success + duration / failure are logged for you (sync or async)
94
+ export const login = log.wrap('login', async (email: string, password: string) => {
95
+ const res = await api.post('/login', { email, password });
96
+ return res.data;
97
+ });
98
+
99
+ // 2) Manual: log only the steps you care about
100
+ export async function checkout(cart) {
101
+ log.info('Checkout started', { items: cart.length });
102
+ try {
103
+ const order = await api.post('/orders', cart);
104
+ log.info('Order created', { id: order.id });
105
+ return order;
106
+ } catch (err) {
107
+ log.error('Checkout failed', err);
108
+ throw err;
109
+ }
110
+ }
81
111
  ```
82
112
 
83
- ## From POC to the real modules
113
+ Arguments and results are not logged unless you pass `{ logArgs: true }` / `{ logResult: true }`. Never enable them for passwords or tokens.
114
+
115
+ ## Heatmap (mouse, clicks, scroll, time per section)
116
+
117
+ ```tsx
118
+ import { HeatmapApp, startHeatmapCapture } from '@shiva004/surveys';
119
+
120
+ startHeatmapCapture(); // call once at app start, so every page is recorded
121
+ <HeatmapApp /> // the report: heatmap, scroll time per page part, most hovered elements
122
+ ```
84
123
 
85
- | POC | Real module |
86
- | --- | --- |
87
- | `survey/nps.ts`, `journey/analytics.ts` | Move to the backend (or a shared util); the real UI only renders summaries |
88
- | In-memory state | `surveysApi` / `journeysApi` with react-query |
89
- | Plain tables and cards | shared `DataTable`, `Header`, `StatCard`, `Card` |
90
- | Simulated sessions | Real page-view events from tracking |
124
+ Recorded per page (route): where the mouse rests (20px grid, time in ms), where people click, scroll depth,
125
+ which tenth of the page is in the middle of the screen the longest, and the elements the mouse hovers longest.
126
+ Time only counts while the tab is visible and active (5s idle stops the clock). Typed input values are never recorded.
127
+ Data is kept in localStorage (`pulseLogs.heatmap.v1`) and a summary line per page goes to `heatmap.logger.log`.
128
+ 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.
@@ -0,0 +1,22 @@
1
+ import React from 'react';
2
+ import './feedback.css';
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,10 +1,11 @@
1
1
  import './styles.css';
2
- export { App as SurveyJourneyApp } from './App';
3
- export { SurveyApp } from './survey/SurveyApp';
4
- export { JourneyApp } from './journey/JourneyApp';
2
+ export { App as LogsFeedbackApp } from './App';
3
+ export { LogsApp } from './logs/LogsApp';
4
+ export { createLogger, logger } from './logs/data';
5
+ export type { Logger, WrapOptions } from './logs/data';
6
+ export { FeedbackApp } from './feedback/FeedbackApp';
7
+ export type { FeedbackAppProps, FeedbackResponse } from './feedback/FeedbackApp';
5
8
  export * from './walkthrough';
6
- export { npsOf, npsCategory, npsScores } from './survey/nps';
7
- export type { NpsCategory } from './survey/nps';
8
- export { simulate, navigationStats, pathStats, flowStats, stageReach } from './journey/analytics';
9
- export type { NavRow, PathRow, FlowRow } from './journey/analytics';
10
- export type { Survey, Question, QType, SurveyStatus, Answer, SurveyResponse, Stage, JourneyMap } from './types';
9
+ export { getNetworkInfo, setNetworkName, refreshNetwork, setPublicLookup, isPublicLookupEnabled, formatLocalTime, } from './logs/environment';
10
+ export { HeatmapApp } from './heatmap/HeatmapApp';
11
+ export { startHeatmapCapture, clearHeatmap, getHeatmapData } from './heatmap/capture';