@atlantjs/arch 4.1.4 → 4.1.6

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.
Files changed (50) hide show
  1. package/@tool-box/tests/builders/user/email.builder.d.ts +6 -0
  2. package/@tool-box/tests/builders/user/email.builder.js +15 -0
  3. package/@tool-box/tests/builders/user/person-name.builder.d.ts +6 -0
  4. package/@tool-box/tests/builders/user/person-name.builder.js +15 -0
  5. package/@tool-box/tests/builders/user/user-id.builder.d.ts +6 -0
  6. package/@tool-box/tests/builders/user/user-id.builder.js +14 -0
  7. package/@tool-box/tests/builders/user/username.builder.d.ts +6 -0
  8. package/@tool-box/tests/builders/user/username.builder.js +15 -0
  9. package/arch/modules/domain/entities/user/password/password.abstract.d.ts +8 -0
  10. package/arch/modules/domain/entities/user/password/password.abstract.js +41 -0
  11. package/arch/modules/domain/entities/user/password/password.abstract.type.d.ts +5 -0
  12. package/arch/modules/domain/entities/user/password/password.abstract.type.js +2 -0
  13. package/arch/modules/domain/entities/user/password/steps/not-allowing-consecutive-chars-step.d.ts +11 -0
  14. package/arch/modules/domain/entities/user/password/steps/not-allowing-consecutive-chars-step.js +34 -0
  15. package/arch/modules/domain/entities/user/password/steps/not-allowing-date-step.d.ts +11 -0
  16. package/arch/modules/domain/entities/user/password/steps/not-allowing-date-step.js +61 -0
  17. package/arch/modules/domain/entities/user/password/steps/not-allowing-phone-step.d.ts +7 -0
  18. package/arch/modules/domain/entities/user/password/steps/not-allowing-phone-step.js +27 -0
  19. package/arch/modules/domain/entities/user/password/steps/not-allowing-repeated-chars-step.d.ts +11 -0
  20. package/arch/modules/domain/entities/user/password/steps/not-allowing-repeated-chars-step.js +34 -0
  21. package/arch/modules/domain/entities/user/password/steps/not-allowing-string-step.d.ts +7 -0
  22. package/arch/modules/domain/entities/user/password/steps/not-allowing-string-step.js +19 -0
  23. package/arch/modules/domain/entities/user/password/steps/not-allowing-these-chars-step.d.ts +10 -0
  24. package/arch/modules/domain/entities/user/password/steps/not-allowing-these-chars-step.js +17 -0
  25. package/arch/modules/domain/entities/user/password/steps/numeric-step.d.ts +5 -0
  26. package/arch/modules/domain/entities/user/password/steps/numeric-step.js +13 -0
  27. package/arch/modules/domain/entities/user/password/steps/with-at-least-one-letter-step.d.ts +5 -0
  28. package/arch/modules/domain/entities/user/password/steps/with-at-least-one-letter-step.js +14 -0
  29. package/arch/modules/domain/entities/user/password/steps/with-at-least-one-number-digit-step.d.ts +5 -0
  30. package/arch/modules/domain/entities/user/password/steps/with-at-least-one-number-digit-step.js +14 -0
  31. package/arch/modules/domain/entities/user/password/steps/with-at-least-one-special-char-step.d.ts +5 -0
  32. package/arch/modules/domain/entities/user/password/steps/with-at-least-one-special-char-step.js +14 -0
  33. package/arch/modules/domain/entities/user/password/steps/with-length-step.d.ts +11 -0
  34. package/arch/modules/domain/entities/user/password/steps/with-length-step.js +18 -0
  35. package/arch/modules/domain/entities/user/password/validation-step.d.ts +5 -0
  36. package/arch/modules/domain/entities/user/password/validation-step.js +9 -0
  37. package/arch/modules/domain/entities/user/password/validation-step.type.d.ts +4 -0
  38. package/arch/modules/domain/entities/user/password/validation-step.type.js +2 -0
  39. package/arch/modules/domain/entities/user/value-objects/email.d.ts +6 -0
  40. package/arch/modules/domain/entities/user/value-objects/email.js +17 -0
  41. package/arch/modules/domain/entities/user/value-objects/person-name.d.ts +7 -0
  42. package/arch/modules/domain/entities/user/value-objects/person-name.js +17 -0
  43. package/arch/modules/domain/entities/user/value-objects/user-id.d.ts +3 -0
  44. package/arch/modules/domain/entities/user/value-objects/user-id.js +7 -0
  45. package/arch/modules/domain/entities/user/value-objects/username.d.ts +3 -0
  46. package/arch/modules/domain/entities/user/value-objects/username.js +7 -0
  47. package/index.d.ts +10 -0
  48. package/index.js +21 -1
  49. package/package.json +1 -1
  50. package/tsconfig.tsbuildinfo +1 -1
@@ -0,0 +1,6 @@
1
+ import { EntityBuilder } from "../../entity-builder.util";
2
+ import { Email } from "../../../../arch/modules/domain/entities/user/value-objects/email";
3
+ export declare class EmailBuilder extends EntityBuilder<Email, EmailBuilder> {
4
+ constructor();
5
+ protected buildDefault(): Email;
6
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EmailBuilder = void 0;
4
+ const entity_builder_util_1 = require("../../entity-builder.util");
5
+ const email_1 = require("../../../../arch/modules/domain/entities/user/value-objects/email");
6
+ const _1 = require("@faker-js/faker/.");
7
+ class EmailBuilder extends entity_builder_util_1.EntityBuilder {
8
+ constructor() {
9
+ super(EmailBuilder);
10
+ }
11
+ buildDefault() {
12
+ return new email_1.Email(_1.faker.internet.email());
13
+ }
14
+ }
15
+ exports.EmailBuilder = EmailBuilder;
@@ -0,0 +1,6 @@
1
+ import { EntityBuilder } from "../../entity-builder.util";
2
+ import { PersonName } from "../../../../arch/modules/domain/entities/user/value-objects/person-name";
3
+ export declare class PersonNameBuilder extends EntityBuilder<PersonName, PersonNameBuilder> {
4
+ constructor();
5
+ protected buildDefault(): PersonName;
6
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PersonNameBuilder = void 0;
4
+ const entity_builder_util_1 = require("../../entity-builder.util");
5
+ const person_name_1 = require("../../../../arch/modules/domain/entities/user/value-objects/person-name");
6
+ const _1 = require("@faker-js/faker/.");
7
+ class PersonNameBuilder extends entity_builder_util_1.EntityBuilder {
8
+ constructor() {
9
+ super(PersonNameBuilder);
10
+ }
11
+ buildDefault() {
12
+ return new person_name_1.PersonName(_1.faker.person.fullName());
13
+ }
14
+ }
15
+ exports.PersonNameBuilder = PersonNameBuilder;
@@ -0,0 +1,6 @@
1
+ import { EntityBuilder } from "../../entity-builder.util";
2
+ import { UserId } from "../../../../arch/modules/domain/entities/user/value-objects/user-id";
3
+ export declare class UserIdBuilder extends EntityBuilder<UserId, UserIdBuilder> {
4
+ constructor();
5
+ protected buildDefault(): UserId;
6
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UserIdBuilder = void 0;
4
+ const entity_builder_util_1 = require("../../entity-builder.util");
5
+ const user_id_1 = require("../../../../arch/modules/domain/entities/user/value-objects/user-id");
6
+ class UserIdBuilder extends entity_builder_util_1.EntityBuilder {
7
+ constructor() {
8
+ super(UserIdBuilder);
9
+ }
10
+ buildDefault() {
11
+ return new user_id_1.UserId();
12
+ }
13
+ }
14
+ exports.UserIdBuilder = UserIdBuilder;
@@ -0,0 +1,6 @@
1
+ import { EntityBuilder } from "../../entity-builder.util";
2
+ import { Username } from "../../../../arch/modules/domain/entities/user/value-objects/username";
3
+ export declare class UsernameBuilder extends EntityBuilder<Username, UsernameBuilder> {
4
+ constructor();
5
+ protected buildDefault(): Username;
6
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UsernameBuilder = void 0;
4
+ const entity_builder_util_1 = require("../../entity-builder.util");
5
+ const username_1 = require("../../../../arch/modules/domain/entities/user/value-objects/username");
6
+ const _1 = require("@faker-js/faker/.");
7
+ class UsernameBuilder extends entity_builder_util_1.EntityBuilder {
8
+ constructor() {
9
+ super(UsernameBuilder);
10
+ }
11
+ buildDefault() {
12
+ return new username_1.Username(_1.faker.internet.username());
13
+ }
14
+ }
15
+ exports.UsernameBuilder = UsernameBuilder;
@@ -0,0 +1,8 @@
1
+ import { PasswordPolicyResult } from "./password.abstract.type";
2
+ export declare abstract class PasswordAbstract {
3
+ private readonly password;
4
+ private readonly validationSteps;
5
+ constructor(password: string);
6
+ protected validate(password: string): PasswordPolicyResult;
7
+ toString(): string;
8
+ }
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PasswordAbstract = void 0;
4
+ const guardian_1 = require("../../../../../../@tool-box/utils/type-guard/guardian");
5
+ const with_at_least_one_letter_step_1 = require("./steps/with-at-least-one-letter-step");
6
+ const with_at_least_one_number_digit_step_1 = require("./steps/with-at-least-one-number-digit-step");
7
+ const with_at_least_one_special_char_step_1 = require("./steps/with-at-least-one-special-char-step");
8
+ const with_length_step_1 = require("./steps/with-length-step");
9
+ class PasswordAbstract {
10
+ constructor(password) {
11
+ this.password = password;
12
+ this.validationSteps = [
13
+ new with_at_least_one_letter_step_1.WithAtLeastOneLetterStep(),
14
+ new with_at_least_one_number_digit_step_1.WithAtLeastOneNumberDigitStep(),
15
+ new with_at_least_one_special_char_step_1.WithAtLeastOneSpecialCharStep(),
16
+ new with_length_step_1.WithLengthStep({ min: 6, max: 999 }),
17
+ ];
18
+ const { valid, validationStepsResults } = this.validate(this.password);
19
+ if (guardian_1.Guardian.isFalsy(valid)) {
20
+ throw new TypeError(`Password is invalid: ${validationStepsResults.map((result) => result.name)}`);
21
+ }
22
+ }
23
+ validate(password) {
24
+ if (guardian_1.Guardian.isEqual(this.validationSteps.length, 0)) {
25
+ throw new TypeError("No validations found");
26
+ }
27
+ const validationStepsResults = [];
28
+ for (const step of this.validationSteps) {
29
+ validationStepsResults.push(step.validate(password));
30
+ }
31
+ const valid = validationStepsResults.every((result) => result.valid);
32
+ return {
33
+ valid,
34
+ validationStepsResults,
35
+ };
36
+ }
37
+ toString() {
38
+ return this.password;
39
+ }
40
+ }
41
+ exports.PasswordAbstract = PasswordAbstract;
@@ -0,0 +1,5 @@
1
+ import { ValidationStepResult } from "./validation-step.type";
2
+ export interface PasswordPolicyResult {
3
+ valid: boolean;
4
+ validationStepsResults: ValidationStepResult[];
5
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,11 @@
1
+ import { ValidationStep } from "../validation-step";
2
+ import { ValidationStepResult } from "../validation-step.type";
3
+ export interface NotAllowingConsecutiveCharsStepOptions {
4
+ maxAllowedConsecutiveChars: number;
5
+ }
6
+ export declare class NotAllowingConsecutiveCharsStep extends ValidationStep {
7
+ private readonly params;
8
+ constructor(params: NotAllowingConsecutiveCharsStepOptions);
9
+ validate(password: string): ValidationStepResult;
10
+ private getMaxNumberOfConsecutiveChars;
11
+ }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NotAllowingConsecutiveCharsStep = void 0;
4
+ const validation_step_1 = require("../validation-step");
5
+ class NotAllowingConsecutiveCharsStep extends validation_step_1.ValidationStep {
6
+ constructor(params) {
7
+ super();
8
+ this.params = params;
9
+ }
10
+ validate(password) {
11
+ return {
12
+ valid: this.getMaxNumberOfConsecutiveChars(password) <=
13
+ this.params.maxAllowedConsecutiveChars,
14
+ name: this.name,
15
+ };
16
+ }
17
+ getMaxNumberOfConsecutiveChars(password) {
18
+ let numberOfConsecutiveChars = 1;
19
+ let maxNumberOfConsecutiveChars = 1;
20
+ for (let i = 1; i < password.length; i++) {
21
+ const previousChar = password[i - 1];
22
+ const char = password[i];
23
+ if (Math.abs(previousChar.charCodeAt(0) - char.charCodeAt(0)) === 1) {
24
+ numberOfConsecutiveChars += 1;
25
+ }
26
+ else {
27
+ maxNumberOfConsecutiveChars = Math.max(numberOfConsecutiveChars, maxNumberOfConsecutiveChars);
28
+ numberOfConsecutiveChars = 1;
29
+ }
30
+ }
31
+ return Math.max(numberOfConsecutiveChars, maxNumberOfConsecutiveChars);
32
+ }
33
+ }
34
+ exports.NotAllowingConsecutiveCharsStep = NotAllowingConsecutiveCharsStep;
@@ -0,0 +1,11 @@
1
+ import { ValidationStep } from "../validation-step";
2
+ import { ValidationStepResult } from "../validation-step.type";
3
+ export declare class NotAllowingDateStep extends ValidationStep {
4
+ private readonly notAllowedDate;
5
+ constructor(notAllowedDate: Date);
6
+ validate(password: string): ValidationStepResult;
7
+ private possibleDateCombinations;
8
+ private buildDayFormats;
9
+ private buildMonthFormats;
10
+ private buildYearFormat;
11
+ }
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NotAllowingDateStep = void 0;
4
+ const validation_step_1 = require("../validation-step");
5
+ class NotAllowingDateStep extends validation_step_1.ValidationStep {
6
+ constructor(notAllowedDate) {
7
+ super();
8
+ this.notAllowedDate = notAllowedDate;
9
+ }
10
+ validate(password) {
11
+ const cleanPassword = password.replace(/[^\w]/gi, "");
12
+ const result = this.possibleDateCombinations().every((dateFormat) => !cleanPassword.includes(dateFormat.toLowerCase()));
13
+ return {
14
+ valid: result,
15
+ name: this.name,
16
+ };
17
+ }
18
+ possibleDateCombinations() {
19
+ const formats = [];
20
+ this.buildDayFormats().forEach((day) => {
21
+ this.buildMonthFormats().forEach((month) => {
22
+ this.buildYearFormat().forEach((year) => {
23
+ formats.push(`${day}${month}`);
24
+ formats.push(`${month}${day}`);
25
+ formats.push(`${day}${month}${year}`);
26
+ formats.push(`${month}${day}${year}`);
27
+ formats.push(`${year}${month}${day}`);
28
+ });
29
+ });
30
+ });
31
+ return [...new Set(formats)];
32
+ }
33
+ buildDayFormats() {
34
+ const day = this.notAllowedDate.getUTCDate();
35
+ const dayLength = 2;
36
+ return [
37
+ ...new Set([day.toString(), day.toString().padStart(dayLength, "0")]),
38
+ ];
39
+ }
40
+ buildMonthFormats() {
41
+ const month = this.notAllowedDate.getUTCMonth() + 1;
42
+ const monthLength = 2;
43
+ return [
44
+ ...new Set([
45
+ month.toString(),
46
+ month.toString().padStart(monthLength, "0"),
47
+ ]),
48
+ ];
49
+ }
50
+ buildYearFormat() {
51
+ const year = this.notAllowedDate.getUTCFullYear();
52
+ const abbreviateYearLength = 2;
53
+ return [
54
+ ...new Set([
55
+ year.toString(),
56
+ year.toString().slice(-abbreviateYearLength),
57
+ ]),
58
+ ];
59
+ }
60
+ }
61
+ exports.NotAllowingDateStep = NotAllowingDateStep;
@@ -0,0 +1,7 @@
1
+ import { ValidationStep } from "../validation-step";
2
+ import { ValidationStepResult } from "../validation-step.type";
3
+ export declare class NotAllowingPhoneStep extends ValidationStep {
4
+ private readonly notAllowedPhone?;
5
+ constructor(phone: string);
6
+ validate(password: string): ValidationStepResult;
7
+ }
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NotAllowingPhoneStep = void 0;
4
+ const validation_step_1 = require("../validation-step");
5
+ class NotAllowingPhoneStep extends validation_step_1.ValidationStep {
6
+ constructor(phone) {
7
+ super();
8
+ const matches = phone.match(/\d{4}\-?\d{4}$/);
9
+ if (matches) {
10
+ this.notAllowedPhone = matches[0].replace(/\-/, "");
11
+ }
12
+ }
13
+ validate(password) {
14
+ if (!this.notAllowedPhone) {
15
+ return {
16
+ valid: true,
17
+ name: this.name,
18
+ };
19
+ }
20
+ const cleanPassword = password.replace(/[\-\s]/gi, "");
21
+ return {
22
+ valid: !cleanPassword.includes(this.notAllowedPhone),
23
+ name: this.name,
24
+ };
25
+ }
26
+ }
27
+ exports.NotAllowingPhoneStep = NotAllowingPhoneStep;
@@ -0,0 +1,11 @@
1
+ import { ValidationStep } from "../validation-step";
2
+ import { ValidationStepResult } from "../validation-step.type";
3
+ export interface NotAllowingRepeatedCharsStepOptions {
4
+ maxAllowedRepeatedChars: number;
5
+ }
6
+ export declare class NotAllowingRepeatedCharsStep extends ValidationStep {
7
+ private readonly options;
8
+ constructor(options: NotAllowingRepeatedCharsStepOptions);
9
+ validate(password: string): ValidationStepResult;
10
+ private getMaxNumberOfRepeatedChars;
11
+ }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NotAllowingRepeatedCharsStep = void 0;
4
+ const validation_step_1 = require("../validation-step");
5
+ class NotAllowingRepeatedCharsStep extends validation_step_1.ValidationStep {
6
+ constructor(options) {
7
+ super();
8
+ this.options = options;
9
+ }
10
+ validate(password) {
11
+ return {
12
+ valid: this.getMaxNumberOfRepeatedChars(password) <=
13
+ this.options.maxAllowedRepeatedChars,
14
+ name: this.name,
15
+ };
16
+ }
17
+ getMaxNumberOfRepeatedChars(password) {
18
+ let numberOfRepeatedChars = 1;
19
+ let maxNumberOfRepeatedChars = 1;
20
+ for (let i = 1; i < password.length; i++) {
21
+ const previousChar = password[i - 1];
22
+ const char = password[i];
23
+ if (previousChar === char) {
24
+ numberOfRepeatedChars += 1;
25
+ }
26
+ else {
27
+ maxNumberOfRepeatedChars = Math.max(numberOfRepeatedChars, maxNumberOfRepeatedChars);
28
+ numberOfRepeatedChars = 1;
29
+ }
30
+ }
31
+ return Math.max(numberOfRepeatedChars, maxNumberOfRepeatedChars);
32
+ }
33
+ }
34
+ exports.NotAllowingRepeatedCharsStep = NotAllowingRepeatedCharsStep;
@@ -0,0 +1,7 @@
1
+ import { ValidationStep } from "../validation-step";
2
+ import { ValidationStepResult } from "../validation-step.type";
3
+ export declare class NotAllowingStringStep extends ValidationStep {
4
+ private readonly forbiddenString;
5
+ constructor(forbiddenString: string);
6
+ validate(password: string): ValidationStepResult;
7
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NotAllowingStringStep = void 0;
4
+ const validation_step_1 = require("../validation-step");
5
+ class NotAllowingStringStep extends validation_step_1.ValidationStep {
6
+ constructor(forbiddenString) {
7
+ super();
8
+ this.forbiddenString = forbiddenString;
9
+ }
10
+ validate(password) {
11
+ return {
12
+ valid: !password
13
+ .toLowerCase()
14
+ .includes(this.forbiddenString.toLowerCase()),
15
+ name: this.name,
16
+ };
17
+ }
18
+ }
19
+ exports.NotAllowingStringStep = NotAllowingStringStep;
@@ -0,0 +1,10 @@
1
+ import { ValidationStep } from "../validation-step";
2
+ import { ValidationStepResult } from "../validation-step.type";
3
+ export interface NotAllowingTheseCharsStepOptions {
4
+ notAllowedCharsList: string[];
5
+ }
6
+ export declare class NotAllowingTheseCharsStep extends ValidationStep {
7
+ private readonly options;
8
+ constructor(options: NotAllowingTheseCharsStepOptions);
9
+ validate(password: string): ValidationStepResult;
10
+ }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NotAllowingTheseCharsStep = void 0;
4
+ const validation_step_1 = require("../validation-step");
5
+ class NotAllowingTheseCharsStep extends validation_step_1.ValidationStep {
6
+ constructor(options) {
7
+ super();
8
+ this.options = options;
9
+ }
10
+ validate(password) {
11
+ return {
12
+ valid: this.options.notAllowedCharsList.every((char) => !password.toLowerCase().includes(char.toLowerCase())),
13
+ name: this.name,
14
+ };
15
+ }
16
+ }
17
+ exports.NotAllowingTheseCharsStep = NotAllowingTheseCharsStep;
@@ -0,0 +1,5 @@
1
+ import { ValidationStep } from "../validation-step";
2
+ import { ValidationStepResult } from "../validation-step.type";
3
+ export declare class NumericStep extends ValidationStep {
4
+ validate(password: string): ValidationStepResult;
5
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NumericStep = void 0;
4
+ const validation_step_1 = require("../validation-step");
5
+ class NumericStep extends validation_step_1.ValidationStep {
6
+ validate(password) {
7
+ return {
8
+ valid: /^\d+$/.test(password),
9
+ name: this.name,
10
+ };
11
+ }
12
+ }
13
+ exports.NumericStep = NumericStep;
@@ -0,0 +1,5 @@
1
+ import { ValidationStep } from "../validation-step";
2
+ import { ValidationStepResult } from "../validation-step.type";
3
+ export declare class WithAtLeastOneLetterStep extends ValidationStep {
4
+ validate(password: string): ValidationStepResult;
5
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WithAtLeastOneLetterStep = void 0;
4
+ const validation_step_1 = require("../validation-step");
5
+ class WithAtLeastOneLetterStep extends validation_step_1.ValidationStep {
6
+ validate(password) {
7
+ const regex = /[a-zA-Z]/;
8
+ return {
9
+ valid: regex.test(password),
10
+ name: this.name,
11
+ };
12
+ }
13
+ }
14
+ exports.WithAtLeastOneLetterStep = WithAtLeastOneLetterStep;
@@ -0,0 +1,5 @@
1
+ import { ValidationStep } from "../validation-step";
2
+ import { ValidationStepResult } from "../validation-step.type";
3
+ export declare class WithAtLeastOneNumberDigitStep extends ValidationStep {
4
+ validate(password: string): ValidationStepResult;
5
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WithAtLeastOneNumberDigitStep = void 0;
4
+ const validation_step_1 = require("../validation-step");
5
+ class WithAtLeastOneNumberDigitStep extends validation_step_1.ValidationStep {
6
+ validate(password) {
7
+ const regex = /\d/;
8
+ return {
9
+ valid: regex.test(password),
10
+ name: this.name,
11
+ };
12
+ }
13
+ }
14
+ exports.WithAtLeastOneNumberDigitStep = WithAtLeastOneNumberDigitStep;
@@ -0,0 +1,5 @@
1
+ import { ValidationStep } from "../validation-step";
2
+ import { ValidationStepResult } from "../validation-step.type";
3
+ export declare class WithAtLeastOneSpecialCharStep extends ValidationStep {
4
+ validate(password: string): ValidationStepResult;
5
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WithAtLeastOneSpecialCharStep = void 0;
4
+ const validation_step_1 = require("../validation-step");
5
+ class WithAtLeastOneSpecialCharStep extends validation_step_1.ValidationStep {
6
+ validate(password) {
7
+ const regex = /[ `!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?~]/;
8
+ return {
9
+ valid: regex.test(password),
10
+ name: this.name,
11
+ };
12
+ }
13
+ }
14
+ exports.WithAtLeastOneSpecialCharStep = WithAtLeastOneSpecialCharStep;
@@ -0,0 +1,11 @@
1
+ import { ValidationStep } from "../validation-step";
2
+ import { ValidationStepResult } from "../validation-step.type";
3
+ export interface WithLengthStepOptions {
4
+ min: number;
5
+ max: number;
6
+ }
7
+ export declare class WithLengthStep extends ValidationStep {
8
+ private readonly options;
9
+ constructor(options: WithLengthStepOptions);
10
+ validate(password: string): ValidationStepResult;
11
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WithLengthStep = void 0;
4
+ const validation_step_1 = require("../validation-step");
5
+ class WithLengthStep extends validation_step_1.ValidationStep {
6
+ constructor(options) {
7
+ super();
8
+ this.options = options;
9
+ }
10
+ validate(password) {
11
+ return {
12
+ valid: password.length >= this.options.min &&
13
+ password.length <= this.options.max,
14
+ name: this.name,
15
+ };
16
+ }
17
+ }
18
+ exports.WithLengthStep = WithLengthStep;
@@ -0,0 +1,5 @@
1
+ import { ValidationStepResult } from "./validation-step.type";
2
+ export declare abstract class ValidationStep {
3
+ abstract validate(password: string): ValidationStepResult;
4
+ protected get name(): string;
5
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ValidationStep = void 0;
4
+ class ValidationStep {
5
+ get name() {
6
+ return this.constructor.name;
7
+ }
8
+ }
9
+ exports.ValidationStep = ValidationStep;
@@ -0,0 +1,4 @@
1
+ export interface ValidationStepResult {
2
+ valid: boolean;
3
+ name: string;
4
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,6 @@
1
+ import { $string } from "../../$string.abstract";
2
+ export declare class Email extends $string {
3
+ private readonly email;
4
+ constructor(email: string);
5
+ protected validation(): void;
6
+ }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Email = void 0;
4
+ const _string_abstract_1 = require("../../$string.abstract");
5
+ class Email extends _string_abstract_1.$string {
6
+ constructor(email) {
7
+ super(email);
8
+ this.email = email;
9
+ this.validation();
10
+ }
11
+ validation() {
12
+ if (!/^[\w-\\.]+@([\w-]+\.)+[\w-]{2,4}$/.test(this.email)) {
13
+ throw new TypeError(`${this.constructor.name} should be valid.`);
14
+ }
15
+ }
16
+ }
17
+ exports.Email = Email;
@@ -0,0 +1,7 @@
1
+ import { $string } from "../../$string.abstract";
2
+ export declare class PersonName extends $string {
3
+ private readonly name;
4
+ constructor(name: string);
5
+ get firstName(): string;
6
+ get lastName(): string;
7
+ }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PersonName = void 0;
4
+ const _string_abstract_1 = require("../../$string.abstract");
5
+ class PersonName extends _string_abstract_1.$string {
6
+ constructor(name) {
7
+ super(name);
8
+ this.name = name;
9
+ }
10
+ get firstName() {
11
+ return this.name.split(" ")[0];
12
+ }
13
+ get lastName() {
14
+ return this.name.split(" ").slice(1).join(" ");
15
+ }
16
+ }
17
+ exports.PersonName = PersonName;
@@ -0,0 +1,3 @@
1
+ import { UuidAbstract } from "../../uuid.abstract";
2
+ export declare class UserId extends UuidAbstract {
3
+ }
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UserId = void 0;
4
+ const uuid_abstract_1 = require("../../uuid.abstract");
5
+ class UserId extends uuid_abstract_1.UuidAbstract {
6
+ }
7
+ exports.UserId = UserId;