install-guard 1.0.1 → 1.1.2
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/LICENSE +21 -0
- package/README.md +229 -52
- package/bin/cli.js +40 -14
- package/package.json +13 -4
- package/src/analyze.js +15 -22
- package/src/checks/dependencyDiff.js +114 -0
- package/src/checks/deprecation.js +24 -0
- package/src/checks/githubVerify.js +67 -0
- package/src/checks/index.js +8 -0
- package/src/checks/license.js +35 -0
- package/src/checks/maintainers.js +30 -0
- package/src/checks/recentPublish.js +70 -0
- package/src/checks/scripts.js +45 -0
- package/src/checks/typosquat.js +77 -0
- package/src/format.js +258 -0
- package/src/index.js +2 -2
- package/src/install.js +43 -15
- package/src/npm.js +31 -16
- package/src/scan.js +55 -5
- package/src/score.js +107 -26
- package/src/services/pipeline.js +105 -0
- package/src/services/scorer.js +36 -0
- package/src/typosquat.js +50 -0
- package/src/utils/cache.js +44 -0
- package/src/utils/github.js +64 -0
- package/src/utils/registry.js +99 -0
- package/install-guard-1.0.0.tgz +0 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { getCached, setCache } from "./cache.js";
|
|
2
|
+
|
|
3
|
+
function encodePkg(pkg) {
|
|
4
|
+
return encodeURIComponent(pkg).replace("%40", "@");
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
async function fetchJSON(url) {
|
|
8
|
+
const res = await fetch(url);
|
|
9
|
+
if (!res.ok) throw new Error(`HTTP ${res.status} for ${url}`);
|
|
10
|
+
return res.json();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Fetches full registry metadata for a package.
|
|
15
|
+
* Returns the raw document from registry.npmjs.org/<pkg>
|
|
16
|
+
*/
|
|
17
|
+
export async function getRegistryData(pkg) {
|
|
18
|
+
const key = `registry:${pkg}`;
|
|
19
|
+
const cached = getCached(key);
|
|
20
|
+
if (cached) return cached;
|
|
21
|
+
|
|
22
|
+
const data = await fetchJSON(`https://registry.npmjs.org/${encodePkg(pkg)}`);
|
|
23
|
+
setCache(key, data);
|
|
24
|
+
return data;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Fetches weekly download count.
|
|
29
|
+
*/
|
|
30
|
+
export async function getDownloads(pkg) {
|
|
31
|
+
const key = `downloads:${pkg}`;
|
|
32
|
+
const cached = getCached(key);
|
|
33
|
+
if (cached) return cached;
|
|
34
|
+
|
|
35
|
+
try {
|
|
36
|
+
const data = await fetchJSON(
|
|
37
|
+
`https://api.npmjs.org/downloads/point/last-week/${encodePkg(pkg)}`
|
|
38
|
+
);
|
|
39
|
+
setCache(key, data);
|
|
40
|
+
return data;
|
|
41
|
+
} catch {
|
|
42
|
+
return { downloads: 0 };
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Resolves version, fetches metadata + downloads, returns a normalized context
|
|
48
|
+
* that every check module can consume.
|
|
49
|
+
*/
|
|
50
|
+
export async function buildContext(pkg, requestedVersion) {
|
|
51
|
+
const registry = await getRegistryData(pkg);
|
|
52
|
+
const latest = registry["dist-tags"]?.latest;
|
|
53
|
+
if (!latest) throw new Error(`No published version found for "${pkg}"`);
|
|
54
|
+
|
|
55
|
+
const version = requestedVersion || latest;
|
|
56
|
+
const versionData = registry.versions?.[version];
|
|
57
|
+
if (!versionData) throw new Error(`Version "${version}" not found for "${pkg}"`);
|
|
58
|
+
|
|
59
|
+
const timeData = registry.time || {};
|
|
60
|
+
const allVersions = Object.keys(registry.versions || {});
|
|
61
|
+
const versionIndex = allVersions.indexOf(version);
|
|
62
|
+
const previousVersion = versionIndex > 0 ? allVersions[versionIndex - 1] : null;
|
|
63
|
+
const previousVersionData = previousVersion
|
|
64
|
+
? registry.versions[previousVersion]
|
|
65
|
+
: null;
|
|
66
|
+
|
|
67
|
+
const downloads = await getDownloads(pkg);
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
name: registry.name,
|
|
71
|
+
version,
|
|
72
|
+
previousVersion,
|
|
73
|
+
description: registry.description || "",
|
|
74
|
+
downloads: downloads.downloads || 0,
|
|
75
|
+
maintainers: registry.maintainers || [],
|
|
76
|
+
license: versionData.license || registry.license || "Unknown",
|
|
77
|
+
publishedAt: timeData[version],
|
|
78
|
+
previousPublishedAt: previousVersion ? timeData[previousVersion] : null,
|
|
79
|
+
firstPublished: timeData.created,
|
|
80
|
+
repository: registry.repository?.url || versionData.repository?.url || null,
|
|
81
|
+
deprecated: versionData.deprecated || false,
|
|
82
|
+
totalVersions: allVersions.length,
|
|
83
|
+
allVersions,
|
|
84
|
+
|
|
85
|
+
// Script data
|
|
86
|
+
scripts: versionData.scripts || {},
|
|
87
|
+
|
|
88
|
+
// Dependency data
|
|
89
|
+
dependencies: versionData.dependencies || {},
|
|
90
|
+
previousDependencies: previousVersionData?.dependencies || {},
|
|
91
|
+
|
|
92
|
+
// Maintainer history — registry only exposes current maintainers
|
|
93
|
+
currentMaintainers: registry.maintainers || [],
|
|
94
|
+
|
|
95
|
+
// Raw registry for advanced checks
|
|
96
|
+
_registry: registry,
|
|
97
|
+
_versionData: versionData,
|
|
98
|
+
};
|
|
99
|
+
}
|
package/install-guard-1.0.0.tgz
DELETED
|
Binary file
|