diff --git a/common/src/index.ts b/common/src/index.ts index aaeb002c3..c66b42e75 100644 --- a/common/src/index.ts +++ b/common/src/index.ts @@ -5,3 +5,4 @@ export * as gameClasses from "./game-classes"; export * as ESDCore from "./lib/esd"; export * as StaticConfig from "./config/static-config"; export * from "./utils/util"; +export * from "./webhooks"; diff --git a/common/src/types.ts b/common/src/types.ts index e3419212d..707e73673 100644 --- a/common/src/types.ts +++ b/common/src/types.ts @@ -1,6 +1,6 @@ import { IObjectID } from "monk"; import { FilterQuery } from "mongodb"; -import { AllClassSets, GameClasses, GameClassSets } from "./game-classes"; +import { AllClassSets, GameClasses } from "./game-classes"; export interface CounterDocument { counterName: string; @@ -1256,29 +1256,6 @@ export interface BMSCourseDocument { value: integer; } -export type RedisIPCChannels = "class-update" | "goal-achieved" | "milestone-achieved"; - -export type RedisIPCData = { - "class-update": { - userID: integer; - set: GameClassSets[IDStrings]; - old: integer | null; - new: integer | null; - }; - "goal-achieved": { - userID: integer; - goalID: string; - old: GoalImportStat; - new: GoalImportStat; - }; - "milestone-achieved": { - userID: integer; - milestoneID: string; - old: MilestoneImportStat; - new: MilestoneImportStat; - }; -}; - /** * All the permissions a token may have. */ diff --git a/common/src/webhooks.ts b/common/src/webhooks.ts new file mode 100644 index 000000000..67972ea97 --- /dev/null +++ b/common/src/webhooks.ts @@ -0,0 +1,59 @@ +import { GameClassSets } from "./game-classes"; +import { GoalImportStat, IDStrings, integer, MilestoneImportStat } from "./types"; + +/** + * An event fired when a users class improves. + */ +export interface WebhookEventClassUpdateV1 { + type: "class-update/v1"; + content: { + userID: integer; + set: GameClassSets[IDStrings]; + old: integer | null; + new: integer | null; + }; +} + +/** + * An event fired when a goal is achieved. + */ +export interface WebhookEventGoalAchievedV1 { + type: "goal-achieved/v1"; + content: { + userID: integer; + goalID: string; + old: GoalImportStat; + new: GoalImportStat; + }; +} + +/** + * An event fired when a milestone is achieved. + */ +export interface WebhookEventMilestoneAchievedV1 { + type: "milestone-achieved/v1"; + content: { + userID: integer; + milestoneID: string; + old: MilestoneImportStat; + new: MilestoneImportStat; + }; +} + +/** + * An event used for debugging. Contains information about the + * registered client and the server. + */ +export interface WebhookEventStatusV1 { + type: "status/v1"; + content: { + clientName: string; + clientID: string; + serverVersion: string; + }; +} + +export type WebhookEvents = + | WebhookEventClassUpdateV1 + | WebhookEventGoalAchievedV1 + | WebhookEventMilestoneAchievedV1;