cynx-lib 1.3.110 → 1.3.112
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/gen.js +77 -77
- package/package.json +1 -1
- package/ui/components/ActionsMenu.jsx +357 -357
- package/ui/components/Drawer.jsx +208 -208
- package/ui/components/Globe.jsx +764 -764
- package/ui/components/HoverCard.jsx +85 -85
- package/ui/components/PrivacyBlur.jsx +603 -603
- package/ui/components/Sidebar.jsx +10 -47
- package/ui/components/useRuler.jsx +0 -1
- package/ui/index.cjs +0 -2
- package/ui/index.js +1 -2
- package/utils/index.js +24 -24
- package/utils/utils/duration.js +139 -139
- package/utils/utils/oidc.js +214 -214
- package/utils/utils/realtime.js +1634 -1634
- package/utils/utils/server.js +371 -371
- package/utils/utils/session.js +131 -131
- package/utils/utils/session_manager.js +580 -580
- package/utils/utils/sso_manager.js +702 -702
- package/utils/utils/storage.js +393 -393
- package/utils/utils/ui.js +111 -111
- package/vue/components/Badge.vue +79 -79
- package/vue/components/Button.vue +209 -209
- package/vue/components/Checkbox.vue +103 -103
- package/vue/components/CircularProgress.vue +383 -383
- package/vue/components/Divider.vue +94 -94
- package/vue/components/Drawer.vue +243 -243
- package/vue/components/InfoBadge.vue +223 -223
- package/vue/components/Input.vue +341 -341
- package/vue/components/LinearProgress.vue +268 -268
- package/vue/components/Modal.vue +226 -226
- package/vue/components/Pagination.vue +199 -199
- package/vue/components/Select.vue +713 -713
- package/vue/components/Sidebar.vue +955 -955
- package/vue/components/Skeleton.vue +91 -91
- package/vue/components/Spinner.vue +263 -263
- package/vue/components/StatusTag.vue +89 -89
- package/vue/components/TabBar.vue +176 -176
- package/vue/components/Table.vue +388 -388
- package/vue/components/TimePicker.vue +399 -399
- package/vue/components/Toggle.vue +115 -115
- package/vue/components/XTable.vue +140 -140
- package/vue/composables/useAutoSkeletonRows.ts +71 -71
- package/vue/index.d.ts +67 -67
- package/vue/index.js +86 -86
package/utils/utils/session.js
CHANGED
|
@@ -1,131 +1,131 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* cynx/utils — Session and Device Resolution Utilities (session.js)
|
|
3
|
-
*
|
|
4
|
-
* Helpers for generating secure session tokens and extracting human-friendly device names
|
|
5
|
-
* from request headers and user-agent strings.
|
|
6
|
-
*
|
|
7
|
-
* STRICT NO EMOJIS!
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { getRandomBytes } from './uid.js';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Generate a cryptographically secure random session token.
|
|
14
|
-
* Example: "st_9b1deb4d3b7d4bad9bdd2b0d7b3dcb6d..."
|
|
15
|
-
*
|
|
16
|
-
* @param {number} [byteLength=32]
|
|
17
|
-
* @returns {string}
|
|
18
|
-
*/
|
|
19
|
-
export function genSessionToken(byteLength = 32) {
|
|
20
|
-
const bytes = getRandomBytes(byteLength);
|
|
21
|
-
let hex = '';
|
|
22
|
-
for (let i = 0; i < bytes.length; i++) {
|
|
23
|
-
hex += bytes[i].toString(16).padStart(2, '0');
|
|
24
|
-
}
|
|
25
|
-
return `st_${hex}`;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Extract human-readable device label from User-Agent string.
|
|
30
|
-
*
|
|
31
|
-
* @param {string} ua User-Agent string
|
|
32
|
-
* @returns {string} e.g. "Windows 10/11 PC", "MacBook / Mac", "iPhone", "Android Phone", "Linux PC"
|
|
33
|
-
*/
|
|
34
|
-
export function getDeviceLabel(ua) {
|
|
35
|
-
if (!ua) return 'PC';
|
|
36
|
-
if (/windows phone/i.test(ua)) return 'Windows Phone';
|
|
37
|
-
if (/windows nt 10\.0/i.test(ua)) return 'Windows 10/11 PC';
|
|
38
|
-
if (/windows nt 6\.3/i.test(ua)) return 'Windows 8.1 PC';
|
|
39
|
-
if (/windows nt 6\.1/i.test(ua)) return 'Windows 7 PC';
|
|
40
|
-
if (/win64|win32|windows/i.test(ua)) return 'Windows PC';
|
|
41
|
-
if (/ipad/i.test(ua)) return 'iPad';
|
|
42
|
-
if (/iphone/i.test(ua)) return 'iPhone';
|
|
43
|
-
if (/macintosh|mac os x/i.test(ua)) return 'MacBook / Mac';
|
|
44
|
-
if (/android/i.test(ua)) return /mobile/i.test(ua) ? 'Android Phone' : 'Android Tablet';
|
|
45
|
-
if (/cros/i.test(ua)) return 'Chromebook';
|
|
46
|
-
if (/linux/i.test(ua)) return 'Linux PC';
|
|
47
|
-
return 'Desktop PC';
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Parse User-Agent string into browser, OS, and device type.
|
|
52
|
-
*
|
|
53
|
-
* @param {string} ua User-Agent string
|
|
54
|
-
* @returns {{ browser: string, os: string, deviceType: 'desktop' | 'mobile' | 'tablet' }}
|
|
55
|
-
*/
|
|
56
|
-
export function parseUserAgent(ua) {
|
|
57
|
-
if (!ua) return { browser: 'Unknown', os: 'Unknown', deviceType: 'desktop' };
|
|
58
|
-
|
|
59
|
-
let os = 'Unknown';
|
|
60
|
-
let browser = 'Unknown';
|
|
61
|
-
let deviceType = 'desktop';
|
|
62
|
-
|
|
63
|
-
if (/windows phone/i.test(ua)) { os = 'Windows Phone'; deviceType = 'mobile'; }
|
|
64
|
-
else if (/win64|win32|windows/i.test(ua)) { os = 'Windows'; deviceType = 'desktop'; }
|
|
65
|
-
else if (/ipad/i.test(ua)) { os = 'iPadOS'; deviceType = 'tablet'; }
|
|
66
|
-
else if (/iphone|ipod/i.test(ua)) { os = 'iOS'; deviceType = 'mobile'; }
|
|
67
|
-
else if (/android/i.test(ua)) { os = 'Android'; deviceType = /mobile/i.test(ua) ? 'mobile' : 'tablet'; }
|
|
68
|
-
else if (/macintosh|mac os x/i.test(ua)) { os = 'macOS'; deviceType = 'desktop'; }
|
|
69
|
-
else if (/cros/i.test(ua)) { os = 'Chrome OS'; deviceType = 'desktop'; }
|
|
70
|
-
else if (/linux/i.test(ua)) { os = 'Linux'; deviceType = 'desktop'; }
|
|
71
|
-
|
|
72
|
-
if (/edg\//i.test(ua)) {
|
|
73
|
-
const m = ua.match(/edg\/(\d+)/i);
|
|
74
|
-
browser = m ? `Edge ${m[1]}` : 'Edge';
|
|
75
|
-
} else if (/opr\/|opera/i.test(ua)) {
|
|
76
|
-
const m = ua.match(/(?:opr|opera)\/(\d+)/i);
|
|
77
|
-
browser = m ? `Opera ${m[1]}` : 'Opera';
|
|
78
|
-
} else if (/chrome|crios/i.test(ua)) {
|
|
79
|
-
const m = ua.match(/(?:chrome|crios)\/(\d+)/i);
|
|
80
|
-
browser = m ? `Chrome ${m[1]}` : 'Chrome';
|
|
81
|
-
} else if (/firefox|fxios/i.test(ua)) {
|
|
82
|
-
const m = ua.match(/(?:firefox|fxios)\/(\d+)/i);
|
|
83
|
-
browser = m ? `Firefox ${m[1]}` : 'Firefox';
|
|
84
|
-
} else if (/safari/i.test(ua) && !/chrome|crios/i.test(ua)) {
|
|
85
|
-
const m = ua.match(/version\/(\d+)/i);
|
|
86
|
-
browser = m ? `Safari ${m[1]}` : 'Safari';
|
|
87
|
-
} else if (/postman/i.test(ua)) {
|
|
88
|
-
browser = 'Postman API';
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
return { browser, os, deviceType };
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Derive human-readable device name from Express/Fastify request or User-Agent string.
|
|
96
|
-
*
|
|
97
|
-
* @param {object} [req] HTTP request object
|
|
98
|
-
* @param {string} [userAgent=''] User-Agent string
|
|
99
|
-
* @returns {string} e.g. "Windows 10/11 PC", "MacBook / Mac", "iPhone", "Android Phone", "Desktop PC"
|
|
100
|
-
*/
|
|
101
|
-
export function deriveDeviceName(req, userAgent = '') {
|
|
102
|
-
const headers = req?.headers || {};
|
|
103
|
-
const fromHeader = headers['x-device-name'] || headers['x-pc-name'] || headers['x-computer-name'] || '';
|
|
104
|
-
if (typeof fromHeader === 'string' && fromHeader.trim()) {
|
|
105
|
-
return fromHeader.trim().slice(0, 120);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const fromBody = req?.body?.deviceName || req?.body?.device_name || req?.body?.pcName || req?.body?.pc_name;
|
|
109
|
-
if (typeof fromBody === 'string' && fromBody.trim()) {
|
|
110
|
-
return fromBody.trim().slice(0, 120);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
const ua = userAgent || headers['user-agent'] || '';
|
|
114
|
-
return getDeviceLabel(ua);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
export {
|
|
118
|
-
formatToken,
|
|
119
|
-
parseToken,
|
|
120
|
-
getSessionId,
|
|
121
|
-
extractToken,
|
|
122
|
-
SessionManager,
|
|
123
|
-
createSessionManager,
|
|
124
|
-
} from './session_manager.js';
|
|
125
|
-
|
|
126
|
-
export default {
|
|
127
|
-
genSessionToken,
|
|
128
|
-
getDeviceLabel,
|
|
129
|
-
parseUserAgent,
|
|
130
|
-
deriveDeviceName,
|
|
131
|
-
};
|
|
1
|
+
/**
|
|
2
|
+
* cynx/utils — Session and Device Resolution Utilities (session.js)
|
|
3
|
+
*
|
|
4
|
+
* Helpers for generating secure session tokens and extracting human-friendly device names
|
|
5
|
+
* from request headers and user-agent strings.
|
|
6
|
+
*
|
|
7
|
+
* STRICT NO EMOJIS!
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { getRandomBytes } from './uid.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Generate a cryptographically secure random session token.
|
|
14
|
+
* Example: "st_9b1deb4d3b7d4bad9bdd2b0d7b3dcb6d..."
|
|
15
|
+
*
|
|
16
|
+
* @param {number} [byteLength=32]
|
|
17
|
+
* @returns {string}
|
|
18
|
+
*/
|
|
19
|
+
export function genSessionToken(byteLength = 32) {
|
|
20
|
+
const bytes = getRandomBytes(byteLength);
|
|
21
|
+
let hex = '';
|
|
22
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
23
|
+
hex += bytes[i].toString(16).padStart(2, '0');
|
|
24
|
+
}
|
|
25
|
+
return `st_${hex}`;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Extract human-readable device label from User-Agent string.
|
|
30
|
+
*
|
|
31
|
+
* @param {string} ua User-Agent string
|
|
32
|
+
* @returns {string} e.g. "Windows 10/11 PC", "MacBook / Mac", "iPhone", "Android Phone", "Linux PC"
|
|
33
|
+
*/
|
|
34
|
+
export function getDeviceLabel(ua) {
|
|
35
|
+
if (!ua) return 'PC';
|
|
36
|
+
if (/windows phone/i.test(ua)) return 'Windows Phone';
|
|
37
|
+
if (/windows nt 10\.0/i.test(ua)) return 'Windows 10/11 PC';
|
|
38
|
+
if (/windows nt 6\.3/i.test(ua)) return 'Windows 8.1 PC';
|
|
39
|
+
if (/windows nt 6\.1/i.test(ua)) return 'Windows 7 PC';
|
|
40
|
+
if (/win64|win32|windows/i.test(ua)) return 'Windows PC';
|
|
41
|
+
if (/ipad/i.test(ua)) return 'iPad';
|
|
42
|
+
if (/iphone/i.test(ua)) return 'iPhone';
|
|
43
|
+
if (/macintosh|mac os x/i.test(ua)) return 'MacBook / Mac';
|
|
44
|
+
if (/android/i.test(ua)) return /mobile/i.test(ua) ? 'Android Phone' : 'Android Tablet';
|
|
45
|
+
if (/cros/i.test(ua)) return 'Chromebook';
|
|
46
|
+
if (/linux/i.test(ua)) return 'Linux PC';
|
|
47
|
+
return 'Desktop PC';
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Parse User-Agent string into browser, OS, and device type.
|
|
52
|
+
*
|
|
53
|
+
* @param {string} ua User-Agent string
|
|
54
|
+
* @returns {{ browser: string, os: string, deviceType: 'desktop' | 'mobile' | 'tablet' }}
|
|
55
|
+
*/
|
|
56
|
+
export function parseUserAgent(ua) {
|
|
57
|
+
if (!ua) return { browser: 'Unknown', os: 'Unknown', deviceType: 'desktop' };
|
|
58
|
+
|
|
59
|
+
let os = 'Unknown';
|
|
60
|
+
let browser = 'Unknown';
|
|
61
|
+
let deviceType = 'desktop';
|
|
62
|
+
|
|
63
|
+
if (/windows phone/i.test(ua)) { os = 'Windows Phone'; deviceType = 'mobile'; }
|
|
64
|
+
else if (/win64|win32|windows/i.test(ua)) { os = 'Windows'; deviceType = 'desktop'; }
|
|
65
|
+
else if (/ipad/i.test(ua)) { os = 'iPadOS'; deviceType = 'tablet'; }
|
|
66
|
+
else if (/iphone|ipod/i.test(ua)) { os = 'iOS'; deviceType = 'mobile'; }
|
|
67
|
+
else if (/android/i.test(ua)) { os = 'Android'; deviceType = /mobile/i.test(ua) ? 'mobile' : 'tablet'; }
|
|
68
|
+
else if (/macintosh|mac os x/i.test(ua)) { os = 'macOS'; deviceType = 'desktop'; }
|
|
69
|
+
else if (/cros/i.test(ua)) { os = 'Chrome OS'; deviceType = 'desktop'; }
|
|
70
|
+
else if (/linux/i.test(ua)) { os = 'Linux'; deviceType = 'desktop'; }
|
|
71
|
+
|
|
72
|
+
if (/edg\//i.test(ua)) {
|
|
73
|
+
const m = ua.match(/edg\/(\d+)/i);
|
|
74
|
+
browser = m ? `Edge ${m[1]}` : 'Edge';
|
|
75
|
+
} else if (/opr\/|opera/i.test(ua)) {
|
|
76
|
+
const m = ua.match(/(?:opr|opera)\/(\d+)/i);
|
|
77
|
+
browser = m ? `Opera ${m[1]}` : 'Opera';
|
|
78
|
+
} else if (/chrome|crios/i.test(ua)) {
|
|
79
|
+
const m = ua.match(/(?:chrome|crios)\/(\d+)/i);
|
|
80
|
+
browser = m ? `Chrome ${m[1]}` : 'Chrome';
|
|
81
|
+
} else if (/firefox|fxios/i.test(ua)) {
|
|
82
|
+
const m = ua.match(/(?:firefox|fxios)\/(\d+)/i);
|
|
83
|
+
browser = m ? `Firefox ${m[1]}` : 'Firefox';
|
|
84
|
+
} else if (/safari/i.test(ua) && !/chrome|crios/i.test(ua)) {
|
|
85
|
+
const m = ua.match(/version\/(\d+)/i);
|
|
86
|
+
browser = m ? `Safari ${m[1]}` : 'Safari';
|
|
87
|
+
} else if (/postman/i.test(ua)) {
|
|
88
|
+
browser = 'Postman API';
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return { browser, os, deviceType };
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Derive human-readable device name from Express/Fastify request or User-Agent string.
|
|
96
|
+
*
|
|
97
|
+
* @param {object} [req] HTTP request object
|
|
98
|
+
* @param {string} [userAgent=''] User-Agent string
|
|
99
|
+
* @returns {string} e.g. "Windows 10/11 PC", "MacBook / Mac", "iPhone", "Android Phone", "Desktop PC"
|
|
100
|
+
*/
|
|
101
|
+
export function deriveDeviceName(req, userAgent = '') {
|
|
102
|
+
const headers = req?.headers || {};
|
|
103
|
+
const fromHeader = headers['x-device-name'] || headers['x-pc-name'] || headers['x-computer-name'] || '';
|
|
104
|
+
if (typeof fromHeader === 'string' && fromHeader.trim()) {
|
|
105
|
+
return fromHeader.trim().slice(0, 120);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const fromBody = req?.body?.deviceName || req?.body?.device_name || req?.body?.pcName || req?.body?.pc_name;
|
|
109
|
+
if (typeof fromBody === 'string' && fromBody.trim()) {
|
|
110
|
+
return fromBody.trim().slice(0, 120);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const ua = userAgent || headers['user-agent'] || '';
|
|
114
|
+
return getDeviceLabel(ua);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export {
|
|
118
|
+
formatToken,
|
|
119
|
+
parseToken,
|
|
120
|
+
getSessionId,
|
|
121
|
+
extractToken,
|
|
122
|
+
SessionManager,
|
|
123
|
+
createSessionManager,
|
|
124
|
+
} from './session_manager.js';
|
|
125
|
+
|
|
126
|
+
export default {
|
|
127
|
+
genSessionToken,
|
|
128
|
+
getDeviceLabel,
|
|
129
|
+
parseUserAgent,
|
|
130
|
+
deriveDeviceName,
|
|
131
|
+
};
|