-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove internal events, rework public API, add inline docs, align code standards
- Loading branch information
HunteRoi
committed
Nov 16, 2022
1 parent
8a02a58
commit 379f810
Showing
12 changed files
with
419 additions
and
48 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
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 |
---|---|---|
@@ -1,11 +1,14 @@ | ||
/** | ||
* The events emitted by the {@link VerificationManager} on specific actions. | ||
* | ||
* @export | ||
* @enum {number} | ||
*/ | ||
export enum VerificationManagerEvents { | ||
codeCreate = 'codeCreate', | ||
codeVerify = 'codeVerify', | ||
|
||
userCreate = 'userCreate', | ||
userAwait = 'userAwait', | ||
userActive = 'userActive', | ||
|
||
senderCall = 'senderCall', | ||
storingSystemCall = 'storingSystemCall', | ||
userActive = 'userActive' | ||
} |
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,4 +1,7 @@ | ||
export { JSONDatabaseService, SendGridService } from './services'; | ||
export { | ||
UserModel, JSONDatabaseService, | ||
SendGridMailData, SendGridOptions, SendGridService | ||
} from './services'; | ||
export * from './types'; | ||
export * from './VerificationManager'; | ||
export * from './VerificationManagerEvents'; |
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,24 +1,42 @@ | ||
/** | ||
* The service handling the code generation. | ||
* | ||
* @export | ||
* @class CodeGeneratorService | ||
*/ | ||
export class CodeGeneratorService { | ||
private readonly characters: string; | ||
readonly #characters: string; | ||
|
||
/** | ||
* Creates an instance of CodeGeneratorService. | ||
* @param {string} charactersWhitelist default = '0123456789' | ||
* @memberof CodeGeneratorService | ||
*/ | ||
constructor(charactersWhitelist: string) { | ||
this.characters = charactersWhitelist || '0123456789'; | ||
this.#characters = charactersWhitelist || '0123456789'; | ||
} | ||
|
||
/** | ||
* Generates a code of {length} characters based on the whitelist. | ||
* | ||
* @param {number} length | ||
* @return {string} the code | ||
* @memberof CodeGeneratorService | ||
*/ | ||
generateCode(length: number): string { | ||
if (isNaN(length)) throw new TypeError('Length must be a number'); | ||
if (length < 1) throw new RangeError('Length must be at least 1'); | ||
|
||
let code = ''; | ||
for (let i = 0; i < length; i++) { | ||
code += this.getCharacterAtRandomPosition(); | ||
code += this.#getCharacterAtRandomPosition(); | ||
} | ||
return code.trim(); | ||
} | ||
|
||
private getCharacterAtRandomPosition(): string { | ||
return this.characters.charAt( | ||
Math.floor(Math.random() * this.characters.length) | ||
#getCharacterAtRandomPosition(): string { | ||
return this.#characters.charAt( | ||
Math.floor(Math.random() * this.#characters.length) | ||
); | ||
} | ||
} |
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
Oops, something went wrong.