Skip to content

Instantly share code, notes, and snippets.

@brianfoody
Last active August 24, 2020 05:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brianfoody/1892aec07498f7156d293aff9ef564e1 to your computer and use it in GitHub Desktop.
Save brianfoody/1892aec07498f7156d293aff9ef564e1 to your computer and use it in GitHub Desktop.
Organisational Event typings
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