@matija2209/payload-plugin-admin-feedback 1.0.3 → 1.0.4

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,29 @@
1
+ # Changelog
2
+
3
+ ## 1.0.4
4
+
5
+ ### Added
6
+
7
+ - **Multi-tenant screenshot uploads** — optional `tenant` config on `adminFeedbackPlugin()` (`collectionSlug`, `fieldName`, `formDataSlugKey`, `pathMarkers`, `resolveTenantId`)
8
+ - `FrontendFeedbackWidget` props: `tenantPathMarkers`, `tenantFormDataKey`
9
+ - Exported `extractTenantSlugFromPathname` for path-based tenant slug detection
10
+ - Screenshot capture policies (`current-tab-first`, `strict-current-tab`, `any-surface`) and plugin screenshot limits / MIME allowlist
11
+
12
+ ### Changed
13
+
14
+ - **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
15
+ - Plugin configuration options (`screenshot`, `frontend`, `strictMediaCollection`, `mediaCollectionSlug`)
16
+ - Email notifications — improved HTML template and metadata
17
+ - Internal structure split into focused modules (endpoints, hooks, client, tenant helpers)
18
+ - Build uses tsup with explicit client boundary stamping for Next.js App Router
19
+
20
+ ### Fixed
21
+
22
+ - Page path tracking on feedback submit
23
+ - Admin feedback collection request typing
24
+
25
+ ### Upgrade notes (from 1.0.3)
26
+
27
+ - Use scoped package name: `@matija2209/payload-plugin-admin-feedback`
28
+ - Remove custom Next.js routes under `src/app/api/admin-feedback/` — the plugin registers Payload collection endpoints (`/submit`, `/upload`, …)
29
+ - 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,162 @@ 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
69
92
 
70
- ## Client Components
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.
71
94
 
72
- ### Frontend Widget
95
+ ### 2. Add the admin panel widget
73
96
 
74
- Add the `FeedbackWidget` to your frontend layout to enable feedback for your users.
97
+ In your Payload admin layout (`src/app/(payload)/layout.tsx`):
75
98
 
76
99
  ```tsx
77
- import { FeedbackWidget } from '@matija2209/payload-plugin-admin-feedback/client';
100
+ import { AdminFeedbackWidget } from '@matija2209/payload-plugin-admin-feedback/client'
78
101
 
79
- export default function RootLayout({ children }) {
102
+ export default function Layout({ children }: { children: React.ReactNode }) {
103
+ return (
104
+ <RootLayout config={config} importMap={importMap} serverFunction={serverFunction}>
105
+ {children}
106
+ <AdminFeedbackWidget />
107
+ </RootLayout>
108
+ )
109
+ }
110
+ ```
111
+
112
+ The admin widget automatically sends authenticated requests (HTTP-only cookies via `credentials: 'include'`).
113
+
114
+ ### 3. Add the frontend widget
115
+
116
+ In your Next.js frontend locale layout (`src/app/(frontend)/[locale]/layout.tsx`):
117
+
118
+ ```tsx
119
+ import { FrontendFeedbackWidget } from '@matija2209/payload-plugin-admin-feedback/client'
120
+
121
+ export default async function LocaleLayout({ children, params }) {
80
122
  return (
81
123
  <html>
82
124
  <body>
83
- {children}
84
- <FeedbackWidget
85
- title="Send us your feedback"
86
- include={['/shop*', '/account*']}
125
+ {/* ... */}
126
+ <FrontendFeedbackWidget
127
+ include={['/marketplace*', '/profile*', '/checkout*']}
128
+ locales={['en', 'ru', 'sl']}
87
129
  />
130
+ {children}
131
+ {/* ... */}
88
132
  </body>
89
133
  </html>
90
- );
134
+ )
91
135
  }
92
136
  ```
93
137
 
94
- ### Admin Widget
138
+ **`FrontendFeedbackWidget` props:**
139
+
140
+ | Prop | Type | Default | Description |
141
+ |------|------|---------|-------------|
142
+ | `include` | `string[]` | required | Glob-style route patterns to show the widget on. Supports `*` wildcard suffixes (e.g. `'/profil*'` matches `/profile`, `/profile/orders/123`). |
143
+ | `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. |
144
+ | `title` | `string` | `'Feedback'` | Widget title. |
145
+ | `submitLabel` | `string` | `'Send'` | Submit button label. |
146
+ | `uploadLabel` | `string` | `'Upload image'` | Upload button label. |
147
+ | `tenantPathMarkers` | `string[]` | `[]` | Path markers — tenant slug is the segment before each marker; sent on upload. |
148
+ | `tenantFormDataKey` | `string` | `'tenant'` | FormData key for tenant slug. |
149
+
150
+ **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.
151
+
152
+ ## Plugin Options
153
+
154
+ - `enabled?: boolean` default `true`
155
+ - `emailTo: string | string[]` required recipient address or addresses
156
+ - `fromLabel?: string` label used by the widget and email output
157
+ - `fromName?: string` optional sender name for feedback emails
158
+ - `fromAddress?: string` optional sender address for feedback emails
159
+ - `email?: Config['email']` optional Payload email config injected only when `config.email` is not already set
160
+ - `allowScreenshotUpload?: boolean` default `true`; enables image upload support in the widget, including annotated screenshot uploads
161
+ - `maxMessageLength?: number` default `3000`
162
+ - `mediaCollectionSlug?: string` default `'media'`; slug of the upload-enabled collection used for image uploads
163
+ - `strictMediaCollection?: boolean` default `true`; when `true`, startup fails if `mediaCollectionSlug` is missing or not upload-enabled
164
+ - `screenshot?: { enabled?: boolean; maxFileSizeBytes?: number; allowedMimeTypes?: string[]; capturePolicy?: 'current-tab-first' | 'strict-current-tab' | 'any-surface' }`
165
+ - `frontend?: { enabled?: boolean; include?: string[] }`
166
+ - `frontendRouteMatcher?: (pathname: string) => boolean` optional custom route matcher for frontend display logic
167
+ - `tenant?: TenantConfig` optional multi-tenant upload scoping (`enabled`, `collectionSlug`, `fieldName`, `formDataSlugKey`, `pathMarkers`, `resolveTenantId`)
168
+
169
+ ## Screenshot Capture Behavior
170
+
171
+ - `allowScreenshotUpload: false` disables image uploads from the widget entirely, including saving annotated screenshots.
172
+ - `screenshot.enabled: false` disables browser screenshot capture while still allowing regular file uploads if `allowScreenshotUpload` remains `true`.
173
+ - `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.
174
+ - `strict-current-tab` requires the captured surface to resolve as a browser tab and fails otherwise.
175
+ - `any-surface` allows the browser to offer any supported surface without tab-first constraints.
176
+ - Captured, pasted, and uploaded images all open in the same full-screen HTML5 annotation editor and are exported as a flattened PNG before upload.
177
+
178
+ ## Storage Adapter Compatibility
179
+
180
+ The plugin uploads images through the resolved Payload upload collection, not directly to a specific storage adapter.
181
+
182
+ - If your upload collection is configured with `@payloadcms/storage-*`, uploads are automatically stored there.
183
+ - If `strictMediaCollection` is `true` (default), plugin initialization fails when the configured `mediaCollectionSlug` is missing or not upload-enabled.
184
+ - 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.
185
+ - A collection that exists but is not upload-enabled still fails validation.
186
+
187
+ ## Custom Frontend Matching
188
+
189
+ 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.
190
+
191
+ ```ts
192
+ adminFeedbackPlugin({
193
+ emailTo: 'it@example.com',
194
+ frontend: {
195
+ enabled: true,
196
+ },
197
+ frontendRouteMatcher: (pathname) => pathname.startsWith('/app') && !pathname.startsWith('/app/embed'),
198
+ })
199
+ ```
200
+
201
+ ## Migration Notes
95
202
 
96
- The plugin automatically integrates with the Payload admin panel, but you can also use the exported components for custom placement.
203
+ - The plugin uses native Payload advanced plugin metadata (`slug`, `order`, `options`) via `definePlugin`.
204
+ - Existing usage with `adminFeedbackPlugin({ ...options })` remains unchanged.
97
205
 
98
206
  ## License
99
207