crux-api 3.0.1 → 4.0.0
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/README.md +289 -904
- package/package.json +13 -9
- package/src/index.js +32 -8
- package/types/index.d.ts +127 -17
package/package.json
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "crux-api",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "A tiny CrUX API wrapper that supports record & history API, handles errors, and provides types.",
|
|
5
5
|
"repository": "https://github.com/treosh/crux-api",
|
|
6
6
|
"bugs": "https://github.com/treosh/crux-api/issues",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"type": "module",
|
|
9
|
-
"exports":
|
|
10
|
-
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./types/index.d.ts",
|
|
12
|
+
"default": "./src/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
11
15
|
"files": [
|
|
12
16
|
"src",
|
|
13
17
|
"types"
|
|
@@ -17,13 +21,13 @@
|
|
|
17
21
|
"test": "yarn types && ava -v test/index.js && prettier -c src test script README.md && tsc -p . && size-limit"
|
|
18
22
|
},
|
|
19
23
|
"devDependencies": {
|
|
20
|
-
"@size-limit/preset-small-lib": "^
|
|
21
|
-
"@types/node": "^
|
|
22
|
-
"ava": "^
|
|
24
|
+
"@size-limit/preset-small-lib": "^12.0.0",
|
|
25
|
+
"@types/node": "^25.2.2",
|
|
26
|
+
"ava": "^6.4.1",
|
|
23
27
|
"node-fetch": "^3.3.2",
|
|
24
|
-
"prettier": "^3.
|
|
25
|
-
"size-limit": "^
|
|
26
|
-
"typescript": "^5.
|
|
28
|
+
"prettier": "^3.8.1",
|
|
29
|
+
"size-limit": "^12.0.0",
|
|
30
|
+
"typescript": "^5.9.3"
|
|
27
31
|
},
|
|
28
32
|
"keywords": [
|
|
29
33
|
"CrUX",
|
package/src/index.js
CHANGED
|
@@ -3,10 +3,14 @@ const maxRetryTimeout = 60 * 1000 // 60s
|
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @typedef {{ key: string, fetch?: function }} CreateOptions
|
|
6
|
-
* @typedef {{ url?: string, origin?: string, formFactor?: FormFactor
|
|
6
|
+
* @typedef {{ url?: string, origin?: string, formFactor?: FormFactor }} QueryRecordOptions
|
|
7
7
|
* @typedef {'ALL_FORM_FACTORS' | 'PHONE' | 'DESKTOP' | 'TABLET'} FormFactor
|
|
8
|
-
* @typedef {
|
|
8
|
+
* @typedef {{ percentiles: { p75: number } }} PercentileValue
|
|
9
9
|
* @typedef {{ histogram: { start: number | string, end: number | string, density: number }[], percentiles: { p75: number | string } }} MetricValue
|
|
10
|
+
* @typedef {{ histogram: { start: string, end: string, density: number }[], percentiles: { p75: string } }} MetricStringValue
|
|
11
|
+
* @typedef {{ fractions: { desktop: number, phone: number, tablet: number } }} FormFactorFractionValue
|
|
12
|
+
* @typedef {{ fractions: { image: number, text: number } }} NavigationTypesFractionValue
|
|
13
|
+
* @typedef {{ fractions: { navigate: number, navigate_cache: number, back_forward: number, back_forward_cache: number, reload: number, restore: number, prerender: number } }} ResourceTypesFractionValue
|
|
10
14
|
* @typedef {{ year: number, month: number, day: number }} MetricDate
|
|
11
15
|
* @typedef {{ firstDate: MetricDate, lastDate: MetricDate }} CollectionPeriod
|
|
12
16
|
* @typedef {{ error: { code: number, message: string, status: string } }} ErrorResponse
|
|
@@ -15,23 +19,29 @@ const maxRetryTimeout = 60 * 1000 // 60s
|
|
|
15
19
|
* key: {
|
|
16
20
|
* url?: string,
|
|
17
21
|
* origin?: string,
|
|
18
|
-
* effectiveConnectionType?: Connection,
|
|
19
22
|
* formFactor?: FormFactor
|
|
20
23
|
* },
|
|
21
24
|
* metrics: {
|
|
22
25
|
* first_contentful_paint?: MetricValue,
|
|
23
26
|
* largest_contentful_paint?: MetricValue,
|
|
24
|
-
*
|
|
25
|
-
* cumulative_layout_shift?: MetricValue,
|
|
27
|
+
* cumulative_layout_shift?: MetricStringValue,
|
|
26
28
|
* interaction_to_next_paint?: MetricValue,
|
|
27
29
|
* experimental_time_to_first_byte?: MetricValue,
|
|
28
|
-
*
|
|
30
|
+
* round_trip_time?: MetricValue,
|
|
31
|
+
* form_factors?: FormFactorFractionValue,
|
|
32
|
+
* navigation_types?: NavigationTypesFractionValue,
|
|
33
|
+
* largest_contentful_paint_resource_type: ResourceTypesFractionValue,
|
|
34
|
+
* largest_contentful_paint_image_time_to_first_byte: PercentileValue,
|
|
35
|
+
* largest_contentful_paint_image_resource_load_delay: PercentileValue,
|
|
36
|
+
* largest_contentful_paint_image_resource_load_duration: PercentileValue,
|
|
37
|
+
* largest_contentful_paint_image_element_render_delay: PercentileValue,
|
|
38
|
+
* }
|
|
29
39
|
* collectionPeriod: CollectionPeriod
|
|
30
40
|
* },
|
|
31
41
|
* urlNormalizationDetails?: {
|
|
32
42
|
* originalUrl: string,
|
|
33
43
|
* normalizedUrl: string
|
|
34
|
-
* }
|
|
44
|
+
* },
|
|
35
45
|
* }} SuccessResponse
|
|
36
46
|
*
|
|
37
47
|
* @typedef {(?number | string)[]} PercentileValues
|
|
@@ -41,6 +51,13 @@ const maxRetryTimeout = 60 * 1000 // 60s
|
|
|
41
51
|
* percentilesTimeseries: { p75s: PercentileValues }
|
|
42
52
|
* }} HistoryValue
|
|
43
53
|
*
|
|
54
|
+
* @typedef {number | 'NaN'} DensityValue
|
|
55
|
+
* @typedef {{ fractions: DensityValue[] }} Fractions
|
|
56
|
+
* @typedef {Object<string, Fractions>} FractionTimeseries
|
|
57
|
+
* @typedef {{ desktop: Fractions, phone: Fractions, tablet: Fractions }} FormFactorsFractionTimeseries
|
|
58
|
+
* @typedef {{ back_forward_cache: Fractions, prerender: Fractions, navigate: Fractions, navigate_cache: Fractions, reload: Fractions, restore: Fractions, back_forward: Fractions }} NavigationTypesFractionTimeseries
|
|
59
|
+
* @typedef {{ image: Fractions, text: Fractions }} ResourceTypesFractionTimeseries
|
|
60
|
+
* @typedef {{ percentilesTimeseries: { p75s: (?number)[] } }} HistoryPercentile
|
|
44
61
|
* @typedef {{
|
|
45
62
|
* record: {
|
|
46
63
|
* key: {
|
|
@@ -49,12 +66,19 @@ const maxRetryTimeout = 60 * 1000 // 60s
|
|
|
49
66
|
* formFactor?: FormFactor
|
|
50
67
|
* },
|
|
51
68
|
* metrics: {
|
|
52
|
-
* first_input_delay?: HistoryValue,
|
|
53
69
|
* first_contentful_paint?: HistoryValue,
|
|
54
70
|
* largest_contentful_paint?: HistoryValue,
|
|
55
71
|
* cumulative_layout_shift?: HistoryValue,
|
|
56
72
|
* interaction_to_next_paint?: HistoryValue,
|
|
57
73
|
* experimental_time_to_first_byte?: HistoryValue,
|
|
74
|
+
* round_trip_time?: HistoryValue,
|
|
75
|
+
* form_factors?: { fractionTimeseries: FormFactorsFractionTimeseries },
|
|
76
|
+
* navigation_types?: { fractionTimeseries: NavigationTypesFractionTimeseries },
|
|
77
|
+
* largest_contentful_paint_resource_type: { fractionTimeseries: ResourceTypesFractionTimeseries },
|
|
78
|
+
* largest_contentful_paint_image_time_to_first_byte: HistoryPercentile,
|
|
79
|
+
* largest_contentful_paint_image_resource_load_delay: HistoryPercentile,
|
|
80
|
+
* largest_contentful_paint_image_resource_load_duration: HistoryPercentile,
|
|
81
|
+
* largest_contentful_paint_image_element_render_delay: HistoryPercentile,
|
|
58
82
|
* }
|
|
59
83
|
* collectionPeriods: CollectionPeriod[]
|
|
60
84
|
* },
|
package/types/index.d.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @typedef {{ key: string, fetch?: function }} CreateOptions
|
|
3
|
-
* @typedef {{ url?: string, origin?: string, formFactor?: FormFactor
|
|
3
|
+
* @typedef {{ url?: string, origin?: string, formFactor?: FormFactor }} QueryRecordOptions
|
|
4
4
|
* @typedef {'ALL_FORM_FACTORS' | 'PHONE' | 'DESKTOP' | 'TABLET'} FormFactor
|
|
5
|
-
* @typedef {
|
|
5
|
+
* @typedef {{ percentiles: { p75: number } }} PercentileValue
|
|
6
6
|
* @typedef {{ histogram: { start: number | string, end: number | string, density: number }[], percentiles: { p75: number | string } }} MetricValue
|
|
7
|
+
* @typedef {{ histogram: { start: string, end: string, density: number }[], percentiles: { p75: string } }} MetricStringValue
|
|
8
|
+
* @typedef {{ fractions: { desktop: number, phone: number, tablet: number } }} FormFactorFractionValue
|
|
9
|
+
* @typedef {{ fractions: { image: number, text: number } }} NavigationTypesFractionValue
|
|
10
|
+
* @typedef {{ fractions: { navigate: number, navigate_cache: number, back_forward: number, back_forward_cache: number, reload: number, restore: number, prerender: number } }} ResourceTypesFractionValue
|
|
7
11
|
* @typedef {{ year: number, month: number, day: number }} MetricDate
|
|
8
12
|
* @typedef {{ firstDate: MetricDate, lastDate: MetricDate }} CollectionPeriod
|
|
9
13
|
* @typedef {{ error: { code: number, message: string, status: string } }} ErrorResponse
|
|
@@ -12,23 +16,29 @@
|
|
|
12
16
|
* key: {
|
|
13
17
|
* url?: string,
|
|
14
18
|
* origin?: string,
|
|
15
|
-
* effectiveConnectionType?: Connection,
|
|
16
19
|
* formFactor?: FormFactor
|
|
17
20
|
* },
|
|
18
21
|
* metrics: {
|
|
19
22
|
* first_contentful_paint?: MetricValue,
|
|
20
23
|
* largest_contentful_paint?: MetricValue,
|
|
21
|
-
*
|
|
22
|
-
* cumulative_layout_shift?: MetricValue,
|
|
24
|
+
* cumulative_layout_shift?: MetricStringValue,
|
|
23
25
|
* interaction_to_next_paint?: MetricValue,
|
|
24
26
|
* experimental_time_to_first_byte?: MetricValue,
|
|
25
|
-
*
|
|
27
|
+
* round_trip_time?: MetricValue,
|
|
28
|
+
* form_factors?: FormFactorFractionValue,
|
|
29
|
+
* navigation_types?: NavigationTypesFractionValue,
|
|
30
|
+
* largest_contentful_paint_resource_type: ResourceTypesFractionValue,
|
|
31
|
+
* largest_contentful_paint_image_time_to_first_byte: PercentileValue,
|
|
32
|
+
* largest_contentful_paint_image_resource_load_delay: PercentileValue,
|
|
33
|
+
* largest_contentful_paint_image_resource_load_duration: PercentileValue,
|
|
34
|
+
* largest_contentful_paint_image_element_render_delay: PercentileValue,
|
|
35
|
+
* }
|
|
26
36
|
* collectionPeriod: CollectionPeriod
|
|
27
37
|
* },
|
|
28
38
|
* urlNormalizationDetails?: {
|
|
29
39
|
* originalUrl: string,
|
|
30
40
|
* normalizedUrl: string
|
|
31
|
-
* }
|
|
41
|
+
* },
|
|
32
42
|
* }} SuccessResponse
|
|
33
43
|
*
|
|
34
44
|
* @typedef {(?number | string)[]} PercentileValues
|
|
@@ -38,6 +48,13 @@
|
|
|
38
48
|
* percentilesTimeseries: { p75s: PercentileValues }
|
|
39
49
|
* }} HistoryValue
|
|
40
50
|
*
|
|
51
|
+
* @typedef {number | 'NaN'} DensityValue
|
|
52
|
+
* @typedef {{ fractions: DensityValue[] }} Fractions
|
|
53
|
+
* @typedef {Object<string, Fractions>} FractionTimeseries
|
|
54
|
+
* @typedef {{ desktop: Fractions, phone: Fractions, tablet: Fractions }} FormFactorsFractionTimeseries
|
|
55
|
+
* @typedef {{ back_forward_cache: Fractions, prerender: Fractions, navigate: Fractions, navigate_cache: Fractions, reload: Fractions, restore: Fractions, back_forward: Fractions }} NavigationTypesFractionTimeseries
|
|
56
|
+
* @typedef {{ image: Fractions, text: Fractions }} ResourceTypesFractionTimeseries
|
|
57
|
+
* @typedef {{ percentilesTimeseries: { p75s: (?number)[] } }} HistoryPercentile
|
|
41
58
|
* @typedef {{
|
|
42
59
|
* record: {
|
|
43
60
|
* key: {
|
|
@@ -46,12 +63,19 @@
|
|
|
46
63
|
* formFactor?: FormFactor
|
|
47
64
|
* },
|
|
48
65
|
* metrics: {
|
|
49
|
-
* first_input_delay?: HistoryValue,
|
|
50
66
|
* first_contentful_paint?: HistoryValue,
|
|
51
67
|
* largest_contentful_paint?: HistoryValue,
|
|
52
68
|
* cumulative_layout_shift?: HistoryValue,
|
|
53
69
|
* interaction_to_next_paint?: HistoryValue,
|
|
54
70
|
* experimental_time_to_first_byte?: HistoryValue,
|
|
71
|
+
* round_trip_time?: HistoryValue,
|
|
72
|
+
* form_factors?: { fractionTimeseries: FormFactorsFractionTimeseries },
|
|
73
|
+
* navigation_types?: { fractionTimeseries: NavigationTypesFractionTimeseries },
|
|
74
|
+
* largest_contentful_paint_resource_type: { fractionTimeseries: ResourceTypesFractionTimeseries },
|
|
75
|
+
* largest_contentful_paint_image_time_to_first_byte: HistoryPercentile,
|
|
76
|
+
* largest_contentful_paint_image_resource_load_delay: HistoryPercentile,
|
|
77
|
+
* largest_contentful_paint_image_resource_load_duration: HistoryPercentile,
|
|
78
|
+
* largest_contentful_paint_image_element_render_delay: HistoryPercentile,
|
|
55
79
|
* }
|
|
56
80
|
* collectionPeriods: CollectionPeriod[]
|
|
57
81
|
* },
|
|
@@ -87,10 +111,13 @@ export type QueryRecordOptions = {
|
|
|
87
111
|
url?: string;
|
|
88
112
|
origin?: string;
|
|
89
113
|
formFactor?: FormFactor;
|
|
90
|
-
effectiveConnectionType?: Connection;
|
|
91
114
|
};
|
|
92
|
-
export type FormFactor =
|
|
93
|
-
export type
|
|
115
|
+
export type FormFactor = "ALL_FORM_FACTORS" | "PHONE" | "DESKTOP" | "TABLET";
|
|
116
|
+
export type PercentileValue = {
|
|
117
|
+
percentiles: {
|
|
118
|
+
p75: number;
|
|
119
|
+
};
|
|
120
|
+
};
|
|
94
121
|
export type MetricValue = {
|
|
95
122
|
histogram: {
|
|
96
123
|
start: number | string;
|
|
@@ -101,6 +128,40 @@ export type MetricValue = {
|
|
|
101
128
|
p75: number | string;
|
|
102
129
|
};
|
|
103
130
|
};
|
|
131
|
+
export type MetricStringValue = {
|
|
132
|
+
histogram: {
|
|
133
|
+
start: string;
|
|
134
|
+
end: string;
|
|
135
|
+
density: number;
|
|
136
|
+
}[];
|
|
137
|
+
percentiles: {
|
|
138
|
+
p75: string;
|
|
139
|
+
};
|
|
140
|
+
};
|
|
141
|
+
export type FormFactorFractionValue = {
|
|
142
|
+
fractions: {
|
|
143
|
+
desktop: number;
|
|
144
|
+
phone: number;
|
|
145
|
+
tablet: number;
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
export type NavigationTypesFractionValue = {
|
|
149
|
+
fractions: {
|
|
150
|
+
image: number;
|
|
151
|
+
text: number;
|
|
152
|
+
};
|
|
153
|
+
};
|
|
154
|
+
export type ResourceTypesFractionValue = {
|
|
155
|
+
fractions: {
|
|
156
|
+
navigate: number;
|
|
157
|
+
navigate_cache: number;
|
|
158
|
+
back_forward: number;
|
|
159
|
+
back_forward_cache: number;
|
|
160
|
+
reload: number;
|
|
161
|
+
restore: number;
|
|
162
|
+
prerender: number;
|
|
163
|
+
};
|
|
164
|
+
};
|
|
104
165
|
export type MetricDate = {
|
|
105
166
|
year: number;
|
|
106
167
|
month: number;
|
|
@@ -122,16 +183,22 @@ export type SuccessResponse = {
|
|
|
122
183
|
key: {
|
|
123
184
|
url?: string;
|
|
124
185
|
origin?: string;
|
|
125
|
-
effectiveConnectionType?: Connection;
|
|
126
186
|
formFactor?: FormFactor;
|
|
127
187
|
};
|
|
128
188
|
metrics: {
|
|
129
189
|
first_contentful_paint?: MetricValue;
|
|
130
190
|
largest_contentful_paint?: MetricValue;
|
|
131
|
-
|
|
132
|
-
cumulative_layout_shift?: MetricValue;
|
|
191
|
+
cumulative_layout_shift?: MetricStringValue;
|
|
133
192
|
interaction_to_next_paint?: MetricValue;
|
|
134
193
|
experimental_time_to_first_byte?: MetricValue;
|
|
194
|
+
round_trip_time?: MetricValue;
|
|
195
|
+
form_factors?: FormFactorFractionValue;
|
|
196
|
+
navigation_types?: NavigationTypesFractionValue;
|
|
197
|
+
largest_contentful_paint_resource_type: ResourceTypesFractionValue;
|
|
198
|
+
largest_contentful_paint_image_time_to_first_byte: PercentileValue;
|
|
199
|
+
largest_contentful_paint_image_resource_load_delay: PercentileValue;
|
|
200
|
+
largest_contentful_paint_image_resource_load_duration: PercentileValue;
|
|
201
|
+
largest_contentful_paint_image_element_render_delay: PercentileValue;
|
|
135
202
|
};
|
|
136
203
|
collectionPeriod: CollectionPeriod;
|
|
137
204
|
};
|
|
@@ -144,12 +211,42 @@ export type PercentileValues = ((number | string) | null)[];
|
|
|
144
211
|
export type HistorgramTimeserie = {
|
|
145
212
|
start: number;
|
|
146
213
|
end?: number;
|
|
147
|
-
densities: (number |
|
|
214
|
+
densities: (number | "NaN")[];
|
|
148
215
|
};
|
|
149
216
|
export type HistoryValue = {
|
|
150
217
|
histogramTimeseries: HistorgramTimeserie[];
|
|
151
218
|
percentilesTimeseries: {
|
|
152
|
-
p75s:
|
|
219
|
+
p75s: PercentileValues;
|
|
220
|
+
};
|
|
221
|
+
};
|
|
222
|
+
export type DensityValue = number | "NaN";
|
|
223
|
+
export type Fractions = {
|
|
224
|
+
fractions: DensityValue[];
|
|
225
|
+
};
|
|
226
|
+
export type FractionTimeseries = {
|
|
227
|
+
[x: string]: Fractions;
|
|
228
|
+
};
|
|
229
|
+
export type FormFactorsFractionTimeseries = {
|
|
230
|
+
desktop: Fractions;
|
|
231
|
+
phone: Fractions;
|
|
232
|
+
tablet: Fractions;
|
|
233
|
+
};
|
|
234
|
+
export type NavigationTypesFractionTimeseries = {
|
|
235
|
+
back_forward_cache: Fractions;
|
|
236
|
+
prerender: Fractions;
|
|
237
|
+
navigate: Fractions;
|
|
238
|
+
navigate_cache: Fractions;
|
|
239
|
+
reload: Fractions;
|
|
240
|
+
restore: Fractions;
|
|
241
|
+
back_forward: Fractions;
|
|
242
|
+
};
|
|
243
|
+
export type ResourceTypesFractionTimeseries = {
|
|
244
|
+
image: Fractions;
|
|
245
|
+
text: Fractions;
|
|
246
|
+
};
|
|
247
|
+
export type HistoryPercentile = {
|
|
248
|
+
percentilesTimeseries: {
|
|
249
|
+
p75s: (number | null)[];
|
|
153
250
|
};
|
|
154
251
|
};
|
|
155
252
|
export type HistoryResponse = {
|
|
@@ -160,12 +257,25 @@ export type HistoryResponse = {
|
|
|
160
257
|
formFactor?: FormFactor;
|
|
161
258
|
};
|
|
162
259
|
metrics: {
|
|
163
|
-
first_input_delay?: HistoryValue;
|
|
164
260
|
first_contentful_paint?: HistoryValue;
|
|
165
261
|
largest_contentful_paint?: HistoryValue;
|
|
166
262
|
cumulative_layout_shift?: HistoryValue;
|
|
167
263
|
interaction_to_next_paint?: HistoryValue;
|
|
168
264
|
experimental_time_to_first_byte?: HistoryValue;
|
|
265
|
+
round_trip_time?: HistoryValue;
|
|
266
|
+
form_factors?: {
|
|
267
|
+
fractionTimeseries: FormFactorsFractionTimeseries;
|
|
268
|
+
};
|
|
269
|
+
navigation_types?: {
|
|
270
|
+
fractionTimeseries: NavigationTypesFractionTimeseries;
|
|
271
|
+
};
|
|
272
|
+
largest_contentful_paint_resource_type: {
|
|
273
|
+
fractionTimeseries: ResourceTypesFractionTimeseries;
|
|
274
|
+
};
|
|
275
|
+
largest_contentful_paint_image_time_to_first_byte: HistoryPercentile;
|
|
276
|
+
largest_contentful_paint_image_resource_load_delay: HistoryPercentile;
|
|
277
|
+
largest_contentful_paint_image_resource_load_duration: HistoryPercentile;
|
|
278
|
+
largest_contentful_paint_image_element_render_delay: HistoryPercentile;
|
|
169
279
|
};
|
|
170
280
|
collectionPeriods: CollectionPeriod[];
|
|
171
281
|
};
|