-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from treosh/v3
v3: new metrics & history API
- Loading branch information
Showing
11 changed files
with
2,042 additions
and
7,289 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
dist | ||
results | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,55 @@ | ||
{ | ||
"name": "crux-api", | ||
"version": "2.0.0", | ||
"description": "A Chrome UX Report API wrapper wrapper that handles errors and provides types", | ||
"version": "3.0.0", | ||
"description": "A tiny CrUX API wrapper that supports record & history API, handles errors, and provides types.", | ||
"repository": "https://github.com/treosh/crux-api", | ||
"bugs": "https://github.com/treosh/crux-api/issues", | ||
"license": "MIT", | ||
"type": "module", | ||
"source": "src/index.js", | ||
"module": "src/index.js", | ||
"types": "dist/crux-api.d.ts", | ||
"main": "dist/crux-api.js", | ||
"types": "types/index.d.ts", | ||
"files": [ | ||
"dist", | ||
"src" | ||
"src", | ||
"types" | ||
], | ||
"scripts": { | ||
"build": "run-s build:*", | ||
"build:src": "microbundle build --no-sourcemap --format=cjs", | ||
"build:src-ts": "tsc --declaration --noEmit false --outDir dist/ --allowJs src/index.js && rm dist/index.js && mv dist/index.d.ts dist/crux-api.d.ts", | ||
"test": "ava -v && prettier -c src test script README.md && yarn build && tsc -p . && size-limit", | ||
"prepack": "yarn build" | ||
"types": "tsc --declaration --emitDeclarationOnly --noEmit false --outDir types/ --allowJs src/index.js", | ||
"test": "yarn types && ava -v test/index.js && prettier -c src test script README.md && tsc -p . && size-limit" | ||
}, | ||
"devDependencies": { | ||
"@size-limit/preset-small-lib": "^4.11.0", | ||
"@types/node-fetch": "^2.5.10", | ||
"ava": "^3.15.0", | ||
"esm": "^3.2.25", | ||
"microbundle": "^0.13.1", | ||
"node-fetch": "^2.6.1", | ||
"npm-run-all": "^4.1.5", | ||
"prettier": "^2.3.1", | ||
"size-limit": "^4.11.0", | ||
"typescript": "^4.3.2" | ||
"@size-limit/preset-small-lib": "^9.0.0", | ||
"@types/node": "^20.8.6", | ||
"ava": "^5.3.1", | ||
"node-fetch": "^3.3.2", | ||
"prettier": "^3.0.3", | ||
"size-limit": "^9.0.0", | ||
"typescript": "^5.2.2" | ||
}, | ||
"keywords": [ | ||
"CrUX", | ||
"CrUX API", | ||
"CrUX History API", | ||
"Chrome User Experience Report", | ||
"Chrome UX Report", | ||
"Core Web Vitals", | ||
"Web Performance", | ||
"records.queryRecord", | ||
"FCP", | ||
"First Contentful Paint", | ||
"LCP", | ||
"Largest Contentful Paint", | ||
"FID", | ||
"First Input Delay", | ||
"CLS", | ||
"Cumulative Layout Shift" | ||
"Cumulative Layout Shift", | ||
"INP", | ||
"Interation to Next Paint", | ||
"TTFB", | ||
"Time to First Byte" | ||
], | ||
"size-limit": [ | ||
{ | ||
"limit": "450B", | ||
"limit": "510B", | ||
"path": "./src/index.js" | ||
} | ||
], | ||
"ava": { | ||
"require": [ | ||
"esm" | ||
], | ||
"files": [ | ||
"test/*.js" | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// usage: | ||
// • CRUX_KEY='...' node script/crux-api.js record '{"origin": "https://example.com", "formFactor": "DESKTOP", "effectiveConnectionType": "4G" }' > results/record-example.json | ||
// • CRUX_KEY='...' node script/crux-api.js history '{"url": "https://www.apple.com/", "formFactor": "PHONE" }' > results/history-apple.json | ||
|
||
import nodeFetch from 'node-fetch' | ||
import { createQueryRecord, createQueryHistoryRecord } from '../src/index.js' | ||
|
||
const key = process.env.CRUX_KEY || 'no-key' | ||
const apiMethod = process.argv[2] || 'record' | ||
const params = JSON.parse(process.argv[3] || '') | ||
|
||
try { | ||
const createMethod = apiMethod === 'record' ? createQueryRecord : createQueryHistoryRecord | ||
const queryMethod = createMethod({ key, fetch: nodeFetch }) | ||
const res = await queryMethod(params) | ||
console.log(JSON.stringify(res, null, ' ')) | ||
} catch (err) { | ||
console.error(err) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.