This repository has been archived by the owner on Aug 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refacto: some improvements * fix: review
- Loading branch information
Showing
3 changed files
with
48 additions
and
36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,34 @@ | ||
// Import Third-party Dependencies | ||
import { Scanner } from "@nodesecure/scanner"; | ||
|
||
export function extractAllAuthorsFromLibrary(library: Scanner.Payload, opts: options): Promise<authorResponse[]> | ||
export function extractAllAuthors(library: Scanner.Payload, opts: options): Promise<extractionResult> | ||
|
||
export interface options { | ||
flags: flagAuthor[], | ||
flags: extractedAuthor[], | ||
domainInformations: boolean, | ||
} | ||
|
||
export interface authorResponse { | ||
export interface extractionResult { | ||
authors: author[], | ||
flaggedAuthors: extractedAuthor[], | ||
} | ||
|
||
export interface author { | ||
name?: string; | ||
email?: string; | ||
url?: string; | ||
flagged: boolean, | ||
packages: unknown[], | ||
packages: { | ||
homepage: string, | ||
spec: string, | ||
version: string, | ||
at?: string, | ||
}[], | ||
domain?: { | ||
expirationDate?: string, | ||
mxRecords?: unknown[], | ||
} | ||
} | ||
export interface flagAuthor { | ||
export interface extractedAuthor { | ||
name: string, | ||
email: string, | ||
} |
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 |
---|---|---|
|
@@ -6,7 +6,7 @@ import { readFile } from "fs/promises"; | |
import test from "tape"; | ||
|
||
// Import Internal Dependencies | ||
import { extractAllAuthorsFromLibrary } from "../src/index.js"; | ||
import { extractAllAuthors } from "../src/index.js"; | ||
|
||
const nsecureTestFile = JSON.parse( | ||
await readFile( | ||
|
@@ -17,38 +17,38 @@ const nsecureTestFile = JSON.parse( | |
test("All authors from library without flags involved", async(tape) => { | ||
const packageTest = nsecureTestFile; | ||
|
||
const authors = await extractAllAuthorsFromLibrary(packageTest, { flags: [], domainInformations: true }); | ||
const res = await extractAllAuthors(packageTest, { flags: [], domainInformations: true }); | ||
|
||
tape.isNot(authors.length, 0, "There should be authors in the response"); | ||
tape.isNot(res.authors.length, 0, "There should be authors in the response"); | ||
tape.end(); | ||
}); | ||
|
||
test("test authors from library with flag", async(tape) => { | ||
const packageTest = nsecureTestFile; | ||
const flaggedAuthors = [ | ||
{ name: "Blakeembrey", email: "hello@blakeembrey.com" } | ||
{ name: "kesla", email: "david.bjorklund@gmail.com" } | ||
]; | ||
const authors = await extractAllAuthorsFromLibrary(packageTest, { | ||
const res = await extractAllAuthors(packageTest, { | ||
flags: flaggedAuthors | ||
}); | ||
tape.deepEqual(authors.slice(4, 5), [{ | ||
name: "Blake Embrey", | ||
email: "[email protected]", | ||
flagged: true, | ||
packages: [ | ||
{ | ||
homepage: "https://github.com/blakeembrey/array-flatten", | ||
spec: "array-flatten", | ||
versions: "3.0.0", | ||
isPublishers: false | ||
}, | ||
|
||
tape.deepEqual(res.authorsFlagged, flaggedAuthors); | ||
tape.deepEqual(res.authors.slice(1, 2), | ||
[ | ||
{ | ||
homepage: "https://github.com/pillarjs/path-to-regexp#readme", | ||
spec: "path-to-regexp", | ||
versions: "6.2.1", | ||
isPublishers: true | ||
name: "kesla", | ||
email: "[email protected]", | ||
packages: | ||
[ | ||
{ | ||
homepage: "https://github.com/jshttp/etag#readme", | ||
spec: "etag", | ||
versions: "1.8.1", | ||
at: "2014-05-18T11:14:58.281Z" | ||
} | ||
] | ||
} | ||
] | ||
}]); | ||
); | ||
tape.end(); | ||
}); |