@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/dist/index.js ADDED
@@ -0,0 +1,576 @@
1
+ import { definePlugin, headersWithCors } from 'payload';
2
+
3
+ // src/index.ts
4
+ var trim = (value) => {
5
+ if (typeof value !== "string") {
6
+ return null;
7
+ }
8
+ const nextValue = value.trim();
9
+ return nextValue.length > 0 ? nextValue : null;
10
+ };
11
+ var corsHeaders = (req, init) => headersWithCors({
12
+ headers: new Headers(init),
13
+ req
14
+ });
15
+
16
+ // src/endpoints/deleteUpload.ts
17
+ var createDeleteUploadEndpoint = (mediaCollectionSlug) => ({
18
+ path: "/upload/:id",
19
+ method: "delete",
20
+ handler: async (req) => {
21
+ try {
22
+ if (!req.user) {
23
+ return Response.json(
24
+ { success: false, error: "Unauthorized" },
25
+ { status: 401, headers: corsHeaders(req) }
26
+ );
27
+ }
28
+ const id = req.routeParams?.id;
29
+ if (!id) {
30
+ return Response.json(
31
+ { success: false, error: "Missing media ID." },
32
+ { status: 400, headers: corsHeaders(req) }
33
+ );
34
+ }
35
+ await req.payload.delete({
36
+ collection: mediaCollectionSlug,
37
+ id
38
+ });
39
+ return Response.json(
40
+ { success: true },
41
+ { headers: corsHeaders(req) }
42
+ );
43
+ } catch (error) {
44
+ return Response.json(
45
+ { success: false, error: error instanceof Error ? error.message : "Unknown error" },
46
+ { status: 500, headers: corsHeaders(req) }
47
+ );
48
+ }
49
+ }
50
+ });
51
+
52
+ // src/endpoints/submit.ts
53
+ var createSubmitEndpoint = () => ({
54
+ path: "/submit",
55
+ method: "post",
56
+ handler: async (req) => {
57
+ try {
58
+ const body = await req.json();
59
+ const message = trim(body?.message);
60
+ if (!message) {
61
+ return Response.json(
62
+ { success: false, error: "Message is required." },
63
+ { status: 400, headers: corsHeaders(req) }
64
+ );
65
+ }
66
+ const doc = await req.payload.create({
67
+ collection: "admin-feedback",
68
+ data: {
69
+ message,
70
+ pagePath: trim(body?.pagePath) || "/",
71
+ selector: trim(body?.selector) || void 0,
72
+ selectedText: trim(body?.selectedText) || void 0,
73
+ screenshot: body?.screenshotId || void 0,
74
+ createdBy: req.user?.id,
75
+ meta: {
76
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
77
+ userAgent: trim(body?.meta?.userAgent),
78
+ locale: trim(body?.meta?.locale),
79
+ viewport: trim(body?.meta?.viewport)
80
+ }
81
+ }
82
+ });
83
+ return Response.json(
84
+ { success: true, id: doc.id },
85
+ { headers: corsHeaders(req) }
86
+ );
87
+ } catch (error) {
88
+ return Response.json(
89
+ { success: false, error: error instanceof Error ? error.message : "Unknown error" },
90
+ { status: 500, headers: corsHeaders(req) }
91
+ );
92
+ }
93
+ }
94
+ });
95
+
96
+ // src/tenant/extractTenantSlug.ts
97
+ var extractTenantSlugFromPathname = (pathname, pathMarkers) => {
98
+ if (pathMarkers.length === 0) {
99
+ return null;
100
+ }
101
+ const segments = pathname.split("?")[0].split("/").filter(Boolean);
102
+ for (const marker of pathMarkers) {
103
+ const markerIndex = segments.indexOf(marker);
104
+ if (markerIndex > 0) {
105
+ return segments[markerIndex - 1] ?? null;
106
+ }
107
+ }
108
+ return null;
109
+ };
110
+
111
+ // src/tenant/resolveUploadTenant.ts
112
+ var resolveFeedbackUploadTenantId = async (req, options, tenantSlugFromForm) => {
113
+ const tenantConfig = options.tenant;
114
+ if (!tenantConfig?.enabled) {
115
+ return null;
116
+ }
117
+ let tenantSlug = tenantSlugFromForm;
118
+ if (!tenantSlug && tenantConfig.pathMarkers?.length) {
119
+ try {
120
+ const url = new URL(req.url || "", `http://${req.headers.get("host") || "localhost"}`);
121
+ tenantSlug = extractTenantSlugFromPathname(url.pathname, tenantConfig.pathMarkers);
122
+ } catch {
123
+ tenantSlug = null;
124
+ }
125
+ }
126
+ const collectionSlug = tenantConfig.collectionSlug || "tenants";
127
+ if (tenantSlug) {
128
+ const found = await req.payload.find({
129
+ collection: collectionSlug,
130
+ where: { slug: { equals: tenantSlug } },
131
+ limit: 1,
132
+ overrideAccess: true
133
+ });
134
+ const doc = found.docs[0];
135
+ if (doc?.id != null) {
136
+ return Number(doc.id);
137
+ }
138
+ }
139
+ if (tenantConfig.resolveTenantId) {
140
+ return tenantConfig.resolveTenantId({ req, tenantSlug: tenantSlug ?? null });
141
+ }
142
+ return null;
143
+ };
144
+
145
+ // src/endpoints/upload.ts
146
+ var createUploadEndpoint = (mediaCollectionSlug, options) => ({
147
+ path: "/upload",
148
+ method: "post",
149
+ handler: async (req) => {
150
+ try {
151
+ if (!req.user) {
152
+ return Response.json(
153
+ { success: false, error: "Unauthorized" },
154
+ { status: 401, headers: corsHeaders(req) }
155
+ );
156
+ }
157
+ const formData = await req.formData();
158
+ const file = formData.get("file");
159
+ const altRaw = formData.get("alt");
160
+ const tenantSlugKey = options.tenant?.formDataSlugKey || "tenant";
161
+ const tenantSlugRaw = formData.get(tenantSlugKey);
162
+ const alt = typeof altRaw === "string" ? altRaw.trim() : "";
163
+ const tenantSlugFromForm = typeof tenantSlugRaw === "string" ? tenantSlugRaw.trim() : "";
164
+ if (!(file instanceof File)) {
165
+ return Response.json(
166
+ { success: false, error: "Missing file." },
167
+ { status: 400, headers: corsHeaders(req) }
168
+ );
169
+ }
170
+ if (file.size === 0) {
171
+ return Response.json(
172
+ { success: false, error: "File is empty." },
173
+ { status: 400, headers: corsHeaders(req) }
174
+ );
175
+ }
176
+ const mediaData = {
177
+ alt: alt || file.name
178
+ };
179
+ if (options.tenant?.enabled) {
180
+ const tenantId = await resolveFeedbackUploadTenantId(
181
+ req,
182
+ options,
183
+ tenantSlugFromForm || null
184
+ );
185
+ if (typeof tenantId !== "number") {
186
+ return Response.json(
187
+ { success: false, error: "Tenant context required." },
188
+ { status: 400, headers: corsHeaders(req) }
189
+ );
190
+ }
191
+ mediaData[options.tenant.fieldName || "tenant"] = tenantId;
192
+ }
193
+ const media = await req.payload.create({
194
+ collection: mediaCollectionSlug,
195
+ overrideAccess: true,
196
+ data: mediaData,
197
+ file: {
198
+ data: Buffer.from(await file.arrayBuffer()),
199
+ mimetype: file.type || "application/octet-stream",
200
+ name: file.name,
201
+ size: file.size
202
+ }
203
+ });
204
+ return Response.json(
205
+ { success: true, mediaId: Number(media.id) },
206
+ { headers: corsHeaders(req) }
207
+ );
208
+ } catch (error) {
209
+ return Response.json(
210
+ { success: false, error: error instanceof Error ? error.message : "Unknown error" },
211
+ { status: 500, headers: corsHeaders(req) }
212
+ );
213
+ }
214
+ }
215
+ });
216
+
217
+ // src/server/sendFeedbackEmail.ts
218
+ async function sendFeedbackEmail(payload, options, data) {
219
+ if (!options.emailTo) {
220
+ return;
221
+ }
222
+ const to = Array.isArray(options.emailTo) ? options.emailTo : [options.emailTo];
223
+ const sourceLabel = options.fromLabel || "Admin Feedback";
224
+ const createdBy = data.createdByName || data.createdByEmail || "Unknown";
225
+ let formattedDate = "Unknown";
226
+ try {
227
+ formattedDate = data.createdAt ? new Date(data.createdAt).toLocaleString("sl-SI", {
228
+ day: "numeric",
229
+ month: "long",
230
+ year: "numeric",
231
+ hour: "2-digit",
232
+ minute: "2-digit"
233
+ }) : (/* @__PURE__ */ new Date()).toLocaleString();
234
+ } catch (e) {
235
+ formattedDate = data.createdAt || "Unknown";
236
+ }
237
+ const serverUrl = process.env.NEXT_PUBLIC_SERVER_URL || "http://localhost:34572";
238
+ const adminUrl = data.id ? `${serverUrl}/admin/collections/admin-feedback/${data.id}` : null;
239
+ const from = options.fromAddress ? `${options.fromName || options.fromLabel || "Admin Feedback"} <${options.fromAddress}>` : void 0;
240
+ const screenshotHtml = data.screenshotUrl && data.screenshotUrl !== "-" ? `
241
+ <div style="margin-top: 24px;">
242
+ <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
+ <div style="border-radius: 12px; overflow: hidden; border: 1px solid #d6e3e7; background: #00455a;">
244
+ <img src="${data.screenshotUrl}" alt="Feedback Screenshot" style="width: 100%; height: auto; display: block;" />
245
+ </div>
246
+ <p style="margin: 8px 0 0 0; font-size: 12px; color: #8b8b8b;">
247
+ Full URL: <a href="${data.screenshotUrl}" style="color: #00455a; text-decoration: none;">${data.screenshotUrl}</a>
248
+ </p>
249
+ </div>
250
+ ` : "";
251
+ const html = `
252
+ <!DOCTYPE html>
253
+ <html>
254
+ <head>
255
+ <meta charset="utf-8">
256
+ <style>
257
+ body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif; line-height: 1.6; color: #353535; background-color: #f7f7f7; margin: 0; padding: 40px 20px; }
258
+ .container { max-width: 600px; margin: 0 auto; background: #ffffff; border-radius: 20px; overflow: hidden; border: 1px solid #d6e3e7; box-shadow: 0 12px 36px rgba(0, 69, 90, 0.08); }
259
+ .header { background: #00455a; color: #fbfbfb; padding: 32px 24px; text-align: center; }
260
+ .header h1 { margin: 0; font-size: 24px; font-weight: 700; }
261
+ .content { padding: 36px 30px; }
262
+ .section { margin-bottom: 24px; }
263
+ .label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: #8b8b8b; font-weight: 700; margin-bottom: 4px; }
264
+ .value { font-size: 16px; color: #353535; margin: 0; }
265
+ .message-box { background: #f1f7f8; border-left: 4px solid #00455a; padding: 16px 20px; border-radius: 8px; margin-top: 8px; }
266
+ .footer { background: #fbfbfb; padding: 24px; text-align: center; border-top: 1px solid #e3edef; color: #8b8b8b; font-size: 13px; }
267
+ .button { display: inline-block; background: #00455a; color: #fbfbfb !important; padding: 12px 24px; border-radius: 999px; text-decoration: none; font-weight: 600; margin-top: 20px; }
268
+ </style>
269
+ </head>
270
+ <body>
271
+ <div class="container">
272
+ <div class="header">
273
+ <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>
275
+ </div>
276
+ <div class="content">
277
+ <div class="section">
278
+ <p class="label">Message</p>
279
+ <div class="message-box">
280
+ <p class="value" style="white-space: pre-wrap;">${data.message}</p>
281
+ </div>
282
+ </div>
283
+
284
+ <div style="display: flex; flex-wrap: wrap; gap: 20px; border-top: 1px solid #e3edef; padding-top: 24px;">
285
+ <div style="flex: 1; min-width: 200px; margin-bottom: 16px;">
286
+ <p class="label">Page Path</p>
287
+ <p class="value" style="word-break: break-all;">${data.pagePath}</p>
288
+ </div>
289
+ <div style="flex: 1; min-width: 200px; margin-bottom: 16px;">
290
+ <p class="label">Created By</p>
291
+ <p class="value">${createdBy}</p>
292
+ </div>
293
+ </div>
294
+
295
+ <div style="display: flex; flex-wrap: wrap; gap: 20px;">
296
+ <div style="flex: 1; min-width: 200px; margin-bottom: 16px;">
297
+ <p class="label">Selector</p>
298
+ <p class="value" style="font-family: monospace; font-size: 13px;">${data.selector || "-"}</p>
299
+ </div>
300
+ <div style="flex: 1; min-width: 200px; margin-bottom: 16px;">
301
+ <p class="label">Created At</p>
302
+ <p class="value">${formattedDate}</p>
303
+ </div>
304
+ </div>
305
+
306
+ ${data.selectedText && data.selectedText !== "-" ? `
307
+ <div class="section">
308
+ <p class="label">Selected Text</p>
309
+ <p class="value" style="font-style: italic; color: #555;">"${data.selectedText}"</p>
310
+ </div>
311
+ ` : ""}
312
+
313
+ ${screenshotHtml}
314
+
315
+ ${adminUrl ? `
316
+ <div style="text-align: center; margin-top: 32px;">
317
+ <a href="${adminUrl}" class="button">View in Admin Panel</a>
318
+ </div>
319
+ ` : ""}
320
+ </div>
321
+ <div class="footer">
322
+ <p>This automated notification was sent from your Store Admin.</p>
323
+ </div>
324
+ </div>
325
+ </body>
326
+ </html>
327
+ `;
328
+ const emailMessage = {
329
+ to,
330
+ subject: `[${sourceLabel}] New feedback from ${createdBy}`,
331
+ html
332
+ };
333
+ if (from) {
334
+ emailMessage.from = from;
335
+ }
336
+ await payload.sendEmail(emailMessage);
337
+ }
338
+
339
+ // src/hooks/afterChange.ts
340
+ var createAfterChangeHook = (options) => {
341
+ return async ({ doc, operation, req }) => {
342
+ if (operation !== "create") {
343
+ return doc;
344
+ }
345
+ const screenshotDoc = typeof doc.screenshot === "object" && doc.screenshot !== null ? doc.screenshot : null;
346
+ const createdByDoc = typeof doc.createdBy === "object" && doc.createdBy !== null ? doc.createdBy : null;
347
+ const screenshotUrl = typeof screenshotDoc?.url === "string" ? screenshotDoc.url : typeof screenshotDoc?.filename === "string" ? screenshotDoc.filename : null;
348
+ try {
349
+ await sendFeedbackEmail(req.payload, options, {
350
+ id: doc.id,
351
+ message: String(doc.message || ""),
352
+ pagePath: String(doc.pagePath || "/"),
353
+ selector: typeof doc.selector === "string" ? doc.selector : null,
354
+ selectedText: typeof doc.selectedText === "string" ? doc.selectedText : null,
355
+ screenshotUrl,
356
+ createdByEmail: createdByDoc && typeof createdByDoc.email === "string" ? createdByDoc.email : null,
357
+ createdByName: createdByDoc && typeof createdByDoc.first_name === "string" ? `${createdByDoc.first_name} ${String(createdByDoc.last_name || "")}`.trim() : null,
358
+ createdAt: typeof doc.createdAt === "string" ? doc.createdAt : null
359
+ });
360
+ } catch (error) {
361
+ req.payload.logger.error(
362
+ `Failed to send admin feedback email: ${error instanceof Error ? error.message : "unknown error"}`
363
+ );
364
+ }
365
+ return doc;
366
+ };
367
+ };
368
+
369
+ // src/hooks/beforeChange.ts
370
+ var createBeforeChangeHook = () => {
371
+ return ({ data, req, operation }) => {
372
+ if (!data) {
373
+ return data;
374
+ }
375
+ const nextData = { ...data };
376
+ const message = trim(nextData.message);
377
+ const pagePath = trim(nextData.pagePath);
378
+ nextData.message = message || "";
379
+ nextData.pagePath = pagePath || "/";
380
+ nextData.selector = trim(nextData.selector);
381
+ nextData.selectedText = trim(nextData.selectedText);
382
+ const existingMeta = typeof nextData.meta === "object" && nextData.meta !== null ? nextData.meta : {};
383
+ nextData.meta = {
384
+ ...existingMeta,
385
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
386
+ userAgent: trim(existingMeta.userAgent),
387
+ locale: trim(existingMeta.locale),
388
+ viewport: trim(existingMeta.viewport)
389
+ };
390
+ if (operation === "create" && req.user && !nextData.createdBy) {
391
+ nextData.createdBy = req.user.id;
392
+ }
393
+ return nextData;
394
+ };
395
+ };
396
+
397
+ // src/collections/AdminFeedback.ts
398
+ var createAdminFeedbackCollection = (options, mediaCollectionSlug) => {
399
+ return {
400
+ slug: "admin-feedback",
401
+ admin: {
402
+ group: {
403
+ sl: "System",
404
+ en: "System",
405
+ ru: "System"
406
+ },
407
+ useAsTitle: "message",
408
+ defaultColumns: ["createdAt", "pagePath", "status"]
409
+ },
410
+ access: {
411
+ read: ({ req }) => Boolean(req.user),
412
+ create: () => true,
413
+ update: ({ req }) => Boolean(req.user),
414
+ delete: ({ req }) => Boolean(req.user)
415
+ },
416
+ endpoints: [
417
+ createSubmitEndpoint(),
418
+ createUploadEndpoint(mediaCollectionSlug, options),
419
+ createDeleteUploadEndpoint(mediaCollectionSlug)
420
+ ],
421
+ hooks: {
422
+ beforeChange: [createBeforeChangeHook()],
423
+ afterChange: [createAfterChangeHook(options)]
424
+ },
425
+ fields: [
426
+ {
427
+ name: "message",
428
+ type: "textarea",
429
+ required: true,
430
+ maxLength: options.maxMessageLength || 3e3
431
+ },
432
+ {
433
+ name: "pagePath",
434
+ type: "text",
435
+ required: true
436
+ },
437
+ {
438
+ name: "selector",
439
+ type: "text"
440
+ },
441
+ {
442
+ name: "selectedText",
443
+ type: "text"
444
+ },
445
+ {
446
+ name: "screenshot",
447
+ type: "upload",
448
+ relationTo: mediaCollectionSlug,
449
+ required: false,
450
+ admin: {
451
+ description: "Uploaded screenshot preview"
452
+ }
453
+ },
454
+ {
455
+ name: "createdBy",
456
+ type: "relationship",
457
+ relationTo: "users",
458
+ admin: {
459
+ position: "sidebar",
460
+ readOnly: true
461
+ }
462
+ },
463
+ {
464
+ name: "status",
465
+ type: "select",
466
+ defaultValue: "new",
467
+ options: [
468
+ { label: "New", value: "new" },
469
+ { label: "Triaged", value: "triaged" },
470
+ { label: "Resolved", value: "resolved" }
471
+ ],
472
+ admin: {
473
+ position: "sidebar"
474
+ }
475
+ },
476
+ {
477
+ name: "meta",
478
+ type: "json",
479
+ admin: {
480
+ readOnly: true
481
+ }
482
+ }
483
+ ]
484
+ };
485
+ };
486
+
487
+ // src/client/routeMatcher.ts
488
+ var escapeRegex = (input) => input.replace(/[.+^${}()|[\]\\]/g, "\\$&");
489
+ var toRegExp = (pattern) => {
490
+ const escaped = pattern.split("*").map((segment) => escapeRegex(segment)).join(".*");
491
+ return new RegExp(`^${escaped}$`);
492
+ };
493
+ var pathMatchesAllowlist = (pathname, patterns) => {
494
+ if (patterns.length === 0) {
495
+ return false;
496
+ }
497
+ return patterns.some((pattern) => toRegExp(pattern).test(pathname));
498
+ };
499
+
500
+ // src/index.ts
501
+ var PLUGIN_SLUG = "payload-plugin-admin-feedback";
502
+ var DEFAULT_MEDIA_COLLECTION_SLUG = "media";
503
+ var DEFAULT_ORDER = 10;
504
+ var isUploadCollection = (collection) => Boolean(collection.upload);
505
+ var getCollectionLabel = (slug) => `Collection "${slug}"`;
506
+ var resolveMediaCollectionSlug = (config, options) => {
507
+ const collections = config.collections || [];
508
+ const targetCollection = collections.find((collection) => collection.slug === options.mediaCollectionSlug);
509
+ if (!targetCollection) {
510
+ if (!options.strictMediaCollection && options.mediaCollectionSlug !== DEFAULT_MEDIA_COLLECTION_SLUG) {
511
+ const defaultCollection = collections.find(
512
+ (collection) => collection.slug === DEFAULT_MEDIA_COLLECTION_SLUG
513
+ );
514
+ if (defaultCollection && isUploadCollection(defaultCollection)) {
515
+ return defaultCollection.slug;
516
+ }
517
+ }
518
+ throw new Error(
519
+ `${PLUGIN_SLUG}: ${getCollectionLabel(
520
+ options.mediaCollectionSlug
521
+ )} was not found. Add an upload-enabled collection or set mediaCollectionSlug explicitly.`
522
+ );
523
+ }
524
+ if (!isUploadCollection(targetCollection)) {
525
+ throw new Error(
526
+ `${PLUGIN_SLUG}: ${getCollectionLabel(
527
+ targetCollection.slug
528
+ )} is not upload-enabled. Configure an upload collection and set mediaCollectionSlug to that slug.`
529
+ );
530
+ }
531
+ return targetCollection.slug;
532
+ };
533
+ var resolveOptions = (pluginOptions) => ({
534
+ enabled: true,
535
+ allowScreenshotUpload: true,
536
+ maxMessageLength: 3e3,
537
+ mediaCollectionSlug: DEFAULT_MEDIA_COLLECTION_SLUG,
538
+ strictMediaCollection: true,
539
+ ...pluginOptions,
540
+ frontend: {
541
+ enabled: true,
542
+ include: [],
543
+ ...pluginOptions.frontend
544
+ },
545
+ screenshot: {
546
+ enabled: true,
547
+ maxFileSizeBytes: 5 * 1024 * 1024,
548
+ allowedMimeTypes: ["image/png", "image/jpeg", "image/webp"],
549
+ capturePolicy: "current-tab-first",
550
+ ...pluginOptions.screenshot
551
+ }
552
+ });
553
+ var adminFeedbackPlugin = definePlugin({
554
+ slug: PLUGIN_SLUG,
555
+ order: DEFAULT_ORDER,
556
+ plugin: ({ config, ...pluginOptions }) => {
557
+ const options = resolveOptions(pluginOptions);
558
+ if (!options.enabled) {
559
+ return config;
560
+ }
561
+ if (!options.emailTo || Array.isArray(options.emailTo) && options.emailTo.length === 0) {
562
+ throw new Error("adminFeedbackPlugin requires emailTo option.");
563
+ }
564
+ if (pluginOptions.email && !config.email) {
565
+ config.email = pluginOptions.email;
566
+ }
567
+ const resolvedMediaCollectionSlug = resolveMediaCollectionSlug(config, options);
568
+ const feedbackCollection = createAdminFeedbackCollection(options, resolvedMediaCollectionSlug);
569
+ return {
570
+ ...config,
571
+ collections: [...config.collections || [], feedbackCollection]
572
+ };
573
+ }
574
+ });
575
+
576
+ export { adminFeedbackPlugin, extractTenantSlugFromPathname, pathMatchesAllowlist };
package/package.json CHANGED
@@ -1,11 +1,23 @@
1
1
  {
2
2
  "name": "@matija2209/payload-plugin-admin-feedback",
3
- "version": "1.0.0",
3
+ "version": "1.0.4",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "git+https://github.com/matija2209/payload-plugin-admin-feedback.git"
7
+ },
8
+ "publishConfig": {
9
+ "access": "public"
10
+ },
4
11
  "description": "Floating admin feedback widget plugin for Payload CMS.",
5
12
  "license": "MIT",
6
13
  "type": "module",
7
14
  "main": "./dist/index.js",
8
15
  "types": "./dist/index.d.ts",
16
+ "files": [
17
+ "dist",
18
+ "README.md",
19
+ "CHANGELOG.md"
20
+ ],
9
21
  "exports": {
10
22
  ".": {
11
23
  "types": "./dist/index.d.ts",
@@ -19,11 +31,23 @@
19
31
  }
20
32
  },
21
33
  "scripts": {
22
- "build": "tsup src/index.ts src/client/index.ts --format cjs,esm --dts --clean --minify",
23
- "dev": "tsup src/index.ts src/client/index.ts --format cjs,esm --dts --watch"
34
+ "build": "tsup && node scripts/stamp-client-boundary.mjs",
35
+ "dev": "tsup --watch",
36
+ "prepublishOnly": "npm run build"
24
37
  },
25
38
  "peerDependencies": {
39
+ "next": "^15.0.0 || ^16.0.0",
26
40
  "payload": "^3.84.1",
27
- "react": "^19.0.0"
41
+ "react": "^19.0.0",
42
+ "react-dom": "^19.0.0"
43
+ },
44
+ "devDependencies": {
45
+ "@types/react": "^19.2.14",
46
+ "next": "^16.0.0",
47
+ "payload": "^3.0.0",
48
+ "react": "^19.0.0",
49
+ "react-dom": "^19.0.0",
50
+ "tsup": "^8.5.1",
51
+ "typescript": "^5.9.3"
28
52
  }
29
53
  }
@@ -1,63 +0,0 @@
1
- 'use client';
2
-
3
- import React from 'react';
4
-
5
- import { FeedbackWidget } from './FeedbackWidget';
6
-
7
- export function AdminFeedbackWidget() {
8
- return (
9
- <FeedbackWidget
10
- title="Admin feedback"
11
- submitLabel="Send"
12
- uploadLabel="Upload image"
13
- allowScreenshotUpload
14
- onSubmit={async (payload) => {
15
- const response = await fetch('/api/admin-feedback/submit', {
16
- method: 'POST',
17
- credentials: 'include',
18
- headers: { 'content-type': 'application/json' },
19
- body: JSON.stringify(payload),
20
- });
21
-
22
- const result = (await response.json()) as { success: boolean; error?: string };
23
- if (!result.success) {
24
- return { success: false as const, error: result.error || 'Submit failed.' };
25
- }
26
-
27
- return { success: true as const };
28
- }}
29
- onUpload={async (formData) => {
30
- const response = await fetch('/api/admin-feedback/upload', {
31
- method: 'POST',
32
- credentials: 'include',
33
- body: formData,
34
- });
35
-
36
- const result = (await response.json()) as {
37
- success: boolean;
38
- error?: string;
39
- mediaId?: number;
40
- };
41
-
42
- if (!result.success || typeof result.mediaId !== 'number') {
43
- return { success: false as const, error: result.error || 'Upload failed.' };
44
- }
45
-
46
- return { success: true as const, mediaId: result.mediaId };
47
- }}
48
- onDeleteScreenshot={async (mediaId) => {
49
- const response = await fetch(`/api/admin-feedback/upload/${mediaId}`, {
50
- method: 'DELETE',
51
- credentials: 'include',
52
- });
53
-
54
- const result = (await response.json()) as { success: boolean; error?: string };
55
- if (!result.success) {
56
- return { success: false as const, error: result.error || 'Delete failed.' };
57
- }
58
-
59
- return { success: true as const };
60
- }}
61
- />
62
- );
63
- }