diff --git a/README.md b/README.md index 4cd7d1c..01a9757 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,8 @@ Guardian is a powerful JavaScript library designed to fortify your application's This library is easy to integrate into your project and offers a comprehensive set of features, making it a reliable choice for enhancing the security of your application. +you can run it with TypeScript or JavaScript. + ## Installation To install Guardian, simply run the following command using npm: diff --git a/dist/index.d.ts b/dist/index.d.ts new file mode 100644 index 0000000..74a2bcd --- /dev/null +++ b/dist/index.d.ts @@ -0,0 +1,6 @@ +import PassCheck from "./passwordcheck"; +import JwtAuth from "jsonwebtoken"; +import PassPolicy from "./passpolicy"; +import RateLimit from "./ratelimit"; +import PasswordGenerator from "./passgen"; +export { PassCheck, JwtAuth, PassPolicy, RateLimit, PasswordGenerator }; diff --git a/dist/jwt.d.ts b/dist/jwt.d.ts new file mode 100644 index 0000000..a808ebf --- /dev/null +++ b/dist/jwt.d.ts @@ -0,0 +1,37 @@ +import * as jwt from 'jsonwebtoken'; +export default class JwtAuth { + private JWTSecretKey; + private blacklist; + constructor(JWTSecretKey: string); + generateJWT(payload: { + [key: string]: any; + }, settings?: jwt.SignOptions, secretKey?: string): string; + verifyJWT(token: string, secretKey?: string): jwt.JwtPayload | undefined; + decodeJWT(token: string): string | jwt.JwtPayload | null; + getJWTExpirationDate(token: string): any; + isJWTExpired(token: string): boolean | { + valid: boolean; + message: string; + }; + refreshJWT(token: string, settings?: jwt.SignOptions, secretKey?: string): string | { + valid: boolean; + message: string; + }; + BlackListJWT(token: string): { + valid: boolean; + message: string; + }; + ClearBlackList(): { + valid: boolean; + message: string; + }; + GetBlackList(): string[]; + RemoveFromBlackList(token: string): { + valid: boolean; + message: string; + }; + IsBlackListed(token: string): { + valid: boolean; + message: string; + }; +} diff --git a/dist/passgen.d.ts b/dist/passgen.d.ts new file mode 100644 index 0000000..2ad447b --- /dev/null +++ b/dist/passgen.d.ts @@ -0,0 +1,13 @@ +export default class PasswordGenerator { + private options; + constructor(options: { + minLength: number; + maxLength: number; + minLower: number; + minUpper: number; + minNum: number; + minSpecial: number; + specialChars: string; + }); + Generate(length?: number): string; +} diff --git a/dist/passpolicy.d.ts b/dist/passpolicy.d.ts new file mode 100644 index 0000000..bbce5bd --- /dev/null +++ b/dist/passpolicy.d.ts @@ -0,0 +1,26 @@ +export default class PassPolicy { + private options; + constructor(options: { + minLength: number; + maxLength: number; + minLower: number; + minUpper: number; + minNum: number; + minSpecial: number; + specialChars: string; + }); + validate(password: string): { + valid: boolean; + message: string; + } | { + valid: boolean; + message?: undefined; + }; + CheckDifference(newPassword: string, oldPassword: string, neededDifference?: number): { + valid: boolean; + message: string; + } | { + valid: boolean; + message?: undefined; + }; +} diff --git a/dist/passwordcheck.d.ts b/dist/passwordcheck.d.ts new file mode 100644 index 0000000..502a913 --- /dev/null +++ b/dist/passwordcheck.d.ts @@ -0,0 +1,15 @@ +export default class PassCheck { + private BcryptSaltRounds; + private PassPolicy; + constructor(BcryptSaltRounds: number, PassPolicyOptions: { + minLength: number; + maxLength: number; + minLower: number; + minUpper: number; + minNum: number; + minSpecial: number; + specialChars: string; + }); + verifyPassword(password: string, hash: string): Promise; + hashPassword(password: string): Promise; +} diff --git a/dist/ratelimit.d.ts b/dist/ratelimit.d.ts new file mode 100644 index 0000000..10ad027 --- /dev/null +++ b/dist/ratelimit.d.ts @@ -0,0 +1,46 @@ +type Event = { + name: string; + cooldown: number; + maxAttempts: number; + lastAttempt?: number; + attempts?: number[]; +}; +type user = { + token: string; + events: { + [name: string]: Event; + }; +}; +export default class RateLimit { + users: { + [token: string]: user; + }; + events: { + [name: string]: Event; + }; + constructor(users?: { + [token: string]: user; + }, events?: { + [name: string]: Event; + }); + addEvent(event: Event): boolean; + removeEvent(name: string): boolean; + addUser(token: string): boolean; + removeUser(token: string): boolean; + attempt(token: string, name: string): boolean; + getEvents(): { + [name: string]: Event; + }; + getUsers(): { + [token: string]: user; + }; + getEvent(name: string): Event; + getUser(token: string): user; + remainingAttempts(token: string, name: string): number; + resetAttempts(token: string, name: string): boolean; + resetAllAttempts(token: string): boolean; + resetAllUsers(): boolean; + resetEvent(name: string): boolean; + resetUser(token: string): boolean; +} +export {}; diff --git a/package.json b/package.json index 2ffe76a..2e73f89 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,10 @@ { - "name": "@kajvans/auth-guardian", - "version": "2.0.0", + "name": "auth-guardian", + "version": "2.0.1", "description": "auth-guardian a library for enhancing application security", - "main": "index.js", + "main": "./dist/index.js", + "types": "./dist/index.d.ts", + "typings": "./dist/index.d.ts", "scripts": { "test": "jest", "build": "tsc" diff --git a/tsconfig.json b/tsconfig.json index 1f621f9..3322677 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -49,7 +49,7 @@ // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */ /* Emit */ - // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ + "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ // "declarationMap": true, /* Create sourcemaps for d.ts files. */ // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ // "sourceMap": true, /* Create source map files for emitted JavaScript files. */