feeef 0.0.8 → 0.0.10
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.
- package/build/index.d.ts +1 -0
- package/build/index.js +1 -0
- package/build/src/core/core.d.ts +8 -0
- package/build/src/core/core.js +10 -0
- package/build/src/core/embadded/address.d.ts +13 -0
- package/build/src/core/embadded/address.js +1 -0
- package/build/src/core/embadded/category.d.ts +7 -0
- package/build/src/core/embadded/category.js +1 -0
- package/build/src/core/embadded/contact.d.ts +21 -0
- package/build/src/core/embadded/contact.js +17 -0
- package/build/src/core/entities/order.d.ts +49 -0
- package/build/src/core/entities/order.js +22 -0
- package/build/src/core/entities/product.d.ts +65 -0
- package/build/src/core/entities/product.js +19 -0
- package/build/src/core/entities/shipping_method.d.ts +29 -0
- package/build/src/core/entities/shipping_method.js +11 -0
- package/build/src/core/entities/store.d.ts +71 -0
- package/build/src/core/entities/store.js +15 -0
- package/build/src/core/entities/user.d.ts +23 -0
- package/build/src/core/entities/user.js +1 -0
- package/build/src/core/sdk/fif.d.ts +1 -0
- package/build/src/core/sdk/fif.js +4 -0
- package/build/src/feeef/feeef.d.ts +62 -0
- package/build/src/feeef/feeef.js +65 -0
- package/build/src/feeef/repositories/orders.d.ts +21 -0
- package/build/src/feeef/repositories/orders.js +27 -0
- package/build/src/feeef/repositories/products.d.ts +15 -0
- package/build/src/feeef/repositories/products.js +13 -0
- package/build/src/feeef/repositories/repository.d.ts +112 -0
- package/build/src/feeef/repositories/repository.js +96 -0
- package/build/src/feeef/repositories/stores.d.ts +22 -0
- package/build/src/feeef/repositories/stores.js +25 -0
- package/build/src/feeef/repositories/users.d.ts +51 -0
- package/build/src/feeef/repositories/users.js +65 -0
- package/build/src/feeef/validators/auth.js +46 -0
- package/build/src/feeef/validators/custom/datetime.d.ts +1 -0
- package/build/src/feeef/validators/custom/datetime.js +7 -0
- package/build/src/feeef/validators/helpers.js +65 -0
- package/build/src/feeef/validators/order.js +84 -0
- package/build/src/feeef/validators/product.js +92 -0
- package/build/src/feeef/validators/shipping_method.js +41 -0
- package/build/src/feeef/validators/stores.js +97 -0
- package/build/src/feeef/validators/user_stores.js +74 -0
- package/build/src/feeef/validators/users.js +67 -0
- package/build/vite.config.d.ts +2 -0
- package/build/vite.config.js +5 -0
- package/package.json +1 -1
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { AxiosInstance } from "axios";
|
|
2
|
+
/**
|
|
3
|
+
* Represents a generic model repository.
|
|
4
|
+
* @template T - The type of the model.
|
|
5
|
+
* @template C - The type of the create options.
|
|
6
|
+
* @template U - The type of the update options.
|
|
7
|
+
*/
|
|
8
|
+
export declare abstract class ModelRepository<T, C, U> {
|
|
9
|
+
resource: string;
|
|
10
|
+
client: AxiosInstance;
|
|
11
|
+
/**
|
|
12
|
+
* Constructs a new instance of the ModelRepository class.
|
|
13
|
+
* @param resource - The resource name.
|
|
14
|
+
* @param client - The Axios instance used for making HTTP requests.
|
|
15
|
+
*/
|
|
16
|
+
constructor(resource: string, client: AxiosInstance);
|
|
17
|
+
/**
|
|
18
|
+
* Finds a model by its ID or other criteria.
|
|
19
|
+
* @param options - The options for finding the model.
|
|
20
|
+
* @returns A promise that resolves to the found model.
|
|
21
|
+
*/
|
|
22
|
+
find(options: ModelFindOptions): Promise<T>;
|
|
23
|
+
/**
|
|
24
|
+
* Lists models with optional pagination and filtering.
|
|
25
|
+
* @param options - The options for listing the models.
|
|
26
|
+
* @returns A promise that resolves to a list of models.
|
|
27
|
+
*/
|
|
28
|
+
list(options?: ModelListOptions): Promise<ListResponse<T>>;
|
|
29
|
+
/**
|
|
30
|
+
* Creates a new model.
|
|
31
|
+
* @param options - The options for creating the model.
|
|
32
|
+
* @returns A promise that resolves to the created model.
|
|
33
|
+
*/
|
|
34
|
+
create(options: ModelCreateOptions<C>): Promise<T>;
|
|
35
|
+
/**
|
|
36
|
+
* Updates an existing model.
|
|
37
|
+
* @param options - The options for updating the model.
|
|
38
|
+
* @returns A promise that resolves to the updated model.
|
|
39
|
+
*/
|
|
40
|
+
update(options: ModelUpdateOptions<U>): Promise<T>;
|
|
41
|
+
/**
|
|
42
|
+
* Deletes a model by its ID or other criteria.
|
|
43
|
+
* @param options - The options for deleting the model.
|
|
44
|
+
* @returns A promise that resolves when the model is deleted.
|
|
45
|
+
*/
|
|
46
|
+
delete(options: ModelFindOptions): Promise<void>;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Represents a list response containing an array of data of type T.
|
|
50
|
+
*/
|
|
51
|
+
export interface ListResponse<T> {
|
|
52
|
+
data: T[];
|
|
53
|
+
total?: number;
|
|
54
|
+
page?: number;
|
|
55
|
+
limit?: number;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Represents the options for making a request.
|
|
59
|
+
*/
|
|
60
|
+
interface RequestOptions {
|
|
61
|
+
params?: Record<string, any>;
|
|
62
|
+
}
|
|
63
|
+
export interface ModelFindOptions extends RequestOptions {
|
|
64
|
+
/**
|
|
65
|
+
* The ID of the model to find or the value to find by.
|
|
66
|
+
*/
|
|
67
|
+
id: string;
|
|
68
|
+
/**
|
|
69
|
+
* The field to find by.
|
|
70
|
+
* @default "id" - The ID field.
|
|
71
|
+
*/
|
|
72
|
+
by?: string;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Options for listing models.
|
|
76
|
+
*/
|
|
77
|
+
export interface ModelListOptions extends RequestOptions {
|
|
78
|
+
/**
|
|
79
|
+
* The page number to retrieve.
|
|
80
|
+
*/
|
|
81
|
+
page?: number;
|
|
82
|
+
/**
|
|
83
|
+
* The offset from the beginning of the list.
|
|
84
|
+
*/
|
|
85
|
+
offset?: number;
|
|
86
|
+
/**
|
|
87
|
+
* The maximum number of models to retrieve per page.
|
|
88
|
+
*/
|
|
89
|
+
limit?: number;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Represents the options for creating a model.
|
|
93
|
+
* @template T - The type of data being created.
|
|
94
|
+
*/
|
|
95
|
+
export interface ModelCreateOptions<T> extends RequestOptions {
|
|
96
|
+
data: T;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Represents the options for updating a model.
|
|
100
|
+
* @template T - The type of the data being updated.
|
|
101
|
+
*/
|
|
102
|
+
export interface ModelUpdateOptions<T> extends RequestOptions {
|
|
103
|
+
/**
|
|
104
|
+
* The ID of the model to update.
|
|
105
|
+
*/
|
|
106
|
+
id: string;
|
|
107
|
+
/**
|
|
108
|
+
* The data to update the model with.
|
|
109
|
+
*/
|
|
110
|
+
data: T;
|
|
111
|
+
}
|
|
112
|
+
export {};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a generic model repository.
|
|
3
|
+
* @template T - The type of the model.
|
|
4
|
+
* @template C - The type of the create options.
|
|
5
|
+
* @template U - The type of the update options.
|
|
6
|
+
*/
|
|
7
|
+
export class ModelRepository {
|
|
8
|
+
resource;
|
|
9
|
+
// client
|
|
10
|
+
client;
|
|
11
|
+
/**
|
|
12
|
+
* Constructs a new instance of the ModelRepository class.
|
|
13
|
+
* @param resource - The resource name.
|
|
14
|
+
* @param client - The Axios instance used for making HTTP requests.
|
|
15
|
+
*/
|
|
16
|
+
constructor(resource, client) {
|
|
17
|
+
this.resource = resource;
|
|
18
|
+
this.client = client;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Finds a model by its ID or other criteria.
|
|
22
|
+
* @param options - The options for finding the model.
|
|
23
|
+
* @returns A promise that resolves to the found model.
|
|
24
|
+
*/
|
|
25
|
+
async find(options) {
|
|
26
|
+
const { id, by, params } = options;
|
|
27
|
+
const res = await this.client.get(`/${this.resource}/${id}`, {
|
|
28
|
+
params: {
|
|
29
|
+
by: by || "id",
|
|
30
|
+
...params,
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
return res.data;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Lists models with optional pagination and filtering.
|
|
37
|
+
* @param options - The options for listing the models.
|
|
38
|
+
* @returns A promise that resolves to a list of models.
|
|
39
|
+
*/
|
|
40
|
+
async list(options) {
|
|
41
|
+
const { page, offset, limit, params } = options || {};
|
|
42
|
+
const res = await this.client.get(`/${this.resource}`, {
|
|
43
|
+
params: { page, offset, limit, ...params },
|
|
44
|
+
});
|
|
45
|
+
// if res.data is an array then create ListResponse
|
|
46
|
+
if (Array.isArray(res.data)) {
|
|
47
|
+
return {
|
|
48
|
+
data: res.data,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
return {
|
|
53
|
+
data: res.data.data,
|
|
54
|
+
total: res.data.meta.total,
|
|
55
|
+
page: res.data.meta.currentPage,
|
|
56
|
+
limit: res.data.meta.perPage,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Creates a new model.
|
|
62
|
+
* @param options - The options for creating the model.
|
|
63
|
+
* @returns A promise that resolves to the created model.
|
|
64
|
+
*/
|
|
65
|
+
async create(options) {
|
|
66
|
+
const { data, params } = options;
|
|
67
|
+
const res = await this.client.post(`/${this.resource}`, data, { params });
|
|
68
|
+
return res.data;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Updates an existing model.
|
|
72
|
+
* @param options - The options for updating the model.
|
|
73
|
+
* @returns A promise that resolves to the updated model.
|
|
74
|
+
*/
|
|
75
|
+
async update(options) {
|
|
76
|
+
const { id, data, params } = options;
|
|
77
|
+
const res = await this.client.put(`/${this.resource}/${id}`, data, {
|
|
78
|
+
params,
|
|
79
|
+
});
|
|
80
|
+
return res.data;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Deletes a model by its ID or other criteria.
|
|
84
|
+
* @param options - The options for deleting the model.
|
|
85
|
+
* @returns A promise that resolves when the model is deleted.
|
|
86
|
+
*/
|
|
87
|
+
async delete(options) {
|
|
88
|
+
const { id, by, params } = options;
|
|
89
|
+
await this.client.delete(`/${this.resource}/${id}`, {
|
|
90
|
+
params: {
|
|
91
|
+
by: by || "id",
|
|
92
|
+
...params,
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { InferInput } from "@vinejs/vine/types";
|
|
2
|
+
import { AxiosInstance } from "axios";
|
|
3
|
+
import { StoreEntity } from "../../core/core";
|
|
4
|
+
import { CreateStoreSchema } from "../validators/stores";
|
|
5
|
+
import { CreateUserStoreSchema, UpdateUserStoreSchema } from "../validators/user_stores";
|
|
6
|
+
import { ModelRepository, ModelCreateOptions } from "./repository";
|
|
7
|
+
/**
|
|
8
|
+
* Repository for managing Store entities.
|
|
9
|
+
*/
|
|
10
|
+
export declare class StoreRepository extends ModelRepository<StoreEntity, InferInput<typeof CreateUserStoreSchema>, InferInput<typeof UpdateUserStoreSchema>> {
|
|
11
|
+
/**
|
|
12
|
+
* Constructs a new StoreRepository instance.
|
|
13
|
+
* @param client The AxiosInstance used for making HTTP requests.
|
|
14
|
+
*/
|
|
15
|
+
constructor(client: AxiosInstance);
|
|
16
|
+
/**
|
|
17
|
+
* Creates a new Store entity.
|
|
18
|
+
* @param options The options for creating the Store entity.
|
|
19
|
+
* @returns A Promise that resolves to the created Store entity.
|
|
20
|
+
*/
|
|
21
|
+
create(options: ModelCreateOptions<InferInput<typeof CreateStoreSchema>>): Promise<StoreEntity>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import vine from "@vinejs/vine";
|
|
2
|
+
import { CreateStoreSchema } from "../validators/stores";
|
|
3
|
+
import { ModelRepository } from "./repository";
|
|
4
|
+
/**
|
|
5
|
+
* Repository for managing Store entities.
|
|
6
|
+
*/
|
|
7
|
+
export class StoreRepository extends ModelRepository {
|
|
8
|
+
/**
|
|
9
|
+
* Constructs a new StoreRepository instance.
|
|
10
|
+
* @param client The AxiosInstance used for making HTTP requests.
|
|
11
|
+
*/
|
|
12
|
+
constructor(client) {
|
|
13
|
+
super("stores", client);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Creates a new Store entity.
|
|
17
|
+
* @param options The options for creating the Store entity.
|
|
18
|
+
* @returns A Promise that resolves to the created Store entity.
|
|
19
|
+
*/
|
|
20
|
+
async create(options) {
|
|
21
|
+
const validator = vine.compile(CreateStoreSchema);
|
|
22
|
+
const output = await validator.validate(options.data);
|
|
23
|
+
return super.create({ ...options, data: output });
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { InferInput } from "@vinejs/vine/types";
|
|
2
|
+
import { AxiosInstance } from "axios";
|
|
3
|
+
import { AuthToken, UserEntity } from "../../core/core";
|
|
4
|
+
import { SigninSchema, AuthUpdateUserSchema } from "../validators/auth";
|
|
5
|
+
import { CreateUserSchema, UpdateUserSchema } from "../validators/users";
|
|
6
|
+
import { ModelRepository } from "./repository";
|
|
7
|
+
/**
|
|
8
|
+
* Represents the response returned by the authentication process.
|
|
9
|
+
*/
|
|
10
|
+
export interface AuthResponse {
|
|
11
|
+
token: AuthToken;
|
|
12
|
+
user: UserEntity;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Represents a repository for managing user data.
|
|
16
|
+
* Extends the ModelRepository class.
|
|
17
|
+
*/
|
|
18
|
+
export declare class UserRepository extends ModelRepository<UserEntity, InferInput<typeof CreateUserSchema>, InferInput<typeof UpdateUserSchema>> {
|
|
19
|
+
/**
|
|
20
|
+
* Represents the authentication response.
|
|
21
|
+
*/
|
|
22
|
+
auth: AuthResponse | null;
|
|
23
|
+
/**
|
|
24
|
+
* Constructs a new UserRepository instance.
|
|
25
|
+
* @param client - The AxiosInstance used for making HTTP requests.
|
|
26
|
+
*/
|
|
27
|
+
constructor(client: AxiosInstance);
|
|
28
|
+
/**
|
|
29
|
+
* Signs in a user with the provided credentials.
|
|
30
|
+
* @param credentials - The user credentials.
|
|
31
|
+
* @returns A promise that resolves to the authentication response.
|
|
32
|
+
*/
|
|
33
|
+
signin(credentials: InferInput<typeof SigninSchema>): Promise<AuthResponse>;
|
|
34
|
+
/**
|
|
35
|
+
* Signs up a new user with the provided credentials.
|
|
36
|
+
* @param credentials - The user credentials.
|
|
37
|
+
* @returns A promise that resolves to the authentication response.
|
|
38
|
+
*/
|
|
39
|
+
signup(credentials: InferInput<typeof CreateUserSchema>): Promise<AuthResponse>;
|
|
40
|
+
/**
|
|
41
|
+
* Signs out the currently authenticated user.
|
|
42
|
+
* @returns A promise that resolves when the user is signed out.
|
|
43
|
+
*/
|
|
44
|
+
signout(): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Updates the authenticated user's data.
|
|
47
|
+
* @param data - The updated user data.
|
|
48
|
+
* @returns A promise that resolves to the updated user entity.
|
|
49
|
+
*/
|
|
50
|
+
updateMe(data: InferInput<typeof AuthUpdateUserSchema>): Promise<UserEntity>;
|
|
51
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import vine from "@vinejs/vine";
|
|
2
|
+
import { SigninSchema, AuthUpdateUserSchema } from "../validators/auth";
|
|
3
|
+
import { CreateUserSchema } from "../validators/users";
|
|
4
|
+
import { ModelRepository } from "./repository";
|
|
5
|
+
/**
|
|
6
|
+
* Represents a repository for managing user data.
|
|
7
|
+
* Extends the ModelRepository class.
|
|
8
|
+
*/
|
|
9
|
+
export class UserRepository extends ModelRepository {
|
|
10
|
+
/**
|
|
11
|
+
* Represents the authentication response.
|
|
12
|
+
*/
|
|
13
|
+
auth = null;
|
|
14
|
+
/**
|
|
15
|
+
* Constructs a new UserRepository instance.
|
|
16
|
+
* @param client - The AxiosInstance used for making HTTP requests.
|
|
17
|
+
*/
|
|
18
|
+
constructor(client) {
|
|
19
|
+
super("users", client);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Signs in a user with the provided credentials.
|
|
23
|
+
* @param credentials - The user credentials.
|
|
24
|
+
* @returns A promise that resolves to the authentication response.
|
|
25
|
+
*/
|
|
26
|
+
async signin(credentials) {
|
|
27
|
+
// validate the input
|
|
28
|
+
const validator = vine.compile(SigninSchema);
|
|
29
|
+
const output = await validator.validate(credentials);
|
|
30
|
+
const res = await this.client.post(`/${this.resource}/auth/signin`, output);
|
|
31
|
+
this.auth = res.data;
|
|
32
|
+
return res.data;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Signs up a new user with the provided credentials.
|
|
36
|
+
* @param credentials - The user credentials.
|
|
37
|
+
* @returns A promise that resolves to the authentication response.
|
|
38
|
+
*/
|
|
39
|
+
async signup(credentials) {
|
|
40
|
+
// validate the input
|
|
41
|
+
const validator = vine.compile(CreateUserSchema);
|
|
42
|
+
const output = await validator.validate(credentials);
|
|
43
|
+
const res = await this.client.post(`/${this.resource}/auth/signup`, output);
|
|
44
|
+
this.auth = res.data;
|
|
45
|
+
return res.data;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Signs out the currently authenticated user.
|
|
49
|
+
* @returns A promise that resolves when the user is signed out.
|
|
50
|
+
*/
|
|
51
|
+
async signout() {
|
|
52
|
+
this.auth = null;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Updates the authenticated user's data.
|
|
56
|
+
* @param data - The updated user data.
|
|
57
|
+
* @returns A promise that resolves to the updated user entity.
|
|
58
|
+
*/
|
|
59
|
+
async updateMe(data) {
|
|
60
|
+
const validator = vine.compile(AuthUpdateUserSchema);
|
|
61
|
+
const output = await validator.validate(data);
|
|
62
|
+
const res = await this.client.put(`/${this.resource}/auth`, output);
|
|
63
|
+
return res.data;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import vine from '@vinejs/vine';
|
|
2
|
+
import { ImageFileSchema } from './helpers.js';
|
|
3
|
+
export const PhoneShema = vine.string().regex(/^0(5|6|7)\d{8}$|^0(2)\d{7}$/);
|
|
4
|
+
export const SignupSchema = vine.object({
|
|
5
|
+
name: vine.string().minLength(2).maxLength(32),
|
|
6
|
+
email: vine.string()
|
|
7
|
+
// .unique(async (db, value, field) => {
|
|
8
|
+
// const user = await db.from('users').where('email', value).first()
|
|
9
|
+
// return !user
|
|
10
|
+
// })
|
|
11
|
+
,
|
|
12
|
+
phone: PhoneShema
|
|
13
|
+
// .unique(async (db, value, field) => {
|
|
14
|
+
// const user = await db.from('users').where('phone', value).first()
|
|
15
|
+
// return !user
|
|
16
|
+
// })
|
|
17
|
+
.optional(),
|
|
18
|
+
photoFile: ImageFileSchema.optional(),
|
|
19
|
+
photoUrl: vine.string().optional(),
|
|
20
|
+
password: vine.string().minLength(8).maxLength(32),
|
|
21
|
+
});
|
|
22
|
+
export const SigninSchema = vine.object({
|
|
23
|
+
email: vine.string().email(),
|
|
24
|
+
password: vine.string().minLength(8).maxLength(32),
|
|
25
|
+
});
|
|
26
|
+
export const AuthUpdateUserSchema = vine.object({
|
|
27
|
+
name: vine.string().minLength(2).maxLength(32).optional(),
|
|
28
|
+
email: vine
|
|
29
|
+
.string()
|
|
30
|
+
// .unique(async (db, value, field) => {
|
|
31
|
+
// const user = await db.from('users').where('email', value).first()
|
|
32
|
+
// return !user
|
|
33
|
+
// })
|
|
34
|
+
.optional(),
|
|
35
|
+
phone: PhoneShema.optional(),
|
|
36
|
+
// for upload file
|
|
37
|
+
photoFile: vine
|
|
38
|
+
// .file({
|
|
39
|
+
// size: '1mb',
|
|
40
|
+
// extnames: ['jpg', 'jpeg', 'png', 'gif', 'webp'],
|
|
41
|
+
// })
|
|
42
|
+
.any(),
|
|
43
|
+
photoUrl: vine.string().optional(),
|
|
44
|
+
oldPassword: vine.string().minLength(8).maxLength(32).optional(),
|
|
45
|
+
newPassword: vine.string().minLength(8).maxLength(32).notSameAs('oldPassword').optional(),
|
|
46
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// import { FieldContext } from '@vinejs/compiler/types'
|
|
2
|
+
// import vine from '@vinejs/vine'
|
|
3
|
+
export {};
|
|
4
|
+
// type Options = {}
|
|
5
|
+
// // custom rule (datetime ISO 8601)
|
|
6
|
+
// async function datetime(value: unknown, options: Options, field: FieldContext) {}
|
|
7
|
+
// export const datetimeRule = vine.createRule(datetime)
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import vine from "@vinejs/vine";
|
|
2
|
+
export const AvatarFileSchema = vine.any();
|
|
3
|
+
// .file({
|
|
4
|
+
// size: '1mb',
|
|
5
|
+
// extnames: ['jpg', 'jpeg', 'png', 'gif', 'webp'],
|
|
6
|
+
// })
|
|
7
|
+
export const ImageFileSchema = vine.any();
|
|
8
|
+
// .file({
|
|
9
|
+
// size: '1mb',
|
|
10
|
+
// extnames: ['jpg', 'jpeg', 'png', 'gif', 'webp'],
|
|
11
|
+
// })
|
|
12
|
+
export const DomainSchema = vine.object({
|
|
13
|
+
name: vine.string().minLength(3).maxLength(32),
|
|
14
|
+
verifiedAt: vine.date().optional(),
|
|
15
|
+
metadata: vine.object({}).optional(),
|
|
16
|
+
});
|
|
17
|
+
// decoration
|
|
18
|
+
export const StoreDecorationSchema = vine.object({
|
|
19
|
+
primary: vine.number().min(0x0).max(0xffffffff),
|
|
20
|
+
onPrimary: vine.number().min(0x0).max(0xffffffff),
|
|
21
|
+
showStoreLogoInHeader: vine.boolean().optional(),
|
|
22
|
+
logoFullHeight: vine.boolean().optional(),
|
|
23
|
+
showStoreNameInHeader: vine.boolean().optional(),
|
|
24
|
+
metadata: vine.any().optional(),
|
|
25
|
+
});
|
|
26
|
+
// export const EmbaddedImageSchema = vine.object({
|
|
27
|
+
// url: vine.string().url(),
|
|
28
|
+
// alt: vine.string().optional(),
|
|
29
|
+
// width: vine.number().optional(),
|
|
30
|
+
// height: vine.number().optional(),
|
|
31
|
+
// })
|
|
32
|
+
export const EmbaddedCategorySchema = vine.object({
|
|
33
|
+
name: vine.string().minLength(2).maxLength(32),
|
|
34
|
+
description: vine.string().minLength(2).maxLength(255).optional(),
|
|
35
|
+
photoUrl: vine.string().optional(),
|
|
36
|
+
ondarkPhotoUrl: vine.string().optional(),
|
|
37
|
+
photoFile: AvatarFileSchema.optional(),
|
|
38
|
+
ondarkPhotoFile: AvatarFileSchema.optional(),
|
|
39
|
+
metadata: vine.object({}).optional(),
|
|
40
|
+
});
|
|
41
|
+
export const EmbaddedAddressSchema = vine.object({
|
|
42
|
+
country: vine.string().minLength(2).maxLength(32).optional(),
|
|
43
|
+
state: vine.string().minLength(2).maxLength(32).optional(),
|
|
44
|
+
city: vine.string().minLength(2).maxLength(32).optional(),
|
|
45
|
+
street: vine.string().minLength(2).maxLength(32).optional(),
|
|
46
|
+
zip: vine.string().minLength(2).maxLength(32).optional(),
|
|
47
|
+
metadata: vine.object({}).optional().optional(),
|
|
48
|
+
});
|
|
49
|
+
export const EmbaddedContactSchema = vine.object({
|
|
50
|
+
type: vine.string().minLength(2).maxLength(32),
|
|
51
|
+
value: vine.string().minLength(2).maxLength(255),
|
|
52
|
+
metadata: vine.object({}).optional(),
|
|
53
|
+
});
|
|
54
|
+
export const ContactSchema = vine.object({
|
|
55
|
+
type: vine.string().minLength(2).maxLength(32),
|
|
56
|
+
value: vine.string().minLength(2).maxLength(255),
|
|
57
|
+
metadata: vine.object({}).optional(),
|
|
58
|
+
});
|
|
59
|
+
// StoreBunner
|
|
60
|
+
export const StoreBunner = vine.object({
|
|
61
|
+
url: vine.string().url().optional(),
|
|
62
|
+
title: vine.string(),
|
|
63
|
+
enabled: vine.boolean().optional(),
|
|
64
|
+
metadata: vine.object({}).optional(),
|
|
65
|
+
});
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// import { OrderStatus } from '#core/core'
|
|
2
|
+
import vine from "@vinejs/vine";
|
|
3
|
+
import { PhoneShema } from "./auth.js";
|
|
4
|
+
import { OrderStatus } from "../../core/core.js";
|
|
5
|
+
export const OrderItemSchema = vine.object({
|
|
6
|
+
productId: vine.string(),
|
|
7
|
+
// productId: vine.string().exists(async (db, value, field) => {
|
|
8
|
+
// const product = await db.from('products').where('id', value).first()
|
|
9
|
+
// return !!product
|
|
10
|
+
// }),
|
|
11
|
+
productName: vine.string().optional(),
|
|
12
|
+
variant: vine.any().optional(),
|
|
13
|
+
quantity: vine.number(),
|
|
14
|
+
price: vine.number().optional(),
|
|
15
|
+
});
|
|
16
|
+
export const GuestOrderItemSchema = vine.object({
|
|
17
|
+
productId: vine.string(),
|
|
18
|
+
variantPath: vine.string().optional(),
|
|
19
|
+
quantity: vine.number(),
|
|
20
|
+
});
|
|
21
|
+
export const SendOrderSchema = vine.object({
|
|
22
|
+
id: vine.string().optional(),
|
|
23
|
+
customerName: vine.string().optional(),
|
|
24
|
+
customerPhone: vine.string(),
|
|
25
|
+
// customerIp: vine.string().optional(),
|
|
26
|
+
shippingAddress: vine.string().optional(),
|
|
27
|
+
shippingCity: vine.string().optional(),
|
|
28
|
+
shippingState: vine.string().optional(),
|
|
29
|
+
shippingMethodId: vine.string().optional(),
|
|
30
|
+
paymentMethodId: vine.string().optional(),
|
|
31
|
+
items: vine.array(GuestOrderItemSchema).minLength(1),
|
|
32
|
+
// subtotal: vine.number().optional(),
|
|
33
|
+
// shippingPrice: vine.number().optional(),
|
|
34
|
+
// total: vine.number().optional(),
|
|
35
|
+
// discount: vine.number().optional(),
|
|
36
|
+
coupon: vine.string().optional(),
|
|
37
|
+
status: vine.enum(["pending", "draft"]),
|
|
38
|
+
// TODO: validate storeId is exists and not blocked
|
|
39
|
+
storeId: vine.string(),
|
|
40
|
+
metadata: vine.any().optional(),
|
|
41
|
+
});
|
|
42
|
+
/// store owner section
|
|
43
|
+
// CreateOrderSchema
|
|
44
|
+
export const CreateOrderSchema = vine.object({
|
|
45
|
+
id: vine.string().optional(),
|
|
46
|
+
customerName: vine.string().optional(),
|
|
47
|
+
customerPhone: PhoneShema,
|
|
48
|
+
customerIp: vine.string().optional(),
|
|
49
|
+
shippingAddress: vine.string().optional(),
|
|
50
|
+
shippingCity: vine.string().optional(),
|
|
51
|
+
shippingState: vine.string().optional(),
|
|
52
|
+
shippingMethodId: vine.string().optional(),
|
|
53
|
+
paymentMethodId: vine.string().optional(),
|
|
54
|
+
items: vine.array(OrderItemSchema).minLength(1),
|
|
55
|
+
subtotal: vine.number().optional(),
|
|
56
|
+
shippingPrice: vine.number().optional(),
|
|
57
|
+
total: vine.number().optional(),
|
|
58
|
+
discount: vine.number().optional(),
|
|
59
|
+
coupon: vine.string().optional(),
|
|
60
|
+
status: vine.enum(OrderStatus),
|
|
61
|
+
storeId: vine.string(),
|
|
62
|
+
metadata: vine.any().optional(),
|
|
63
|
+
});
|
|
64
|
+
// UpdateOrderSchema
|
|
65
|
+
export const UpdateOrderSchema = vine.object({
|
|
66
|
+
id: vine.string().optional(),
|
|
67
|
+
customerName: vine.string().optional(),
|
|
68
|
+
customerPhone: PhoneShema.optional(),
|
|
69
|
+
customerIp: vine.string().optional(),
|
|
70
|
+
shippingAddress: vine.string().optional(),
|
|
71
|
+
shippingCity: vine.string().optional(),
|
|
72
|
+
shippingState: vine.string().optional(),
|
|
73
|
+
shippingMethodId: vine.string().optional(),
|
|
74
|
+
paymentMethodId: vine.string().optional(),
|
|
75
|
+
items: vine.array(OrderItemSchema).minLength(1).optional(),
|
|
76
|
+
subtotal: vine.number().optional(),
|
|
77
|
+
shippingPrice: vine.number().optional(),
|
|
78
|
+
total: vine.number().optional(),
|
|
79
|
+
discount: vine.number().optional(),
|
|
80
|
+
coupon: vine.string().optional(),
|
|
81
|
+
status: vine.enum(OrderStatus).optional(),
|
|
82
|
+
storeId: vine.string(),
|
|
83
|
+
metadata: vine.any().optional(),
|
|
84
|
+
});
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// import { ProductStatus } from '#models/product'
|
|
2
|
+
import vine from "@vinejs/vine";
|
|
3
|
+
import { EmbaddedCategorySchema, ImageFileSchema } from "./helpers.js";
|
|
4
|
+
import { ProductStatus } from "../../core/core.js";
|
|
5
|
+
// import Store from '#models/store'
|
|
6
|
+
export const ProductVariantOptionSchema = vine.object({
|
|
7
|
+
name: vine.string().minLength(1).maxLength(32),
|
|
8
|
+
sku: vine.string().optional(),
|
|
9
|
+
price: vine.number().min(0).max(1000000).optional().nullable(),
|
|
10
|
+
discount: vine.number().min(0).max(1000000).optional().nullable(),
|
|
11
|
+
stock: vine.number().min(0).max(1000000).optional().nullable(),
|
|
12
|
+
sold: vine.number().min(0).max(1000000).optional().nullable(),
|
|
13
|
+
child: vine.any().optional().nullable(),
|
|
14
|
+
});
|
|
15
|
+
export const ProductVariantSchema = vine
|
|
16
|
+
.object({
|
|
17
|
+
name: vine.string().minLength(1).maxLength(32),
|
|
18
|
+
options: vine.array(ProductVariantOptionSchema),
|
|
19
|
+
})
|
|
20
|
+
.optional();
|
|
21
|
+
export const CreateProductSchema = vine.object({
|
|
22
|
+
slug: vine
|
|
23
|
+
.string()
|
|
24
|
+
.regex(/^[a-z0-9-]+$/)
|
|
25
|
+
.minLength(2)
|
|
26
|
+
.maxLength(32),
|
|
27
|
+
// .unique(async (db, value, field) => {
|
|
28
|
+
// const product = await db.from('products').where('slug', value).first()
|
|
29
|
+
// return !product
|
|
30
|
+
// }),
|
|
31
|
+
sku: vine.string().optional(),
|
|
32
|
+
decoration: vine.object({}).optional(),
|
|
33
|
+
name: vine.string().minLength(2).maxLength(32),
|
|
34
|
+
photoUrl: vine.string().optional(),
|
|
35
|
+
photoFile: ImageFileSchema.optional(),
|
|
36
|
+
media: vine.array(vine.string()).optional(),
|
|
37
|
+
mediaFiles: vine.array(ImageFileSchema).optional(),
|
|
38
|
+
// storeId must exist in the database
|
|
39
|
+
storeId: vine.string(),
|
|
40
|
+
// .exists(async (db, value, field) => {
|
|
41
|
+
// return !!field.meta.store && (field.meta.store as Store).userId === field.meta.userId
|
|
42
|
+
// }),
|
|
43
|
+
category: EmbaddedCategorySchema.optional(),
|
|
44
|
+
title: vine.string().minLength(2).maxLength(255),
|
|
45
|
+
description: vine.string().minLength(2).maxLength(255).optional(),
|
|
46
|
+
body: vine.string().minLength(2).maxLength(1000).optional(),
|
|
47
|
+
price: vine.number().min(0).max(1000000),
|
|
48
|
+
discount: vine.number().min(0).max(1000000).optional(),
|
|
49
|
+
stock: vine.number().min(0).max(1000000).optional(),
|
|
50
|
+
variant: ProductVariantSchema,
|
|
51
|
+
metadata: vine.object({}).optional(),
|
|
52
|
+
status: vine.enum(ProductStatus),
|
|
53
|
+
verifiedAt: vine.date().optional(),
|
|
54
|
+
blockedAt: vine.date().optional(),
|
|
55
|
+
});
|
|
56
|
+
export const UpdateProductSchema = vine.object({
|
|
57
|
+
slug: vine
|
|
58
|
+
.string()
|
|
59
|
+
.regex(/^[a-z0-9-]+$/)
|
|
60
|
+
.minLength(2)
|
|
61
|
+
.maxLength(32)
|
|
62
|
+
// .unique(async (db, value, field) => {
|
|
63
|
+
// const product = await db.from('products').where('slug', value).first()
|
|
64
|
+
// return !product
|
|
65
|
+
// })
|
|
66
|
+
.optional(),
|
|
67
|
+
sku: vine.string().optional(),
|
|
68
|
+
decoration: vine.object({}).optional(),
|
|
69
|
+
name: vine.string().minLength(2).maxLength(32).optional(),
|
|
70
|
+
photoUrl: vine.string().optional(),
|
|
71
|
+
photoFile: ImageFileSchema.optional(),
|
|
72
|
+
media: vine.array(vine.string()).optional(),
|
|
73
|
+
mediaFiles: vine.array(ImageFileSchema).optional(),
|
|
74
|
+
// storeId must exist in the database
|
|
75
|
+
storeId: vine.string(),
|
|
76
|
+
// .exists(async (db, value, field) => {
|
|
77
|
+
// return !!field.meta.store && (field.meta.store as Store).userId === field.meta.userId
|
|
78
|
+
// })
|
|
79
|
+
// .optional(),
|
|
80
|
+
category: EmbaddedCategorySchema.optional(),
|
|
81
|
+
title: vine.string().minLength(2).maxLength(255).optional(),
|
|
82
|
+
description: vine.string().minLength(2).maxLength(255).optional(),
|
|
83
|
+
body: vine.string().minLength(2).maxLength(1000).optional(),
|
|
84
|
+
price: vine.number().min(0).max(1000000).optional(),
|
|
85
|
+
discount: vine.number().min(0).max(1000000).optional(),
|
|
86
|
+
stock: vine.number().min(0).max(1000000).optional(),
|
|
87
|
+
variant: ProductVariantSchema,
|
|
88
|
+
metadata: vine.object({}).optional(),
|
|
89
|
+
status: vine.enum(ProductStatus).optional(),
|
|
90
|
+
verifiedAt: vine.date().optional(),
|
|
91
|
+
blockedAt: vine.date().optional(),
|
|
92
|
+
});
|