Skip to content

Commit 7965d93

Browse files
[Dashboard] Add webhook version support to Universal Bridge (#6779)
Co-authored-by: gregfromstl <[email protected]>
1 parent 4ccf062 commit 7965d93

File tree

6 files changed

+349
-223
lines changed

6 files changed

+349
-223
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
"use server";
2+
import { getAuthToken } from "app/api/lib/getAuthToken";
3+
4+
const UB_BASE_URL = process.env.NEXT_PUBLIC_THIRDWEB_BRIDGE_HOST;
5+
6+
type Webhook = {
7+
url: string;
8+
label: string;
9+
active: boolean;
10+
createdAt: string;
11+
id: string;
12+
secret: string;
13+
version?: number; // TODO (UB) make this mandatory after migration
14+
};
15+
16+
export async function getWebhooks(props: {
17+
clientId: string;
18+
}) {
19+
const authToken = await getAuthToken();
20+
const res = await fetch(`${UB_BASE_URL}/v1/developer/webhooks`, {
21+
method: "GET",
22+
headers: {
23+
"Content-Type": "application/json",
24+
"x-client-id-override": props.clientId,
25+
Authorization: `Bearer ${authToken}`,
26+
},
27+
});
28+
29+
if (!res.ok) {
30+
const text = await res.text();
31+
throw new Error(text);
32+
}
33+
34+
const json = await res.json();
35+
return json.data as Array<Webhook>;
36+
}
37+
38+
export async function createWebhook(props: {
39+
clientId: string;
40+
version?: number;
41+
url: string;
42+
label: string;
43+
secret?: string;
44+
}) {
45+
const authToken = await getAuthToken();
46+
const res = await fetch(`${UB_BASE_URL}/v1/developer/webhooks`, {
47+
method: "POST",
48+
body: JSON.stringify({
49+
url: props.url,
50+
label: props.label,
51+
version: props.version,
52+
secret: props.secret,
53+
}),
54+
headers: {
55+
"Content-Type": "application/json",
56+
"x-client-id-override": props.clientId,
57+
Authorization: `Bearer ${authToken}`,
58+
},
59+
});
60+
61+
if (!res.ok) {
62+
const text = await res.text();
63+
throw new Error(text);
64+
}
65+
66+
return;
67+
}
68+
69+
export async function deleteWebhook(props: {
70+
clientId: string;
71+
webhookId: string;
72+
}) {
73+
const authToken = await getAuthToken();
74+
const res = await fetch(
75+
`${UB_BASE_URL}/v1/developer/webhooks/${props.webhookId}`,
76+
{
77+
method: "DELETE",
78+
headers: {
79+
"Content-Type": "application/json",
80+
"x-client-id-override": props.clientId,
81+
Authorization: `Bearer ${authToken}`,
82+
},
83+
},
84+
);
85+
86+
if (!res.ok) {
87+
const text = await res.text();
88+
throw new Error(text);
89+
}
90+
91+
return;
92+
}
93+
94+
export type Fee = {
95+
feeRecipient: string;
96+
feeBps: number;
97+
createdAt: string;
98+
updatedAt: string;
99+
};
100+
101+
export async function getFees(props: {
102+
clientId: string;
103+
}) {
104+
const authToken = await getAuthToken();
105+
const res = await fetch(`${UB_BASE_URL}/v1/developer/fees`, {
106+
method: "GET",
107+
headers: {
108+
"Content-Type": "application/json",
109+
"x-client-id-override": props.clientId,
110+
Authorization: `Bearer ${authToken}`,
111+
},
112+
});
113+
114+
if (!res.ok) {
115+
const text = await res.text();
116+
throw new Error(text);
117+
}
118+
119+
const json = await res.json();
120+
return json.data as Fee;
121+
}
122+
123+
export async function updateFee(props: {
124+
clientId: string;
125+
feeRecipient: string;
126+
feeBps: number;
127+
}) {
128+
const authToken = await getAuthToken();
129+
const res = await fetch(`${UB_BASE_URL}/v1/developer/fees`, {
130+
method: "PUT",
131+
headers: {
132+
"Content-Type": "application/json",
133+
"x-client-id-override": props.clientId,
134+
Authorization: `Bearer ${authToken}`,
135+
},
136+
body: JSON.stringify({
137+
feeRecipient: props.feeRecipient,
138+
feeBps: props.feeBps,
139+
}),
140+
});
141+
142+
if (!res.ok) {
143+
const text = await res.text();
144+
throw new Error(text);
145+
}
146+
147+
return;
148+
}

apps/dashboard/src/app/team/[team_slug]/[project_slug]/connect/universal-bridge/settings/page.tsx

+29-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { getProject } from "@/api/projects";
22
import { getTeamBySlug } from "@/api/team";
3+
import { getFees } from "@/api/universal-bridge/developer";
34
import { redirect } from "next/navigation";
45
import { PayConfig } from "../../../../../../../components/pay/PayConfig";
56

@@ -24,5 +25,32 @@ export default async function Page(props: {
2425
redirect(`/team/${team_slug}`);
2526
}
2627

27-
return <PayConfig project={project} teamId={team.id} teamSlug={team_slug} />;
28+
let fees = await getFees({
29+
clientId: project.publishableKey,
30+
}).catch(() => {
31+
return {
32+
feeRecipient: "",
33+
feeBps: 0,
34+
createdAt: "",
35+
updatedAt: "",
36+
};
37+
});
38+
39+
if (!fees) {
40+
fees = {
41+
feeRecipient: "",
42+
feeBps: 0,
43+
createdAt: "",
44+
updatedAt: "",
45+
};
46+
}
47+
48+
return (
49+
<PayConfig
50+
project={project}
51+
teamId={team.id}
52+
teamSlug={team_slug}
53+
fees={fees}
54+
/>
55+
);
2856
}

0 commit comments

Comments
 (0)