@matija2209/payload-plugin-admin-feedback 1.0.0 → 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 +29 -0
- package/README.md +108 -59
- package/dist/client/index.cjs +1638 -0
- package/dist/client/index.d.cts +64 -0
- package/dist/client/index.d.ts +64 -0
- package/dist/client/index.js +1630 -0
- package/dist/index.cjs +580 -0
- package/dist/index.d.cts +60 -0
- package/dist/index.d.ts +60 -0
- package/dist/index.js +576 -0
- package/package.json +28 -4
- package/public/payload-admin-plugin-header.png +0 -0
- package/src/client/AdminFeedbackWidget.tsx +0 -63
- package/src/client/FeedbackWidget.tsx +0 -1438
- package/src/client/FrontendFeedbackWidget.tsx +0 -100
- package/src/client/index.ts +0 -4
- package/src/client/routeMatcher.ts +0 -18
- package/src/collections/AdminFeedback.ts +0 -325
- package/src/index.ts +0 -108
- package/src/server/sendFeedbackEmail.ts +0 -141
- package/src/types.ts +0 -73
- package/tsconfig.build.json +0 -14
- package/tsconfig.json +0 -19
- package/tsup.config.ts +0 -29
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
|
@@ -20,7 +20,7 @@ Floating feedback/chat widget plugin for Payload CMS admin and selected Next.js
|
|
|
20
20
|
## Install
|
|
21
21
|
|
|
22
22
|
```bash
|
|
23
|
-
pnpm add payload-plugin-admin-feedback
|
|
23
|
+
pnpm add @matija2209/payload-plugin-admin-feedback
|
|
24
24
|
```
|
|
25
25
|
|
|
26
26
|
## Requirements
|
|
@@ -34,11 +34,13 @@ pnpm add payload-plugin-admin-feedback
|
|
|
34
34
|
| -------------- | --------------- |
|
|
35
35
|
| 1.x.x | ^3.84.1 |
|
|
36
36
|
|
|
37
|
-
##
|
|
37
|
+
## Setup
|
|
38
|
+
|
|
39
|
+
### 1. Register the plugin in your Payload config
|
|
38
40
|
|
|
39
41
|
```ts
|
|
40
42
|
import { buildConfig } from 'payload'
|
|
41
|
-
import { adminFeedbackPlugin } from 'payload-plugin-admin-feedback'
|
|
43
|
+
import { adminFeedbackPlugin } from '@matija2209/payload-plugin-admin-feedback'
|
|
42
44
|
|
|
43
45
|
export default buildConfig({
|
|
44
46
|
// ...
|
|
@@ -46,10 +48,13 @@ export default buildConfig({
|
|
|
46
48
|
adminFeedbackPlugin({
|
|
47
49
|
emailTo: 'it@example.com',
|
|
48
50
|
fromLabel: 'Store Admin Feedback',
|
|
51
|
+
fromName: 'Payload Admin',
|
|
52
|
+
fromAddress: 'noreply@example.com',
|
|
49
53
|
allowScreenshotUpload: true,
|
|
50
|
-
mediaCollectionSlug: '
|
|
54
|
+
mediaCollectionSlug: 'files',
|
|
51
55
|
strictMediaCollection: true,
|
|
52
56
|
screenshot: {
|
|
57
|
+
enabled: true,
|
|
53
58
|
maxFileSizeBytes: 5 * 1024 * 1024,
|
|
54
59
|
allowedMimeTypes: ['image/png', 'image/jpeg', 'image/webp'],
|
|
55
60
|
capturePolicy: 'current-tab-first',
|
|
@@ -59,94 +64,138 @@ export default buildConfig({
|
|
|
59
64
|
enabled: true,
|
|
60
65
|
include: ['/marketplace*', '/profile*'],
|
|
61
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
|
+
},
|
|
62
78
|
}),
|
|
63
79
|
],
|
|
64
80
|
})
|
|
65
81
|
```
|
|
66
82
|
|
|
67
|
-
|
|
83
|
+
This registers the `admin-feedback` collection with custom endpoints (`/submit`, `/upload`, `/upload/:id`) — no additional API routes are needed.
|
|
68
84
|
|
|
69
|
-
-
|
|
70
|
-
- `emailTo: string | string[]` required
|
|
71
|
-
- `fromLabel?: string`
|
|
72
|
-
- `allowScreenshotUpload?: boolean` default `true`
|
|
73
|
-
- `mediaCollectionSlug?: string` default `'media'`
|
|
74
|
-
- `strictMediaCollection?: boolean` default `true`
|
|
75
|
-
- `screenshot?: { enabled?: boolean; maxFileSizeBytes?: number; allowedMimeTypes?: string[]; capturePolicy?: 'current-tab-first' | 'strict-current-tab' | 'any-surface' }`
|
|
76
|
-
- `maxMessageLength?: number` default `3000`
|
|
77
|
-
- `frontend?: { enabled?: boolean; include?: string[] }`
|
|
78
|
-
- `frontendRouteMatcher?: (pathname: string) => boolean`
|
|
85
|
+
### Multi-tenant media uploads
|
|
79
86
|
|
|
80
|
-
|
|
87
|
+
When `tenant.enabled` is true, screenshot uploads set the configured relationship field on `mediaCollectionSlug`. Resolution order:
|
|
81
88
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
- Captured, pasted, and uploaded images all open in the same full-screen HTML5 annotation editor and are exported as a flattened PNG before upload.
|
|
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
|
|
86
92
|
|
|
87
|
-
|
|
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.
|
|
88
94
|
|
|
89
|
-
|
|
95
|
+
### 2. Add the admin panel widget
|
|
90
96
|
|
|
91
|
-
|
|
92
|
-
- If the configured collection slug is missing or not upload-enabled, plugin initialization fails with a clear error.
|
|
93
|
-
- In strict mode (default), there are no fallback guesses to other collections.
|
|
97
|
+
In your Payload admin layout (`src/app/(payload)/layout.tsx`):
|
|
94
98
|
|
|
95
|
-
|
|
99
|
+
```tsx
|
|
100
|
+
import { AdminFeedbackWidget } from '@matija2209/payload-plugin-admin-feedback/client'
|
|
101
|
+
|
|
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
|
+
```
|
|
96
111
|
|
|
97
|
-
The
|
|
112
|
+
The admin widget automatically sends authenticated requests (HTTP-only cookies via `credentials: 'include'`).
|
|
98
113
|
|
|
99
|
-
###
|
|
114
|
+
### 3. Add the frontend widget
|
|
100
115
|
|
|
101
|
-
|
|
116
|
+
In your Next.js frontend locale layout (`src/app/(frontend)/[locale]/layout.tsx`):
|
|
102
117
|
|
|
103
118
|
```tsx
|
|
104
|
-
import { FrontendFeedbackWidget } from 'payload-plugin-admin-feedback/client'
|
|
119
|
+
import { FrontendFeedbackWidget } from '@matija2209/payload-plugin-admin-feedback/client'
|
|
105
120
|
|
|
106
|
-
export default function
|
|
121
|
+
export default async function LocaleLayout({ children, params }) {
|
|
107
122
|
return (
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
123
|
+
<html>
|
|
124
|
+
<body>
|
|
125
|
+
{/* ... */}
|
|
126
|
+
<FrontendFeedbackWidget
|
|
127
|
+
include={['/marketplace*', '/profile*', '/checkout*']}
|
|
128
|
+
locales={['en', 'ru', 'sl']}
|
|
129
|
+
/>
|
|
130
|
+
{children}
|
|
131
|
+
{/* ... */}
|
|
132
|
+
</body>
|
|
133
|
+
</html>
|
|
134
|
+
)
|
|
115
135
|
}
|
|
116
136
|
```
|
|
117
137
|
|
|
118
|
-
|
|
138
|
+
**`FrontendFeedbackWidget` props:**
|
|
119
139
|
|
|
120
140
|
| Prop | Type | Default | Description |
|
|
121
|
-
|
|
122
|
-
| `include` | `string[]` | required | Glob patterns
|
|
123
|
-
| `
|
|
124
|
-
| `
|
|
125
|
-
| `
|
|
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. |
|
|
126
149
|
|
|
127
|
-
**
|
|
128
|
-
`/admin/*` matches `/admin/users` but not `/admin/settings/roles`.
|
|
129
|
-
`/admin/**` matches `/admin`, `/admin/users`, `/admin/settings/roles`, etc.
|
|
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.
|
|
130
151
|
|
|
131
|
-
|
|
152
|
+
## Plugin Options
|
|
132
153
|
|
|
133
|
-
|
|
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`)
|
|
134
168
|
|
|
135
|
-
|
|
136
|
-
import { AdminFeedbackWidget } from 'payload-plugin-admin-feedback/client';
|
|
169
|
+
## Screenshot Capture Behavior
|
|
137
170
|
|
|
138
|
-
|
|
139
|
-
|
|
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.
|
|
140
177
|
|
|
141
|
-
|
|
178
|
+
## Storage Adapter Compatibility
|
|
142
179
|
|
|
143
|
-
|
|
180
|
+
The plugin uploads images through the resolved Payload upload collection, not directly to a specific storage adapter.
|
|
144
181
|
|
|
145
|
-
|
|
146
|
-
|
|
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.
|
|
147
190
|
|
|
148
|
-
|
|
149
|
-
|
|
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
|
+
})
|
|
150
199
|
```
|
|
151
200
|
|
|
152
201
|
## Migration Notes
|