@ecopex/ecopex-framework 1.0.0 → 1.0.1
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/index.js +6 -0
- package/libraries/fastify.js +126 -0
- package/package.json +6 -2
- package/.env +0 -73
- package/database/migrations/20240000135243_timezones.js +0 -22
- package/database/migrations/20240000135244_countries.js +0 -23
- package/database/migrations/20240000135244_create_admins_table.js +0 -66
- package/database/migrations/20240000135244_currencies.js +0 -21
- package/database/migrations/20240000135244_languages.js +0 -21
- package/database/migrations/20240000135244_taxes.js +0 -10
- package/database/migrations/20240000135245_sites.js +0 -37
- package/database/migrations/20240000135246_payment_methods.js +0 -33
- package/database/migrations/20251016113547_devices.js +0 -37
- package/database/migrations/20251019192600_users.js +0 -62
- package/database/migrations/20251019213551_language_lines.js +0 -35
- package/database/migrations/20251222214131_category_groups.js +0 -18
- package/database/migrations/20251222214619_categories.js +0 -27
- package/database/migrations/20251222214848_brands.js +0 -23
- package/database/migrations/20251222214946_products.js +0 -30
- package/database/migrations/20251222215428_product_images.js +0 -18
- package/database/migrations/20251222215553_options.js +0 -30
- package/database/migrations/20251222215806_variants.js +0 -23
- package/database/migrations/20251222215940_attributes.js +0 -25
- package/database/migrations/20251222220135_discounts.js +0 -15
- package/database/migrations/20251222220253_reviews.js +0 -22
- package/database/migrations/20251222220341_favorites.js +0 -10
- package/database/migrations/20251222220422_search_logs.js +0 -17
- package/database/migrations/20251222220636_orders.js +0 -16
- package/database/migrations/20251222220806_order_items.js +0 -19
- package/database/migrations/20251222221317_order_statuses.js +0 -10
- package/database/migrations/20251222221446_order_payments.js +0 -13
- package/database/migrations/20251222221654_order_addresses.js +0 -23
- package/database/migrations/20251222221807_order_status_logs.js +0 -13
- package/database/seeds/admins.js +0 -37
- package/database/seeds/countries.js +0 -203
- package/database/seeds/currencies.js +0 -165
- package/database/seeds/languages.js +0 -113
- package/database/seeds/timezones.js +0 -149
- package/ecosystem.config.js +0 -26
- package/routes/admin/auto/admins.json +0 -63
- package/routes/admin/auto/devices.json +0 -37
- package/routes/admin/auto/migrations.json +0 -21
- package/routes/admin/auto/users.json +0 -61
- package/routes/admin/middlewares/index.js +0 -87
- package/routes/admin/spec/auth.js +0 -626
- package/routes/admin/spec/users.js +0 -3
- package/routes/auto/handler.js +0 -635
- package/routes/common/auto/countries.json +0 -28
- package/routes/common/auto/currencies.json +0 -26
- package/routes/common/auto/languages.json +0 -26
- package/routes/common/auto/taxes.json +0 -46
- package/routes/common/auto/timezones.json +0 -29
- package/workers/admin.js +0 -124
- package/workers/api.js +0 -106
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"table": "users",
|
|
3
|
-
"primary_key": "user_id",
|
|
4
|
-
"schema": {
|
|
5
|
-
"user_id": { "type": "integer" },
|
|
6
|
-
"username": { "type": "string", "default": "", "search_type": "equal" },
|
|
7
|
-
"email": { "type": "string", "format": "email", "default": null, "search_type": "equal" },
|
|
8
|
-
"type_user": { "type": "string", "enum": ["vip", "new", "risky"], "search_type": "equal" },
|
|
9
|
-
"manager_id": { "type": "integer", "nullable": true, "search_type": "equal" },
|
|
10
|
-
"phone_verified": { "type": "boolean", "default": false, "search_type": "equal" },
|
|
11
|
-
"email_verified": { "type": "boolean", "default": false, "search_type": "equal" },
|
|
12
|
-
"phone_number": { "type": "string", "nullable": true, "search_type": "like" },
|
|
13
|
-
"two_factor_enabled": { "type": "boolean", "default": false, "search_type": "equal" },
|
|
14
|
-
"is_active": { "type": "boolean", "default": true, "search_type": "equal" },
|
|
15
|
-
"login_attempts": { "type": "integer", "default": 0, "nullable": true, "search_type": "equal" },
|
|
16
|
-
"locked_until": { "type": "string", "format": "date-time", "default": null, "nullable": true, "search_type": "like" },
|
|
17
|
-
"created_at": { "type": "string", "format": "date-time", "default": null, "search_type": "like" },
|
|
18
|
-
"updated_at": { "type": "string", "format": "date-time", "default": null, "search_type": "like" },
|
|
19
|
-
"manager": {
|
|
20
|
-
"type": ["object", "null"],
|
|
21
|
-
"properties": {
|
|
22
|
-
"manager_id": { "type": "integer" },
|
|
23
|
-
"username": { "type": "string" },
|
|
24
|
-
"email": { "type": "string", "format": "email", "default": null }
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
"routes": [
|
|
29
|
-
{
|
|
30
|
-
"action": "list",
|
|
31
|
-
"method": "GET",
|
|
32
|
-
"path": "/users",
|
|
33
|
-
"searchable_fields": ["username", "email"],
|
|
34
|
-
"pagination": true,
|
|
35
|
-
"additionalProperties": false,
|
|
36
|
-
"security": "auth"
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
"action": "get",
|
|
40
|
-
"method": "GET",
|
|
41
|
-
"path": "/users/:user_id",
|
|
42
|
-
"searchable_fields": ["username", "email"],
|
|
43
|
-
"security": "auth",
|
|
44
|
-
"additionalProperties": false
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
"action": "create",
|
|
48
|
-
"method": "POST",
|
|
49
|
-
"path": "/users",
|
|
50
|
-
"security": "auth",
|
|
51
|
-
"additionalProperties": false
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
"action": "update",
|
|
55
|
-
"method": "PUT",
|
|
56
|
-
"path": "/users/:user_id",
|
|
57
|
-
"security": "auth",
|
|
58
|
-
"additionalProperties": false
|
|
59
|
-
}
|
|
60
|
-
]
|
|
61
|
-
}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
const JWT = require('@root/libraries/jwt');
|
|
2
|
-
const db = require('@root/libraries/knex');
|
|
3
|
-
const jwt = new JWT();
|
|
4
|
-
|
|
5
|
-
const auth = async (request, reply) => {
|
|
6
|
-
|
|
7
|
-
const { authorization } = request.headers;
|
|
8
|
-
const activePath = request.routeOptions?.url?.replace('/', '').replace(/\//g, '.') || 'unknown';
|
|
9
|
-
|
|
10
|
-
if(!authorization) {
|
|
11
|
-
return reply.status(401).send({
|
|
12
|
-
status: false,
|
|
13
|
-
message: 'Unauthorized',
|
|
14
|
-
code: 401
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const token = authorization.split(' ')[1];
|
|
19
|
-
if(!token) {
|
|
20
|
-
return reply.status(401).send({
|
|
21
|
-
status: false,
|
|
22
|
-
message: 'Unauthorized',
|
|
23
|
-
code: 401
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const decoded = jwt.verify(token);
|
|
28
|
-
|
|
29
|
-
if(!decoded) {
|
|
30
|
-
return reply.status(401).send({
|
|
31
|
-
status: false,
|
|
32
|
-
message: 'Token is invalid',
|
|
33
|
-
code: 401
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
let user = null;
|
|
38
|
-
|
|
39
|
-
if(decoded.type === 'admin') {
|
|
40
|
-
user = await db('admins').where('admin_id', decoded.id).first();
|
|
41
|
-
} else if(decoded.type === 'manager') {
|
|
42
|
-
user = await db('managers').where('manager_id', decoded.id).first();
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if(!user) {
|
|
46
|
-
return reply.status(401).send({
|
|
47
|
-
status: false,
|
|
48
|
-
message: 'Unauthorized',
|
|
49
|
-
code: 401
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
user.id = user.admin_id || user.manager_id;
|
|
54
|
-
user.type = decoded.type;
|
|
55
|
-
|
|
56
|
-
const device = await db('devices').where({ personal_id: user.id, personal_type: user.type, unique_id: decoded.device || '--' }).first();
|
|
57
|
-
|
|
58
|
-
if(!device) {
|
|
59
|
-
return reply.status(401).send({
|
|
60
|
-
status: false,
|
|
61
|
-
message: 'Unauthorized',
|
|
62
|
-
code: 401
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if(user.two_factor_enabled && !device.two_factor_approved && activePath !== 'auth.login-2fa') {
|
|
67
|
-
return reply.status(303).send({
|
|
68
|
-
status: false,
|
|
69
|
-
message: 'Device is not approved',
|
|
70
|
-
details: {
|
|
71
|
-
token: device.token,
|
|
72
|
-
two_factor_approved: device.two_factor_approved
|
|
73
|
-
},
|
|
74
|
-
code: 303
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
delete user.admin_id;
|
|
79
|
-
delete user.manager_id;
|
|
80
|
-
|
|
81
|
-
request.user = user;
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
module.exports = {
|
|
86
|
-
auth
|
|
87
|
-
}
|