@nodesecure/js-x-ray 5.0.0 → 5.0.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/package.json CHANGED
@@ -1,57 +1,58 @@
1
- {
2
- "name": "@nodesecure/js-x-ray",
3
- "version": "5.0.0",
4
- "description": "JavaScript AST XRay analysis",
5
- "type": "module",
6
- "exports": "./index.js",
7
- "engines": {
8
- "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
9
- },
10
- "scripts": {
11
- "lint": "eslint src test",
12
- "prepublishOnly": "pkg-ok",
13
- "test": "cross-env esm-tape-runner 'test/**/*.spec.js' | tap-monkey",
14
- "check": "cross-env npm run lint && npm run test"
15
- },
16
- "repository": {
17
- "type": "git",
18
- "url": "git+https://github.com/NodeSecure/js-x-ray.git"
19
- },
20
- "keywords": [
21
- "ast",
22
- "nsecure",
23
- "nodesecure",
24
- "analysis",
25
- "dependencies",
26
- "security"
27
- ],
28
- "files": [
29
- "src",
30
- "index.js",
31
- "index.d.ts"
32
- ],
33
- "author": "GENTILHOMME Thomas <gentilhomme.thomas@gmail.com>",
34
- "license": "MIT",
35
- "bugs": {
36
- "url": "https://github.com/NodeSecure/js-x-ray/issues"
37
- },
38
- "homepage": "https://github.com/NodeSecure/js-x-ray#readme",
39
- "dependencies": {
40
- "@nodesecure/sec-literal": "^1.1.0",
41
- "estree-walker": "^3.0.1",
42
- "is-minified-code": "^2.0.0",
43
- "meriyah": "^4.2.1",
44
- "safe-regex": "^2.1.1"
45
- },
46
- "devDependencies": {
47
- "@nodesecure/eslint-config": "^1.4.1",
48
- "@slimio/is": "^1.5.1",
49
- "@small-tech/esm-tape-runner": "^2.0.0",
50
- "@small-tech/tap-monkey": "^1.4.0",
51
- "@types/node": "^17.0.42",
52
- "cross-env": "^7.0.3",
53
- "eslint": "^8.17.0",
54
- "pkg-ok": "^3.0.0",
55
- "tape": "^5.5.3"
56
- }
57
- }
1
+ {
2
+ "name": "@nodesecure/js-x-ray",
3
+ "version": "5.0.1",
4
+ "description": "JavaScript AST XRay analysis",
5
+ "type": "module",
6
+ "exports": "./index.js",
7
+ "engines": {
8
+ "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
9
+ },
10
+ "scripts": {
11
+ "lint": "eslint src test",
12
+ "prepublishOnly": "pkg-ok",
13
+ "test": "cross-env esm-tape-runner 'test/**/*.spec.js' | tap-monkey",
14
+ "check": "cross-env npm run lint && npm run test"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/NodeSecure/js-x-ray.git"
19
+ },
20
+ "keywords": [
21
+ "ast",
22
+ "nsecure",
23
+ "nodesecure",
24
+ "analysis",
25
+ "dependencies",
26
+ "security"
27
+ ],
28
+ "files": [
29
+ "src",
30
+ "types",
31
+ "index.js",
32
+ "index.d.ts"
33
+ ],
34
+ "author": "GENTILHOMME Thomas <gentilhomme.thomas@gmail.com>",
35
+ "license": "MIT",
36
+ "bugs": {
37
+ "url": "https://github.com/NodeSecure/js-x-ray/issues"
38
+ },
39
+ "homepage": "https://github.com/NodeSecure/js-x-ray#readme",
40
+ "dependencies": {
41
+ "@nodesecure/sec-literal": "^1.1.0",
42
+ "estree-walker": "^3.0.1",
43
+ "is-minified-code": "^2.0.0",
44
+ "meriyah": "^4.2.1",
45
+ "safe-regex": "^2.1.1"
46
+ },
47
+ "devDependencies": {
48
+ "@nodesecure/eslint-config": "^1.4.1",
49
+ "@slimio/is": "^1.5.1",
50
+ "@small-tech/esm-tape-runner": "^2.0.0",
51
+ "@small-tech/tap-monkey": "^1.4.0",
52
+ "@types/node": "^17.0.42",
53
+ "cross-env": "^7.0.3",
54
+ "eslint": "^8.17.0",
55
+ "pkg-ok": "^3.0.0",
56
+ "tape": "^5.5.3"
57
+ }
58
+ }
package/types/api.d.ts ADDED
@@ -0,0 +1,44 @@
1
+ import { ASTDeps } from "./astdeps";
2
+ import { Warning } from "./warnings";
3
+
4
+ export {
5
+ runASTAnalysis,
6
+ runASTAnalysisOnFile,
7
+
8
+ RuntimeOptions,
9
+ RuntimeFileOptions,
10
+
11
+ Report,
12
+ ReportOnFile
13
+ }
14
+
15
+ interface RuntimeOptions {
16
+ module?: boolean;
17
+ isMinified?: boolean;
18
+ }
19
+
20
+ interface Report {
21
+ dependencies: ASTDeps;
22
+ warnings: Warning[];
23
+ idsLengthAvg: number;
24
+ stringScore: number;
25
+ isOneLineRequire: boolean;
26
+ }
27
+
28
+ interface RuntimeFileOptions {
29
+ packageName?: string;
30
+ module?: boolean;
31
+ }
32
+
33
+ type ReportOnFile = {
34
+ ok: true,
35
+ warnings: Warning[];
36
+ dependencies: ASTDeps;
37
+ isMinified: boolean;
38
+ } | {
39
+ ok: false,
40
+ warnings: Warning[];
41
+ }
42
+
43
+ declare function runASTAnalysis(str: string, options?: RuntimeOptions): Report;
44
+ declare function runASTAnalysisOnFile(pathToFile: string, options?: RuntimeFileOptions): Promise<ReportOnFile>;
@@ -0,0 +1,30 @@
1
+ export {
2
+ ASTDeps,
3
+ SourceLocation
4
+ }
5
+
6
+ interface SourceLocation {
7
+ start: {
8
+ line: number;
9
+ column: number;
10
+ };
11
+ end: {
12
+ line: number;
13
+ column: number;
14
+ }
15
+ }
16
+
17
+ declare class ASTDeps {
18
+ constructor();
19
+ removeByName(name: string): void;
20
+ add(depName: string): void;
21
+ getDependenciesInTryStatement(): IterableIterator<string>;
22
+
23
+ public isInTryStmt: boolean;
24
+ public dependencies: Record<string, {
25
+ unsafe: boolean;
26
+ inTry: boolean;
27
+ location?: SourceLocation;
28
+ }>;
29
+ public readonly size: number;
30
+ }
@@ -0,0 +1,33 @@
1
+
2
+ export {
3
+ Warning,
4
+ WarningDefault,
5
+ WarningLocation,
6
+ WarningName,
7
+ WarningNameWithValue
8
+ }
9
+
10
+ type WarningNameWithValue = "parsing-error"
11
+ | "encoded-literal"
12
+ | "unsafe-regex"
13
+ | "unsafe-stmt"
14
+ | "unsafe-assign"
15
+ | "short-identifiers"
16
+ | "suspicious-literal"
17
+ | "obfuscated-code"
18
+ | "weak-crypto";
19
+ type WarningName = WarningNameWithValue | "unsafe-import";
20
+
21
+ type WarningLocation = [[number, number], [number, number]];
22
+
23
+ interface WarningDefault {
24
+ kind: WarningName;
25
+ file?: string;
26
+ value: string;
27
+ location: WarningLocation | WarningLocation[];
28
+ i18n: string;
29
+ severity: "Information" | "Warning" | "Critical";
30
+ experimental?: boolean;
31
+ }
32
+
33
+ type Warning<T extends WarningDefault = WarningDefault> = T extends { kind: WarningNameWithValue } ? T : Omit<T, "value">;