payload-plugin-newsletter 0.8.5 → 0.8.6
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 +16 -0
- package/CLAUDE.md +53 -0
- package/dist/index.cjs +18 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +18 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
## [0.8.6] - 2025-07-02
|
|
2
|
+
|
|
3
|
+
### Fixed
|
|
4
|
+
- **Critical**: Fixed all endpoint handlers for Payload v3 compatibility
|
|
5
|
+
- ✅ Updated request body access from `req.data` to `await req.json()`
|
|
6
|
+
- ✅ Fixed cookie access from `req.cookies` to parsing from headers
|
|
7
|
+
- ✅ All endpoints now properly handle request data
|
|
8
|
+
- Affects: signin, subscribe, unsubscribe, preferences, verify-magic-link, me endpoints
|
|
9
|
+
- **Resolves**: "Cannot destructure property 'email' of 'req.data' as it is undefined" error
|
|
10
|
+
- **Resolves**: "Cannot read properties of undefined (reading 'newsletter-auth')" error
|
|
11
|
+
|
|
12
|
+
### Technical Details
|
|
13
|
+
- Updated all POST endpoints to use `const data = await req.json()` per Payload v3 patterns
|
|
14
|
+
- Updated cookie parsing to read from `req.headers.get('cookie')` instead of `req.cookies`
|
|
15
|
+
- All endpoint handlers now follow official Payload v3 REST API documentation patterns
|
|
16
|
+
|
|
1
17
|
## [0.8.5] - 2025-07-01
|
|
2
18
|
|
|
3
19
|
### Fixed
|
package/CLAUDE.md
CHANGED
|
@@ -4,6 +4,59 @@ This file contains development guidelines and reference information for Claude w
|
|
|
4
4
|
|
|
5
5
|
**Note**: This plugin is developed by Aniket Panjwani, who uses Broadcast (sendbroadcast.net) for newsletter management.
|
|
6
6
|
|
|
7
|
+
## Payload CMS Documentation Reference
|
|
8
|
+
|
|
9
|
+
The official Payload CMS documentation is available locally at:
|
|
10
|
+
`/Users/aniketpanjwani/Projects/reference_repos/payload/docs/`
|
|
11
|
+
|
|
12
|
+
Key directories for plugin development:
|
|
13
|
+
- `plugins/` - Official plugin examples and patterns
|
|
14
|
+
- `rest-api/` - REST API documentation and endpoint patterns
|
|
15
|
+
- `custom-components/` - Custom views and UI components
|
|
16
|
+
- `configuration/` - Core configuration patterns
|
|
17
|
+
- `hooks/` - Hook system documentation
|
|
18
|
+
- `authentication/` - Auth patterns and examples
|
|
19
|
+
- `local-api/` - Local API usage patterns
|
|
20
|
+
- `typescript/` - TypeScript patterns and best practices
|
|
21
|
+
|
|
22
|
+
When developing features, always reference these docs for:
|
|
23
|
+
1. Current Payload v3 patterns and best practices
|
|
24
|
+
2. Endpoint handler signatures and request/response formats
|
|
25
|
+
3. Authentication and authorization patterns
|
|
26
|
+
4. Plugin architecture guidelines
|
|
27
|
+
5. TypeScript type definitions and interfaces
|
|
28
|
+
|
|
29
|
+
### Critical Payload v3 Endpoint Patterns
|
|
30
|
+
|
|
31
|
+
From the official Payload v3 REST API documentation (`rest-api/overview.mdx`):
|
|
32
|
+
|
|
33
|
+
1. **Request Body Access**:
|
|
34
|
+
- Data is NOT automatically appended to the request
|
|
35
|
+
- Use `await req.json()` to read the body
|
|
36
|
+
- Or use `await addDataAndFileToRequest(req)` helper to mutate req and add req.data
|
|
37
|
+
|
|
38
|
+
2. **Response Format**:
|
|
39
|
+
- Return `Response.json()` objects, not `res.status().json()`
|
|
40
|
+
- Example: `return Response.json({ message: 'success' }, { status: 200 })`
|
|
41
|
+
|
|
42
|
+
3. **Cookie Access**:
|
|
43
|
+
- Cookies are NOT available at `req.cookies`
|
|
44
|
+
- Access via request headers instead
|
|
45
|
+
|
|
46
|
+
4. **Handler Signature**:
|
|
47
|
+
```ts
|
|
48
|
+
handler: async (req) => {
|
|
49
|
+
// NOT (req, res) - just req!
|
|
50
|
+
const data = await req.json() // or use addDataAndFileToRequest(req)
|
|
51
|
+
return Response.json({ result: 'data' })
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
**Current Plugin Bug**: The newsletter plugin endpoints are using old Payload v2 patterns:
|
|
56
|
+
- Trying to access `req.data` directly (undefined)
|
|
57
|
+
- Trying to access `req.cookies` directly (undefined)
|
|
58
|
+
- Need to update ALL endpoints to use the new patterns
|
|
59
|
+
|
|
7
60
|
## Important Security Guidelines
|
|
8
61
|
|
|
9
62
|
**NEVER include any of the following in the repository:**
|
package/dist/index.cjs
CHANGED
|
@@ -1451,6 +1451,7 @@ var createSubscribeEndpoint = (config) => {
|
|
|
1451
1451
|
method: "post",
|
|
1452
1452
|
handler: async (req) => {
|
|
1453
1453
|
try {
|
|
1454
|
+
const data = await req.json();
|
|
1454
1455
|
const {
|
|
1455
1456
|
email,
|
|
1456
1457
|
name,
|
|
@@ -1459,7 +1460,7 @@ var createSubscribeEndpoint = (config) => {
|
|
|
1459
1460
|
leadMagnet,
|
|
1460
1461
|
surveyResponses,
|
|
1461
1462
|
metadata = {}
|
|
1462
|
-
} =
|
|
1463
|
+
} = data;
|
|
1463
1464
|
const trimmedEmail = email?.trim();
|
|
1464
1465
|
const validation = validateSubscriberData({ email: trimmedEmail, name, source });
|
|
1465
1466
|
if (!validation.valid) {
|
|
@@ -1621,7 +1622,8 @@ var createVerifyMagicLinkEndpoint = (config) => {
|
|
|
1621
1622
|
method: "post",
|
|
1622
1623
|
handler: async (req) => {
|
|
1623
1624
|
try {
|
|
1624
|
-
const
|
|
1625
|
+
const data = await req.json();
|
|
1626
|
+
const { token } = data;
|
|
1625
1627
|
if (!token) {
|
|
1626
1628
|
return Response.json({
|
|
1627
1629
|
success: false,
|
|
@@ -1826,7 +1828,8 @@ var createUpdatePreferencesEndpoint = (config) => {
|
|
|
1826
1828
|
error: error instanceof Error ? error.message : "Invalid token"
|
|
1827
1829
|
}, { status: 401 });
|
|
1828
1830
|
}
|
|
1829
|
-
const
|
|
1831
|
+
const data = await req.json();
|
|
1832
|
+
const { name, locale, emailPreferences } = data;
|
|
1830
1833
|
const updateData = {};
|
|
1831
1834
|
if (name !== void 0) {
|
|
1832
1835
|
updateData.name = name;
|
|
@@ -1877,7 +1880,8 @@ var createUnsubscribeEndpoint = (config) => {
|
|
|
1877
1880
|
method: "post",
|
|
1878
1881
|
handler: async (req) => {
|
|
1879
1882
|
try {
|
|
1880
|
-
const
|
|
1883
|
+
const data = await req.json();
|
|
1884
|
+
const { email, token } = data;
|
|
1881
1885
|
if (!email && !token) {
|
|
1882
1886
|
return Response.json({
|
|
1883
1887
|
success: false,
|
|
@@ -2024,7 +2028,8 @@ var createSigninEndpoint = (config) => {
|
|
|
2024
2028
|
method: "post",
|
|
2025
2029
|
handler: async (req) => {
|
|
2026
2030
|
try {
|
|
2027
|
-
const
|
|
2031
|
+
const data = await req.json();
|
|
2032
|
+
const { email } = data;
|
|
2028
2033
|
const validation = validateSubscriberData({ email });
|
|
2029
2034
|
if (!validation.valid) {
|
|
2030
2035
|
return Response.json({
|
|
@@ -2105,7 +2110,14 @@ var createMeEndpoint = (config) => {
|
|
|
2105
2110
|
method: "get",
|
|
2106
2111
|
handler: async (req) => {
|
|
2107
2112
|
try {
|
|
2108
|
-
const
|
|
2113
|
+
const cookieHeader = req.headers.get("cookie") || "";
|
|
2114
|
+
const cookies = Object.fromEntries(
|
|
2115
|
+
cookieHeader.split("; ").map((c) => {
|
|
2116
|
+
const [key, ...value] = c.split("=");
|
|
2117
|
+
return [key, value.join("=")];
|
|
2118
|
+
})
|
|
2119
|
+
);
|
|
2120
|
+
const token = cookies["newsletter-auth"];
|
|
2109
2121
|
if (!token) {
|
|
2110
2122
|
return Response.json({
|
|
2111
2123
|
success: false,
|