@zeroheight/adoption-cli 2.2.0 → 2.2.1
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 +4 -0
- package/dist/cli.js +1 -1
- package/dist/common/api.js +27 -12
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Release notes
|
|
2
2
|
|
|
3
|
+
## [2.2.1](https://www.npmjs.com/package/@zeroheight/adoption-cli/v/2.2.1) - 13th November 2024
|
|
4
|
+
|
|
5
|
+
- Handle API throttling
|
|
6
|
+
|
|
3
7
|
## [2.2.0](https://www.npmjs.com/package/@zeroheight/adoption-cli/v/2.2.0) - 8th November 2024
|
|
4
8
|
|
|
5
9
|
- Include export names in package file as part of component analyzing
|
package/dist/cli.js
CHANGED
|
@@ -12,7 +12,7 @@ const { output, cleanup } = render(React.createElement(HelpInfo, null));
|
|
|
12
12
|
program
|
|
13
13
|
.name("zh-adoption")
|
|
14
14
|
.description("CLI for measuring design system usage usage in your products")
|
|
15
|
-
.version("2.2.
|
|
15
|
+
.version("2.2.1")
|
|
16
16
|
.addHelpText("before", output)
|
|
17
17
|
.addCommand(analyzeCommand())
|
|
18
18
|
.addCommand(authCommand())
|
package/dist/common/api.js
CHANGED
|
@@ -52,25 +52,40 @@ async function post(path, body, credentials) {
|
|
|
52
52
|
body: JSON.stringify(body),
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
|
+
async function sleep(ms) {
|
|
56
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
57
|
+
}
|
|
55
58
|
async function request(path, credentials, init) {
|
|
56
59
|
const url = getZeroheightURL();
|
|
57
60
|
url.pathname = API_PATH + path;
|
|
58
61
|
if (process.env["NODE_ENV"] === "dev") {
|
|
59
62
|
process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = "0";
|
|
60
63
|
}
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
64
|
+
const maxRetries = 3;
|
|
65
|
+
let retries = 0;
|
|
66
|
+
while (retries < maxRetries) {
|
|
67
|
+
const response = await fetch(url, {
|
|
68
|
+
...init,
|
|
69
|
+
headers: {
|
|
70
|
+
"X-API-CLIENT-NAME": "cli",
|
|
71
|
+
"X-API-CLIENT": credentials.client,
|
|
72
|
+
"X-API-KEY": credentials.token,
|
|
73
|
+
"Content-Type": "application/json",
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
if (response.status === 401) {
|
|
77
|
+
throw new Error("Unauthorized");
|
|
78
|
+
}
|
|
79
|
+
else if (response.status === 429) {
|
|
80
|
+
retries++;
|
|
81
|
+
const responseData = await response.json();
|
|
82
|
+
const waitTime = responseData.data.reset_time * 1000 - Date.now();
|
|
83
|
+
await sleep(waitTime);
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
return await response.json();
|
|
72
87
|
}
|
|
73
|
-
|
|
88
|
+
throw new Error(`Request failed after ${maxRetries} retries`);
|
|
74
89
|
}
|
|
75
90
|
export function mergeUsageProps(newProps, currentProps) {
|
|
76
91
|
if (!currentProps)
|