Last active
August 24, 2020 05:33
-
-
Save brianfoody/1892aec07498f7156d293aff9ef564e1 to your computer and use it in GitHub Desktop.
Organisational Event typings
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
import { Events as MarketingEvents } from "./MarketingEvents"; | |
import { Events as SalesEvents } from "./SalesEvents"; | |
import { Events as UserEvents } from "./UserEvents"; | |
type EventsBySource = { | |
Marketing: MarketingEvents; | |
Sales: SalesEvents; | |
User: UserEvents; | |
}; | |
type Source = keyof EventsBySource; | |
type OrganisationalEvent<S extends Source, T> = { | |
source: S; // The source of the events. | |
type: keyof EventsBySource[S]; // The type of event. Will be one of possible source events. | |
utcTime: number; // Time event happened in UTC | |
version: number; // schema version of the data | |
data: T; // The event data type which matches the schema version. | |
}; | |
// TODO Create a type to map these automagically | |
// Marketing Events | |
export type MarketingSubscribeEvent = OrganisationalEvent<"Marketing", MarketingEvents["Subscribe"]>; | |
export type MarketingUnsubscribeEvent = OrganisationalEvent<"Marketing", MarketingEvents["Unsubscribe"]>; | |
// Sales Events | |
export type SalesLeadEvent = OrganisationalEvent<"Sales", SalesEvents["Lead"]>; | |
export type SalesCloseEvent = OrganisationalEvent<"Sales", SalesEvents["Close"]>; | |
export type SalesEndEvent = OrganisationalEvent<"Sales", SalesEvents["End"]>; | |
// User Events | |
export type UserSignUpEvent = OrganisationalEvent<"User", UserEvents["SignUp"]>; | |
export type UserMembershipUpdateEvent = OrganisationalEvent<"User", UserEvents["MembershipUpdate"]>; | |
export type UserCloseAccountEvent = OrganisationalEvent<"User", UserEvents["CloseAccount"]>; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment