-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(webhooks): add support for workers (#637)
* Emit events * Boot only on main thread * Move interfaces * Move identifiers * Use database contract * Add webhooks to transaction pool * Fix tests * Add handler * Listen to events * Fix tests
- Loading branch information
1 parent
d387364
commit 116cd96
Showing
20 changed files
with
165 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
export interface Webhook { | ||
id?: string; | ||
token?: string; | ||
|
||
event: string; | ||
target: string; | ||
enabled: boolean; | ||
conditions: Array<{ | ||
key: string; | ||
value: any; | ||
condition: string; | ||
}>; | ||
} | ||
|
||
export interface Database { | ||
boot(): void; | ||
restore(): void; | ||
all(): Webhook[]; | ||
hasById(id: string): boolean; | ||
findById(id: string): Webhook | undefined; | ||
findByEvent(event: string): Webhook[]; | ||
create(data: Webhook): Webhook; | ||
update(id: string, data: Webhook): Webhook | undefined; | ||
destroy(id: string): Webhook | undefined; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -276,6 +276,9 @@ | |
}, | ||
{ | ||
"package": "@mainsail/api-transaction-pool" | ||
}, | ||
{ | ||
"package": "@mainsail/webhooks" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
packages/transaction-pool-worker/source/handlers/reload-webhooks.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { inject, injectable } from "@mainsail/container"; | ||
import { Contracts, Identifiers } from "@mainsail/contracts"; | ||
|
||
@injectable() | ||
export class ReloadWebhooksHandler { | ||
@inject(Identifiers.Webhooks.Database) | ||
protected readonly database!: Contracts.Webhooks.Database; | ||
|
||
public async handle(): Promise<void> { | ||
this.database.restore(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.