File size: 925 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
import wpcom from 'calypso/lib/wp';
export interface BasicMetricsData {
token?: string;
}
export interface PerformanceReport {
overall_score: number;
}
export interface UrlPerformanceInsights {
pagespeed: {
status: string;
mobile: PerformanceReport | string;
desktop: PerformanceReport | string;
};
wpscan: {
status: string;
};
}
export async function fetchBasicMetrics( url: string ): Promise< BasicMetricsData > {
return wpcom.req.get(
{
path: '/site-profiler/metrics/basic',
apiNamespace: 'wpcom/v2',
},
// Important: advance=1 is needed to get the `token` and request advanced metrics.
{ url, advance: '1' }
);
}
export async function fetchPerformanceInsights(
url: string,
token: string
): Promise< UrlPerformanceInsights > {
return wpcom.req.get(
{
path: '/site-profiler/metrics/advanced/insights',
apiNamespace: 'wpcom/v2',
},
{ url, advance: '1', hash: token }
);
}
|