@automattic/jetpack-boost-score-api 0.1.5 → 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 CHANGED
@@ -5,6 +5,17 @@ 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
+
15
+ ## [0.1.6] - 2023-08-09
16
+ ### Changed
17
+ - Updated package dependencies. [#32166]
18
+
8
19
  ## [0.1.5] - 2023-07-17
9
20
  ### Changed
10
21
  - Updated package dependencies. [#31815]
@@ -35,6 +46,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
35
46
  ### Added
36
47
  - Create package for the boost score bar API [#30781]
37
48
 
49
+ [0.1.7]: https://github.com/Automattic/jetpack-boost-score-api/compare/v0.1.6...v0.1.7
50
+ [0.1.6]: https://github.com/Automattic/jetpack-boost-score-api/compare/v0.1.5...v0.1.6
38
51
  [0.1.5]: https://github.com/Automattic/jetpack-boost-score-api/compare/v0.1.4...v0.1.5
39
52
  [0.1.4]: https://github.com/Automattic/jetpack-boost-score-api/compare/v0.1.3...v0.1.4
40
53
  [0.1.3]: https://github.com/Automattic/jetpack-boost-score-api/compare/v0.1.2...v0.1.3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automattic/jetpack-boost-score-api",
3
- "version": "0.1.5",
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": {
@@ -20,7 +20,7 @@
20
20
  "test": "jest tests"
21
21
  },
22
22
  "dependencies": {
23
- "@wordpress/i18n": "4.37.0",
23
+ "@wordpress/i18n": "4.38.0",
24
24
  "zod": "3.20.2"
25
25
  },
26
26
  "devDependencies": {
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).