test_notification
Version: 
JavaScript middleware designed to streamline interaction for managing and displaying in-app notifications seamlessly
135 lines (134 loc) • 5.82 kB
TypeScript
import { EventType } from './constants/generic';
import type { FetchNotificationsParamsType, InitConfigType, NotificationsApiResponse, NotificationDataResponse, ActionResponse, MarkAsViewedResponse, UnviewedCountReturnResponse, BulkUpdateParamsType } from "./types";
export declare class Siren {
    private token;
    private recipientId;
    private notificationFetchIntervalId;
    private unViewedCountFetchIntervalId;
    private latestNotification;
    private actionCallbacks;
    /**
     * Binds specific class methods to ensure the correct `this` context when called.
     * This is necessary for methods that are used asynchronously or passed as callbacks.
     * @private
     */
    private bindMethods;
    /**
     * Creates a new `Siren` instance with the provided configuration.
     *
     * @param {InitConfigType} config - Configuration options for the Siren instance.
     * @param {string} config.token - User's session token.
     * @param {string} config.recipientId - User's Siren recipient ID.
     * @param {(response: SirenErrorType) => void} config.onError - Callback for handling errors.
     * @param {ActionCallbackType} [config.actionCallbacks] - Callbacks for different notification actions.
     *
     * @throws {SirenError} If validation fails
     */
    constructor({ token, recipientId, onError, actionCallbacks }: InitConfigType);
    /**
     * Retrieves the number of unviewed notifications count for the user.
     *
     * @returns {Promise<{ unviewedCount: number }>}
     *   - An object containing the `unviewedCount` on success.
     *
     */
    fetchUnviewedNotificationsCount(): Promise<UnviewedCountReturnResponse | null>;
    /**
     * Fetches all notifications.
     *
     * @param {FetchNotificationsParamsType} params - Parameters for filtering and sorting notifications.
     *
     * @returns {Promise<NotificationsApiResponse>}
     * `NotificationsApiResponse` object containing fetched notifications, metadata, and pagination information on success.
     *
     */
    fetchAllNotifications(params: FetchNotificationsParamsType): Promise<NotificationsApiResponse | null>;
    /**
     * This method start real time data fetching based on the provided parameters.
     * @param {object} props - The properties to be passed to the method.
     * @param {EventType} eventType - For identifying the event type. This can be either `NOTIFICATIONS` or `UNVIEWED_COUNT`.
     * @param {FetchNotificationsParamsType} [params] - Parameters for filtering and sorting notifications.
     */
    startRealTimeFetch({ eventType, params }: {
        eventType: EventType;
        params?: FetchNotificationsParamsType;
    }): void;
    /**
     * Stops the real-time data fetching , if active.
     *
     * @param {EventType} eventType - For identifying the event type. This can be either `NOTIFICATIONS` or `UNVIEWED_COUNT`.
     */
    stopRealTimeFetch(eventType: EventType): void;
    /**
     * Marks a specific notification as read by its ID.
     *
     * @param {string} id - ID of the notification to mark as read.
     *
     * @returns {Promise<NotificationDataType>}
     *  `NotificationDataType` object on success, containing details about the notification.
     *
     */
    markAsReadById(id: string): Promise<NotificationDataResponse | null>;
    /**
     * Marks all notifications as read
     *
     * @param {string} startDate - The date up to which notifications should be marked as read.
     *
     * @returns {Promise<ActionResponse>}
     *   - An `ActionResponse` object on success, contains "SUCCESS" as data.
     */
    markAsReadByDate(params: BulkUpdateParamsType): Promise<ActionResponse | null>;
    /**
     * Deletes a specific notification by its ID.
     *
     * @param {string} id - The ID of the notification to delete.
     *
     * @returns {Promise<ActionResponse>}
     *   - An `ActionResponse` object on success, containing details about the operation.
     */
    deleteById(id: string): Promise<ActionResponse | null>;
    /**
     * Delete all notifications for the user.
     *
     * @param {string} startDate - The date up to which notifications should be cleared.
     *
     * @returns {Promise<ActionResponse>}
     *   - An `ActionResponse` object on success, containing details about the operation.
     */
    deleteByDate(params: BulkUpdateParamsType): Promise<ActionResponse | null>;
    /**
     * Marks all notifications as viewed for the current user.
     * @param {string} startDate - The date up to which notifications should be marked as viewed.
     *
     * @returns {Promise<MarkAsViewedResponse>}
     *   - A `MarkAsViewedResponse` object on success, containing details about the operation.
     *
     */
    markAllAsViewed(startDate: string): Promise<MarkAsViewedResponse | null>;
    /**
     * Starts a real-time interval for fetching new notifications.
     *
     * This method fetches notifications based on the provided parameters and
     * calls the `onNotificationReceived` callback with the latest data.
     *
     * @param {FetchNotificationsParamsType} params - Parameters for filtering notifications.
     */
    private startRealTimeNotificationFetch;
    /**
     * Stops the real-time notification fetching, if active.
     */
    private stopRealTimeNotificationFetch;
    /**
     * Starts a real-time interval for getting unviewed notification.
     *
     * This method calls the `onUnViewedCountReceived` callback with the latest data.
     *
     * @param {FetchNotificationsParamsType} params - Parameters for filtering notifications.
     */
    private startRealTimeUnviewedCountFetch;
    /**
     * Stops the real-time unviewed notification count fetching , if active.
     */
    private stopRealTimeUnviewedCountFetch;
    private emitMissingParameterError;
}