Skip to content

Commit b91991b

Browse files
authored
Merge pull request #175 from timlrx/update-newsletter
Update newsletter APIs and contentlayer dependency
2 parents b91eb82 + c4a356a commit b91991b

11 files changed

+401
-127
lines changed

.changeset/rare-pandas-bow.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'pliny': minor
3+
---
4+
5+
remove revue from newsletter list

.changeset/seven-parents-jog.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'pliny': patch
3+
---
4+
5+
update pliny to v0.5

.changeset/stale-years-kiss.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'pliny': patch
3+
---
4+
5+
update klaviyo api

README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ Pliny provides out of the box components to enhance your static site:
1919
- Email Octopus
2020
- Klaviyo
2121
- Mailchimp
22-
- Revue
2322
- Command palette search with tailwind style sheet
2423
- Algolia
2524
- Kbar (local search)
@@ -245,7 +244,7 @@ import { NewsletterAPI } from 'pliny/newsletter'
245244
import siteMetadata from '@/data/siteMetadata'
246245

247246
const handler = NewsletterAPI({
248-
provider: '', // Use one of mailchimp, buttondown, convertkit, klaviyo, revue, emailOctopus
247+
provider: '', // Use one of mailchimp, buttondown, convertkit, klaviyo emailOctopus
249248
})
250249

251250
export { handler as GET, handler as POST }

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,4 @@
4646
]
4747
},
4848
"packageManager": "[email protected]"
49-
}
49+
}

packages/pliny/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@
3838
"@docsearch/react": "^3.5.0",
3939
"@giscus/react": "^3.0.0",
4040
"@mailchimp/mailchimp_marketing": "^3.0.80",
41-
"contentlayer2": "^0.4.6",
41+
"contentlayer2": "^0.5.0",
4242
"copyfiles": "^2.4.1",
4343
"github-slugger": "^2.0.0",
4444
"js-yaml": "4.1.0",
4545
"kbar": "0.1.0-beta.45",
46-
"next-contentlayer2": "^0.4.6",
46+
"next-contentlayer2": "^0.5.0",
4747
"next-themes": "^0.3.0",
4848
"probe-image-size": "^7.2.3",
4949
"remark": "^15.0.0",

packages/pliny/src/config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ const sampleConfig: PlinyConfig = {
7474
},
7575
},
7676
newsletter: {
77-
// supports mailchimp, buttondown, convertkit, klaviyo, revue, emailOctopus
77+
// supports mailchimp, buttondown, convertkit, klaviyo, emailOctopus
7878
// Please add your .env file and modify it according to your selection
7979
provider: 'buttondown',
8080
},

packages/pliny/src/newsletter/index.ts

+1-8
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ import { buttondownSubscribe } from './buttondown'
55
import { convertkitSubscribe } from './convertkit'
66
import { mailchimpSubscribe } from './mailchimp'
77
import { klaviyoSubscribe } from './klaviyo'
8-
import { revueSubscribe } from './revue'
98
import { emailOctopusSubscribe } from './emailOctopus'
109

1110
export interface NewsletterConfig {
12-
provider: 'buttondown' | 'convertkit' | 'klaviyo' | 'mailchimp' | 'revue' | 'emailoctopus'
11+
provider: 'buttondown' | 'convertkit' | 'klaviyo' | 'mailchimp' | 'emailoctopus'
1312
}
1413

1514
export interface NewsletterRequest extends NextApiRequest {
@@ -42,9 +41,6 @@ async function NewsletterAPIHandler(
4241
case 'klaviyo':
4342
response = await klaviyoSubscribe(email)
4443
break
45-
case 'revue':
46-
response = await revueSubscribe(email)
47-
break
4844
case 'emailoctopus':
4945
response = await emailOctopusSubscribe(email)
5046
break
@@ -80,9 +76,6 @@ async function NewsletterRouteHandler(req: NextRequest, options: NewsletterConfi
8076
case 'klaviyo':
8177
response = await klaviyoSubscribe(email)
8278
break
83-
case 'revue':
84-
response = await revueSubscribe(email)
85-
break
8679
case 'emailoctopus':
8780
response = await emailOctopusSubscribe(email)
8881
break
+45-14
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,51 @@
11
export const klaviyoSubscribe = async (email: string) => {
22
const API_KEY = process.env.KLAVIYO_API_KEY
33
const LIST_ID = process.env.KLAVIYO_LIST_ID
4-
const response = await fetch(
5-
`https://a.klaviyo.com/api/v2/list/${LIST_ID}/subscribe?api_key=${API_KEY}`,
6-
{
7-
method: 'POST',
8-
headers: {
9-
Accept: 'application/json',
10-
'Content-Type': 'application/json',
4+
5+
const data = {
6+
data: {
7+
type: 'profile-subscription-bulk-create-job',
8+
attributes: {
9+
custom_source: 'Marketing Event',
10+
profiles: {
11+
data: [
12+
{
13+
type: 'profile',
14+
attributes: {
15+
email: email,
16+
subscriptions: {
17+
email: {
18+
marketing: {
19+
consent: 'SUBSCRIBED',
20+
},
21+
},
22+
},
23+
},
24+
},
25+
],
26+
},
1127
},
12-
// You can add additional params here i.e. SMS, etc.
13-
// https://developers.klaviyo.com/en/reference/subscribe
14-
body: JSON.stringify({
15-
profiles: [{ email: email }],
16-
}),
17-
}
18-
)
28+
relationships: {
29+
list: {
30+
data: {
31+
type: 'list',
32+
id: LIST_ID,
33+
},
34+
},
35+
},
36+
},
37+
}
38+
39+
const response = await fetch('https://a.klaviyo.com/api/profile-subscription-bulk-create-jobs', {
40+
method: 'POST',
41+
headers: {
42+
Authorization: `Klaviyo-API-Key ${API_KEY}`,
43+
Accept: 'application/json',
44+
'Content-Type': 'application/json',
45+
revision: '2024-07-15',
46+
},
47+
body: JSON.stringify(data),
48+
})
49+
1950
return response
2051
}

packages/pliny/src/newsletter/revue.ts

-15
This file was deleted.

0 commit comments

Comments
 (0)