@@ -6,11 +6,11 @@ import { WebhooksEventTypes } from "../../../schema/webhooks";
66import { createCustomError } from "../../middleware/error" ;
77import { standardResponseSchema } from "../../schemas/sharedApiSchemas" ;
88import { WebhookSchema , toWebhookSchema } from "../../schemas/webhook" ;
9- import { isValidHttpUrl } from "../../utils/validator" ;
9+ import { isValidWebhookUrl } from "../../utils/validator" ;
1010
1111const requestBodySchema = Type . Object ( {
1212 url : Type . String ( {
13- description : "Webhook URL" ,
13+ description : "Webhook URL. Non-HTTPS URLs are not supported. " ,
1414 examples : [ "https://example.com/webhook" ] ,
1515 } ) ,
1616 name : Type . Optional (
@@ -23,52 +23,21 @@ const requestBodySchema = Type.Object({
2323
2424requestBodySchema . examples = [
2525 {
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 : "..." ,
2829 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 ,
6433 } ,
6534] ;
6635
6736const responseBodySchema = Type . Object ( {
6837 result : WebhookSchema ,
6938} ) ;
7039
71- export async function createWebhook ( fastify : FastifyInstance ) {
40+ export async function createWebhookRoute ( fastify : FastifyInstance ) {
7241 fastify . route < {
7342 Body : Static < typeof requestBodySchema > ;
7443 Reply : Static < typeof responseBodySchema > ;
@@ -78,7 +47,7 @@ export async function createWebhook(fastify: FastifyInstance) {
7847 schema : {
7948 summary : "Create a webhook" ,
8049 description :
81- "Create a webhook to call when certain blockchain events occur ." ,
50+ "Create a webhook to call when a specific Engine event occurs ." ,
8251 tags : [ "Webhooks" ] ,
8352 operationId : "createWebhook" ,
8453 body : requestBodySchema ,
@@ -90,7 +59,7 @@ export async function createWebhook(fastify: FastifyInstance) {
9059 handler : async ( req , res ) => {
9160 const { url, name, eventType } = req . body ;
9261
93- if ( ! isValidHttpUrl ( url ) ) {
62+ if ( ! isValidWebhookUrl ( url ) ) {
9463 throw createCustomError (
9564 "Invalid webhook URL. Make sure it starts with 'https://'." ,
9665 StatusCodes . BAD_REQUEST ,
0 commit comments