@automattic/jetpack-boost-score-api 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/package.json +1 -1
- package/src/index.ts +63 -0
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.1.7] - 2023-08-28
|
|
9
|
+
### Added
|
|
10
|
+
- New section to display boost history on jetpack boost admin page [#32016]
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
- Updated package dependencies. [#32605]
|
|
14
|
+
|
|
8
15
|
## [0.1.6] - 2023-08-09
|
|
9
16
|
### Changed
|
|
10
17
|
- Updated package dependencies. [#32166]
|
|
@@ -39,6 +46,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
39
46
|
### Added
|
|
40
47
|
- Create package for the boost score bar API [#30781]
|
|
41
48
|
|
|
49
|
+
[0.1.7]: https://github.com/Automattic/jetpack-boost-score-api/compare/v0.1.6...v0.1.7
|
|
42
50
|
[0.1.6]: https://github.com/Automattic/jetpack-boost-score-api/compare/v0.1.5...v0.1.6
|
|
43
51
|
[0.1.5]: https://github.com/Automattic/jetpack-boost-score-api/compare/v0.1.4...v0.1.5
|
|
44
52
|
[0.1.4]: https://github.com/Automattic/jetpack-boost-score-api/compare/v0.1.3...v0.1.4
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@automattic/jetpack-boost-score-api",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "A package to get the Jetpack Boost score of a site",
|
|
5
5
|
"homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/js-packages/boost-score-api/#readme",
|
|
6
6
|
"bugs": {
|
package/src/index.ts
CHANGED
|
@@ -20,6 +20,43 @@ type SpeedScoresSet = {
|
|
|
20
20
|
isStale: boolean;
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
+
interface ScoreValue {
|
|
24
|
+
score: number;
|
|
25
|
+
value: number;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface SpeedHistoryDimension {
|
|
29
|
+
mobile_overall_score: number;
|
|
30
|
+
desktop_overall_score: number;
|
|
31
|
+
mobile_lcp: ScoreValue;
|
|
32
|
+
desktop_lcp: ScoreValue;
|
|
33
|
+
mobile_tbt: ScoreValue;
|
|
34
|
+
desktop_tbt: ScoreValue;
|
|
35
|
+
mobile_cls: ScoreValue;
|
|
36
|
+
desktop_cls: ScoreValue;
|
|
37
|
+
mobile_si: ScoreValue;
|
|
38
|
+
desktop_si: ScoreValue;
|
|
39
|
+
mobile_tti: ScoreValue;
|
|
40
|
+
desktop_tti: ScoreValue;
|
|
41
|
+
mobile_fcp: ScoreValue;
|
|
42
|
+
desktop_fcp: ScoreValue;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
interface SpeedHistoryPeriod {
|
|
46
|
+
timestamp: number;
|
|
47
|
+
dimensions: SpeedHistoryDimension[];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
interface SpeedHistoryResponse {
|
|
51
|
+
data: {
|
|
52
|
+
_meta: {
|
|
53
|
+
start: number;
|
|
54
|
+
end: number;
|
|
55
|
+
};
|
|
56
|
+
periods: SpeedHistoryPeriod[];
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
23
60
|
type ParsedApiResponse = {
|
|
24
61
|
status: string;
|
|
25
62
|
scores?: SpeedScoresSet;
|
|
@@ -60,6 +97,32 @@ export async function requestSpeedScores(
|
|
|
60
97
|
return await pollRequest( rootUrl, siteUrl, nonce );
|
|
61
98
|
}
|
|
62
99
|
|
|
100
|
+
/**
|
|
101
|
+
* Get SpeedScores gistory to render the Graph. Will automatically
|
|
102
|
+
* poll for a response until the task is done, returning a SpeedHistory object.
|
|
103
|
+
*
|
|
104
|
+
* @param {string} rootUrl - Root URL for the HTTP request.
|
|
105
|
+
* @param {string} siteUrl - URL of the site.
|
|
106
|
+
* @param {string} nonce - Nonce to use for authentication.
|
|
107
|
+
* @returns {SpeedHistoryResponse} Speed score history returned by the server.
|
|
108
|
+
*/
|
|
109
|
+
export async function requestSpeedScoresHistory(
|
|
110
|
+
rootUrl: string,
|
|
111
|
+
siteUrl: string,
|
|
112
|
+
nonce: string
|
|
113
|
+
): Promise< SpeedHistoryResponse > {
|
|
114
|
+
const end = new Date().getTime();
|
|
115
|
+
const start = end - 1000 * 60 * 60 * 24 * 30; // 30 days ago
|
|
116
|
+
// Request metrics
|
|
117
|
+
const response = await api.post< SpeedHistoryResponse >(
|
|
118
|
+
rootUrl,
|
|
119
|
+
'/speed-scores-history',
|
|
120
|
+
{ start, end },
|
|
121
|
+
nonce
|
|
122
|
+
);
|
|
123
|
+
return response;
|
|
124
|
+
}
|
|
125
|
+
|
|
63
126
|
/**
|
|
64
127
|
* Helper method for parsing a response from a speed score API request. Returns
|
|
65
128
|
* scores (if ready), and a status (success|pending|error).
|