1 | |
2 | type Buttondown = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Update Webhook |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Buttondown, |
11 | id: string, |
12 | body: { |
13 | status?: "enabled" | "disabled"; |
14 | event_types: |
15 | | "subscriber.created" |
16 | | "subscriber.unsubscribed" |
17 | | "subscriber.changed_email" |
18 | | "subscriber.confirmed" |
19 | | "subscriber.trial_started" |
20 | | "subscriber.trial_ended" |
21 | | "subscriber.type.changed" |
22 | | "subscriber.tags.changed" |
23 | | "subscriber.clicked" |
24 | | "subscriber.opened" |
25 | | "subscriber.paid" |
26 | | "subscriber.churned" |
27 | | "subscriber.updated" |
28 | | "subscriber.deleted" |
29 | | "subscriber.viewed_checkout_page" |
30 | | "subscriber.replied" |
31 | | "subscriber.paused" |
32 | | "subscriber.resumed" |
33 | | "subscriber.responded_to_survey" |
34 | | "subscriber.referred" |
35 | | "subscriber.referred.paid" |
36 | | "subscriber.commented" |
37 | | "email.created" |
38 | | "email.sent" |
39 | | "email.updated" |
40 | | "email.deleted" |
41 | | "email.status.changed" |
42 | | "scheduled_email.converted" |
43 | | "mention.created" |
44 | | "advertising_slot.purchased" |
45 | | "social_mention.created" |
46 | | "export.created" |
47 | | "export.completed" |
48 | | "export.failed" |
49 | | "automation.invoked" |
50 | | "stripe.checkout.session.completed" |
51 | | "stripe.subscription.activated" |
52 | | "stripe.subscription.churning" |
53 | | "stripe.subscription.deactivated" |
54 | | "stripe.customer.updated" |
55 | | "memberful.subscription.created" |
56 | | "memberful.subscription.deleted" |
57 | | "memberful.member.updated"[]; |
58 | url: string; |
59 | description?: string; |
60 | }, |
61 | ) { |
62 | const url = new URL(`https://api.buttondown.com/v1/webhooks/${id}`); |
63 |
|
64 | const response = await fetch(url, { |
65 | method: "PATCH", |
66 | headers: { |
67 | "Content-Type": "application/json", |
68 | Authorization: "Token " + auth.token, |
69 | }, |
70 | body: JSON.stringify(body), |
71 | }); |
72 | if (!response.ok) { |
73 | const text = await response.text(); |
74 | throw new Error(`${response.status} ${text}`); |
75 | } |
76 | return await response.json(); |
77 | } |
78 |
|