import { Context } from './context.js'; import '@kustomer/apps-common'; /** Various enums that represent a publish command to the server to perform an action with a modal dialog */ declare enum Modal { /** Update the context provided to a modal */ ContextUpdate = "MODAL_CONTEXT_UPDATE", /** Initialize a modal */ Initialize = "MODAL_INITIALIZE", /** Show a modal */ Show = "MODAL_SHOW", /** Hide a modal */ Hide = "MODAL_HIDE", /** Close a modal */ Close = "MODAL_CLOSE", /** Close all modals */ CloseAll = "MODAL_CLOSE_ALL", /** Navigate a modal */ Navigate = "MODAL_NAVIGATE" } /** Various enums that represent a publish command to the server that signify the state of an app */ declare enum App { /** Update the context provided to an app */ ContextUpdate = "CONTEXT_UPDATE", /** Finished the setup of an app */ SetupComplete = "APP_SETUP_COMPLETE", /** Started the setup of an app */ SetupStarted = "APP_SETUP_STARTED", /** Canceled the setup of an app */ SetupCanceled = "APP_SETUP_CANCELED", /** Closed the setup of an app */ SetupClosed = "APP_SETUP_CLOSED", /** Initialze an app */ Initialize = "INITIALIZE", /** Close an app */ Close = "CLOSE", /** Open an app */ Open = "OPEN", /** Resize an app */ Resize = "RESIZE", /** Issue a networking request for an app */ Request = "REQUEST" } /** A union of all possible events that can be published to the server */ type Event = Modal | App; type RequestResponseData = { /** The type of event */ readonly type: App.Request; /** The data returned by the server, is any */ readonly data: unknown; /** The id of the request to be resolved */ readonly requestId: string; /** The error returned by the server, if any */ readonly err?: unknown; /** Whether or not the modal is targeted for this event */ readonly targetModal?: boolean; /** The token of the modal, if it's being targeted */ readonly modalToken?: string; }; type GenericEventData = { /** The type of event */ readonly type: Exclude; /** The contextual data for that event */ readonly context?: Context; /** The error returned by the server, if any */ readonly err?: unknown; /** The data returned by the server, if any (only works with kobjects) */ readonly data?: unknown; /** The theme values of the app, should you need them for styling your app's UI */ readonly theme?: unknown; /** Whether or not the modal is targeted for this event */ readonly targetModal?: boolean; /** The token of the modal, if it's being targeted */ readonly modalToken?: string; /** The locale of the user */ readonly userLocale?: string; /** The roles of the user */ readonly userRoles?: Record; }; /** The data returned by the server of any given event for a modal or an app */ type EventData = RequestResponseData | GenericEventData; type Subscriptions = { [key in Exclude]?: (ctx: Context) => void; } & { [App.Request]?: (response: RequestResponseData) => void; }; export { App, Event, EventData, Modal, RequestResponseData, Subscriptions };