import { BridgeConfigFigma } from "../Config/Config" ; import { MessageQueue } from "../MessageQueue" ; import { Request , Response , Router , json } from "express" ; import { FigmaPayload } from "./types" ; export class FigmaWebhooksRouter { constructor ( private readonly config , private readonly queue ) { } private onWebhook ( req , res ) { const payload = req . body ; const instance = Object . entries ( this . config . instances ) . find ( ( [ , p ] ) => p . passcode === payload . passcode ) ; if ( ! instance ) { res . sendStatus ( 401 ) ; return ; } if ( typeof payload . file_name !== "string" || typeof payload . file_key !== "string" ) { res . status ( 400 ) . send ( { error : "Missing required object keys file_name, file_key" } ) ; return ; } res . status ( 200 ) . send ( ) ; this . queue . push ( { eventName : 'figma.payload' , data : { payload , instanceName : instance [ 0 ] , } , sender : 'GithubWebhooks' , } ) ; } public getRouter ( ) { const router = Router ( ) ; router . use ( json ( ) ) ; router . post ( "/webhook" , this . onWebhook . bind ( this ) ) ; return router ; } }