@rensblitz/customer-instant-feedback-app 3.0.2 → 3.1.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/README.md +97 -232
- package/dist/customer-instant-feedback.js +1591 -1608
- package/dist/customer-instant-feedback.umd.cjs +15 -15
- package/dist/feedback/FeedbackAuthContext.d.ts +0 -1
- package/dist/feedback/FeedbackReviewPage.d.ts +1 -1
- package/dist/feedback/supabase.d.ts +1 -1
- package/migrations/rls_central.sql +13 -5
- package/package.json +1 -1
- package/supabase/config.toml +5 -0
- package/supabase/functions/README.md +4 -0
- package/supabase/functions/create-reviewer/index.ts +0 -110
- package/supabase/functions/delete-reviewer/index.ts +0 -111
package/README.md
CHANGED
|
@@ -1,75 +1,39 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Feedback Module Setup
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This project integrates the `@rensblitz/customer-instant-feedback-app` npm package to collect in-app feedback from reviewers. Feedback is stored in a **dedicated, separate Supabase project** — not in this project's own database.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
---
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
- **`apps/demo`** — local consumer app (workspace `file:` link).
|
|
9
|
-
- **`apps/demo-npm`** — same idea, but depends on the **published** package from npm (see `apps/demo-npm/README.md`).
|
|
10
|
-
- **`apps/feedback-admin-app`** — standalone admin UI (deploy from repo root; see [`render.yaml`](./render.yaml)).
|
|
7
|
+
## 1. Environment variables
|
|
11
8
|
|
|
12
|
-
|
|
9
|
+
Add the following to `frontend/.env`:
|
|
13
10
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
18
|
-
- Admin UI is a **standalone app** in [`apps/feedback-admin-app/`](./apps/feedback-admin-app/) (not exported from the npm package in v3+)
|
|
19
|
-
- Feedback review page for reviewers to see all feedback (including from colleagues)
|
|
20
|
-
- Client-side rate limiting
|
|
21
|
-
- Input validation
|
|
11
|
+
```env
|
|
12
|
+
# Feedback module — dedicated Supabase project
|
|
13
|
+
VITE_FEEDBACK_SUPABASE_URL=https://<your-supabase-project>.supabase.co
|
|
14
|
+
VITE_FEEDBACK_SUPABASE_ANON_KEY=<your-anon-key>
|
|
22
15
|
|
|
23
|
-
|
|
16
|
+
# The project ID assigned by projectinablitz (format: short-code_uuid)
|
|
17
|
+
VITE_FEEDBACK_PROJECT_ID=<your-project-id>
|
|
24
18
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
```bash
|
|
28
|
-
npm install @rensblitz/customer-instant-feedback-app @supabase/supabase-js react react-dom react-router-dom
|
|
19
|
+
# Set to "true" to enable the feedback widget, "false" to disable it
|
|
20
|
+
VITE_FEEDBACK_ENABLED=true
|
|
29
21
|
```
|
|
30
22
|
|
|
31
|
-
|
|
23
|
+
These are distinct from the app's own Supabase credentials (`VITE_SUPABASE_URL` / `VITE_SUPABASE_ANON_KEY`), which are used for the app's own auth and data and must remain in `.env` alongside these.
|
|
32
24
|
|
|
33
|
-
|
|
34
|
-
yarn add @rensblitz/customer-instant-feedback-app @supabase/supabase-js react react-dom react-router-dom
|
|
35
|
-
```
|
|
25
|
+
> **Note:** Because Vite does not substitute env vars inside pre-bundled npm packages, `configureFeedbackClient()` must be called from within the host project's own source (see section 3). This is what makes the env vars available to the package at runtime.
|
|
36
26
|
|
|
37
|
-
|
|
27
|
+
**Next.js users:** use `NEXT_PUBLIC_` instead of `VITE_`:
|
|
38
28
|
|
|
39
|
-
```
|
|
40
|
-
|
|
29
|
+
```env
|
|
30
|
+
NEXT_PUBLIC_FEEDBACK_SUPABASE_URL=https://<your-supabase-project>.supabase.co
|
|
31
|
+
NEXT_PUBLIC_FEEDBACK_SUPABASE_ANON_KEY=<your-anon-key>
|
|
32
|
+
NEXT_PUBLIC_FEEDBACK_PROJECT_ID=<your-project-id>
|
|
33
|
+
NEXT_PUBLIC_FEEDBACK_ENABLED=true
|
|
41
34
|
```
|
|
42
35
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
### Upgrading from 2.x to 3.x
|
|
46
|
-
|
|
47
|
-
- **`FeedbackAdminPage` was removed** from the package. Remove any import and route; use the standalone [`apps/feedback-admin-app`](./apps/feedback-admin-app/) (or deploy it separately).
|
|
48
|
-
- **`getSupabaseClient`** is now exported if you need direct Supabase access in advanced integrations.
|
|
49
|
-
|
|
50
|
-
## Quick Start
|
|
51
|
-
|
|
52
|
-
**Host app integration (typical):** install the package, add Supabase URL + anon key to `.env`, wrap the app with `FeedbackAuthProvider` / `FeedbackProvider`, and pass the `project_id` string from your operator. You do **not** need to run database migrations in your repo—that happens on the Supabase project (see below if you operate that backend). The in-app setup page at `/readme` (`FeedbackReadmePage`) describes only this flow; full operator steps stay in this README.
|
|
53
|
-
|
|
54
|
-
### 1. Environment variables (host project)
|
|
55
|
-
|
|
56
|
-
Add these to your **host project's** `.env` file (not this package):
|
|
57
|
-
|
|
58
|
-
**Vite / Create React App:**
|
|
59
|
-
```
|
|
60
|
-
VITE_FEEDBACK_SUPABASE_URL=https://your-project.supabase.co
|
|
61
|
-
VITE_FEEDBACK_SUPABASE_ANON_KEY=your-anon-key
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
**Next.js:**
|
|
65
|
-
```
|
|
66
|
-
NEXT_PUBLIC_FEEDBACK_SUPABASE_URL=https://your-project.supabase.co
|
|
67
|
-
NEXT_PUBLIC_FEEDBACK_SUPABASE_ANON_KEY=your-anon-key
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
Get these from Supabase: Project Settings → API. Use the `anon` (public) key.
|
|
71
|
-
|
|
72
|
-
**TypeScript users:** Add type definitions for these environment variables. For Vite projects, create `src/vite-env.d.ts`:
|
|
36
|
+
**TypeScript users:** add type declarations for these env vars. For Vite, in `src/vite-env.d.ts`:
|
|
73
37
|
|
|
74
38
|
```typescript
|
|
75
39
|
/// <reference types="vite/client" />
|
|
@@ -77,37 +41,37 @@ Get these from Supabase: Project Settings → API. Use the `anon` (public) key.
|
|
|
77
41
|
interface ImportMetaEnv {
|
|
78
42
|
readonly VITE_FEEDBACK_SUPABASE_URL: string
|
|
79
43
|
readonly VITE_FEEDBACK_SUPABASE_ANON_KEY: string
|
|
44
|
+
readonly VITE_FEEDBACK_PROJECT_ID: string
|
|
45
|
+
readonly VITE_FEEDBACK_ENABLED: string
|
|
80
46
|
}
|
|
81
47
|
```
|
|
82
48
|
|
|
83
|
-
|
|
49
|
+
---
|
|
84
50
|
|
|
85
|
-
|
|
51
|
+
## 2. Installation
|
|
86
52
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
53
|
+
```bash
|
|
54
|
+
npm install @rensblitz/customer-instant-feedback-app
|
|
55
|
+
```
|
|
90
56
|
|
|
91
|
-
|
|
92
|
-
2. `migrations/extend_feedback_items.sql` – **Skip for new installs.** Only run if you already have `feedback_items` from a previous setup; running on a fresh install will fail.
|
|
93
|
-
3. `migrations/rls_central.sql` – RLS policies
|
|
94
|
-
4. `migrations/create_admin.sql` – Creates your first admin (replace placeholder UUID)
|
|
57
|
+
The package requires these peer dependencies, which are already present in this project:
|
|
95
58
|
|
|
96
|
-
|
|
59
|
+
- `react` ^18
|
|
60
|
+
- `react-dom` ^18
|
|
61
|
+
- `react-router-dom` ^6
|
|
62
|
+
- `@supabase/supabase-js` ^2
|
|
97
63
|
|
|
98
|
-
|
|
64
|
+
Also import the stylesheet once in the app entry point:
|
|
99
65
|
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
supabase functions deploy create-reviewer
|
|
103
|
-
supabase functions deploy delete-reviewer
|
|
66
|
+
```tsx
|
|
67
|
+
import '@rensblitz/customer-instant-feedback-app/style.css'
|
|
104
68
|
```
|
|
105
69
|
|
|
106
|
-
|
|
70
|
+
---
|
|
107
71
|
|
|
108
|
-
|
|
72
|
+
## 3. App.tsx setup
|
|
109
73
|
|
|
110
|
-
|
|
74
|
+
### Imports
|
|
111
75
|
|
|
112
76
|
```tsx
|
|
113
77
|
import {
|
|
@@ -115,189 +79,90 @@ import {
|
|
|
115
79
|
FeedbackProvider,
|
|
116
80
|
FeedbackLoginPage,
|
|
117
81
|
FeedbackReviewPage,
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
import
|
|
121
|
-
|
|
122
|
-
const projectId = 'your-project-id';
|
|
123
|
-
|
|
124
|
-
function App() {
|
|
125
|
-
return (
|
|
126
|
-
<FeedbackAuthProvider>
|
|
127
|
-
<BrowserRouter>
|
|
128
|
-
<Routes>
|
|
129
|
-
<Route path="/feedback-login" element={<FeedbackLoginPage />} />
|
|
130
|
-
<Route path="/feedback" element={<FeedbackReviewPage projectId={projectId} />} />
|
|
131
|
-
<Route
|
|
132
|
-
path="/*"
|
|
133
|
-
element={
|
|
134
|
-
<FeedbackProvider projectId={projectId} feedbackReviewPath="/feedback">
|
|
135
|
-
<YourApp />
|
|
136
|
-
</FeedbackProvider>
|
|
137
|
-
}
|
|
138
|
-
/>
|
|
139
|
-
</Routes>
|
|
140
|
-
</BrowserRouter>
|
|
141
|
-
</FeedbackAuthProvider>
|
|
142
|
-
);
|
|
143
|
-
}
|
|
82
|
+
configureFeedbackClient,
|
|
83
|
+
} from '@rensblitz/customer-instant-feedback-app'
|
|
84
|
+
import '@rensblitz/customer-instant-feedback-app/style.css'
|
|
144
85
|
```
|
|
145
86
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
**Important:** Always import the CSS file. Without it, the feedback modal has no styles.
|
|
149
|
-
|
|
150
|
-
### 5. Get your project ID
|
|
87
|
+
### Client configuration (module level, after all imports)
|
|
151
88
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
### 6. Create the first admin
|
|
155
|
-
|
|
156
|
-
1. Create a user in Supabase: Authentication → Users → Add user (email + password)
|
|
157
|
-
2. Copy the user's UUID
|
|
158
|
-
3. Run the SQL from `migrations/create_admin.sql` (replace the placeholder UUID)
|
|
159
|
-
|
|
160
|
-
## How it works
|
|
161
|
-
|
|
162
|
-
- **Reviewers** visit `/feedback-login` to sign in with credentials provided by an admin. Only logged-in reviewers can see and use the feedback widget. They can visit `/feedback` to see all feedback for the project (including from colleagues).
|
|
163
|
-
- **Admins** use the standalone **Feedback Admin** app (`apps/feedback-admin-app/` in this repository, or your deployed instance) to manage companies, projects, and reviewers. Only users in the `admins` table can access it.
|
|
164
|
-
- **Feedback** is stored in the centralized Supabase project, scoped by project. Each host app passes its `projectId` to identify which project the feedback belongs to.
|
|
165
|
-
|
|
166
|
-
## Usage
|
|
167
|
-
|
|
168
|
-
### FeedbackProvider props
|
|
89
|
+
Call this once at module level — outside any component or function — so the package has its Supabase credentials before it initialises:
|
|
169
90
|
|
|
170
91
|
```tsx
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
validation={{
|
|
176
|
-
maxCommentLength: 2000,
|
|
177
|
-
maxNameLength: 100,
|
|
178
|
-
maxScreenshotSize: 500000,
|
|
179
|
-
}}
|
|
180
|
-
>
|
|
181
|
-
<YourApp />
|
|
182
|
-
</FeedbackProvider>
|
|
92
|
+
configureFeedbackClient({
|
|
93
|
+
url: import.meta.env.VITE_FEEDBACK_SUPABASE_URL,
|
|
94
|
+
anonKey: import.meta.env.VITE_FEEDBACK_SUPABASE_ANON_KEY,
|
|
95
|
+
})
|
|
183
96
|
```
|
|
184
97
|
|
|
185
|
-
|
|
186
|
-
- **enabled**: Toggle the feedback feature on/off.
|
|
187
|
-
- **feedbackReviewPath**: Path to the feedback review page (default: `/feedback`). Used for the "View all" link in the feedback toolbar.
|
|
188
|
-
- **rateLimitSeconds**: Minimum seconds between submissions.
|
|
189
|
-
- **validation**: Input validation limits.
|
|
190
|
-
|
|
191
|
-
### Rate limiting
|
|
192
|
-
|
|
193
|
-
```tsx
|
|
194
|
-
<FeedbackProvider projectId="..." rateLimitSeconds={60}>
|
|
195
|
-
<YourApp />
|
|
196
|
-
</FeedbackProvider>
|
|
197
|
-
```
|
|
98
|
+
### Component tree structure
|
|
198
99
|
|
|
199
|
-
|
|
100
|
+
The full provider/route structure in `App.tsx`:
|
|
200
101
|
|
|
201
102
|
```tsx
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
allowScreenshots: true,
|
|
208
|
-
maxScreenshotSize: 1024 * 1024,
|
|
209
|
-
}}
|
|
210
|
-
>
|
|
211
|
-
<YourApp />
|
|
212
|
-
</FeedbackProvider>
|
|
213
|
-
```
|
|
214
|
-
|
|
215
|
-
## Migrations (central Supabase project)
|
|
216
|
-
|
|
217
|
-
Run these migrations in your Supabase SQL editor, in order:
|
|
218
|
-
|
|
219
|
-
1. `migrations/schema_central.sql` – Creates companies, projects, admins, reviewers, and feedback_items tables
|
|
220
|
-
2. `migrations/extend_feedback_items.sql` – **Skip for new installs.** Only run if you are upgrading an existing installation that already has a `feedback_items` table from a prior setup. Running on a fresh install will fail.
|
|
221
|
-
3. `migrations/rls_central.sql` – RLS policies
|
|
222
|
-
4. `migrations/create_admin.sql` – Template for creating first admin(s)
|
|
223
|
-
|
|
224
|
-
## TypeScript types
|
|
225
|
-
|
|
226
|
-
```typescript
|
|
227
|
-
interface ValidationConfig {
|
|
228
|
-
maxCommentLength?: number;
|
|
229
|
-
maxNameLength?: number;
|
|
230
|
-
allowScreenshots?: boolean;
|
|
231
|
-
maxScreenshotSize?: number;
|
|
232
|
-
}
|
|
103
|
+
function App() {
|
|
104
|
+
return (
|
|
105
|
+
<FeedbackAuthProvider> {/* outermost — manages reviewer auth state */}
|
|
106
|
+
<BrowserRouter>
|
|
107
|
+
<Routes>
|
|
233
108
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
}
|
|
109
|
+
{/* Feedback-specific routes — rendered outside FeedbackProvider intentionally */}
|
|
110
|
+
<Route path="/feedback-login" element={<FeedbackLoginPage />} />
|
|
111
|
+
<Route path="/feedback" element={<FeedbackReviewPage projectId={import.meta.env.VITE_FEEDBACK_PROJECT_ID} />} />
|
|
112
|
+
|
|
113
|
+
{/* All app routes — wrapped with FeedbackProvider so the widget appears on every page */}
|
|
114
|
+
<Route path="*" element={
|
|
115
|
+
<FeedbackProvider
|
|
116
|
+
projectId={import.meta.env.VITE_FEEDBACK_PROJECT_ID}
|
|
117
|
+
rateLimitSeconds={30}
|
|
118
|
+
enabled={import.meta.env.VITE_FEEDBACK_ENABLED === 'true'}
|
|
119
|
+
feedbackReviewPath="/feedback"
|
|
120
|
+
>
|
|
121
|
+
{/* rest of the app */}
|
|
122
|
+
</FeedbackProvider>
|
|
123
|
+
} />
|
|
242
124
|
|
|
243
|
-
|
|
244
|
-
|
|
125
|
+
</Routes>
|
|
126
|
+
</BrowserRouter>
|
|
127
|
+
</FeedbackAuthProvider>
|
|
128
|
+
)
|
|
245
129
|
}
|
|
246
130
|
```
|
|
247
131
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
### Testing the library locally
|
|
132
|
+
### FeedbackProvider props
|
|
251
133
|
|
|
252
|
-
|
|
134
|
+
| Prop | Type | Description |
|
|
135
|
+
|---|---|---|
|
|
136
|
+
| `projectId` | `string` | Project ID from projectinablitz. Required for feedback to be stored correctly. |
|
|
137
|
+
| `enabled` | `boolean` | Toggle the widget on/off without redeployment. Driven by `VITE_FEEDBACK_ENABLED`. |
|
|
138
|
+
| `rateLimitSeconds` | `number` | Minimum seconds between submissions per reviewer. |
|
|
139
|
+
| `feedbackReviewPath` | `string` | Path to the review page. Used for the "View all" link in the widget. |
|
|
140
|
+
| `validation` | `object` | Optional. Limits: `maxCommentLength`, `maxNameLength`, `allowScreenshots`, `maxScreenshotSize`. |
|
|
253
141
|
|
|
254
|
-
|
|
255
|
-
```bash
|
|
256
|
-
npm run demo:install
|
|
257
|
-
npm link
|
|
258
|
-
cd demo && npm link @rensblitz/customer-instant-feedback-app
|
|
259
|
-
```
|
|
260
|
-
Add `VITE_FEEDBACK_SUPABASE_URL` and `VITE_FEEDBACK_SUPABASE_ANON_KEY` to `apps/demo/.env` (copy from `apps/demo/.env.example` if present).
|
|
142
|
+
---
|
|
261
143
|
|
|
262
|
-
|
|
263
|
-
```bash
|
|
264
|
-
npm run build
|
|
265
|
-
```
|
|
144
|
+
## 4. Reviewer flow
|
|
266
145
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
```
|
|
146
|
+
- Reviewers navigate to `/feedback-login` and sign in with credentials provisioned by an admin.
|
|
147
|
+
- Once logged in, the feedback widget becomes visible on all app pages (wherever `FeedbackProvider` wraps the UI).
|
|
148
|
+
- Reviewers can visit `/feedback` to see all submitted feedback for the project.
|
|
271
149
|
|
|
272
|
-
|
|
150
|
+
---
|
|
273
151
|
|
|
274
|
-
|
|
275
|
-
- Rebuild: `npm run build`
|
|
276
|
-
- The demo will hot-reload automatically
|
|
152
|
+
## 5. Managing companies, projects, and reviewers
|
|
277
153
|
|
|
278
|
-
|
|
279
|
-
- `/feedback-login` - Login page for reviewers
|
|
280
|
-
- `/feedback` - Feedback review page
|
|
281
|
-
- `/readme` - Setup guide (also available as `FeedbackReadmePage` for host apps)
|
|
282
|
-
- `/` - Demo page with the feedback widget
|
|
154
|
+
The operator UI (**projectinablitz**) is a separate application that lives in the package's monorepo (`apps/projectinablitz-frontend`). It is not part of this project. Use it to:
|
|
283
155
|
|
|
284
|
-
|
|
156
|
+
- Create companies and projects (which gives you the `project_id` to use in the env)
|
|
157
|
+
- Provision and manage reviewer accounts
|
|
285
158
|
|
|
286
|
-
|
|
159
|
+
---
|
|
287
160
|
|
|
288
|
-
|
|
289
|
-
npm run build
|
|
290
|
-
```
|
|
161
|
+
## 6. Toggling feedback off
|
|
291
162
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
### Publishing to npm
|
|
295
|
-
|
|
296
|
-
```bash
|
|
297
|
-
npm publish --access public
|
|
298
|
-
```
|
|
163
|
+
Set `VITE_FEEDBACK_ENABLED=false` in `frontend/.env` and restart the Vite dev server. The widget will not render. All other feedback infrastructure (routes, providers) remains in place but is inert.
|
|
299
164
|
|
|
300
|
-
|
|
165
|
+
---
|
|
301
166
|
|
|
302
167
|
## License
|
|
303
168
|
|