UNPKG

@medusajs/types

Version:
54 lines 1.64 kB
import { Context } from "../shared-context"; export type Subscriber<TData = unknown> = (data: Event<TData>) => Promise<void>; export type SubscriberContext = { /** * The ID of the subscriber. Useful when retrying failed subscribers. */ subscriberId: string; }; export type SubscriberDescriptor = { id: string; subscriber: Subscriber; }; export type EventMetadata = Record<string, unknown> & { /** * The ID of the event's group. Grouped events are useful when you have distributed transactions * where you need to explicitly group, release and clear events upon lifecycle events of a transaction. * * When set, you must release the grouped events using the Event Module's `releaseGroupedEvents` method to emit the events. */ eventGroupId?: string; }; export type Event<TData = unknown> = { /** * The event's name. * * @example * user.created */ name: string; /** * Additional meadata to pass with the event. */ metadata?: EventMetadata; /** * The data payload that subscribers receive. For example, the ID or IDs of the created user. (e.g. { id: "123" } or { ids: ["123", "456"] }) */ data: TData; }; /** * The details of an event to emit. */ export type Message<TData = unknown> = Event<TData> & { options?: Record<string, unknown>; }; export type RawMessageFormat<TData = any> = { eventName: string; data: TData; source: string; object: string; action?: string; context?: Pick<Context, "eventGroupId">; options?: Record<string, any>; }; //# sourceMappingURL=common.d.ts.map