@chrysb/alphaclaw 0.1.5 → 0.1.6
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/lib/server/alphaclaw-version.js +20 -12
- package/package.json +1 -1
|
@@ -30,19 +30,27 @@ const createAlphaclawVersionService = () => {
|
|
|
30
30
|
|
|
31
31
|
const fetchLatestVersionFromRegistry = () =>
|
|
32
32
|
new Promise((resolve, reject) => {
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
resolve(parsed["dist-tags"]?.latest || null);
|
|
41
|
-
} catch (e) {
|
|
42
|
-
reject(new Error("Failed to parse registry response"));
|
|
33
|
+
const doGet = (url, redirects = 0) => {
|
|
34
|
+
if (redirects > 3) return reject(new Error("Too many redirects"));
|
|
35
|
+
const get = url.startsWith("https") ? https.get : http.get;
|
|
36
|
+
get(url, { headers: { Accept: "application/vnd.npm.install-v1+json" } }, (res) => {
|
|
37
|
+
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
38
|
+
res.resume();
|
|
39
|
+
return doGet(res.headers.location, redirects + 1);
|
|
43
40
|
}
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
let data = "";
|
|
42
|
+
res.on("data", (chunk) => { data += chunk; });
|
|
43
|
+
res.on("end", () => {
|
|
44
|
+
try {
|
|
45
|
+
const parsed = JSON.parse(data);
|
|
46
|
+
resolve(parsed["dist-tags"]?.latest || null);
|
|
47
|
+
} catch (e) {
|
|
48
|
+
reject(new Error(`Failed to parse registry response (status ${res.statusCode})`));
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}).on("error", reject);
|
|
52
|
+
};
|
|
53
|
+
doGet(kAlphaclawRegistryUrl);
|
|
46
54
|
});
|
|
47
55
|
|
|
48
56
|
const readAlphaclawUpdateStatus = async ({ refresh = false } = {}) => {
|