@ecopex/ecopex-framework 1.0.0 → 1.0.2

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 (60) hide show
  1. package/index.js +5 -0
  2. package/libraries/fastify.js +120 -0
  3. package/libraries/knex.js +1 -1
  4. package/package.json +6 -2
  5. package/stores/base.js +1 -1
  6. package/utils/jsonRouteLoader.js +3 -3
  7. package/utils/middleware.js +1 -1
  8. package/utils/routeLoader.js +1 -1
  9. package/.env +0 -73
  10. package/database/migrations/20240000135243_timezones.js +0 -22
  11. package/database/migrations/20240000135244_countries.js +0 -23
  12. package/database/migrations/20240000135244_create_admins_table.js +0 -66
  13. package/database/migrations/20240000135244_currencies.js +0 -21
  14. package/database/migrations/20240000135244_languages.js +0 -21
  15. package/database/migrations/20240000135244_taxes.js +0 -10
  16. package/database/migrations/20240000135245_sites.js +0 -37
  17. package/database/migrations/20240000135246_payment_methods.js +0 -33
  18. package/database/migrations/20251016113547_devices.js +0 -37
  19. package/database/migrations/20251019192600_users.js +0 -62
  20. package/database/migrations/20251019213551_language_lines.js +0 -35
  21. package/database/migrations/20251222214131_category_groups.js +0 -18
  22. package/database/migrations/20251222214619_categories.js +0 -27
  23. package/database/migrations/20251222214848_brands.js +0 -23
  24. package/database/migrations/20251222214946_products.js +0 -30
  25. package/database/migrations/20251222215428_product_images.js +0 -18
  26. package/database/migrations/20251222215553_options.js +0 -30
  27. package/database/migrations/20251222215806_variants.js +0 -23
  28. package/database/migrations/20251222215940_attributes.js +0 -25
  29. package/database/migrations/20251222220135_discounts.js +0 -15
  30. package/database/migrations/20251222220253_reviews.js +0 -22
  31. package/database/migrations/20251222220341_favorites.js +0 -10
  32. package/database/migrations/20251222220422_search_logs.js +0 -17
  33. package/database/migrations/20251222220636_orders.js +0 -16
  34. package/database/migrations/20251222220806_order_items.js +0 -19
  35. package/database/migrations/20251222221317_order_statuses.js +0 -10
  36. package/database/migrations/20251222221446_order_payments.js +0 -13
  37. package/database/migrations/20251222221654_order_addresses.js +0 -23
  38. package/database/migrations/20251222221807_order_status_logs.js +0 -13
  39. package/database/seeds/admins.js +0 -37
  40. package/database/seeds/countries.js +0 -203
  41. package/database/seeds/currencies.js +0 -165
  42. package/database/seeds/languages.js +0 -113
  43. package/database/seeds/timezones.js +0 -149
  44. package/ecosystem.config.js +0 -26
  45. package/libraries/stores.js +0 -22
  46. package/routes/admin/auto/admins.json +0 -63
  47. package/routes/admin/auto/devices.json +0 -37
  48. package/routes/admin/auto/migrations.json +0 -21
  49. package/routes/admin/auto/users.json +0 -61
  50. package/routes/admin/middlewares/index.js +0 -87
  51. package/routes/admin/spec/auth.js +0 -626
  52. package/routes/admin/spec/users.js +0 -3
  53. package/routes/auto/handler.js +0 -635
  54. package/routes/common/auto/countries.json +0 -28
  55. package/routes/common/auto/currencies.json +0 -26
  56. package/routes/common/auto/languages.json +0 -26
  57. package/routes/common/auto/taxes.json +0 -46
  58. package/routes/common/auto/timezones.json +0 -29
  59. package/workers/admin.js +0 -124
  60. package/workers/api.js +0 -106
@@ -1,149 +0,0 @@
1
- /**
2
- * Seed the timezones table with unique offsets.
3
- * @param { import("knex").Knex } knex
4
- */
5
- exports.seed = async function(knex) {
6
- // Inserts seed entries with unique offsets
7
- await knex('timezones').insert([
8
- {
9
- timezone_id: 1,
10
- name: 'Greenwich Mean Time',
11
- code: 'GMT',
12
- offset: '+00:00',
13
- gmt: 'GMT+0'
14
- },
15
- {
16
- timezone_id: 2,
17
- name: 'Central European Time',
18
- code: 'CET',
19
- offset: '+01:00',
20
- gmt: 'GMT+1'
21
- },
22
- {
23
- timezone_id: 3,
24
- name: 'Eastern European Time',
25
- code: 'EET',
26
- offset: '+02:00',
27
- gmt: 'GMT+2'
28
- },
29
- {
30
- timezone_id: 4,
31
- name: 'Moscow Standard Time',
32
- code: 'MSK',
33
- offset: '+03:00',
34
- gmt: 'GMT+3'
35
- },
36
- {
37
- timezone_id: 5,
38
- name: 'Pakistan Standard Time',
39
- code: 'PKT',
40
- offset: '+05:00',
41
- gmt: 'GMT+5'
42
- },
43
- {
44
- timezone_id: 6,
45
- name: 'India Standard Time',
46
- code: 'IST',
47
- offset: '+05:30',
48
- gmt: 'GMT+5:30'
49
- },
50
- {
51
- timezone_id: 7,
52
- name: 'Bangladesh Standard Time',
53
- code: 'BST',
54
- offset: '+06:00',
55
- gmt: 'GMT+6'
56
- },
57
- {
58
- timezone_id: 8,
59
- name: 'Indochina Time',
60
- code: 'ICT',
61
- offset: '+07:00',
62
- gmt: 'GMT+7'
63
- },
64
- {
65
- timezone_id: 9,
66
- name: 'China Standard Time',
67
- code: 'CST',
68
- offset: '+08:00',
69
- gmt: 'GMT+8'
70
- },
71
- {
72
- timezone_id: 10,
73
- name: 'Japan Standard Time',
74
- code: 'JST',
75
- offset: '+09:00',
76
- gmt: 'GMT+9'
77
- },
78
- {
79
- timezone_id: 11,
80
- name: 'Australian Eastern Standard Time',
81
- code: 'AEST',
82
- offset: '+10:00',
83
- gmt: 'GMT+10'
84
- },
85
- {
86
- timezone_id: 12,
87
- name: 'New Zealand Standard Time',
88
- code: 'NZST',
89
- offset: '+12:00',
90
- gmt: 'GMT+12'
91
- },
92
- {
93
- timezone_id: 13,
94
- name: 'Atlantic Standard Time',
95
- code: 'AST',
96
- offset: '-04:00',
97
- gmt: 'GMT-4'
98
- },
99
- {
100
- timezone_id: 14,
101
- name: 'Eastern Standard Time',
102
- code: 'EST',
103
- offset: '-05:00',
104
- gmt: 'GMT-5'
105
- },
106
- {
107
- timezone_id: 15,
108
- name: 'Central Standard Time',
109
- code: 'CST',
110
- offset: '-06:00',
111
- gmt: 'GMT-6'
112
- },
113
- {
114
- timezone_id: 16,
115
- name: 'Mountain Standard Time',
116
- code: 'MST',
117
- offset: '-07:00',
118
- gmt: 'GMT-7'
119
- },
120
- {
121
- timezone_id: 17,
122
- name: 'Pacific Standard Time',
123
- code: 'PST',
124
- offset: '-08:00',
125
- gmt: 'GMT-8'
126
- },
127
- {
128
- timezone_id: 18,
129
- name: 'Alaska Standard Time',
130
- code: 'AKST',
131
- offset: '-09:00',
132
- gmt: 'GMT-9'
133
- },
134
- {
135
- timezone_id: 19,
136
- name: 'Hawaii-Aleutian Standard Time',
137
- code: 'HST',
138
- offset: '-10:00',
139
- gmt: 'GMT-10'
140
- },
141
- {
142
- timezone_id: 20,
143
- name: 'Samoa Standard Time',
144
- code: 'SST',
145
- offset: '-11:00',
146
- gmt: 'GMT-11'
147
- }
148
- ]).onConflict('timezone_id').ignore();
149
- };
@@ -1,26 +0,0 @@
1
- require('dotenv').config({
2
- path: './.env'
3
- });
4
-
5
- module.exports = {
6
- apps: [
7
- // {
8
- // name: 'sb-system-api',
9
- // script: './backend/workers/api.js',
10
- // watch: process.env.NODE_ENV === 'development',
11
- // ignore_watch: ['node_modules', 'database', 'logs', '*.log', '*.json'],
12
- // },
13
- {
14
- name: 'sb-system-admin',
15
- script: './workers/admin.js',
16
- watch: process.env.NODE_ENV === 'development',
17
- ignore_watch: ['node_modules', 'database', 'logs', '*.log', '*.json']
18
- },
19
- // {
20
- // name : "sb-system-admin-dev",
21
- // cwd : "./admin",
22
- // script : "bun",
23
- // args : "run dev"
24
- // },
25
- ]
26
- };
@@ -1,22 +0,0 @@
1
- const db = require('@root/libraries/knex');
2
-
3
- class Store {
4
- constructor() {
5
- this.db = db;
6
- this.currencies = new Map();
7
- }
8
-
9
- async init() {
10
- await this.get_currencies();
11
- }
12
-
13
- async get_currencies() {
14
- const currencies = await this.db('currencies').select('currency_id', 'name', 'code', 'symbol');
15
- currencies.forEach(currency => {
16
- this.currencies.set(currency.currency_id, currency);
17
- });
18
- return this.currencies;
19
- }
20
- }
21
-
22
- module.exports = new Store();
@@ -1,63 +0,0 @@
1
- {
2
- "table": "admins",
3
- "primary_key": "admin_id",
4
- "schema": {
5
- "admin_id": { "type": "integer" },
6
- "avatar": { "type": "string", "default": null },
7
- "username": { "type": "string", "default": "", "search_type": "equal", "generatable": "email", "updatable": true, "unique": true },
8
- "email": { "type": "string", "format": "email", "default": null, "search_type": "equal", "creatable": true, "create_required": true },
9
- "phone_verified": { "type": "boolean", "default": false, "search_type": "equal" },
10
- "password": { "type": "string", "default": "", "creatable": true, "listable": false, "create_required": true, "crypted": true },
11
- "email_verified": { "type": "boolean", "search_type": "equal" },
12
- "role": { "type": "string", "enum": ["admin", "support"], "search_type": "equal" },
13
- "firstname": { "type": "string", "default": "", "search_type": "like", "creatable": true, "create_required": true, "updatable": true },
14
- "lastname": { "type": "string", "default": "", "search_type": "like", "creatable": true, "create_required": true, "updatable": true },
15
- "phone_number": { "type": "string", "search_type": "like", "creatable": true, "updatable": true },
16
- "two_factor_enabled": { "type": "boolean", "default": false, "search_type": "equal", "updatable": true },
17
- "is_active": { "type": "boolean", "default": true, "search_type": "equal", "updatable": true },
18
- "login_attempts": { "type": "integer", "default": 0, "search_type": "equal", "updatable": true },
19
- "locked_until": { "type": "string", "format": "date", "default": null, "search_type": "like", "updatable": true },
20
- "created_at": { "type": "string", "format": "date-time", "default": null, "search_type": "like" },
21
- "updated_at": { "type": "string", "format": "date-time", "default": null, "search_type": "like" }
22
- },
23
- "routes": [
24
- {
25
- "action": "list",
26
- "method": "GET",
27
- "path": "/admins",
28
- "searchable_fields": ["username", "email"],
29
- "pagination": true,
30
- "additionalProperties": false,
31
- "security": "auth"
32
- },
33
- {
34
- "action": "get",
35
- "method": "GET",
36
- "path": "/admins/:admin_id",
37
- "security": "auth",
38
- "additionalProperties": false
39
- },
40
- {
41
- "action": "create",
42
- "method": "POST",
43
- "path": "/admins",
44
- "security": "auth",
45
- "additionalProperties": false
46
- },
47
- {
48
- "action": "update",
49
- "method": "PUT",
50
- "path": "/admins/:admin_id",
51
- "security": "auth",
52
- "additionalProperties": false
53
- },
54
- {
55
- "action": "upload",
56
- "method": "POST",
57
- "path": "/admins/:admin_id/upload",
58
- "security": "auth",
59
- "upload_field": "avatar",
60
- "additionalProperties": false
61
- }
62
- ]
63
- }
@@ -1,37 +0,0 @@
1
- {
2
- "table": "devices",
3
- "primary_key": "device_id",
4
- "schema": {
5
- "device_id": { "type": "integer" },
6
- "personal_id": { "type": "integer" },
7
- "personal_type": { "type": "string", "enum": ["admin", "manager", "user"] },
8
- "unique_id": { "type": "string", "default": "" },
9
- "ip_address": { "type": "string", "default": "" },
10
- "device_information": { "type": "string", "default": "" },
11
- "two_factor_approved": { "type": "boolean", "default": false },
12
- "token": { "type": "string", "default": "" },
13
- "last_login_at": { "type": "string", "format": "date-time", "default": null },
14
- "last_login_ip": { "type": "string", "default": null },
15
- "created_at": { "type": "string", "format": "date-time", "default": null },
16
- "updated_at": { "type": "string", "format": "date-time", "default": null }
17
- },
18
- "routes": [
19
- {
20
- "action": "list",
21
- "method": "GET",
22
- "path": "/devices",
23
- "searchable_fields": ["unique_id", "ip_address", "device_information"],
24
- "pagination": true,
25
- "additionalProperties": false,
26
- "security": "auth",
27
- "owned": "personal_id",
28
- "owned_type": "personal_type"
29
- },
30
- {
31
- "action": "get",
32
- "method": "GET",
33
- "path": "/devices/:admin_id",
34
- "security": "auth"
35
- }
36
- ]
37
- }
@@ -1,21 +0,0 @@
1
- {
2
- "table": "knex_migrations",
3
- "primary_key": "id",
4
- "schema": {
5
- "id": { "type": "integer" },
6
- "name": { "type": "string" },
7
- "batch": { "type": "integer" },
8
- "migration_time": { "type": "string", "format": "date-time" }
9
- },
10
- "routes": [
11
- {
12
- "action": "list",
13
- "method": "GET",
14
- "path": "/migrations",
15
- "searchable_fields": ["name"],
16
- "pagination": true,
17
- "additionalProperties": false,
18
- "security": "auth"
19
- }
20
- ]
21
- }
@@ -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
- }