Skip to content
This repository has been archived by the owner on Aug 14, 2024. It is now read-only.

refactor!: cleanup codebase & revampirize UT #52

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,5 @@ dist

# TernJS port file
.tern-port

/temp
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 NodeSecure
Copyright (c) 2023 NodeSecure

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
95 changes: 48 additions & 47 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,47 +1,48 @@
{
"name": "@nodesecure/authors",
"version": "1.0.2",
"description": "NodeSecure (npm) authors analysis package",
"exports": "./src/index.js",
"type": "module",
"types": "./src/index.d.ts",
"scripts": {
"lint": "cross-env eslint ./src",
"test-only": "cross-env esm-tape-runner 'test/**/*.js' | tap-monkey",
"test": "npm run lint && npm run test-only",
"coverage": "c8 -r html npm test"
},
"repository": {
"type": "git",
"url": "git+https://github.com/NodeSecure/authors.git"
},
"keywords": [
"NodeSecure",
"authors",
"author",
"npm"
],
"files": [
"src"
],
"author": "GENTILHOMME Thomas <gentilhomme.thomas@gmail.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/NodeSecure/authors/issues"
},
"homepage": "https://github.com/NodeSecure/authors#readme",
"devDependencies": {
"@nodesecure/eslint-config": "^1.6.0",
"@nodesecure/scanner": "^3.8.2",
"@npm/types": "^1.0.2",
"@small-tech/esm-tape-runner": "^2.0.0",
"@small-tech/tap-monkey": "^1.4.0",
"c8": "^7.12.0",
"cross-env": "^7.0.3",
"tape": "^5.6.3"
},
"dependencies": {
"@myunisoft/httpie": "^1.10.0",
"@nodesecure/domain-check": "^1.0.1"
}
}
{
"name": "@nodesecure/authors",
"version": "1.0.2",
"description": "NodeSecure (npm) authors analysis package",
"exports": "./dist/index.js",
"type": "module",
"types": "./dist/index.d.ts",
"scripts": {
"build": "tsc",
"lint": "eslint src/*.ts",
"test-only": "node --test test/",
"test": "npm run lint && npm run test-only",
"coverage": "c8 -r html npm test"
},
"repository": {
"type": "git",
"url": "git+https://github.com/NodeSecure/authors.git"
},
"keywords": [
"NodeSecure",
"authors",
"author",
"npm"
],
"files": [
"index.js",
"index.d.ts",
"src"
],
"author": "GENTILHOMME Thomas <gentilhomme.thomas@gmail.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/NodeSecure/authors/issues"
},
"homepage": "https://github.com/NodeSecure/authors#readme",
"devDependencies": {
"@nodesecure/eslint-config": "^1.8.0",
"@nodesecure/scanner": "^4.0.0",
"@types/node": "^20.5.9",
"c8": "^8.0.1",
"typescript": "^5.2.2"
},
"dependencies": {
"@myunisoft/httpie": "^2.0.1",
"@npm/types": "^1.0.2",
"@openally/result": "^1.2.0"
}
}
66 changes: 66 additions & 0 deletions src/domains.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Import Node.js Dependencies
import dns from "node:dns/promises";

// Import Third-party Dependencies
import { Some, None, Option } from "@openally/result";

// Import Internal Dependencies
import { whois } from "./utils/whois.js";

export type DnsNotFound = {
state: "not found";
}

export type DnsResolved = { state: "not found" } | {
state: "expired" | "active";
expirationDate: string | null;
mxRecords: string[];
}

export type ResolveResult = DnsNotFound | DnsResolved;

export class DomainResolver {
#cache: Map<string, DnsResolved> = new Map();

async resolve(
domain: string
): Promise<ResolveResult> {
if (this.#cache.has(domain)) {
return this.#cache.get(domain)!;
}

const mxRecords = await safeResolveMx(domain);
if (mxRecords.none) {
return {
state: "not found"
};
}

const expirationDate = await whois(domain);
const result: DnsResolved = {
state: expirationDate === null ? "expired" : "active",
expirationDate,
mxRecords: mxRecords.safeUnwrap()
};
this.#cache.set(domain, result);

return result;
}

clear() {
this.#cache.clear();
}
}

async function safeResolveMx(domain: string): Promise<Option<string[]>> {
try {
const mxRecords = await dns.resolveMx(domain);

return Some(
mxRecords.map(({ exchange }) => exchange)
);
}
catch {
return None;
}
}
9 changes: 0 additions & 9 deletions src/helper.js

This file was deleted.

34 changes: 0 additions & 34 deletions src/index.d.ts

This file was deleted.

148 changes: 0 additions & 148 deletions src/index.js

This file was deleted.

Loading