@cohiva/support-widget 1.0.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/README.md ADDED
@@ -0,0 +1,208 @@
1
+ # Cohiva Support Widget
2
+
3
+ [![CI](https://github.com/cohiva/cohiva-support-widget/actions/workflows/ci.yml/badge.svg)](https://github.com/cohiva/cohiva-support-widget/actions/workflows/ci.yml)
4
+ [![Release](https://github.com/cohiva/cohiva-support-widget/actions/workflows/release.yml/badge.svg)](https://github.com/cohiva/cohiva-support-widget/actions/workflows/release.yml)
5
+
6
+ Shared, production-ready Support Ticket package for React apps. It preserves the documented legacy flow from the audit in `docs/support-widget-audit/` with a typed public API, diagnostics capture, and backend-compatible payload generation for `POST /api/feedback`.
7
+
8
+ ## What This Package Does
9
+
10
+ This package provides a reusable support ticket widget that host apps can mount once and configure with app context, route metadata, auth, and API wiring. It standardizes:
11
+
12
+ - floating launcher UX
13
+ - two-step modal flow
14
+ - type-aware validation and payload construction
15
+ - diagnostics capture and redaction hooks
16
+ - central API submission contract compatibility
17
+
18
+ ## What This Package Provides
19
+
20
+ - Floating bottom-right Support Ticket launcher.
21
+ - Two-step modal flow:
22
+ - type selection
23
+ - detailed form
24
+ - Supported types:
25
+ - `bug`
26
+ - `feature`
27
+ - `feedback`
28
+ - `improvement`
29
+ - Type-specific required validation rules with parity error messages.
30
+ - Automatic diagnostics capture (actions, errors, page and runtime metadata).
31
+ - Typed payload generation with backend-compatible keys.
32
+ - Central API adapter (`createCentralFeedbackClient`).
33
+ - Theme/class override surface.
34
+ - Comprehensive test suite derived from migration checklist and parity requirements.
35
+
36
+ ## Install
37
+
38
+ ```bash
39
+ npm install @cohiva/support-widget
40
+ ```
41
+
42
+ Also include package CSS once in your app:
43
+
44
+ ```ts
45
+ import '@cohiva/support-widget/styles.css';
46
+ ```
47
+
48
+ ## Quick Start
49
+
50
+ ```tsx
51
+ import { SupportWidget } from '@cohiva/support-widget';
52
+
53
+ export function App() {
54
+ return (
55
+ <SupportWidget
56
+ config={{
57
+ appName: 'Cohiva Admin',
58
+ environment: 'production',
59
+ repoSlug: 'cohiva/cohiva-admin',
60
+ apiBaseUrl: 'https://api.cohiva.app',
61
+ getAuthToken: () => localStorage.getItem('token'),
62
+ getCurrentRoute: () => ({
63
+ pathname: window.location.pathname,
64
+ href: window.location.href,
65
+ title: document.title,
66
+ }),
67
+ getCurrentUserContext: () => ({
68
+ user_id: 'u-123',
69
+ business_id: 'b-123',
70
+ role: 'admin',
71
+ }),
72
+ }}
73
+ />
74
+ );
75
+ }
76
+ ```
77
+
78
+ ## Advanced Usage
79
+
80
+ ```tsx
81
+ import { SupportWidget, createCentralFeedbackClient } from '@cohiva/support-widget';
82
+
83
+ const submitFeedback = createCentralFeedbackClient({
84
+ apiBaseUrl: 'https://api.cohiva.app',
85
+ getAuthToken: () => window.sessionStorage.getItem('token'),
86
+ });
87
+
88
+ export function AppSupport() {
89
+ return (
90
+ <SupportWidget
91
+ config={{
92
+ appName: 'Cohiva Admin',
93
+ environment: 'production',
94
+ repoSlug: 'cohiva/cohiva-admin',
95
+ apiBaseUrl: 'https://api.cohiva.app',
96
+ getCurrentRoute: () => ({
97
+ pathname: window.location.pathname,
98
+ href: window.location.href,
99
+ title: document.title,
100
+ }),
101
+ getCurrentUserContext: () => ({
102
+ user_id: 'u-123',
103
+ business_id: 'b-456',
104
+ role: 'owner',
105
+ }),
106
+ diagnostics: {
107
+ captureConsoleWarnings: true,
108
+ clearPolicy: 'on_success',
109
+ redact: (entry) => {
110
+ if (entry.message.includes('password')) {
111
+ return null;
112
+ }
113
+ return {
114
+ ...entry,
115
+ message: entry.message.replace(/token=[^\s]+/g, 'token=[redacted]'),
116
+ };
117
+ },
118
+ },
119
+ theme: {
120
+ launcherLabel: 'Support Ticket',
121
+ classNames: {
122
+ launcher: 'my-app-launcher',
123
+ dialog: 'my-app-dialog',
124
+ },
125
+ },
126
+ }}
127
+ onSubmit={submitFeedback}
128
+ onSuccess={(result) => {
129
+ console.info('Support ticket submitted', result.feedback_id);
130
+ }}
131
+ onError={(error) => {
132
+ console.error('Support ticket failed', error);
133
+ }}
134
+ />
135
+ );
136
+ }
137
+ ```
138
+
139
+ ## Development
140
+
141
+ ```bash
142
+ npm install
143
+ npm run dev:example
144
+ npm run lint
145
+ npm run typecheck
146
+ npm test
147
+ npm run test:coverage
148
+ npm run build
149
+ npm run test:smoke
150
+ npm run check
151
+ ```
152
+
153
+ ## Test Commands
154
+
155
+ ```bash
156
+ npm run test:unit
157
+ npm run test:component
158
+ npm run test:smoke
159
+ npm run test:coverage
160
+ ```
161
+
162
+ ## Release Workflow Summary
163
+
164
+ This repository uses Changesets.
165
+
166
+ 1. Create a changeset for user-facing package changes:
167
+
168
+ ```bash
169
+ npm run changeset
170
+ ```
171
+
172
+ 2. CI runs validation on PRs (`lint`, `typecheck`, `test`, `build`, example smoke build).
173
+ 3. On merge to `main`, the Changesets GitHub action either:
174
+ - opens/updates a release PR with version bumps and changelog updates, or
175
+ - publishes to npm when release changes are already prepared.
176
+
177
+ Manual commands:
178
+
179
+ ```bash
180
+ npm run version-packages
181
+ npm run release
182
+ ```
183
+
184
+ ## Docs
185
+
186
+ - `docs/public-api.md`
187
+ - `docs/configuration.md`
188
+ - `docs/diagnostics.md`
189
+ - `docs/theming.md`
190
+ - `docs/accessibility.md`
191
+ - `docs/development.md`
192
+ - `docs/testing.md`
193
+ - `docs/releasing.md`
194
+ - `docs/github-actions.md`
195
+ - `docs/repo-secrets-and-publishing.md`
196
+ - `docs/consuming-the-package.md`
197
+ - `docs/migration-from-legacy-widget.md`
198
+ - `docs/parity-matrix.md`
199
+ - `docs/release-readiness-summary.md`
200
+ - `docs/github-actions-setup-summary.md`
201
+
202
+ ## Node Version Note
203
+
204
+ CI uses Node 20.x. Local development should use Node 20 for best parity with CI validation and release pipelines.
205
+
206
+ ## Source-of-Truth Requirement
207
+
208
+ All implementation decisions in this package are derived from the audit documents under `docs/support-widget-audit/01-14`. If behavior needs to change, update the parity matrix and migration guide in the same change set.