underpost 2.7.93 → 2.8.0
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/.vscode/settings.json +3 -0
- package/bin/deploy.js +39 -0
- package/bin/index.js +1 -1
- package/docker-compose.yml +1 -1
- package/package.json +4 -3
- package/src/api/core/core.service.js +3 -5
- package/src/api/user/user.model.js +1 -1
- package/src/api/user/user.service.js +22 -21
- package/src/client/components/core/Account.js +142 -124
- package/src/client/components/core/Auth.js +94 -1
- package/src/client/components/core/Css.js +1 -1
- package/src/client/components/core/Docs.js +1 -1
- package/src/client/components/core/LogIn.js +8 -1
- package/src/client/components/core/LogOut.js +3 -2
- package/src/client/components/core/Modal.js +11 -7
- package/src/client/components/core/Panel.js +16 -3
- package/src/client/components/core/PanelForm.js +1 -0
- package/src/client/components/core/Scroll.js +35 -3
- package/src/client/components/core/SignUp.js +2 -5
- package/src/client/components/core/SocketIo.js +2 -0
- package/src/client/components/core/Translate.js +4 -0
- package/src/client/components/core/Validator.js +9 -2
- package/src/client/components/core/VanillaJs.js +4 -1
- package/src/client/components/default/LogInDefault.js +2 -23
- package/src/client/components/default/LogOutDefault.js +3 -5
- package/src/client/services/user/user.service.js +9 -1
- package/src/client/ssr/body/CacheControl.js +1 -1
- package/src/client/sw/default.sw.js +10 -4
- package/src/server/client-build.js +22 -21
- package/src/server/client-icons.js +12 -2
- package/src/server/conf.js +2 -1
- package/src/server/network.js +5 -1
- package/src/server/ssl.js +2 -2
- package/src/server/valkey.js +125 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import Valkey from 'iovalkey';
|
|
2
|
+
import mongoose from 'mongoose';
|
|
3
|
+
import { hashPassword } from './auth.js';
|
|
4
|
+
import { loggerFactory } from './logger.js';
|
|
5
|
+
|
|
6
|
+
const logger = loggerFactory(import.meta);
|
|
7
|
+
|
|
8
|
+
let valkeyEnabled = true;
|
|
9
|
+
|
|
10
|
+
const disableValkeyErrorMessage = 'valkey is not enabled';
|
|
11
|
+
|
|
12
|
+
const isValkeyEnable = () => valkeyEnabled;
|
|
13
|
+
|
|
14
|
+
const selectDtoFactory = (payload, select) => {
|
|
15
|
+
const result = {};
|
|
16
|
+
for (const key of Object.keys(select)) {
|
|
17
|
+
if (select[key] === 1 && key in payload) result[key] = payload[key];
|
|
18
|
+
}
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const valkeyClientFactory = async () => {
|
|
23
|
+
const valkey = new Valkey({
|
|
24
|
+
retryStrategy: (attempt) => {
|
|
25
|
+
if (attempt === 1) {
|
|
26
|
+
valkey.disconnect();
|
|
27
|
+
valkeyEnabled = false;
|
|
28
|
+
logger.warn('Valkey service not enabled', { valkeyEnabled });
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
return 1000; // 1 second interval attempt
|
|
32
|
+
},
|
|
33
|
+
}); // Connect to 127.0.0.1:6379
|
|
34
|
+
// new Valkey(6380); // 127.0.0.1:6380
|
|
35
|
+
// new Valkey(6379, '192.168.1.1'); // 192.168.1.1:6379
|
|
36
|
+
// new Valkey('/tmp/redis.sock');
|
|
37
|
+
// new Valkey({
|
|
38
|
+
// port: 6379, // Valkey port
|
|
39
|
+
// host: '127.0.0.1', // Valkey host
|
|
40
|
+
// username: 'default', // needs Valkey >= 6
|
|
41
|
+
// password: 'my-top-secret',
|
|
42
|
+
// db: 0, // Defaults to 0
|
|
43
|
+
// });
|
|
44
|
+
return valkey;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const getValkeyObject = async (key = '') => {
|
|
48
|
+
if (!valkeyEnabled) {
|
|
49
|
+
logger.warn(disableValkeyErrorMessage + ' get', key);
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
const object = await valkey.get(key);
|
|
53
|
+
try {
|
|
54
|
+
return JSON.parse(object);
|
|
55
|
+
} catch (error) {
|
|
56
|
+
return object;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const setValkeyObject = async (key = '', payload = {}) => {
|
|
61
|
+
if (!valkeyEnabled) throw new Error(disableValkeyErrorMessage);
|
|
62
|
+
return await valkey.set(key, JSON.stringify(payload));
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const updateValkeyObject = async (key = '', payload = {}) => {
|
|
66
|
+
if (!valkeyEnabled) throw new Error(disableValkeyErrorMessage);
|
|
67
|
+
const object = await getValkeyObject(key, valkey);
|
|
68
|
+
object.updatedAt = new Date().toISOString();
|
|
69
|
+
return await valkey.set(key, JSON.stringify({ ...object, ...payload }));
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const valkeyObjectFactory = async (module = '', options = { host: 'localhost', object: {} }) => {
|
|
73
|
+
if (!valkeyEnabled) throw new Error(disableValkeyErrorMessage);
|
|
74
|
+
const idoDate = new Date().toISOString();
|
|
75
|
+
options.object = options.object || {};
|
|
76
|
+
const { object } = options;
|
|
77
|
+
const _id = new mongoose.Types.ObjectId().toString();
|
|
78
|
+
object._id = _id;
|
|
79
|
+
object.createdAt = idoDate;
|
|
80
|
+
object.updatedAt = idoDate;
|
|
81
|
+
switch (module) {
|
|
82
|
+
case 'user': {
|
|
83
|
+
const role = 'guest';
|
|
84
|
+
object._id = `${role}${_id}`;
|
|
85
|
+
return {
|
|
86
|
+
...object,
|
|
87
|
+
username: `${role}${_id.slice(-5)}`,
|
|
88
|
+
email: `${_id}@${options.host}`,
|
|
89
|
+
password: hashPassword(process.env.JWT_SECRET),
|
|
90
|
+
role,
|
|
91
|
+
failedLoginAttempts: 0,
|
|
92
|
+
phoneNumbers: [],
|
|
93
|
+
publicKey: [],
|
|
94
|
+
profileImageId: null,
|
|
95
|
+
emailConfirmed: false,
|
|
96
|
+
recoverTimeOut: null,
|
|
97
|
+
lastLoginDate: null,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
default:
|
|
101
|
+
throw new Error(`module schema not found: ${module}`);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const ValkeyAPI = {
|
|
106
|
+
valkeyClientFactory,
|
|
107
|
+
selectDtoFactory,
|
|
108
|
+
getValkeyObject,
|
|
109
|
+
setValkeyObject,
|
|
110
|
+
valkeyObjectFactory,
|
|
111
|
+
updateValkeyObject,
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const valkey = await ValkeyAPI.valkeyClientFactory();
|
|
115
|
+
|
|
116
|
+
export {
|
|
117
|
+
valkeyClientFactory,
|
|
118
|
+
selectDtoFactory,
|
|
119
|
+
getValkeyObject,
|
|
120
|
+
setValkeyObject,
|
|
121
|
+
valkeyObjectFactory,
|
|
122
|
+
updateValkeyObject,
|
|
123
|
+
isValkeyEnable,
|
|
124
|
+
ValkeyAPI,
|
|
125
|
+
};
|