@matija2209/payload-plugin-admin-feedback 1.0.4 → 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 +27 -0
- package/README.md +23 -0
- package/dist/client/index.cjs +106 -76
- package/dist/client/index.d.cts +31 -5
- package/dist/client/index.d.ts +31 -5
- package/dist/client/index.js +106 -77
- package/dist/index.cjs +168 -45
- package/dist/index.d.cts +28 -2
- package/dist/index.d.ts +28 -2
- package/dist/index.js +168 -45
- package/package.json +8 -3
package/dist/index.js
CHANGED
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
import { definePlugin, headersWithCors } from 'payload';
|
|
2
|
+
import { timingSafeEqual, createHmac } from 'crypto';
|
|
2
3
|
|
|
3
4
|
// src/index.ts
|
|
5
|
+
var DELETE_TOKEN_TTL_MS = 60 * 60 * 1e3;
|
|
6
|
+
var sign = (secret, value) => createHmac("sha256", secret).update(`admin-feedback-delete:${value}`).digest("base64url");
|
|
7
|
+
var createDeleteToken = (secret, mediaId, userId, now = Date.now()) => {
|
|
8
|
+
const expiresAt = now + DELETE_TOKEN_TTL_MS;
|
|
9
|
+
return `${expiresAt}.${sign(secret, `${mediaId}.${userId}.${expiresAt}`)}`;
|
|
10
|
+
};
|
|
11
|
+
var verifyDeleteToken = (secret, token, mediaId, userId, now = Date.now()) => {
|
|
12
|
+
if (!token) return false;
|
|
13
|
+
const [expiresRaw, signature] = token.split(".");
|
|
14
|
+
const expiresAt = Number(expiresRaw);
|
|
15
|
+
if (!signature || !Number.isFinite(expiresAt) || expiresAt < now) return false;
|
|
16
|
+
const expected = Buffer.from(sign(secret, `${mediaId}.${userId}.${expiresAt}`));
|
|
17
|
+
const actual = Buffer.from(signature);
|
|
18
|
+
return expected.length === actual.length && timingSafeEqual(expected, actual);
|
|
19
|
+
};
|
|
4
20
|
var trim = (value) => {
|
|
5
21
|
if (typeof value !== "string") {
|
|
6
22
|
return null;
|
|
@@ -26,35 +42,71 @@ var createDeleteUploadEndpoint = (mediaCollectionSlug) => ({
|
|
|
26
42
|
);
|
|
27
43
|
}
|
|
28
44
|
const id = req.routeParams?.id;
|
|
29
|
-
if (
|
|
45
|
+
if (typeof id !== "string" && typeof id !== "number") {
|
|
30
46
|
return Response.json(
|
|
31
47
|
{ success: false, error: "Missing media ID." },
|
|
32
48
|
{ status: 400, headers: corsHeaders(req) }
|
|
33
49
|
);
|
|
34
50
|
}
|
|
51
|
+
const token = req.headers.get("x-feedback-delete-token");
|
|
52
|
+
if (!verifyDeleteToken(req.payload.secret, token, id, req.user.id)) {
|
|
53
|
+
return Response.json(
|
|
54
|
+
{ success: false, error: "Forbidden" },
|
|
55
|
+
{ status: 403, headers: corsHeaders(req) }
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
const attached = await req.payload.count({
|
|
59
|
+
collection: "admin-feedback",
|
|
60
|
+
where: { screenshot: { equals: id } },
|
|
61
|
+
overrideAccess: true
|
|
62
|
+
});
|
|
63
|
+
if (attached.totalDocs > 0) {
|
|
64
|
+
return Response.json(
|
|
65
|
+
{ success: false, error: "This screenshot is already part of a report." },
|
|
66
|
+
{ status: 409, headers: corsHeaders(req) }
|
|
67
|
+
);
|
|
68
|
+
}
|
|
35
69
|
await req.payload.delete({
|
|
36
70
|
collection: mediaCollectionSlug,
|
|
37
|
-
id
|
|
71
|
+
id,
|
|
72
|
+
overrideAccess: true
|
|
38
73
|
});
|
|
39
|
-
return Response.json(
|
|
40
|
-
{ success: true },
|
|
41
|
-
{ headers: corsHeaders(req) }
|
|
42
|
-
);
|
|
74
|
+
return Response.json({ success: true }, { headers: corsHeaders(req) });
|
|
43
75
|
} catch (error) {
|
|
76
|
+
req.payload.logger.error({ err: error, msg: "admin-feedback: delete upload failed" });
|
|
44
77
|
return Response.json(
|
|
45
|
-
{ success: false, error:
|
|
78
|
+
{ success: false, error: "Could not remove the image." },
|
|
46
79
|
{ status: 500, headers: corsHeaders(req) }
|
|
47
80
|
);
|
|
48
81
|
}
|
|
49
82
|
}
|
|
50
83
|
});
|
|
51
84
|
|
|
85
|
+
// src/endpoints/access.ts
|
|
86
|
+
var canCreateFeedback = async (req, options) => {
|
|
87
|
+
const create = options.access.create;
|
|
88
|
+
if (!create) return Boolean(req.user);
|
|
89
|
+
const result = await create({ req });
|
|
90
|
+
return Boolean(result);
|
|
91
|
+
};
|
|
92
|
+
|
|
52
93
|
// src/endpoints/submit.ts
|
|
53
|
-
var
|
|
94
|
+
var toId = (value) => {
|
|
95
|
+
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
96
|
+
if (typeof value === "string" && value.trim()) return value.trim();
|
|
97
|
+
return void 0;
|
|
98
|
+
};
|
|
99
|
+
var createSubmitEndpoint = (options) => ({
|
|
54
100
|
path: "/submit",
|
|
55
101
|
method: "post",
|
|
56
102
|
handler: async (req) => {
|
|
57
103
|
try {
|
|
104
|
+
if (!await canCreateFeedback(req, options)) {
|
|
105
|
+
return Response.json(
|
|
106
|
+
{ success: false, error: req.user ? "Forbidden" : "Unauthorized" },
|
|
107
|
+
{ status: req.user ? 403 : 401, headers: corsHeaders(req) }
|
|
108
|
+
);
|
|
109
|
+
}
|
|
58
110
|
const body = await req.json();
|
|
59
111
|
const message = trim(body?.message);
|
|
60
112
|
if (!message) {
|
|
@@ -65,15 +117,14 @@ var createSubmitEndpoint = () => ({
|
|
|
65
117
|
}
|
|
66
118
|
const doc = await req.payload.create({
|
|
67
119
|
collection: "admin-feedback",
|
|
120
|
+
req,
|
|
68
121
|
data: {
|
|
69
122
|
message,
|
|
70
123
|
pagePath: trim(body?.pagePath) || "/",
|
|
71
124
|
selector: trim(body?.selector) || void 0,
|
|
72
125
|
selectedText: trim(body?.selectedText) || void 0,
|
|
73
|
-
screenshot: body?.screenshotId
|
|
74
|
-
createdBy: req.user?.id,
|
|
126
|
+
screenshot: toId(body?.screenshotId),
|
|
75
127
|
meta: {
|
|
76
|
-
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
77
128
|
userAgent: trim(body?.meta?.userAgent),
|
|
78
129
|
locale: trim(body?.meta?.locale),
|
|
79
130
|
viewport: trim(body?.meta?.viewport)
|
|
@@ -85,8 +136,9 @@ var createSubmitEndpoint = () => ({
|
|
|
85
136
|
{ headers: corsHeaders(req) }
|
|
86
137
|
);
|
|
87
138
|
} catch (error) {
|
|
139
|
+
req.payload.logger.error({ err: error, msg: "admin-feedback: submit failed" });
|
|
88
140
|
return Response.json(
|
|
89
|
-
{ success: false, error:
|
|
141
|
+
{ success: false, error: "Could not save the report." },
|
|
90
142
|
{ status: 500, headers: corsHeaders(req) }
|
|
91
143
|
);
|
|
92
144
|
}
|
|
@@ -148,10 +200,16 @@ var createUploadEndpoint = (mediaCollectionSlug, options) => ({
|
|
|
148
200
|
method: "post",
|
|
149
201
|
handler: async (req) => {
|
|
150
202
|
try {
|
|
151
|
-
if (!
|
|
203
|
+
if (!options.allowScreenshotUpload) {
|
|
152
204
|
return Response.json(
|
|
153
|
-
{ success: false, error: "
|
|
154
|
-
{ status:
|
|
205
|
+
{ success: false, error: "Uploads are disabled." },
|
|
206
|
+
{ status: 404, headers: corsHeaders(req) }
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
if (!req.user || !await canCreateFeedback(req, options)) {
|
|
210
|
+
return Response.json(
|
|
211
|
+
{ success: false, error: req.user ? "Forbidden" : "Unauthorized" },
|
|
212
|
+
{ status: req.user ? 403 : 401, headers: corsHeaders(req) }
|
|
155
213
|
);
|
|
156
214
|
}
|
|
157
215
|
const formData = await req.formData();
|
|
@@ -173,6 +231,18 @@ var createUploadEndpoint = (mediaCollectionSlug, options) => ({
|
|
|
173
231
|
{ status: 400, headers: corsHeaders(req) }
|
|
174
232
|
);
|
|
175
233
|
}
|
|
234
|
+
if (file.size > options.screenshot.maxFileSizeBytes) {
|
|
235
|
+
return Response.json(
|
|
236
|
+
{ success: false, error: "File is too large." },
|
|
237
|
+
{ status: 413, headers: corsHeaders(req) }
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
if (!options.screenshot.allowedMimeTypes.includes(file.type)) {
|
|
241
|
+
return Response.json(
|
|
242
|
+
{ success: false, error: "This file type is not allowed." },
|
|
243
|
+
{ status: 415, headers: corsHeaders(req) }
|
|
244
|
+
);
|
|
245
|
+
}
|
|
176
246
|
const mediaData = {
|
|
177
247
|
alt: alt || file.name
|
|
178
248
|
};
|
|
@@ -202,19 +272,38 @@ var createUploadEndpoint = (mediaCollectionSlug, options) => ({
|
|
|
202
272
|
}
|
|
203
273
|
});
|
|
204
274
|
return Response.json(
|
|
205
|
-
{
|
|
275
|
+
{
|
|
276
|
+
success: true,
|
|
277
|
+
mediaId: Number(media.id),
|
|
278
|
+
deleteToken: createDeleteToken(req.payload.secret, media.id, req.user.id)
|
|
279
|
+
},
|
|
206
280
|
{ headers: corsHeaders(req) }
|
|
207
281
|
);
|
|
208
282
|
} catch (error) {
|
|
283
|
+
req.payload.logger.error({ err: error, msg: "admin-feedback: upload failed" });
|
|
209
284
|
return Response.json(
|
|
210
|
-
{ success: false, error:
|
|
285
|
+
{ success: false, error: "Could not upload the image." },
|
|
211
286
|
{ status: 500, headers: corsHeaders(req) }
|
|
212
287
|
);
|
|
213
288
|
}
|
|
214
289
|
}
|
|
215
290
|
});
|
|
216
291
|
|
|
292
|
+
// src/server/escapeHtml.ts
|
|
293
|
+
var HTML_ESCAPES = {
|
|
294
|
+
"&": "&",
|
|
295
|
+
"<": "<",
|
|
296
|
+
">": ">",
|
|
297
|
+
'"': """,
|
|
298
|
+
"'": "'"
|
|
299
|
+
};
|
|
300
|
+
var escapeHtml = (value) => String(value ?? "").replace(/[&<>"']/g, (char) => HTML_ESCAPES[char] ?? char);
|
|
301
|
+
|
|
217
302
|
// src/server/sendFeedbackEmail.ts
|
|
303
|
+
var toAbsoluteUrl = (base, url) => {
|
|
304
|
+
if (/^https?:\/\//i.test(url)) return url;
|
|
305
|
+
return `${base.replace(/\/+$/, "")}/${url.replace(/^\/+/, "")}`;
|
|
306
|
+
};
|
|
218
307
|
async function sendFeedbackEmail(payload, options, data) {
|
|
219
308
|
if (!options.emailTo) {
|
|
220
309
|
return;
|
|
@@ -224,7 +313,7 @@ async function sendFeedbackEmail(payload, options, data) {
|
|
|
224
313
|
const createdBy = data.createdByName || data.createdByEmail || "Unknown";
|
|
225
314
|
let formattedDate = "Unknown";
|
|
226
315
|
try {
|
|
227
|
-
formattedDate = data.createdAt ? new Date(data.createdAt).toLocaleString("sl-SI", {
|
|
316
|
+
formattedDate = data.createdAt ? new Date(data.createdAt).toLocaleString(options.emailDateLocale || "sl-SI", {
|
|
228
317
|
day: "numeric",
|
|
229
318
|
month: "long",
|
|
230
319
|
year: "numeric",
|
|
@@ -234,17 +323,18 @@ async function sendFeedbackEmail(payload, options, data) {
|
|
|
234
323
|
} catch (e) {
|
|
235
324
|
formattedDate = data.createdAt || "Unknown";
|
|
236
325
|
}
|
|
237
|
-
const serverUrl = process.env.NEXT_PUBLIC_SERVER_URL || "http://localhost:
|
|
238
|
-
const adminUrl = data.id ? `${
|
|
326
|
+
const serverUrl = options.adminBaseUrl || payload.config.serverURL || process.env.NEXT_PUBLIC_SERVER_URL || "http://localhost:3000";
|
|
327
|
+
const adminUrl = data.id ? toAbsoluteUrl(serverUrl, `${options.adminRoute}/collections/admin-feedback/${encodeURIComponent(String(data.id))}`) : null;
|
|
328
|
+
const screenshotUrl = data.screenshotUrl && data.screenshotUrl !== "-" ? toAbsoluteUrl(serverUrl, data.screenshotUrl) : null;
|
|
239
329
|
const from = options.fromAddress ? `${options.fromName || options.fromLabel || "Admin Feedback"} <${options.fromAddress}>` : void 0;
|
|
240
|
-
const screenshotHtml =
|
|
330
|
+
const screenshotHtml = screenshotUrl ? `
|
|
241
331
|
<div style="margin-top: 24px;">
|
|
242
332
|
<p style="margin: 0 0 8px 0; font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; color: #8b8b8b; font-weight: 600;">Screenshot Preview</p>
|
|
243
333
|
<div style="border-radius: 12px; overflow: hidden; border: 1px solid #d6e3e7; background: #00455a;">
|
|
244
|
-
<img src="${
|
|
334
|
+
<img src="${escapeHtml(screenshotUrl)}" alt="Feedback Screenshot" style="width: 100%; height: auto; display: block;" />
|
|
245
335
|
</div>
|
|
246
336
|
<p style="margin: 8px 0 0 0; font-size: 12px; color: #8b8b8b;">
|
|
247
|
-
Full URL: <a href="${
|
|
337
|
+
Full URL: <a href="${escapeHtml(screenshotUrl)}" style="color: #00455a; text-decoration: none;">${escapeHtml(screenshotUrl)}</a>
|
|
248
338
|
</p>
|
|
249
339
|
</div>
|
|
250
340
|
` : "";
|
|
@@ -271,42 +361,42 @@ async function sendFeedbackEmail(payload, options, data) {
|
|
|
271
361
|
<div class="container">
|
|
272
362
|
<div class="header">
|
|
273
363
|
<h1>New Admin Feedback</h1>
|
|
274
|
-
<p style="margin: 8px 0 0 0; opacity: 0.8; font-size: 14px;">[${sourceLabel}] Received via Feedback Widget</p>
|
|
364
|
+
<p style="margin: 8px 0 0 0; opacity: 0.8; font-size: 14px;">[${escapeHtml(sourceLabel)}] Received via Feedback Widget</p>
|
|
275
365
|
</div>
|
|
276
366
|
<div class="content">
|
|
277
367
|
<div class="section">
|
|
278
368
|
<p class="label">Message</p>
|
|
279
369
|
<div class="message-box">
|
|
280
|
-
<p class="value" style="white-space: pre-wrap;">${data.message}</p>
|
|
370
|
+
<p class="value" style="white-space: pre-wrap;">${escapeHtml(data.message)}</p>
|
|
281
371
|
</div>
|
|
282
372
|
</div>
|
|
283
373
|
|
|
284
374
|
<div style="display: flex; flex-wrap: wrap; gap: 20px; border-top: 1px solid #e3edef; padding-top: 24px;">
|
|
285
375
|
<div style="flex: 1; min-width: 200px; margin-bottom: 16px;">
|
|
286
376
|
<p class="label">Page Path</p>
|
|
287
|
-
<p class="value" style="word-break: break-all;">${data.pagePath}</p>
|
|
377
|
+
<p class="value" style="word-break: break-all;">${escapeHtml(data.pagePath)}</p>
|
|
288
378
|
</div>
|
|
289
379
|
<div style="flex: 1; min-width: 200px; margin-bottom: 16px;">
|
|
290
380
|
<p class="label">Created By</p>
|
|
291
|
-
<p class="value">${createdBy}</p>
|
|
381
|
+
<p class="value">${escapeHtml(createdBy)}</p>
|
|
292
382
|
</div>
|
|
293
383
|
</div>
|
|
294
384
|
|
|
295
385
|
<div style="display: flex; flex-wrap: wrap; gap: 20px;">
|
|
296
386
|
<div style="flex: 1; min-width: 200px; margin-bottom: 16px;">
|
|
297
387
|
<p class="label">Selector</p>
|
|
298
|
-
<p class="value" style="font-family: monospace; font-size: 13px;">${data.selector || "-"}</p>
|
|
388
|
+
<p class="value" style="font-family: monospace; font-size: 13px;">${escapeHtml(data.selector || "-")}</p>
|
|
299
389
|
</div>
|
|
300
390
|
<div style="flex: 1; min-width: 200px; margin-bottom: 16px;">
|
|
301
391
|
<p class="label">Created At</p>
|
|
302
|
-
<p class="value">${formattedDate}</p>
|
|
392
|
+
<p class="value">${escapeHtml(formattedDate)}</p>
|
|
303
393
|
</div>
|
|
304
394
|
</div>
|
|
305
395
|
|
|
306
396
|
${data.selectedText && data.selectedText !== "-" ? `
|
|
307
397
|
<div class="section">
|
|
308
398
|
<p class="label">Selected Text</p>
|
|
309
|
-
<p class="value" style="font-style: italic; color: #555;">"${data.selectedText}"</p>
|
|
399
|
+
<p class="value" style="font-style: italic; color: #555;">"${escapeHtml(data.selectedText)}"</p>
|
|
310
400
|
</div>
|
|
311
401
|
` : ""}
|
|
312
402
|
|
|
@@ -314,7 +404,7 @@ async function sendFeedbackEmail(payload, options, data) {
|
|
|
314
404
|
|
|
315
405
|
${adminUrl ? `
|
|
316
406
|
<div style="text-align: center; margin-top: 32px;">
|
|
317
|
-
<a href="${adminUrl}" class="button">View in Admin Panel</a>
|
|
407
|
+
<a href="${escapeHtml(adminUrl)}" class="button">View in Admin Panel</a>
|
|
318
408
|
</div>
|
|
319
409
|
` : ""}
|
|
320
410
|
</div>
|
|
@@ -368,7 +458,7 @@ var createAfterChangeHook = (options) => {
|
|
|
368
458
|
|
|
369
459
|
// src/hooks/beforeChange.ts
|
|
370
460
|
var createBeforeChangeHook = () => {
|
|
371
|
-
return ({ data, req, operation }) => {
|
|
461
|
+
return ({ data, req, operation, originalDoc }) => {
|
|
372
462
|
if (!data) {
|
|
373
463
|
return data;
|
|
374
464
|
}
|
|
@@ -382,13 +472,16 @@ var createBeforeChangeHook = () => {
|
|
|
382
472
|
const existingMeta = typeof nextData.meta === "object" && nextData.meta !== null ? nextData.meta : {};
|
|
383
473
|
nextData.meta = {
|
|
384
474
|
...existingMeta,
|
|
385
|
-
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
475
|
+
createdAt: operation === "create" || typeof existingMeta.createdAt !== "string" ? (/* @__PURE__ */ new Date()).toISOString() : existingMeta.createdAt,
|
|
386
476
|
userAgent: trim(existingMeta.userAgent),
|
|
387
477
|
locale: trim(existingMeta.locale),
|
|
388
478
|
viewport: trim(existingMeta.viewport)
|
|
389
479
|
};
|
|
390
|
-
if (operation === "create"
|
|
391
|
-
nextData.createdBy = req.user
|
|
480
|
+
if (operation === "create") {
|
|
481
|
+
nextData.createdBy = req.user?.id ?? null;
|
|
482
|
+
} else {
|
|
483
|
+
const original = originalDoc?.createdBy;
|
|
484
|
+
nextData.createdBy = original && typeof original === "object" ? original.id ?? null : original ?? null;
|
|
392
485
|
}
|
|
393
486
|
return nextData;
|
|
394
487
|
};
|
|
@@ -407,14 +500,9 @@ var createAdminFeedbackCollection = (options, mediaCollectionSlug) => {
|
|
|
407
500
|
useAsTitle: "message",
|
|
408
501
|
defaultColumns: ["createdAt", "pagePath", "status"]
|
|
409
502
|
},
|
|
410
|
-
access:
|
|
411
|
-
read: ({ req }) => Boolean(req.user),
|
|
412
|
-
create: () => true,
|
|
413
|
-
update: ({ req }) => Boolean(req.user),
|
|
414
|
-
delete: ({ req }) => Boolean(req.user)
|
|
415
|
-
},
|
|
503
|
+
access: options.access,
|
|
416
504
|
endpoints: [
|
|
417
|
-
createSubmitEndpoint(),
|
|
505
|
+
createSubmitEndpoint(options),
|
|
418
506
|
createUploadEndpoint(mediaCollectionSlug, options),
|
|
419
507
|
createDeleteUploadEndpoint(mediaCollectionSlug)
|
|
420
508
|
],
|
|
@@ -501,6 +589,14 @@ var pathMatchesAllowlist = (pathname, patterns) => {
|
|
|
501
589
|
var PLUGIN_SLUG = "payload-plugin-admin-feedback";
|
|
502
590
|
var DEFAULT_MEDIA_COLLECTION_SLUG = "media";
|
|
503
591
|
var DEFAULT_ORDER = 10;
|
|
592
|
+
var CLIENT_EXPORT = "@matija2209/payload-plugin-admin-feedback/client";
|
|
593
|
+
var signedIn = ({ req }) => Boolean(req.user);
|
|
594
|
+
var DEFAULT_ACCESS = {
|
|
595
|
+
create: signedIn,
|
|
596
|
+
read: signedIn,
|
|
597
|
+
update: signedIn,
|
|
598
|
+
delete: signedIn
|
|
599
|
+
};
|
|
504
600
|
var isUploadCollection = (collection) => Boolean(collection.upload);
|
|
505
601
|
var getCollectionLabel = (slug) => `Collection "${slug}"`;
|
|
506
602
|
var resolveMediaCollectionSlug = (config, options) => {
|
|
@@ -530,13 +626,15 @@ var resolveMediaCollectionSlug = (config, options) => {
|
|
|
530
626
|
}
|
|
531
627
|
return targetCollection.slug;
|
|
532
628
|
};
|
|
533
|
-
var resolveOptions = (pluginOptions) => ({
|
|
629
|
+
var resolveOptions = (pluginOptions, config) => ({
|
|
534
630
|
enabled: true,
|
|
535
631
|
allowScreenshotUpload: true,
|
|
536
632
|
maxMessageLength: 3e3,
|
|
537
633
|
mediaCollectionSlug: DEFAULT_MEDIA_COLLECTION_SLUG,
|
|
538
634
|
strictMediaCollection: true,
|
|
539
635
|
...pluginOptions,
|
|
636
|
+
access: { ...DEFAULT_ACCESS, ...pluginOptions.access },
|
|
637
|
+
adminRoute: config.routes?.admin || "/admin",
|
|
540
638
|
frontend: {
|
|
541
639
|
enabled: true,
|
|
542
640
|
include: [],
|
|
@@ -554,7 +652,7 @@ var adminFeedbackPlugin = definePlugin({
|
|
|
554
652
|
slug: PLUGIN_SLUG,
|
|
555
653
|
order: DEFAULT_ORDER,
|
|
556
654
|
plugin: ({ config, ...pluginOptions }) => {
|
|
557
|
-
const options = resolveOptions(pluginOptions);
|
|
655
|
+
const options = resolveOptions(pluginOptions, config);
|
|
558
656
|
if (!options.enabled) {
|
|
559
657
|
return config;
|
|
560
658
|
}
|
|
@@ -565,9 +663,34 @@ var adminFeedbackPlugin = definePlugin({
|
|
|
565
663
|
config.email = pluginOptions.email;
|
|
566
664
|
}
|
|
567
665
|
const resolvedMediaCollectionSlug = resolveMediaCollectionSlug(config, options);
|
|
568
|
-
const
|
|
666
|
+
const generatedCollection = createAdminFeedbackCollection(options, resolvedMediaCollectionSlug);
|
|
667
|
+
const feedbackCollection = options.collectionOverrides ? options.collectionOverrides(generatedCollection) : generatedCollection;
|
|
668
|
+
const adminWidget = options.adminWidget;
|
|
669
|
+
const admin = adminWidget?.enabled ? {
|
|
670
|
+
...config.admin,
|
|
671
|
+
components: {
|
|
672
|
+
...config.admin?.components,
|
|
673
|
+
providers: [
|
|
674
|
+
...config.admin?.components?.providers || [],
|
|
675
|
+
{
|
|
676
|
+
path: `${CLIENT_EXPORT}#AdminFeedbackProvider`,
|
|
677
|
+
clientProps: {
|
|
678
|
+
collectionSlug: feedbackCollection.slug,
|
|
679
|
+
title: adminWidget.title,
|
|
680
|
+
submitLabel: adminWidget.submitLabel,
|
|
681
|
+
uploadLabel: adminWidget.uploadLabel,
|
|
682
|
+
allowScreenshotUpload: options.allowScreenshotUpload,
|
|
683
|
+
screenshotMaxFileSizeBytes: options.screenshot.maxFileSizeBytes,
|
|
684
|
+
screenshotAllowedMimeTypes: options.screenshot.allowedMimeTypes,
|
|
685
|
+
capturePolicy: options.screenshot.capturePolicy
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
]
|
|
689
|
+
}
|
|
690
|
+
} : config.admin;
|
|
569
691
|
return {
|
|
570
692
|
...config,
|
|
693
|
+
admin,
|
|
571
694
|
collections: [...config.collections || [], feedbackCollection]
|
|
572
695
|
};
|
|
573
696
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@matija2209/payload-plugin-admin-feedback",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/matija2209/payload-plugin-admin-feedback.git"
|
|
@@ -33,18 +33,23 @@
|
|
|
33
33
|
"scripts": {
|
|
34
34
|
"build": "tsup && node scripts/stamp-client-boundary.mjs",
|
|
35
35
|
"dev": "tsup --watch",
|
|
36
|
-
"prepublishOnly": "npm run build"
|
|
36
|
+
"prepublishOnly": "npm run build",
|
|
37
|
+
"typecheck": "tsc --noEmit",
|
|
38
|
+
"test": "node --experimental-strip-types --test test/*.test.ts"
|
|
37
39
|
},
|
|
38
40
|
"peerDependencies": {
|
|
41
|
+
"@payloadcms/ui": "^3.84.1",
|
|
39
42
|
"next": "^15.0.0 || ^16.0.0",
|
|
40
43
|
"payload": "^3.84.1",
|
|
41
44
|
"react": "^19.0.0",
|
|
42
45
|
"react-dom": "^19.0.0"
|
|
43
46
|
},
|
|
44
47
|
"devDependencies": {
|
|
48
|
+
"@payloadcms/ui": "^3.84.1",
|
|
49
|
+
"@types/node": "^22.20.7",
|
|
45
50
|
"@types/react": "^19.2.14",
|
|
46
51
|
"next": "^16.0.0",
|
|
47
|
-
"payload": "^3.
|
|
52
|
+
"payload": "^3.84.1",
|
|
48
53
|
"react": "^19.0.0",
|
|
49
54
|
"react-dom": "^19.0.0",
|
|
50
55
|
"tsup": "^8.5.1",
|