import { InboxMessage } from '@trycourier/courier-js'; import { CourierToastDatastoreListener } from './toast-datastore-listener'; /** * Shared datastore for Courier toasts. * * This datastore listens to and stores Courier Inbox messages. * * @public */ export declare class CourierToastDatastore { /** Shared instance. Access via {@link CourierToastDatastore.shared}. */ private static instance; /** FIFO stack of toast messages. The end of the array is index 0 of the stack. */ private _dataset; /** Set of listeners whose handlers will be called when the datastore changes. */ private _datastoreListeners; /** Cleanup function to remove the message event listener. */ private _removeMessageEventListener?; /** The shared instance of CourierToastDatastore, used to access all public methods. */ static get shared(): CourierToastDatastore; /** * Add a listener whose handlers are called when there are changes to the datastore. * * @param listener - an implementation of {@link CourierToastDatastoreListener} */ addDatastoreListener(listener: CourierToastDatastoreListener): void; /** * Remove a previously added listener. * * Note: the `listener` param is matched by object reference, so callers must pass * the same object previously passed to {@link CourierToastDatastore.addDatastoreListener}. * * See also: {@link CourierToastDatastoreListener.remove} * * @param listener - a previously added listener implementation */ removeDatastoreListener(listener: CourierToastDatastoreListener): void; /** * Start listening for toast messages. * * Calling this method will open a WebSocket connection to the Courier backend if one * is not already open. * * See also: {@link @trycourier/courier-js#Courier.shared.signIn} and {@link @trycourier/courier-js#Courier.shared.signOut} */ listenForMessages(): Promise; /** * Find the position of an {@link @trycourier/courier-js#InboxMessage} in the toast stack. * * Notes: * - Since the stack is an array, with the last item being the "top" of the stack, * a toast's position in the underlying array is the inverse of its stack position. * - `message` is matched by {@link @trycourier/courier-js#InboxMessage.messageId}, not by object reference. * * @param message - the {@link @trycourier/courier-js#InboxMessage} to find in the stack */ toastIndexOfMessage(message: InboxMessage): number; /** * Add an {@link @trycourier/courier-js#InboxMessage} toast item to the datastore. * * Calling this directly is useful to send test messages while developing with the Courier SDK.

* * @example * ``` * CourierToastDatastore.shared.addMessage({ * title: 'Lorem ipsum dolor sit', * body: 'Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet', * messageId: '1' * }); * ``` * * @param message - the message to add as a toast item. */ addMessage(message: InboxMessage): void; /** * Remove an {@link @trycourier/courier-js#InboxMessage} from the datastore. * * Note: `message` is matched by {@link @trycourier/courier-js#InboxMessage.messageId}, not by object reference */ removeMessage(message: InboxMessage): void; /** Access the shared instance with {@link CourierToastDatastore.shared}. */ private constructor(); }