@matija2209/payload-plugin-admin-feedback 1.0.3 → 1.1.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/CHANGELOG.md ADDED
@@ -0,0 +1,56 @@
1
+ # Changelog
2
+
3
+ ## 1.1.0
4
+
5
+ ### Security
6
+
7
+ - **Anonymous reports closed** — `admin-feedback` `create` now needs a signed-in user by default (was open to anyone). The `/submit` and `/upload` endpoints check the collection's `create` access, so a host rule applies to them too.
8
+ - **Screenshot delete is token-gated** — `DELETE /upload/:id` used to delete any document of the upload collection for any signed-in user. It now needs the short-lived signed token returned by `/upload` (same user, one hour, not yet attached to a report).
9
+ - **E-mail HTML escaped** — message, page path, selector, selected text and names are escaped before they go into the notification e-mail.
10
+ - `createdBy` always comes from the session; a value in the request body is ignored. Server errors no longer echo internal messages to the client.
11
+ - `/upload` enforces `screenshot.maxFileSizeBytes` and `screenshot.allowedMimeTypes` on the server, and returns 404 when `allowScreenshotUpload` is `false`.
12
+
13
+ ### Added
14
+
15
+ - `access` option: per-operation access for the `admin-feedback` collection.
16
+ - `collectionOverrides` option: last word on the generated collection (labels, admin group, fields). Keep the slug `admin-feedback`.
17
+ - `adminWidget` option: the plugin registers `AdminFeedbackProvider` in `admin.components.providers`, so no layout edit is needed. It shows only for users whose permissions allow creating feedback.
18
+ - `adminBaseUrl` and `emailDateLocale` options for the e-mail.
19
+ - `AdminFeedbackWidget` props (`title`, `submitLabel`, `uploadLabel`, screenshot limits, `apiRoute`); `FrontendFeedbackWidget` `apiRoute`.
20
+
21
+ ### Changed
22
+
23
+ - New peer dependency `@payloadcms/ui` (already present in every Payload admin).
24
+ - `meta.createdAt` is kept on updates instead of being reset.
25
+
26
+ ### Upgrade notes (from 1.0.x)
27
+
28
+ - If anonymous visitors must report, pass `access: { create: () => true }` explicitly.
29
+
30
+ ## 1.0.4
31
+
32
+ ### Added
33
+
34
+ - **Multi-tenant screenshot uploads** — optional `tenant` config on `adminFeedbackPlugin()` (`collectionSlug`, `fieldName`, `formDataSlugKey`, `pathMarkers`, `resolveTenantId`)
35
+ - `FrontendFeedbackWidget` props: `tenantPathMarkers`, `tenantFormDataKey`
36
+ - Exported `extractTenantSlugFromPathname` for path-based tenant slug detection
37
+ - Screenshot capture policies (`current-tab-first`, `strict-current-tab`, `any-surface`) and plugin screenshot limits / MIME allowlist
38
+
39
+ ### Changed
40
+
41
+ - **Feedback widget UI** — tab-first screenshot capture, full-screen annotation (pen, rectangle, arrow, text, undo/redo), clipboard paste, and file upload; improved widget state management and icons
42
+ - Plugin configuration options (`screenshot`, `frontend`, `strictMediaCollection`, `mediaCollectionSlug`)
43
+ - Email notifications — improved HTML template and metadata
44
+ - Internal structure split into focused modules (endpoints, hooks, client, tenant helpers)
45
+ - Build uses tsup with explicit client boundary stamping for Next.js App Router
46
+
47
+ ### Fixed
48
+
49
+ - Page path tracking on feedback submit
50
+ - Admin feedback collection request typing
51
+
52
+ ### Upgrade notes (from 1.0.3)
53
+
54
+ - Use scoped package name: `@matija2209/payload-plugin-admin-feedback`
55
+ - Remove custom Next.js routes under `src/app/api/admin-feedback/` — the plugin registers Payload collection endpoints (`/submit`, `/upload`, …)
56
+ - Multi-tenant is opt-in: set `tenant.enabled: true` and pass `tenantPathMarkers` on `FrontendFeedbackWidget` when media must be tenant-scoped
package/README.md CHANGED
@@ -1,40 +1,42 @@
1
- ![Payload Admin Feedback Plugin header](https://img.buildwithmatija.com/api/images/wv5oune7/file/social)
1
+ ![Payload Admin Feedback Plugin header](./public/payload-admin-plugin-header.png)
2
2
 
3
- # @matija2209/payload-plugin-admin-feedback
3
+ # payload-plugin-admin-feedback
4
4
 
5
5
  Floating feedback/chat widget plugin for Payload CMS admin and selected Next.js frontend routes.
6
6
 
7
7
  ## Features
8
8
 
9
- - **Premium Email Notifications**: Beautifully formatted HTML emails with screenshot previews and direct admin panel links.
10
- - **Flexible Email Routing**: Send feedback to specific addresses with custom "From" name/address support.
11
- - **Smart Path Tracking**: Automatically captures the page path where feedback was submitted.
12
- - **Advanced Annotation Tools**: Full-screen editor for screenshots with pen, rectangle, arrow, and text tools.
13
- - **Easy Integration**: Hooks into your existing Payload email adapter (Brevo, Resend, Nodemailer, etc.).
14
- - **Next.js Support**: Includes client components for both Admin panel and Frontend routes.
9
+ - Adds `admin-feedback` collection to Payload
10
+ - Floating client widget with:
11
+ - message input
12
+ - current page path capture
13
+ - optional CSS selector capture
14
+ - current-tab-first screenshot capture, full-screen annotation, clipboard paste, and file upload
15
+ - native HTML5 tools for pen, rectangle, arrow, text, undo, redo, clear, and revert
16
+ - Email notification on feedback creation through configured Payload email adapter
17
+ - Frontend allowlist route matching helper
18
+ - Strict media collection validation with fail-fast startup errors
15
19
 
16
20
  ## Install
17
21
 
18
22
  ```bash
19
- # pnpm
20
23
  pnpm add @matija2209/payload-plugin-admin-feedback
24
+ ```
21
25
 
22
- # npm
23
- npm install @matija2209/payload-plugin-admin-feedback
26
+ ## Requirements
24
27
 
25
- # yarn
26
- yarn add @matija2209/payload-plugin-admin-feedback
28
+ - `payload` `^3.84.1` (native advanced plugin API with `definePlugin`)
29
+ - `react` ^19
27
30
 
28
- # bun
29
- bun add @matija2209/payload-plugin-admin-feedback
30
- ```
31
+ ## Version Compatibility
31
32
 
32
- ## Requirements
33
+ | Plugin Version | Payload Version |
34
+ | -------------- | --------------- |
35
+ | 1.x.x | ^3.84.1 |
33
36
 
34
- - `payload` `^3.84.1`
35
- - `react` `^19.0.0`
37
+ ## Setup
36
38
 
37
- ## Usage
39
+ ### 1. Register the plugin in your Payload config
38
40
 
39
41
  ```ts
40
42
  import { buildConfig } from 'payload'
@@ -44,56 +46,185 @@ export default buildConfig({
44
46
  // ...
45
47
  plugins: [
46
48
  adminFeedbackPlugin({
47
- emailTo: 'admin@example.com',
48
- fromName: 'Kmetija Mehak Feedback',
49
- fromAddress: 'ne-odgovarjaj@kmetijamehak.si', // Must be a verified sender in your email adapter
50
- fromLabel: 'Store Feedback',
49
+ emailTo: 'it@example.com',
50
+ fromLabel: 'Store Admin Feedback',
51
+ fromName: 'Payload Admin',
52
+ fromAddress: 'noreply@example.com',
51
53
  allowScreenshotUpload: true,
52
- mediaCollectionSlug: 'media',
54
+ mediaCollectionSlug: 'files',
55
+ strictMediaCollection: true,
56
+ screenshot: {
57
+ enabled: true,
58
+ maxFileSizeBytes: 5 * 1024 * 1024,
59
+ allowedMimeTypes: ['image/png', 'image/jpeg', 'image/webp'],
60
+ capturePolicy: 'current-tab-first',
61
+ },
62
+ maxMessageLength: 3000,
63
+ frontend: {
64
+ enabled: true,
65
+ include: ['/marketplace*', '/profile*'],
66
+ },
67
+ tenant: {
68
+ enabled: true,
69
+ collectionSlug: 'tenants',
70
+ fieldName: 'tenant',
71
+ formDataSlugKey: 'tenant',
72
+ pathMarkers: ['pisarna', 'narocilnica'],
73
+ resolveTenantId: async ({ req, tenantSlug }) => {
74
+ // Optional host fallback (admin cookie, subdomain, …)
75
+ return null
76
+ },
77
+ },
53
78
  }),
54
79
  ],
55
80
  })
56
81
  ```
57
82
 
58
- ## Plugin Options
83
+ This registers the `admin-feedback` collection with custom endpoints (`/submit`, `/upload`, `/upload/:id`) — no additional API routes are needed.
59
84
 
60
- - `emailTo: string | string[]` (Required): Where to send the feedback emails.
61
- - `fromName?: string`: The name shown in the "From" field of the email.
62
- - `fromAddress?: string`: The email address used as the sender.
63
- - `email?: EmailAdapter`: Optional override for the Payload email adapter.
64
- - `fromLabel?: string`: A label used in the email subject and header.
65
- - `allowScreenshotUpload?: boolean` (default: `true`)
66
- - `mediaCollectionSlug?: string` (default: `'media'`)
67
- - `maxMessageLength?: number` (default: `3000`)
68
- - `frontend?: { enabled?: boolean; include?: string[] }`
85
+ ### Multi-tenant media uploads
86
+
87
+ When `tenant.enabled` is true, screenshot uploads set the configured relationship field on `mediaCollectionSlug`. Resolution order:
88
+
89
+ 1. Tenant slug in upload `FormData` (set automatically when `tenantPathMarkers` is passed to `FrontendFeedbackWidget`)
90
+ 2. Slug parsed from the request URL via `tenant.pathMarkers`
91
+ 3. `tenant.resolveTenantId` callback for host-specific logic
92
+
93
+ If your project stores uploads in a collection named `files` instead of `media`, set `mediaCollectionSlug: 'files'` exactly as shown above. The plugin validates that the target collection exists and is upload-enabled during startup.
94
+
95
+ ### 2. Add the admin panel widget
96
+
97
+ The simplest way: let the plugin register it.
98
+
99
+ ```ts
100
+ adminFeedbackPlugin({
101
+ emailTo: 'it@example.com',
102
+ adminWidget: { enabled: true, title: 'Report a bug', submitLabel: 'Send report' },
103
+ access: {
104
+ create: ({ req }) => Boolean(req.user),
105
+ read: ({ req }) => req.user?.role === 'admin' || { createdBy: { equals: req.user?.id } },
106
+ },
107
+ })
108
+ ```
109
+
110
+ The widget then shows for every signed-in user whose permissions allow creating feedback. Regenerate the import map (`payload generate:importmap`).
111
+
112
+ Or render it yourself in the admin layout:
113
+
114
+ In your Payload admin layout (`src/app/(payload)/layout.tsx`):
115
+
116
+ ```tsx
117
+ import { AdminFeedbackWidget } from '@matija2209/payload-plugin-admin-feedback/client'
118
+
119
+ export default function Layout({ children }: { children: React.ReactNode }) {
120
+ return (
121
+ <RootLayout config={config} importMap={importMap} serverFunction={serverFunction}>
122
+ {children}
123
+ <AdminFeedbackWidget />
124
+ </RootLayout>
125
+ )
126
+ }
127
+ ```
69
128
 
70
- ## Client Components
129
+ The admin widget automatically sends authenticated requests (HTTP-only cookies via `credentials: 'include'`).
71
130
 
72
- ### Frontend Widget
131
+ ### 3. Add the frontend widget
73
132
 
74
- Add the `FeedbackWidget` to your frontend layout to enable feedback for your users.
133
+ In your Next.js frontend locale layout (`src/app/(frontend)/[locale]/layout.tsx`):
75
134
 
76
135
  ```tsx
77
- import { FeedbackWidget } from '@matija2209/payload-plugin-admin-feedback/client';
136
+ import { FrontendFeedbackWidget } from '@matija2209/payload-plugin-admin-feedback/client'
78
137
 
79
- export default function RootLayout({ children }) {
138
+ export default async function LocaleLayout({ children, params }) {
80
139
  return (
81
140
  <html>
82
141
  <body>
83
- {children}
84
- <FeedbackWidget
85
- title="Send us your feedback"
86
- include={['/shop*', '/account*']}
142
+ {/* ... */}
143
+ <FrontendFeedbackWidget
144
+ include={['/marketplace*', '/profile*', '/checkout*']}
145
+ locales={['en', 'ru', 'sl']}
87
146
  />
147
+ {children}
148
+ {/* ... */}
88
149
  </body>
89
150
  </html>
90
- );
151
+ )
91
152
  }
92
153
  ```
93
154
 
94
- ### Admin Widget
155
+ **`FrontendFeedbackWidget` props:**
156
+
157
+ | Prop | Type | Default | Description |
158
+ |------|------|---------|-------------|
159
+ | `include` | `string[]` | required | Glob-style route patterns to show the widget on. Supports `*` wildcard suffixes (e.g. `'/profil*'` matches `/profile`, `/profile/orders/123`). |
160
+ | `locales` | `string[]` | `[]` | Supported locale prefixes. The widget strips the locale segment before matching against `include` patterns. If all your routes are non-prefixed, leave empty. |
161
+ | `title` | `string` | `'Feedback'` | Widget title. |
162
+ | `submitLabel` | `string` | `'Send'` | Submit button label. |
163
+ | `uploadLabel` | `string` | `'Upload image'` | Upload button label. |
164
+ | `tenantPathMarkers` | `string[]` | `[]` | Path markers — tenant slug is the segment before each marker; sent on upload. |
165
+ | `tenantFormDataKey` | `string` | `'tenant'` | FormData key for tenant slug. |
166
+
167
+ **How locale normalization works:** When `locales` is `['en', 'ru', 'sl']`, the widget strips the first path segment if it matches a locale. For example, `/en/marketplace` becomes `/marketplace` before checking the `include` patterns. This means you write patterns once and they work across all locales.
168
+
169
+ ## Plugin Options
170
+
171
+ - `access?: { create?, read?, update?, delete? }` per-operation collection access; default: signed-in user for each. The endpoints check `create`.
172
+ - `collectionOverrides?: (collection) => collection` adjust labels, admin group, fields; keep the slug `admin-feedback`
173
+ - `adminWidget?: { enabled?: boolean; title?: string; submitLabel?: string; uploadLabel?: string }` register the admin widget as a provider
174
+ - `adminBaseUrl?: string` absolute admin host for e-mail links (default `config.serverURL`, then `NEXT_PUBLIC_SERVER_URL`)
175
+ - `emailDateLocale?: string` default `'sl-SI'`
176
+
177
+ - `enabled?: boolean` default `true`
178
+ - `emailTo: string | string[]` required recipient address or addresses
179
+ - `fromLabel?: string` label used by the widget and email output
180
+ - `fromName?: string` optional sender name for feedback emails
181
+ - `fromAddress?: string` optional sender address for feedback emails
182
+ - `email?: Config['email']` optional Payload email config injected only when `config.email` is not already set
183
+ - `allowScreenshotUpload?: boolean` default `true`; enables image upload support in the widget, including annotated screenshot uploads
184
+ - `maxMessageLength?: number` default `3000`
185
+ - `mediaCollectionSlug?: string` default `'media'`; slug of the upload-enabled collection used for image uploads
186
+ - `strictMediaCollection?: boolean` default `true`; when `true`, startup fails if `mediaCollectionSlug` is missing or not upload-enabled
187
+ - `screenshot?: { enabled?: boolean; maxFileSizeBytes?: number; allowedMimeTypes?: string[]; capturePolicy?: 'current-tab-first' | 'strict-current-tab' | 'any-surface' }`
188
+ - `frontend?: { enabled?: boolean; include?: string[] }`
189
+ - `frontendRouteMatcher?: (pathname: string) => boolean` optional custom route matcher for frontend display logic
190
+ - `tenant?: TenantConfig` optional multi-tenant upload scoping (`enabled`, `collectionSlug`, `fieldName`, `formDataSlugKey`, `pathMarkers`, `resolveTenantId`)
191
+
192
+ ## Screenshot Capture Behavior
193
+
194
+ - `allowScreenshotUpload: false` disables image uploads from the widget entirely, including saving annotated screenshots.
195
+ - `screenshot.enabled: false` disables browser screenshot capture while still allowing regular file uploads if `allowScreenshotUpload` remains `true`.
196
+ - `current-tab-first` is the default. The widget prefers the active browser tab and still accepts window or screen capture if the browser returns a broader surface.
197
+ - `strict-current-tab` requires the captured surface to resolve as a browser tab and fails otherwise.
198
+ - `any-surface` allows the browser to offer any supported surface without tab-first constraints.
199
+ - Captured, pasted, and uploaded images all open in the same full-screen HTML5 annotation editor and are exported as a flattened PNG before upload.
200
+
201
+ ## Storage Adapter Compatibility
202
+
203
+ The plugin uploads images through the resolved Payload upload collection, not directly to a specific storage adapter.
204
+
205
+ - If your upload collection is configured with `@payloadcms/storage-*`, uploads are automatically stored there.
206
+ - If `strictMediaCollection` is `true` (default), plugin initialization fails when the configured `mediaCollectionSlug` is missing or not upload-enabled.
207
+ - If `strictMediaCollection` is `false` and the configured slug is missing, the plugin falls back to `'media'` only when a `'media'` collection exists and is upload-enabled.
208
+ - A collection that exists but is not upload-enabled still fails validation.
209
+
210
+ ## Custom Frontend Matching
211
+
212
+ Use `frontend.include` for simple glob-style path matching. Use `frontendRouteMatcher` when widget visibility depends on custom logic that cannot be expressed as a simple allowlist.
213
+
214
+ ```ts
215
+ adminFeedbackPlugin({
216
+ emailTo: 'it@example.com',
217
+ frontend: {
218
+ enabled: true,
219
+ },
220
+ frontendRouteMatcher: (pathname) => pathname.startsWith('/app') && !pathname.startsWith('/app/embed'),
221
+ })
222
+ ```
223
+
224
+ ## Migration Notes
95
225
 
96
- The plugin automatically integrates with the Payload admin panel, but you can also use the exported components for custom placement.
226
+ - The plugin uses native Payload advanced plugin metadata (`slug`, `order`, `options`) via `definePlugin`.
227
+ - Existing usage with `adminFeedbackPlugin({ ...options })` remains unchanged.
97
228
 
98
229
  ## License
99
230