saleor-app-sdk-REDIS_APL/src/app-bridge/events.ts

70 lines
1.2 KiB
TypeScript
Raw Normal View History

import { Values } from "./helpers";
export type Version = 1;
export const EventType = {
handshake: "handshake",
response: "response",
redirect: "redirect",
theme: "theme",
localeChanged: "localeChanged",
} as const;
2022-08-11 21:14:41 +00:00
export type EventType = Values<typeof EventType>;
type Event<Name extends EventType, Payload extends {}> = {
payload: Payload;
type: Name;
};
export type HandshakeEvent = Event<
"handshake",
{
token: string;
version: Version;
}
>;
export type DispatchResponseEvent = Event<
"response",
{
actionId: string;
ok: boolean;
}
>;
export type RedirectEvent = Event<
"redirect",
{
path: string;
}
>;
export type ThemeType = "light" | "dark";
export type ThemeEvent = Event<
"theme",
{
theme: ThemeType;
}
>;
export type LocaleChangedEvent = Event<
"localeChanged",
{
locale: string;
}
>;
export type Events =
| HandshakeEvent
| DispatchResponseEvent
| RedirectEvent
| ThemeEvent
| LocaleChangedEvent;
export type PayloadOfEvent<
TEventType extends EventType,
TEvent extends Events = Events
// @ts-ignore TODO - why this is not working with this tsconfig? Fixme
2022-09-02 14:53:40 +00:00
> = TEvent extends Event<TEventType, unknown> ? TEvent["payload"] : never;