| 21 | }; |
| 22 | |
| 23 | export class EventTrigger<TEventSpecification extends EventSpecification<any>> |
| 24 | implements Trigger<TEventSpecification> |
| 25 | { |
| 26 | #options: EventTriggerOptions<TEventSpecification>; |
| 27 | |
| 28 | constructor(options: EventTriggerOptions<TEventSpecification>) { |
| 29 | this.#options = options; |
| 30 | } |
| 31 | |
| 32 | toJSON(): TriggerMetadata { |
| 33 | return { |
| 34 | type: "static", |
| 35 | title: this.#options.name ?? this.#options.event.title, |
| 36 | rule: { |
| 37 | event: this.#options.name ?? this.#options.event.name, |
| 38 | source: this.#options.source ?? "trigger.dev", |
| 39 | payload: deepMergeFilters(this.#options.filter ?? {}, this.#options.event.filter ?? {}), |
| 40 | }, |
| 41 | }; |
| 42 | } |
| 43 | |
| 44 | get event() { |
| 45 | return this.#options.event; |
| 46 | } |
| 47 | |
| 48 | attachToJob(triggerClient: TriggerClient, job: Job<Trigger<TEventSpecification>, any>): void {} |
| 49 | |
| 50 | get preprocessRuns() { |
| 51 | return false; |
| 52 | } |
| 53 | |
| 54 | async verifyPayload(payload: ReturnType<TEventSpecification["parsePayload"]>) { |
| 55 | if (this.#options.verify) { |
| 56 | if ((payload as any) instanceof Request) { |
| 57 | const clonedRequest = (payload as Request).clone(); |
| 58 | return this.#options.verify(clonedRequest); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | return { success: true as const }; |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | /** Configuration options for an EventTrigger */ |
| 67 | type TriggerOptions<TEvent> = { |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…