@@ -6,11 +6,11 @@ import { WebhooksEventTypes } from "../../../schema/webhooks";
6
6
import { createCustomError } from "../../middleware/error" ;
7
7
import { standardResponseSchema } from "../../schemas/sharedApiSchemas" ;
8
8
import { WebhookSchema , toWebhookSchema } from "../../schemas/webhook" ;
9
- import { isValidHttpUrl } from "../../utils/validator" ;
9
+ import { isValidWebhookUrl } from "../../utils/validator" ;
10
10
11
11
const requestBodySchema = Type . Object ( {
12
12
url : Type . String ( {
13
- description : "Webhook URL" ,
13
+ description : "Webhook URL. Non-HTTPS URLs are not supported. " ,
14
14
examples : [ "https://example.com/webhook" ] ,
15
15
} ) ,
16
16
name : Type . Optional (
@@ -23,52 +23,21 @@ const requestBodySchema = Type.Object({
23
23
24
24
requestBodySchema . examples = [
25
25
{
26
- url : "https://example.com/allTxUpdate" ,
27
- name : "All Transaction Events" ,
26
+ url : "https://example.com/webhook" ,
27
+ name : "Notify of transaction updates" ,
28
+ secret : "..." ,
28
29
eventType : WebhooksEventTypes . ALL_TX ,
29
- } ,
30
- {
31
- url : "https://example.com/queuedTx" ,
32
- name : "QueuedTx" ,
33
- eventType : WebhooksEventTypes . QUEUED_TX ,
34
- } ,
35
- {
36
- url : "https://example.com/sentTx" ,
37
- name : "Sent Transaction Event" ,
38
- eventType : WebhooksEventTypes . SENT_TX ,
39
- } ,
40
- {
41
- url : "https://example.com/minedTx" ,
42
- name : "Mined Transaction Event" ,
43
- eventType : WebhooksEventTypes . MINED_TX ,
44
- } ,
45
- {
46
- url : "https://example.com/erroredTx" ,
47
- name : "Errored Transaction Event" ,
48
- eventType : WebhooksEventTypes . ERRORED_TX ,
49
- } ,
50
- {
51
- url : "https://example.com/cancelledTx" ,
52
- name : "Cancelled Transaction Event" ,
53
- eventType : WebhooksEventTypes . CANCELLED_TX ,
54
- } ,
55
- {
56
- url : "https://example.com/walletBalance" ,
57
- name : "Backend Wallet Balance Event" ,
58
- eventType : WebhooksEventTypes . BACKEND_WALLET_BALANCE ,
59
- } ,
60
- {
61
- url : "https://example.com/auth" ,
62
- name : "Auth Check" ,
63
- eventType : WebhooksEventTypes . AUTH ,
30
+ active : true ,
31
+ createdAt : "2024-10-02T02:07:27.255Z" ,
32
+ id : 42 ,
64
33
} ,
65
34
] ;
66
35
67
36
const responseBodySchema = Type . Object ( {
68
37
result : WebhookSchema ,
69
38
} ) ;
70
39
71
- export async function createWebhook ( fastify : FastifyInstance ) {
40
+ export async function createWebhookRoute ( fastify : FastifyInstance ) {
72
41
fastify . route < {
73
42
Body : Static < typeof requestBodySchema > ;
74
43
Reply : Static < typeof responseBodySchema > ;
@@ -78,7 +47,7 @@ export async function createWebhook(fastify: FastifyInstance) {
78
47
schema : {
79
48
summary : "Create a webhook" ,
80
49
description :
81
- "Create a webhook to call when certain blockchain events occur ." ,
50
+ "Create a webhook to call when a specific Engine event occurs ." ,
82
51
tags : [ "Webhooks" ] ,
83
52
operationId : "createWebhook" ,
84
53
body : requestBodySchema ,
@@ -90,7 +59,7 @@ export async function createWebhook(fastify: FastifyInstance) {
90
59
handler : async ( req , res ) => {
91
60
const { url, name, eventType } = req . body ;
92
61
93
- if ( ! isValidHttpUrl ( url ) ) {
62
+ if ( ! isValidWebhookUrl ( url ) ) {
94
63
throw createCustomError (
95
64
"Invalid webhook URL. Make sure it starts with 'https://'." ,
96
65
StatusCodes . BAD_REQUEST ,
0 commit comments