@@ -5,13 +5,12 @@ import { NEXT_PUBLIC_THIRDWEB_BRIDGE_HOST } from "@/constants/public-envs";
55
66const UB_BASE_URL = NEXT_PUBLIC_THIRDWEB_BRIDGE_HOST ;
77
8- type Webhook = {
8+ export type Webhook = {
99 url : string ;
1010 label : string ;
1111 active : boolean ;
1212 createdAt : string ;
1313 id : string ;
14- secret : string ;
1514 version ?: number ; // TODO (UB) make this mandatory after migration
1615} ;
1716
@@ -29,11 +28,17 @@ export async function getWebhooks(props: { clientId: string; teamId: string }) {
2928
3029 if ( ! res . ok ) {
3130 const text = await res . text ( ) ;
32- throw new Error ( text ) ;
31+ return {
32+ type : "error" ,
33+ message : text ,
34+ } ;
3335 }
3436
3537 const json = await res . json ( ) ;
36- return json . data as Array < Webhook > ;
38+ return {
39+ type : "success" ,
40+ data : json . data as Array < Webhook > ,
41+ } ;
3742}
3843
3944export async function createWebhook ( props : {
@@ -64,10 +69,18 @@ export async function createWebhook(props: {
6469
6570 if ( ! res . ok ) {
6671 const text = await res . text ( ) ;
67- throw new Error ( text ) ;
72+ return {
73+ type : "error" ,
74+ message : text ,
75+ } ;
6876 }
6977
70- return ;
78+ const json = await res . json ( ) ;
79+
80+ return {
81+ type : "success" ,
82+ data : json . data as Webhook ,
83+ } ;
7184}
7285
7386export async function deleteWebhook ( props : {
@@ -91,10 +104,57 @@ export async function deleteWebhook(props: {
91104
92105 if ( ! res . ok ) {
93106 const text = await res . text ( ) ;
94- throw new Error ( text ) ;
107+ return {
108+ type : "error" ,
109+ message : text ,
110+ } ;
95111 }
96112
97- return ;
113+ return {
114+ type : "success" ,
115+ } ;
116+ }
117+
118+ export async function updateWebhook ( props : {
119+ clientId : string ;
120+ teamId : string ;
121+ webhookId : string ;
122+ body : {
123+ version ?: number ;
124+ url : string ;
125+ label : string ;
126+ } ;
127+ } ) {
128+ const authToken = await getAuthToken ( ) ;
129+
130+ const res = await fetch (
131+ `${ UB_BASE_URL } /v1/developer/webhooks/${ props . webhookId } ` ,
132+ {
133+ method : "PUT" ,
134+ body : JSON . stringify ( props . body ) ,
135+ headers : {
136+ Authorization : `Bearer ${ authToken } ` ,
137+ "Content-Type" : "application/json" ,
138+ "x-client-id" : props . clientId ,
139+ "x-team-id" : props . teamId ,
140+ } ,
141+ } ,
142+ ) ;
143+
144+ if ( ! res . ok ) {
145+ const text = await res . text ( ) ;
146+ return {
147+ type : "error" ,
148+ message : text ,
149+ } ;
150+ }
151+
152+ const json = await res . json ( ) ;
153+
154+ return {
155+ type : "success" ,
156+ data : json . data as Webhook ,
157+ } ;
98158}
99159
100160type PaymentLink = {
0 commit comments