| 264 | }; |
| 265 | |
| 266 | export class WebhookTrigger< |
| 267 | TEventSpecification extends EventSpecification<any>, |
| 268 | TEventSource extends WebhookSource<any, any, any>, |
| 269 | > implements Trigger<TEventSpecification> |
| 270 | { |
| 271 | constructor(private options: WebhookTriggerOptions<TEventSpecification, TEventSource>) {} |
| 272 | |
| 273 | get event() { |
| 274 | return this.options.event; |
| 275 | } |
| 276 | |
| 277 | get source() { |
| 278 | return this.options.source; |
| 279 | } |
| 280 | |
| 281 | get key() { |
| 282 | return slugifyId(this.options.source.key(this.options.params)); |
| 283 | } |
| 284 | |
| 285 | toJSON(): TriggerMetadata { |
| 286 | return { |
| 287 | type: "static", |
| 288 | title: "Webhook", |
| 289 | rule: { |
| 290 | event: this.event.name, |
| 291 | payload: deepMergeFilters( |
| 292 | this.options.source.filter(this.options.params, this.options.config), |
| 293 | this.event.filter ?? {} |
| 294 | ), |
| 295 | source: this.event.source, |
| 296 | }, |
| 297 | properties: this.options.source.properties(this.options.params), |
| 298 | link: `http-endpoints/${this.key}`, |
| 299 | }; |
| 300 | } |
| 301 | |
| 302 | filter(eventFilter: EventFilter) { |
| 303 | const { event, ...optionsWithoutEvent } = this.options; |
| 304 | const { filter, ...eventWithoutFilter } = event; |
| 305 | |
| 306 | return new WebhookTrigger({ |
| 307 | ...optionsWithoutEvent, |
| 308 | event: { |
| 309 | ...eventWithoutFilter, |
| 310 | filter: deepMergeFilters(filter ?? {}, eventFilter), |
| 311 | }, |
| 312 | }); |
| 313 | } |
| 314 | |
| 315 | attachToJob(triggerClient: TriggerClient, job: Job<Trigger<TEventSpecification>, any>) { |
| 316 | triggerClient.defineHttpEndpoint( |
| 317 | { |
| 318 | id: this.key, |
| 319 | source: "trigger.dev", |
| 320 | icon: this.event.icon, |
| 321 | verify: async () => ({ success: true }), |
| 322 | }, |
| 323 | true |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…