@ikas/storefront 0.0.40 → 0.0.41

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.
@@ -5,3 +5,11 @@ export { IkasNavigationLink } from "./navigation-link/index";
5
5
  export { IkasProductDetail } from "./product-detail/index";
6
6
  export { IkasProductList, IkasProductListType, IkasProductListSortType, } from "./product-list/index";
7
7
  export { IkasProductListFilter } from "./product-list/filter";
8
+ export { Validator, ValidationStatus } from "./validator/index";
9
+ export * from "./validator/rules/index";
10
+ export { LoginForm } from "./validator/form/login";
11
+ export { AddressForm } from "./validator/form/address";
12
+ export { RegisterForm } from "./validator/form/register";
13
+ export { ForgotPasswordForm } from "./validator/form/forgot-password";
14
+ export { RecoverPasswordForm } from "./validator/form/recover-password";
15
+ export { AccountInfoForm } from "./validator/form/account-info";
@@ -0,0 +1,40 @@
1
+ import { PhoneRule, RequiredRule } from "../rules/index";
2
+ import { IkasBaseStore } from "../../../../store/index";
3
+ import { IkasCustomer } from "../../../index";
4
+ declare type AccountInfoFormPropsValidatorMessage<T> = {
5
+ requiredRule: ((model: T) => string) | string;
6
+ phoneRule?: ((model: T) => string) | string;
7
+ };
8
+ declare type AccountInfoFormProps<T> = {
9
+ message: AccountInfoFormPropsValidatorMessage<T>;
10
+ customer: IkasCustomer;
11
+ store: IkasBaseStore;
12
+ };
13
+ export declare class AccountInfoForm {
14
+ private customer;
15
+ private validator;
16
+ private store;
17
+ private message;
18
+ constructor(props: AccountInfoFormProps<IkasCustomer>);
19
+ validatorRules: (includePhoneRule?: boolean) => (RequiredRule<IkasCustomer> | PhoneRule<IkasCustomer>)[];
20
+ get hasError(): boolean;
21
+ get email(): string;
22
+ get firstName(): string;
23
+ set firstName(value: string);
24
+ get lastName(): string;
25
+ set lastName(value: string);
26
+ get phone(): string;
27
+ set phone(value: string);
28
+ get firstNameErrorMessage(): string | undefined;
29
+ get lastNameErrorMessage(): string | undefined;
30
+ get phoneErrorMessage(): string | undefined;
31
+ onFirstNameChange: (value: string) => void;
32
+ onLastNameChange: (value: string) => void;
33
+ onPhoneChange: (value: string) => void;
34
+ validateAll(): Promise<boolean>;
35
+ submit(): Promise<{
36
+ isFormError: boolean;
37
+ isSuccess: boolean;
38
+ }>;
39
+ }
40
+ export {};
@@ -0,0 +1,72 @@
1
+ import { IkasCity, IkasCountry, IkasCustomerAddress, IkasDistrict, IkasState } from "../../../data/index";
2
+ import { IkasBaseStore } from "../../../../store/index";
3
+ declare type AddressFormProps<T> = {
4
+ message: {
5
+ requiredRule: ((model: T) => string) | string;
6
+ phoneRule: ((model: T) => string) | string;
7
+ };
8
+ address: IkasCustomerAddress;
9
+ store: IkasBaseStore;
10
+ };
11
+ export declare class AddressForm {
12
+ address: IkasCustomerAddress;
13
+ countries: IkasCountry[];
14
+ states: IkasState[];
15
+ cities: IkasCity[];
16
+ districts: IkasDistrict[];
17
+ private _isCountriesPending;
18
+ private _isStatesPending;
19
+ private _isCitiesPending;
20
+ private _isDistrictsPending;
21
+ private store;
22
+ private validator;
23
+ constructor(props: AddressFormProps<IkasCustomerAddress>);
24
+ onTitleChange: (value: string) => void;
25
+ onFirstNameChange: (value: string) => void;
26
+ onLastNameChange: (value: string) => void;
27
+ onPhoneChange: (value: string) => void;
28
+ onAddressLine1Change: (value: string) => void;
29
+ onAddressLine2Change: (value: string) => void;
30
+ onAddressPostalCodeChange: (value: string) => void;
31
+ onCountryChange: (countryId: string) => void;
32
+ onStateChange: (stateId: string) => void;
33
+ onCityChange: (cityId: string) => void;
34
+ onDistrictChange: (districtId: string) => void;
35
+ onDistrictInputChange: (value: string) => void;
36
+ listCountries: () => Promise<void>;
37
+ listStates: () => Promise<void>;
38
+ listCities: () => Promise<void>;
39
+ listDistricts: () => Promise<void>;
40
+ get isEdit(): boolean;
41
+ private get editingAddressIndex();
42
+ get countryOptions(): {
43
+ label: string;
44
+ value: string;
45
+ }[];
46
+ get stateOptions(): {
47
+ label: string;
48
+ value: string;
49
+ }[];
50
+ get cityOptions(): {
51
+ label: string;
52
+ value: string;
53
+ }[];
54
+ get districtOptions(): {
55
+ label: string;
56
+ value: string;
57
+ }[];
58
+ get hasState(): boolean;
59
+ get isCountriesPending(): boolean;
60
+ get isStatesPending(): boolean;
61
+ get isCitiesPending(): boolean;
62
+ get isDistrictsPending(): boolean;
63
+ get hasValidatorError(): boolean;
64
+ get results(): import("../index").ValidationResults;
65
+ validateAll: () => Promise<boolean>;
66
+ submit: () => Promise<{
67
+ isFormError: boolean;
68
+ isAPIError: boolean;
69
+ isSuccess: boolean;
70
+ }>;
71
+ }
72
+ export {};
@@ -0,0 +1,29 @@
1
+ import { IkasBaseStore } from "../../../../store/index";
2
+ declare type ForgotPasswordProps<T> = {
3
+ message: {
4
+ requiredRule: ((model: T) => string) | string;
5
+ emailRule: ((model: T) => string) | string;
6
+ };
7
+ store: IkasBaseStore;
8
+ };
9
+ declare type ForgotPasswordFormModel = {
10
+ email: string;
11
+ };
12
+ export declare class ForgotPasswordForm {
13
+ private model;
14
+ private validator;
15
+ private store;
16
+ constructor(props: ForgotPasswordProps<ForgotPasswordFormModel>);
17
+ get email(): string;
18
+ set email(value: string);
19
+ onEmailChange: (value: string) => void;
20
+ get hasValidatorError(): boolean;
21
+ get emailErrorMessage(): string | undefined;
22
+ get redirect(): string | null | undefined;
23
+ validateAll(): Promise<boolean>;
24
+ submit(): Promise<{
25
+ isFormError: boolean;
26
+ isAPIError: boolean;
27
+ }>;
28
+ }
29
+ export {};
@@ -0,0 +1,35 @@
1
+ import { IkasBaseStore } from "../../../../store/index";
2
+ declare type LoginFormProps<T> = {
3
+ message: {
4
+ requiredRule: ((model: T) => string) | string;
5
+ emailRule: ((model: T) => string) | string;
6
+ minRule: ((model: T) => string) | string;
7
+ };
8
+ store: IkasBaseStore;
9
+ };
10
+ declare type LoginFormModel = {
11
+ email: string;
12
+ password: string;
13
+ };
14
+ export declare class LoginForm {
15
+ private model;
16
+ private validator;
17
+ private store;
18
+ constructor(props: LoginFormProps<LoginFormModel>);
19
+ get hasError(): boolean;
20
+ get email(): string;
21
+ set email(value: string);
22
+ get password(): string;
23
+ set password(value: string);
24
+ get emailErrorMessage(): string | undefined;
25
+ get passwordErrorMessage(): string | undefined;
26
+ get redirect(): string | null | undefined;
27
+ onEmailChange: (value: string) => void;
28
+ onPasswordChange: (value: string) => void;
29
+ validateAll(): Promise<boolean>;
30
+ logIn(): Promise<{
31
+ isFormError: boolean;
32
+ isLoginError: boolean;
33
+ }>;
34
+ }
35
+ export {};
@@ -0,0 +1,36 @@
1
+ import { IkasBaseStore } from "../../../../store/index";
2
+ declare type RecoverPasswordFormProps<T> = {
3
+ message: {
4
+ requiredRule: ((model: T) => string) | string;
5
+ minRule: ((model: T) => string) | string;
6
+ equalsRule: ((model: T) => string) | string;
7
+ };
8
+ store: IkasBaseStore;
9
+ };
10
+ declare type RecoverPasswordFormModel = {
11
+ password: string;
12
+ passwordAgain: string;
13
+ };
14
+ export declare class RecoverPasswordForm {
15
+ private model;
16
+ private validator;
17
+ private store;
18
+ constructor(props: RecoverPasswordFormProps<RecoverPasswordFormModel>);
19
+ resetModel(): void;
20
+ get password(): string;
21
+ set password(value: string);
22
+ get passwordAgain(): string;
23
+ set passwordAgain(value: string);
24
+ get hasError(): boolean;
25
+ get passwordErrorMessage(): string | undefined;
26
+ get passwordAgainErrorMessage(): string | undefined;
27
+ get redirect(): string | null | undefined;
28
+ onPasswordChange: (value: string) => void;
29
+ onPasswordAgainChange: (value: string) => void;
30
+ validateAll(): Promise<boolean>;
31
+ submit(): Promise<{
32
+ isFormError: boolean;
33
+ isAPIError: boolean;
34
+ }>;
35
+ }
36
+ export {};
@@ -0,0 +1,45 @@
1
+ import { IkasBaseStore } from "../../../../store/index";
2
+ declare type RegisterFormProps<T> = {
3
+ message: {
4
+ requiredRule: ((model: T) => string) | string;
5
+ emailRule: ((model: T) => string) | string;
6
+ minRule: ((model: T) => string) | string;
7
+ };
8
+ store: IkasBaseStore;
9
+ };
10
+ declare type RegisterFormModel = {
11
+ firstName: string;
12
+ lastName: string;
13
+ email: string;
14
+ password: string;
15
+ };
16
+ export declare class RegisterForm {
17
+ private model;
18
+ private validator;
19
+ private store;
20
+ constructor(props: RegisterFormProps<RegisterFormModel>);
21
+ get firstName(): string;
22
+ set firstName(value: string);
23
+ get lastName(): string;
24
+ set lastName(value: string);
25
+ get email(): string;
26
+ set email(value: string);
27
+ get password(): string;
28
+ set password(value: string);
29
+ get hasError(): boolean;
30
+ get firstNameErrorMessage(): string | undefined;
31
+ get lastNameErrorMessage(): string | undefined;
32
+ get emailErrorMessage(): string | undefined;
33
+ get passwordErrorMessage(): string | undefined;
34
+ get redirect(): string | null | undefined;
35
+ onFirstNameChange: (value: string) => void;
36
+ onLastNameChange: (value: string) => void;
37
+ onEmailChange: (value: string) => void;
38
+ onPasswordChange: (value: string) => void;
39
+ validateAll(): Promise<boolean>;
40
+ register(): Promise<{
41
+ isFormError: boolean;
42
+ isRegisterError: boolean;
43
+ }>;
44
+ }
45
+ export {};
@@ -0,0 +1,27 @@
1
+ import { ValidatorErrorType, ValidationRule } from "./rules/index";
2
+ export declare type ValidationResults = {
3
+ [fieldKey: string]: ValidationResult;
4
+ };
5
+ export declare type ValidationStatus = "success" | "warning" | "error" | "validating";
6
+ export declare class Validator<T = any> {
7
+ model: T;
8
+ rules: ValidationRule[];
9
+ results: ValidationResults;
10
+ constructor(model: T, rules: ValidationRule[]);
11
+ get hasError(): boolean;
12
+ onValueChange: (validationRule: ValidationRule) => void;
13
+ setRules(rules: ValidationRule[]): void;
14
+ validateAll(): Promise<boolean>;
15
+ validateFieldRules(fieldKey: string): Promise<void>;
16
+ private runRules;
17
+ }
18
+ declare class ValidationResult {
19
+ fieldKey: string;
20
+ status?: ValidationStatus;
21
+ messages: string[];
22
+ errorTypes: ValidatorErrorType[];
23
+ constructor(fieldKey: string, status?: ValidationStatus, messages?: string[], errorTypes?: ValidatorErrorType[]);
24
+ get errorMessage(): string | undefined;
25
+ get errorType(): ValidatorErrorType | undefined;
26
+ }
27
+ export {};
@@ -0,0 +1,87 @@
1
+ export declare enum ValidatorErrorType {
2
+ "REQUIRED_RULE" = "REQUIRED_RULE",
3
+ "EMAIl_RULE" = "EMAIl_RULE",
4
+ "MIN_RULE" = "MIN_RULE"
5
+ }
6
+ declare type ValueGetter<T> = (model: T) => any;
7
+ declare type ValuePath<T> = string | ValueGetter<T>;
8
+ export interface IValidationRuleParams<T = any> {
9
+ model?: T;
10
+ fieldKey: string;
11
+ fieldName?: string;
12
+ message?: ((model: T) => string) | string;
13
+ errorType?: ValidatorErrorType;
14
+ valuePath: ValuePath<T>;
15
+ onValueChange?: (rule: ValidationRule) => void;
16
+ }
17
+ export declare abstract class ValidationRule<T = any> {
18
+ model?: T;
19
+ fieldKey: string;
20
+ fieldName?: string;
21
+ message?: ((model: T) => string) | string;
22
+ errorType?: ValidatorErrorType;
23
+ valuePath: ValuePath<T>;
24
+ onValueChange?: (rule: ValidationRule) => void;
25
+ disposer?: () => void;
26
+ constructor(data: IValidationRuleParams<T>);
27
+ get value(): any;
28
+ protected getValue(valuePath: ValuePath<T>): any;
29
+ abstract run(): Promise<boolean>;
30
+ abstract get errorMessage(): string;
31
+ }
32
+ export interface IMinRuleParams<T> extends IValidationRuleParams<T> {
33
+ minValue: number;
34
+ }
35
+ export declare class MinRule<T> extends ValidationRule<T> {
36
+ minValue: number;
37
+ errorType: ValidatorErrorType;
38
+ constructor(data: IMinRuleParams<T>);
39
+ get errorMessage(): string;
40
+ run(): Promise<boolean>;
41
+ }
42
+ export interface IMaxRuleParams extends IValidationRuleParams {
43
+ maxValue: number;
44
+ }
45
+ export declare class MaxRule<T> extends ValidationRule<T> {
46
+ maxValue: number;
47
+ constructor(data: IMaxRuleParams);
48
+ get errorMessage(): string;
49
+ run(): Promise<boolean>;
50
+ }
51
+ export declare class RequiredRule<T> extends ValidationRule<T> {
52
+ constructor(data: IValidationRuleParams<T>);
53
+ get errorMessage(): string;
54
+ run(): Promise<boolean>;
55
+ }
56
+ interface ILessThanRuleParams<T> extends IValidationRuleParams<T> {
57
+ otherFieldValuePath: ValuePath<T>;
58
+ otherFieldName?: string;
59
+ }
60
+ export declare class LessThanRule<T> extends ValidationRule<T> {
61
+ otherFieldName?: string;
62
+ otherFieldValuePath: ValuePath<T>;
63
+ constructor(data: ILessThanRuleParams<T>);
64
+ get otherValue(): any;
65
+ get errorMessage(): string;
66
+ run(): Promise<boolean>;
67
+ }
68
+ export declare class EmailRule<T> extends ValidationRule<T> {
69
+ errorType: ValidatorErrorType;
70
+ get errorMessage(): string;
71
+ run(): Promise<boolean>;
72
+ }
73
+ export declare class PhoneRule<T> extends ValidationRule<T> {
74
+ get errorMessage(): string;
75
+ run(): Promise<boolean>;
76
+ }
77
+ export interface IEqualsRuleParams<T> extends IValidationRuleParams<T> {
78
+ equalsValuePath: ValuePath<T>;
79
+ }
80
+ export declare class EqualsRule<T> extends ValidationRule<T> {
81
+ equalsValuePath: ValuePath<T>;
82
+ constructor(data: IEqualsRuleParams<T>);
83
+ get equalsValue(): any;
84
+ get errorMessage(): string;
85
+ run(): Promise<boolean>;
86
+ }
87
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ikas/storefront",
3
- "version": "0.0.40",
3
+ "version": "0.0.41",
4
4
  "main": "./build/index.js",
5
5
  "module": "./build/index.es.js",
6
6
  "author": "Umut Ozan Yıldırım",