@@ -69,6 +69,11 @@ export interface SiteLogsParams {
6969 pageIndex ?: number ;
7070}
7171
72+ export interface SiteLogsData {
73+ total_results : number ;
74+ logs : ( PHPLog | ServerLog ) [ ] ;
75+ }
76+
7277export async function fetchSiteLogs ( {
7378 siteId,
7479 logType,
@@ -78,7 +83,7 @@ export async function fetchSiteLogs( {
7883 sortOrder,
7984 pageSize,
8085 pageIndex,
81- } : SiteLogsParams ) : Promise < SiteLogsAPIResponse > {
86+ } : SiteLogsParams ) : Promise < SiteLogsData > {
8287 const logTypeFragment = logType === LogType . PHP ? 'error-logs' : 'logs' ;
8388 const path = `/sites/${ siteId } /hosting/${ logTypeFragment } ` ;
8489
@@ -98,13 +103,34 @@ export async function fetchSiteLogs( {
98103 delete ( queryParams as Record < string , unknown > ) [ key ]
99104 ) ;
100105
101- const logs = await wpcom . req . get (
106+ const response = await wpcom . req . get (
102107 {
103108 path,
104109 apiNamespace : 'wpcom/v2' ,
105110 } ,
106111 { ...queryParams }
107112 ) ;
108113
109- return logs ;
114+ const { data } = response as SiteLogsAPIResponse ;
115+
116+ const totalResults =
117+ typeof data . total_results === 'number' ? data . total_results : data . total_results ?. value ?? 0 ;
118+
119+ const logs = Array . isArray ( data . logs ) ? data . logs : [ ] ;
120+
121+ if ( logType === LogType . PHP ) {
122+ const normalized = ( logs as PHPLogFromEndpoint [ ] ) . map (
123+ ( { atomic_site_id, ...logWithoutAtomicId } ) => ( {
124+ ...logWithoutAtomicId ,
125+ id : `${ logWithoutAtomicId . timestamp } |${ String ( logWithoutAtomicId . line ) } ` ,
126+ } )
127+ ) ;
128+ return { total_results : totalResults , logs : normalized } ;
129+ }
130+
131+ const normalized = ( logs as ServerLogFromEndpoint [ ] ) . map ( ( log ) => ( {
132+ ...log ,
133+ id : `${ String ( log . timestamp ) } |${ log . status } ` ,
134+ } ) ) ;
135+ return { total_results : totalResults , logs : normalized } ;
110136}
0 commit comments