import type { AxiosRequestConfig } from 'axios' ; import type { HttpClient } from '../http/' ; import type { Notification , NotificationList } from './' ; export const NOTIFICATION_SIZE_MAXIMUM = 10000 ; export class NotificationAPI { constructor ( private readonly client ) { } public static readonly URL = { LAST : 'last' , NOTIFICATION : '/notifications' , } ; see https public async getLastNotification ( clientId ? ) { const config = { method : 'get' , params : { client : clientId , } , url : `${ NotificationAPI . URL . NOTIFICATION }/${ NotificationAPI . URL . LAST }` , } ; const response = await this . client . sendJSON < Notification > ( config ) ; return response . data ; } param clientId param size param since see https public async getNotifications ( clientId ? , size = NOTIFICATION_SIZE_MAXIMUM , since ? ) { const config = { method : 'get' , params : { client : clientId , since , size , } , url : NotificationAPI . URL . NOTIFICATION , } ; const response = await this . client . sendJSON < NotificationList > ( config ) ; return response . data ; } param clientId param lastNotificationId see https public async getAllNotifications ( clientId ? , lastNotificationId ? ) { let notificationList = [ ] ; const getNotificationChunks = async ( clientId ? , lastNotificationId ? ) : Promise < Notification [ ] > => { const { notifications , has_more } = await this . getNotifications ( clientId , NOTIFICATION_SIZE_MAXIMUM , lastNotificationId ) ; if ( notifications . length ) { notificationList = notificationList . concat ( notifications ) ; } if ( has_more ) { const lastNotification = notifications [ notifications . length - 1 ] ; if ( lastNotification ) { return getNotificationChunks ( clientId , lastNotification . id ) ; } } return notificationList ; } ; return getNotificationChunks ( clientId , lastNotificationId ) ; } see https public async getNotification ( notificationId , clientId ? ) { const config = { method : 'get' , params : { client : clientId , } , url : `${ NotificationAPI . URL . NOTIFICATION }/${ notificationId }` , } ; const response = await this . client . sendJSON < Notification > ( config ) ; return response . data ; } }