@underpostnet/underpost 2.7.9
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/.dockerignore +14 -0
- package/.env.development +6 -0
- package/.env.production +6 -0
- package/.env.test +6 -0
- package/.github/workflows/ghpkg.yml +115 -0
- package/.github/workflows/publish.yml +84 -0
- package/.github/workflows/pwa-microservices-template.page.yml +54 -0
- package/.github/workflows/pwa-microservices-template.test.yml +30 -0
- package/.nycrc +9 -0
- package/.prettierignore +13 -0
- package/.prettierrc +9 -0
- package/.vscode/extensions.json +72 -0
- package/.vscode/settings.json +106 -0
- package/AUTHORS.md +10 -0
- package/CHANGELOG.md +85 -0
- package/Dockerfile +90 -0
- package/LICENSE +21 -0
- package/README.md +96 -0
- package/bin/cron.js +47 -0
- package/bin/db.js +180 -0
- package/bin/deploy.js +859 -0
- package/bin/file.js +109 -0
- package/bin/index.js +82 -0
- package/bin/ssl.js +55 -0
- package/bin/util.js +204 -0
- package/bin/vs.js +35 -0
- package/conf.js +265 -0
- package/docker-compose.yml +67 -0
- package/jsconfig.json +7 -0
- package/jsdoc.json +32 -0
- package/nodemon.json +6 -0
- package/package.json +134 -0
- package/prometheus.yml +36 -0
- package/src/api/core/core.controller.js +69 -0
- package/src/api/core/core.model.js +11 -0
- package/src/api/core/core.router.js +23 -0
- package/src/api/core/core.service.js +31 -0
- package/src/api/crypto/crypto.controller.js +51 -0
- package/src/api/crypto/crypto.model.js +23 -0
- package/src/api/crypto/crypto.router.js +20 -0
- package/src/api/crypto/crypto.service.js +64 -0
- package/src/api/default/default.controller.js +69 -0
- package/src/api/default/default.model.js +20 -0
- package/src/api/default/default.router.js +23 -0
- package/src/api/default/default.service.js +31 -0
- package/src/api/file/file.controller.js +53 -0
- package/src/api/file/file.model.js +19 -0
- package/src/api/file/file.router.js +21 -0
- package/src/api/file/file.service.js +80 -0
- package/src/api/instance/instance.controller.js +69 -0
- package/src/api/instance/instance.model.js +36 -0
- package/src/api/instance/instance.router.js +33 -0
- package/src/api/instance/instance.service.js +48 -0
- package/src/api/test/test.controller.js +59 -0
- package/src/api/test/test.model.js +14 -0
- package/src/api/test/test.router.js +21 -0
- package/src/api/test/test.service.js +35 -0
- package/src/api/user/user.build.js +16 -0
- package/src/api/user/user.controller.js +70 -0
- package/src/api/user/user.model.js +65 -0
- package/src/api/user/user.router.js +345 -0
- package/src/api/user/user.service.js +479 -0
- package/src/api.js +23 -0
- package/src/client/Default.index.js +40 -0
- package/src/client/components/core/Account.js +290 -0
- package/src/client/components/core/AgGrid.js +160 -0
- package/src/client/components/core/Auth.js +19 -0
- package/src/client/components/core/Badge.js +32 -0
- package/src/client/components/core/Blockchain.js +41 -0
- package/src/client/components/core/Blog.js +9 -0
- package/src/client/components/core/BtnIcon.js +101 -0
- package/src/client/components/core/CalendarCore.js +458 -0
- package/src/client/components/core/Chat.js +64 -0
- package/src/client/components/core/ColorPalette.js +5267 -0
- package/src/client/components/core/CommonJs.js +742 -0
- package/src/client/components/core/Content.js +193 -0
- package/src/client/components/core/Css.js +846 -0
- package/src/client/components/core/CssCore.js +844 -0
- package/src/client/components/core/D3Chart.js +44 -0
- package/src/client/components/core/Docs.js +331 -0
- package/src/client/components/core/DropDown.js +164 -0
- package/src/client/components/core/EventsUI.js +46 -0
- package/src/client/components/core/FileExplorer.js +699 -0
- package/src/client/components/core/FullScreen.js +45 -0
- package/src/client/components/core/Input.js +346 -0
- package/src/client/components/core/JoyStick.js +77 -0
- package/src/client/components/core/Keyboard.js +73 -0
- package/src/client/components/core/LoadingAnimation.js +178 -0
- package/src/client/components/core/LogIn.js +187 -0
- package/src/client/components/core/LogOut.js +58 -0
- package/src/client/components/core/Logger.js +26 -0
- package/src/client/components/core/Modal.js +1814 -0
- package/src/client/components/core/NotificationManager.js +84 -0
- package/src/client/components/core/Panel.js +613 -0
- package/src/client/components/core/PanelForm.js +469 -0
- package/src/client/components/core/Polyhedron.js +162 -0
- package/src/client/components/core/Recover.js +204 -0
- package/src/client/components/core/Responsive.js +68 -0
- package/src/client/components/core/RichText.js +53 -0
- package/src/client/components/core/Router.js +76 -0
- package/src/client/components/core/Scroll.js +34 -0
- package/src/client/components/core/SignUp.js +125 -0
- package/src/client/components/core/SocketIo.js +72 -0
- package/src/client/components/core/Stream.js +113 -0
- package/src/client/components/core/ToggleSwitch.js +87 -0
- package/src/client/components/core/ToolTip.js +26 -0
- package/src/client/components/core/Translate.js +446 -0
- package/src/client/components/core/Validator.js +100 -0
- package/src/client/components/core/VanillaJs.js +463 -0
- package/src/client/components/core/Wallet.js +106 -0
- package/src/client/components/core/WebComponent.js +44 -0
- package/src/client/components/core/Webhook.js +25 -0
- package/src/client/components/core/Worker.js +280 -0
- package/src/client/components/default/CommonDefault.js +29 -0
- package/src/client/components/default/CssDefault.js +13 -0
- package/src/client/components/default/ElementsDefault.js +38 -0
- package/src/client/components/default/LogInDefault.js +41 -0
- package/src/client/components/default/LogOutDefault.js +28 -0
- package/src/client/components/default/MenuDefault.js +389 -0
- package/src/client/components/default/RoutesDefault.js +48 -0
- package/src/client/components/default/SettingsDefault.js +16 -0
- package/src/client/components/default/SignUpDefault.js +9 -0
- package/src/client/components/default/SocketIoDefault.js +54 -0
- package/src/client/components/default/TranslateDefault.js +7 -0
- package/src/client/public/default/android-chrome-144x144.png +0 -0
- package/src/client/public/default/android-chrome-192x192.png +0 -0
- package/src/client/public/default/android-chrome-256x256.png +0 -0
- package/src/client/public/default/android-chrome-36x36.png +0 -0
- package/src/client/public/default/android-chrome-384x384.png +0 -0
- package/src/client/public/default/android-chrome-48x48.png +0 -0
- package/src/client/public/default/android-chrome-512x512.png +0 -0
- package/src/client/public/default/android-chrome-72x72.png +0 -0
- package/src/client/public/default/android-chrome-96x96.png +0 -0
- package/src/client/public/default/apple-touch-icon-1024x1024.png +0 -0
- package/src/client/public/default/apple-touch-icon-114x114.png +0 -0
- package/src/client/public/default/apple-touch-icon-120x120.png +0 -0
- package/src/client/public/default/apple-touch-icon-144x144.png +0 -0
- package/src/client/public/default/apple-touch-icon-152x152.png +0 -0
- package/src/client/public/default/apple-touch-icon-167x167.png +0 -0
- package/src/client/public/default/apple-touch-icon-180x180.png +0 -0
- package/src/client/public/default/apple-touch-icon-57x57.png +0 -0
- package/src/client/public/default/apple-touch-icon-60x60.png +0 -0
- package/src/client/public/default/apple-touch-icon-72x72.png +0 -0
- package/src/client/public/default/apple-touch-icon-76x76.png +0 -0
- package/src/client/public/default/apple-touch-icon-precomposed.png +0 -0
- package/src/client/public/default/apple-touch-icon.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-1125x2436.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-1136x640.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-1170x2532.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-1179x2556.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-1242x2208.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-1242x2688.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-1284x2778.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-1290x2796.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-1334x750.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-1488x2266.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-1536x2048.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-1620x2160.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-1640x2160.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-1668x2224.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-1668x2388.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-1792x828.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-2048x1536.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-2048x2732.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-2160x1620.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-2160x1640.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-2208x1242.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-2224x1668.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-2266x1488.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-2388x1668.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-2436x1125.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-2532x1170.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-2556x1179.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-2688x1242.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-2732x2048.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-2778x1284.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-2796x1290.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-640x1136.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-750x1334.png +0 -0
- package/src/client/public/default/apple-touch-startup-image-828x1792.png +0 -0
- package/src/client/public/default/assets/background/white.jpg +0 -0
- package/src/client/public/default/assets/background/white0-min.jpg +0 -0
- package/src/client/public/default/assets/background/white0.jpg +0 -0
- package/src/client/public/default/assets/logo/base-icon.png +0 -0
- package/src/client/public/default/assets/mailer/api-user-check.png +0 -0
- package/src/client/public/default/assets/mailer/api-user-invalid-token.png +0 -0
- package/src/client/public/default/assets/mailer/api-user-recover.png +0 -0
- package/src/client/public/default/browserconfig.xml +12 -0
- package/src/client/public/default/favicon-16x16.png +0 -0
- package/src/client/public/default/favicon-32x32.png +0 -0
- package/src/client/public/default/favicon-48x48.png +0 -0
- package/src/client/public/default/favicon.ico +0 -0
- package/src/client/public/default/manifest.webmanifest +69 -0
- package/src/client/public/default/mstile-144x144.png +0 -0
- package/src/client/public/default/mstile-150x150.png +0 -0
- package/src/client/public/default/mstile-310x150.png +0 -0
- package/src/client/public/default/mstile-310x310.png +0 -0
- package/src/client/public/default/mstile-70x70.png +0 -0
- package/src/client/public/default/plantuml/client-conf.svg +1 -0
- package/src/client/public/default/plantuml/client-schema.svg +1 -0
- package/src/client/public/default/plantuml/cron-conf.svg +1 -0
- package/src/client/public/default/plantuml/cron-schema.svg +1 -0
- package/src/client/public/default/plantuml/server-conf.svg +1 -0
- package/src/client/public/default/plantuml/server-schema.svg +1 -0
- package/src/client/public/default/plantuml/ssr-conf.svg +1 -0
- package/src/client/public/default/plantuml/ssr-schema.svg +1 -0
- package/src/client/public/default/site.webmanifest +69 -0
- package/src/client/public/default/sitemap +148 -0
- package/src/client/public/default/yandex-browser-50x50.png +0 -0
- package/src/client/public/default/yandex-browser-manifest.json +9 -0
- package/src/client/public/doc/favicon.ico +0 -0
- package/src/client/public/doc/sitemap +148 -0
- package/src/client/public/test/favicon.ico +0 -0
- package/src/client/public/test/sitemap +148 -0
- package/src/client/services/core/core.service.js +170 -0
- package/src/client/services/crypto/crypto.service.js +70 -0
- package/src/client/services/default/default.management.js +343 -0
- package/src/client/services/default/default.service.js +89 -0
- package/src/client/services/file/file.service.js +70 -0
- package/src/client/services/instance/instance.management.js +74 -0
- package/src/client/services/instance/instance.service.js +89 -0
- package/src/client/services/test/test.service.js +70 -0
- package/src/client/services/user/user.management.js +50 -0
- package/src/client/services/user/user.service.js +89 -0
- package/src/client/ssr/Render.js +237 -0
- package/src/client/ssr/common/Alert.js +75 -0
- package/src/client/ssr/common/SsrCore.js +91 -0
- package/src/client/ssr/common/Translate.js +26 -0
- package/src/client/ssr/common/Worker.js +28 -0
- package/src/client/ssr/components/body/CacheControl.js +114 -0
- package/src/client/ssr/components/body/DefaultSplashScreen.js +90 -0
- package/src/client/ssr/components/email/DefaultRecoverEmail.js +21 -0
- package/src/client/ssr/components/email/DefaultVerifyEmail.js +17 -0
- package/src/client/ssr/components/head/Css.js +241 -0
- package/src/client/ssr/components/head/DefaultScripts.js +3 -0
- package/src/client/ssr/components/head/Production.js +1 -0
- package/src/client/ssr/components/head/Pwa.js +146 -0
- package/src/client/ssr/components/head/PwaDefault.js +60 -0
- package/src/client/ssr/components/head/Seo.js +14 -0
- package/src/client/ssr/pages/404.js +12 -0
- package/src/client/ssr/pages/500.js +12 -0
- package/src/client/ssr/pages/maintenance.js +14 -0
- package/src/client/ssr/pages/offline.js +21 -0
- package/src/client/sw/default.sw.js +205 -0
- package/src/client/sw/template.sw.js +84 -0
- package/src/client.build.js +22 -0
- package/src/client.dev.js +21 -0
- package/src/db/DataBaseProvider.js +45 -0
- package/src/db/mariadb/MariaDB.js +33 -0
- package/src/db/mongo/MongooseDB.js +124 -0
- package/src/dns.js +22 -0
- package/src/index.js +43 -0
- package/src/mailer/EmailRender.js +69 -0
- package/src/mailer/MailerProvider.js +96 -0
- package/src/proxy.js +22 -0
- package/src/runtime/lampp/Lampp.js +115 -0
- package/src/runtime/nginx/Nginx.js +3 -0
- package/src/runtime/xampp/Xampp.js +49 -0
- package/src/server/auth.js +235 -0
- package/src/server/backup.js +120 -0
- package/src/server/client-build-live.js +98 -0
- package/src/server/client-build.js +754 -0
- package/src/server/client-dev-server.js +60 -0
- package/src/server/client-formatted.js +58 -0
- package/src/server/client-icons.js +151 -0
- package/src/server/conf.js +929 -0
- package/src/server/crypto.js +91 -0
- package/src/server/dns.js +118 -0
- package/src/server/downloader.js +42 -0
- package/src/server/logger.js +190 -0
- package/src/server/network.js +209 -0
- package/src/server/peer.js +33 -0
- package/src/server/process.js +66 -0
- package/src/server/prompt-optimizer.js +28 -0
- package/src/server/proxy.js +118 -0
- package/src/server/runtime.js +463 -0
- package/src/server/ssl.js +120 -0
- package/src/server.js +25 -0
- package/src/ws/IoInterface.js +45 -0
- package/src/ws/IoServer.js +39 -0
- package/src/ws/core/channels/core.ws.chat.js +23 -0
- package/src/ws/core/channels/core.ws.mailer.js +35 -0
- package/src/ws/core/channels/core.ws.stream.js +31 -0
- package/src/ws/core/core.ws.connection.js +28 -0
- package/src/ws/core/core.ws.emit.js +14 -0
- package/src/ws/core/core.ws.server.js +24 -0
- package/src/ws/core/management/core.ws.chat.js +8 -0
- package/src/ws/core/management/core.ws.mailer.js +16 -0
- package/src/ws/core/management/core.ws.stream.js +8 -0
- package/src/ws/default/channels/default.ws.main.js +16 -0
- package/src/ws/default/default.ws.connection.js +22 -0
- package/src/ws/default/default.ws.emit.js +14 -0
- package/src/ws/default/default.ws.server.js +20 -0
- package/src/ws/default/management/default.ws.main.js +8 -0
- package/startup.js +11 -0
- package/supervisord-openssh-server.conf +5 -0
- package/test/api.test.js +60 -0
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { UserService } from '../../services/user/user.service.js';
|
|
2
|
+
import { Auth } from './Auth.js';
|
|
3
|
+
import { BtnIcon } from './BtnIcon.js';
|
|
4
|
+
import { EventsUI } from './EventsUI.js';
|
|
5
|
+
import { Input } from './Input.js';
|
|
6
|
+
import { LogIn } from './LogIn.js';
|
|
7
|
+
import { NotificationManager } from './NotificationManager.js';
|
|
8
|
+
import { Translate } from './Translate.js';
|
|
9
|
+
import { Validator } from './Validator.js';
|
|
10
|
+
import { getQueryParams, s } from './VanillaJs.js';
|
|
11
|
+
|
|
12
|
+
const Recover = {
|
|
13
|
+
Event: {},
|
|
14
|
+
Trigger: async function (options) {
|
|
15
|
+
for (const eventKey of Object.keys(this.Event)) await this.Event[eventKey](options);
|
|
16
|
+
},
|
|
17
|
+
Render: async function (options = { idModal: '', user: {}, bottomRender: async () => '' }) {
|
|
18
|
+
const { idModal, user } = options;
|
|
19
|
+
let mode = 'recover-verify-email';
|
|
20
|
+
const recoverToken = getQueryParams().payload;
|
|
21
|
+
const formData = {
|
|
22
|
+
'recover-username': {
|
|
23
|
+
model: 'username',
|
|
24
|
+
id: `recover-username`,
|
|
25
|
+
rules: [{ type: 'isEmpty' }, { type: 'isLength', options: { min: 2, max: 20 } }],
|
|
26
|
+
show: () => false,
|
|
27
|
+
disable: function () {
|
|
28
|
+
return !this.show();
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
'recover-email': {
|
|
32
|
+
model: 'email',
|
|
33
|
+
id: `recover-email`,
|
|
34
|
+
rules: [{ type: 'isEmpty' }, { type: 'isEmail' }],
|
|
35
|
+
show: () => mode === 'recover-verify-email',
|
|
36
|
+
disable: function () {
|
|
37
|
+
return !this.show();
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
'recover-password': {
|
|
41
|
+
model: 'password',
|
|
42
|
+
id: `recover-password`,
|
|
43
|
+
rules: [{ type: 'isStrongPassword' }],
|
|
44
|
+
show: () => mode === 'change-password',
|
|
45
|
+
disable: function () {
|
|
46
|
+
return !this.show();
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
'recover-repeat-password': {
|
|
50
|
+
id: `recover-repeat-password`,
|
|
51
|
+
rules: [{ type: 'isEmpty' }, { type: 'passwordMismatch', options: `recover-password` }],
|
|
52
|
+
show: () => mode === 'change-password',
|
|
53
|
+
disable: function () {
|
|
54
|
+
return !this.show();
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
if (recoverToken) {
|
|
60
|
+
mode = 'change-password';
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
setTimeout(async () => {
|
|
64
|
+
if (user && user.email) {
|
|
65
|
+
s(`.recover-email`).value = user.email;
|
|
66
|
+
if (user.emailConfirmed) s(`.recover-email`).setAttribute('disabled', '');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const validators = await Validator.instance(formData);
|
|
70
|
+
|
|
71
|
+
EventsUI.onClick(`.btn-recover`, async (e) => {
|
|
72
|
+
e.preventDefault();
|
|
73
|
+
s(`.recover-resend-btn-container`).classList.add('hide');
|
|
74
|
+
s(`.recover-send-btn-container`).classList.remove('hide');
|
|
75
|
+
const { errorMessage } = await validators();
|
|
76
|
+
if (errorMessage) return;
|
|
77
|
+
const body = {};
|
|
78
|
+
for (const inputData of Object.values(formData)) {
|
|
79
|
+
if ('model' in inputData) body[inputData.model] = s(`.${inputData.id}`).value;
|
|
80
|
+
}
|
|
81
|
+
switch (mode) {
|
|
82
|
+
case 'recover-verify-email': {
|
|
83
|
+
const result = await UserService.post({ id: 'recover-verify-email', body });
|
|
84
|
+
NotificationManager.Push({
|
|
85
|
+
html:
|
|
86
|
+
result.status === 'error' ? result.message : Translate.Render(`${result.status}-recover-verify-email`),
|
|
87
|
+
status: result.status,
|
|
88
|
+
});
|
|
89
|
+
if (result.status === 'success') {
|
|
90
|
+
s(`.recover-send-btn-container`).classList.add('hide');
|
|
91
|
+
s(`.recover-resend-btn-container`).classList.remove('hide');
|
|
92
|
+
}
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
case 'change-password': {
|
|
96
|
+
const result = await UserService.put({ id: `recover/${recoverToken}`, body });
|
|
97
|
+
NotificationManager.Push({
|
|
98
|
+
html:
|
|
99
|
+
typeof result.data === 'string' ? result.data : Translate.Render(`${result.status}-recover-password`),
|
|
100
|
+
status: result.status,
|
|
101
|
+
});
|
|
102
|
+
if (result.status === 'success') {
|
|
103
|
+
if (Auth.getToken()) {
|
|
104
|
+
s(`.btn-close-modal-recover`).click();
|
|
105
|
+
s(`.main-btn-account`).click();
|
|
106
|
+
} else {
|
|
107
|
+
s(`.btn-recover`).classList.add('hide');
|
|
108
|
+
s(`.input-container-recover-password`).classList.add('hide');
|
|
109
|
+
s(`.input-container-recover-repeat-password`).classList.add('hide');
|
|
110
|
+
s(`.btn-recover-log-in`).classList.remove('hide');
|
|
111
|
+
}
|
|
112
|
+
this.Trigger({ user: result.data });
|
|
113
|
+
}
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
s(`.btn-recover-resend`).onclick = (e) => {
|
|
119
|
+
e.preventDefault();
|
|
120
|
+
s(`.btn-recover`).click();
|
|
121
|
+
};
|
|
122
|
+
s(`.btn-recover-log-in`).onclick = () => {
|
|
123
|
+
s(`.btn-close-modal-recover`).click();
|
|
124
|
+
s(`.main-btn-log-in`).click();
|
|
125
|
+
};
|
|
126
|
+
});
|
|
127
|
+
return html`
|
|
128
|
+
${await BtnIcon.Render({
|
|
129
|
+
class: 'section-mp form-button btn-recover-log-in hide',
|
|
130
|
+
label: Translate.Render('log-in'),
|
|
131
|
+
type: 'button',
|
|
132
|
+
})}
|
|
133
|
+
<form class="in">
|
|
134
|
+
<div class="in">
|
|
135
|
+
${await Input.Render({
|
|
136
|
+
id: `recover-username`,
|
|
137
|
+
type: 'text',
|
|
138
|
+
label: html`<i class="fa-solid fa-pen-to-square"></i> ${Translate.Render('username')}`,
|
|
139
|
+
containerClass: `inl section-mp width-mini-box input-container ${
|
|
140
|
+
formData[`recover-username`].show() ? '' : 'hide'
|
|
141
|
+
}`,
|
|
142
|
+
placeholder: true,
|
|
143
|
+
})}
|
|
144
|
+
</div>
|
|
145
|
+
<div class="in">
|
|
146
|
+
${await Input.Render({
|
|
147
|
+
id: `recover-email`,
|
|
148
|
+
type: 'email',
|
|
149
|
+
label: html`<i class="fa-solid fa-envelope"></i> ${Translate.Render('email')}`,
|
|
150
|
+
containerClass: `inl section-mp width-mini-box input-container ${
|
|
151
|
+
formData[`recover-email`].show() ? '' : 'hide'
|
|
152
|
+
}`,
|
|
153
|
+
placeholder: true,
|
|
154
|
+
autocomplete: 'email',
|
|
155
|
+
})}
|
|
156
|
+
</div>
|
|
157
|
+
<div class="in">
|
|
158
|
+
${await Input.Render({
|
|
159
|
+
id: `recover-password`,
|
|
160
|
+
type: 'password',
|
|
161
|
+
autocomplete: 'new-password',
|
|
162
|
+
label: html`<i class="fa-solid fa-lock"></i> ${Translate.Render('password')}`,
|
|
163
|
+
containerClass: `inl section-mp width-mini-box input-container ${
|
|
164
|
+
formData[`recover-password`].show() ? '' : 'hide'
|
|
165
|
+
}`,
|
|
166
|
+
placeholder: true,
|
|
167
|
+
})}
|
|
168
|
+
</div>
|
|
169
|
+
<div class="in">
|
|
170
|
+
${await Input.Render({
|
|
171
|
+
id: `recover-repeat-password`,
|
|
172
|
+
type: 'password',
|
|
173
|
+
autocomplete: 'new-password',
|
|
174
|
+
label: html`<i class="fa-solid fa-lock"></i> ${Translate.Render('repeat')} ${Translate.Render('password')}`,
|
|
175
|
+
containerClass: `inl section-mp width-mini-box input-container ${
|
|
176
|
+
formData[`recover-repeat-password`].show() ? '' : 'hide'
|
|
177
|
+
}`,
|
|
178
|
+
placeholder: true,
|
|
179
|
+
})}
|
|
180
|
+
</div>
|
|
181
|
+
${options?.bottomRender ? await options.bottomRender() : ``}
|
|
182
|
+
<div class="in recover-send-btn-container">
|
|
183
|
+
${await BtnIcon.Render({
|
|
184
|
+
class: 'section-mp form-button btn-recover',
|
|
185
|
+
label: Translate.Render(mode === 'recover-verify-email' ? 'send-recover-verify-email' : 'change-password'),
|
|
186
|
+
type: 'button',
|
|
187
|
+
})}
|
|
188
|
+
</div>
|
|
189
|
+
<div class="in recover-resend-btn-container hide">
|
|
190
|
+
<div class="in section-mp form-button" style="color: #ed9d0f">
|
|
191
|
+
<i class="fa-solid fa-triangle-exclamation"></i> ${Translate.Render('15-min-valid-recover-email')}
|
|
192
|
+
</div>
|
|
193
|
+
${await BtnIcon.Render({
|
|
194
|
+
class: 'section-mp form-button btn-recover-resend',
|
|
195
|
+
label: html`${Translate.Render('resend')} ${Translate.Render('recover-verify-email')}`,
|
|
196
|
+
type: 'submit',
|
|
197
|
+
})}
|
|
198
|
+
</div>
|
|
199
|
+
</form>
|
|
200
|
+
`;
|
|
201
|
+
},
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
export { Recover };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { newInstance } from './CommonJs.js';
|
|
2
|
+
import { loggerFactory } from './Logger.js';
|
|
3
|
+
import { getResponsiveData } from './VanillaJs.js';
|
|
4
|
+
|
|
5
|
+
const logger = loggerFactory(import.meta);
|
|
6
|
+
|
|
7
|
+
const Responsive = {
|
|
8
|
+
Data: {},
|
|
9
|
+
Event: {},
|
|
10
|
+
DelayEvent: {},
|
|
11
|
+
Observer: ResizeObserver,
|
|
12
|
+
getResponsiveData: function () {
|
|
13
|
+
return newInstance(this.Data);
|
|
14
|
+
},
|
|
15
|
+
getResponsiveDataAmplitude: function (options) {
|
|
16
|
+
const { dimAmplitude } = options;
|
|
17
|
+
const ResponsiveDataAmplitude = newInstance(this.Data);
|
|
18
|
+
ResponsiveDataAmplitude.minValue = ResponsiveDataAmplitude.minValue * dimAmplitude;
|
|
19
|
+
ResponsiveDataAmplitude.maxValue = ResponsiveDataAmplitude.maxValue * dimAmplitude;
|
|
20
|
+
ResponsiveDataAmplitude.width = ResponsiveDataAmplitude.width * dimAmplitude;
|
|
21
|
+
ResponsiveDataAmplitude.height = ResponsiveDataAmplitude.height * dimAmplitude;
|
|
22
|
+
return ResponsiveDataAmplitude;
|
|
23
|
+
},
|
|
24
|
+
resizeCallback: function () {
|
|
25
|
+
const Data = getResponsiveData();
|
|
26
|
+
if (Data.minValue !== Responsive.Data.minValue || Data.maxValue !== Responsive.Data.maxValue) {
|
|
27
|
+
Responsive.Data = Data;
|
|
28
|
+
Responsive.triggerEvents();
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
resize: 0,
|
|
32
|
+
Init: async function () {
|
|
33
|
+
Responsive.resizeCallback();
|
|
34
|
+
window.onresize = () => {
|
|
35
|
+
Responsive.resize++;
|
|
36
|
+
const resize = Responsive.resize;
|
|
37
|
+
Responsive.resizeCallback();
|
|
38
|
+
setTimeout(() => {
|
|
39
|
+
if (resize === Responsive.resize) {
|
|
40
|
+
Responsive.resizeCallback();
|
|
41
|
+
Responsive.resize = 0;
|
|
42
|
+
for (const event of Object.keys(Responsive.DelayEvent)) Responsive.DelayEvent[event]();
|
|
43
|
+
}
|
|
44
|
+
}, 750);
|
|
45
|
+
};
|
|
46
|
+
// alternative option
|
|
47
|
+
// this.Observer = new ResizeObserver(this.resizeCallback);
|
|
48
|
+
// this.Observer.observe(document.documentElement);
|
|
49
|
+
screen.orientation.addEventListener('change', (event) => {
|
|
50
|
+
const type = event.target.type; // landscape-primary | portrait-primary
|
|
51
|
+
const angle = event.target.angle; // 90 degrees.
|
|
52
|
+
logger.info(`ScreenOrientation change: ${type}, ${angle} degrees.`);
|
|
53
|
+
setTimeout(window.onresize);
|
|
54
|
+
for (const event of Object.keys(this.orientationEvent)) this.orientationEvent[event]();
|
|
55
|
+
setTimeout(() => {
|
|
56
|
+
for (const event of Object.keys(this.orientationDelayEvent)) this.orientationDelayEvent[event]();
|
|
57
|
+
}, 750);
|
|
58
|
+
});
|
|
59
|
+
},
|
|
60
|
+
triggerEvents: function (keyEvent) {
|
|
61
|
+
if (keyEvent) return this.Event[keyEvent]();
|
|
62
|
+
return Object.keys(this.Event).map((key) => this.Event[key]());
|
|
63
|
+
},
|
|
64
|
+
orientationEvent: {},
|
|
65
|
+
orientationDelayEvent: {},
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export { Responsive };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { getId, newInstance } from './CommonJs.js';
|
|
2
|
+
import { Modal } from './Modal.js';
|
|
3
|
+
import { s } from './VanillaJs.js';
|
|
4
|
+
|
|
5
|
+
const RichText = {
|
|
6
|
+
Tokens: {},
|
|
7
|
+
Render: async function (options = { id: '', parentIdModal: '' }) {
|
|
8
|
+
const id = options?.id ? options.id : getId(this.Tokens, 'rich-text-');
|
|
9
|
+
this.Tokens[id] = {};
|
|
10
|
+
let top, height;
|
|
11
|
+
setTimeout(() => {
|
|
12
|
+
const easyMDE = new EasyMDE({
|
|
13
|
+
element: s(`.${id}`),
|
|
14
|
+
onToggleFullScreen: (onFs) => {
|
|
15
|
+
if (onFs) {
|
|
16
|
+
if (options.parentIdModal) {
|
|
17
|
+
s(`.btn-bar-modal-container-${options.parentIdModal}`).classList.add('hide');
|
|
18
|
+
top = newInstance(s(`.${options.parentIdModal}`).style.top);
|
|
19
|
+
height = newInstance(s(`.${options.parentIdModal}`).style.height);
|
|
20
|
+
s(`.${options.parentIdModal}`).style.top = '0px';
|
|
21
|
+
s(`.${options.parentIdModal}`).style.height = `${window.innerHeight}px`;
|
|
22
|
+
}
|
|
23
|
+
// Modal.cleanUI();
|
|
24
|
+
if (s(`.slide-menu-top-bar`)) s(`.slide-menu-top-bar`).classList.add('hide');
|
|
25
|
+
} else {
|
|
26
|
+
if (options.parentIdModal) {
|
|
27
|
+
s(`.btn-bar-modal-container-${options.parentIdModal}`).classList.remove('hide');
|
|
28
|
+
s(`.${options.parentIdModal}`).style.top = top;
|
|
29
|
+
s(`.${options.parentIdModal}`).style.height = height;
|
|
30
|
+
}
|
|
31
|
+
if (s(`.slide-menu-top-bar`)) s(`.slide-menu-top-bar`).classList.add('remove');
|
|
32
|
+
// Modal.restoreUI();
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
this.Tokens[id].easyMDE = easyMDE;
|
|
37
|
+
// easyMDE.value();
|
|
38
|
+
// easyMDE.value(val);
|
|
39
|
+
});
|
|
40
|
+
return html` <style>
|
|
41
|
+
.md-container {
|
|
42
|
+
background: white;
|
|
43
|
+
color: black;
|
|
44
|
+
}
|
|
45
|
+
.md-container button {
|
|
46
|
+
color: black !important;
|
|
47
|
+
}
|
|
48
|
+
</style>
|
|
49
|
+
<div class="in md-container"><textarea class="${id}"></textarea></div>`;
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export { RichText };
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { titleFormatted } from './CommonJs.js';
|
|
2
|
+
import { loggerFactory } from './Logger.js';
|
|
3
|
+
import { getProxyPath, getQueryParams, htmls, s, setPath } from './VanillaJs.js';
|
|
4
|
+
|
|
5
|
+
// Router
|
|
6
|
+
|
|
7
|
+
const logger = loggerFactory(import.meta);
|
|
8
|
+
|
|
9
|
+
const setDocTitle = (options = { Routes: () => {}, route: '', NameApp: '' }) => {
|
|
10
|
+
const { Routes, route, NameApp } = options;
|
|
11
|
+
let title = titleFormatted(Routes()[`/${route}`].title);
|
|
12
|
+
if (Routes()[`/${route}`].upperCase) title = title.toUpperCase();
|
|
13
|
+
htmls('title', html`${title} | ${NameApp}`);
|
|
14
|
+
{
|
|
15
|
+
const routeId = route === '' ? 'home' : route;
|
|
16
|
+
if (s(`.main-btn-${routeId}`)) {
|
|
17
|
+
if (s(`.main-btn-menu-active`)) s(`.main-btn-menu-active`).classList.remove(`main-btn-menu-active`);
|
|
18
|
+
if (s(`.main-btn-${routeId}`)) s(`.main-btn-${routeId}`).classList.add(`main-btn-menu-active`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const RouterEvents = {};
|
|
24
|
+
|
|
25
|
+
const Router = function (options = { Routes: () => {}, e: new PopStateEvent(), NameApp: '' }) {
|
|
26
|
+
const { e, Routes, NameApp } = options;
|
|
27
|
+
const proxyPath = getProxyPath();
|
|
28
|
+
let path = window.location.pathname;
|
|
29
|
+
logger.info(options);
|
|
30
|
+
|
|
31
|
+
for (let route of Object.keys(Routes())) {
|
|
32
|
+
route = route.slice(1);
|
|
33
|
+
let pushPath = `${proxyPath}${route}`;
|
|
34
|
+
|
|
35
|
+
if (path[path.length - 1] !== '/') path = `${path}/`;
|
|
36
|
+
if (pushPath[pushPath.length - 1] !== '/') pushPath = `${pushPath}/`;
|
|
37
|
+
|
|
38
|
+
const routerEvent = { path, pushPath, route };
|
|
39
|
+
|
|
40
|
+
if (path === pushPath) {
|
|
41
|
+
for (const event of Object.keys(RouterEvents)) RouterEvents[event](routerEvent);
|
|
42
|
+
setDocTitle({ Routes, route, NameApp });
|
|
43
|
+
return Routes()[`/${route}`].render();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const LoadRouter = function (RouterInstance) {
|
|
49
|
+
Router(RouterInstance);
|
|
50
|
+
window.onpopstate = (e) => Router({ ...RouterInstance, e });
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const setQueryPath = (options = { path: '', queryPath: '' }, queryKey = 'cid') => {
|
|
54
|
+
const { queryPath, path } = options;
|
|
55
|
+
const newUri = `${getProxyPath()}${path === 'home' ? '' : `${path}/`}${queryPath ? `?${queryKey}=${queryPath}` : ''}`;
|
|
56
|
+
const currentUri = `${window.location.pathname}${location.search}`;
|
|
57
|
+
if (currentUri !== newUri && currentUri !== `${newUri}/`) setPath(newUri);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const listenQueryPathInstance = ({ id, routeId, event }, queryKey = 'cid') => {
|
|
61
|
+
RouterEvents[id] = ({ path, pushPath, proxyPath, route }) => {
|
|
62
|
+
if ((route === '' && routeId === 'home') || (route && routeId && route === routeId)) {
|
|
63
|
+
setTimeout(() => {
|
|
64
|
+
const path = getQueryParams()[queryKey];
|
|
65
|
+
if (path) event(path);
|
|
66
|
+
else event('');
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
if (routeId && routeId !== 'home')
|
|
71
|
+
setTimeout(() => {
|
|
72
|
+
RouterEvents[id]({ route: routeId });
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export { Router, setDocTitle, LoadRouter, RouterEvents, setQueryPath, listenQueryPathInstance };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { s } from './VanillaJs.js';
|
|
2
|
+
|
|
3
|
+
const Scroll = {
|
|
4
|
+
data: {},
|
|
5
|
+
init: function (selector) {
|
|
6
|
+
s(selector).addEventListener('scroll', Scroll.scrollHandler);
|
|
7
|
+
Scroll.data[selector] = {
|
|
8
|
+
element: s(selector),
|
|
9
|
+
};
|
|
10
|
+
return Scroll.data[selector];
|
|
11
|
+
},
|
|
12
|
+
getScrollPosition: function (selector) {
|
|
13
|
+
// Scroll.data[selector].element.clientHeight -
|
|
14
|
+
return Scroll.data[selector].element.scrollTop;
|
|
15
|
+
},
|
|
16
|
+
scrollHandler: async function () {
|
|
17
|
+
for (const selector in Scroll.data) await Scroll.data[selector].callback(Scroll.getScrollPosition(selector));
|
|
18
|
+
},
|
|
19
|
+
addEvent: function (selector = '', callback = () => {}) {
|
|
20
|
+
Scroll.data[selector].callback = callback;
|
|
21
|
+
},
|
|
22
|
+
removeEvent: function (selector) {
|
|
23
|
+
delete Scroll.data[selector];
|
|
24
|
+
},
|
|
25
|
+
to: function (elector = '', options = { top: 100, left: 100, behavior: 'smooth' }) {
|
|
26
|
+
Scroll.data[selector].element.scrollTo({
|
|
27
|
+
top: options.top || Scroll.getScrollPosition(selector),
|
|
28
|
+
left: options.left || 0,
|
|
29
|
+
behavior: options.behavior || 'smooth',
|
|
30
|
+
});
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export { Scroll };
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { UserService } from '../../services/user/user.service.js';
|
|
2
|
+
import { BtnIcon } from './BtnIcon.js';
|
|
3
|
+
import { EventsUI } from './EventsUI.js';
|
|
4
|
+
import { Input } from './Input.js';
|
|
5
|
+
import { LogIn } from './LogIn.js';
|
|
6
|
+
import { NotificationManager } from './NotificationManager.js';
|
|
7
|
+
import { Translate } from './Translate.js';
|
|
8
|
+
import { Validator } from './Validator.js';
|
|
9
|
+
import { s } from './VanillaJs.js';
|
|
10
|
+
|
|
11
|
+
const SignUp = {
|
|
12
|
+
Event: {},
|
|
13
|
+
Trigger: async function (options) {
|
|
14
|
+
for (const eventKey of Object.keys(this.Event)) await this.Event[eventKey](options);
|
|
15
|
+
},
|
|
16
|
+
Render: async function (options = { bottomRender: async () => '' }) {
|
|
17
|
+
setTimeout(async () => {
|
|
18
|
+
const formData = [
|
|
19
|
+
{
|
|
20
|
+
model: 'username',
|
|
21
|
+
id: `sign-up-username`,
|
|
22
|
+
rules: [{ type: 'isEmpty' }, { type: 'isLength', options: { min: 2, max: 20 } }],
|
|
23
|
+
},
|
|
24
|
+
{ model: 'email', id: `sign-up-email`, rules: [{ type: 'isEmpty' }, { type: 'isEmail' }] },
|
|
25
|
+
{
|
|
26
|
+
model: 'password',
|
|
27
|
+
id: `sign-up-password`,
|
|
28
|
+
rules: [{ type: 'isStrongPassword' }],
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
id: `sign-up-repeat-password`,
|
|
32
|
+
rules: [{ type: 'isEmpty' }, { type: 'passwordMismatch', options: `sign-up-password` }],
|
|
33
|
+
},
|
|
34
|
+
];
|
|
35
|
+
const validators = await Validator.instance(formData);
|
|
36
|
+
|
|
37
|
+
EventsUI.onClick(`.btn-sign-up`, async (e) => {
|
|
38
|
+
e.preventDefault();
|
|
39
|
+
const { errorMessage } = await validators();
|
|
40
|
+
if (errorMessage) return;
|
|
41
|
+
const body = {};
|
|
42
|
+
for (const inputData of formData) {
|
|
43
|
+
if ('model' in inputData) body[inputData.model] = s(`.${inputData.id}`).value;
|
|
44
|
+
}
|
|
45
|
+
const result = await UserService.post({ body });
|
|
46
|
+
NotificationManager.Push({
|
|
47
|
+
html:
|
|
48
|
+
typeof result.data === 'string'
|
|
49
|
+
? result.data
|
|
50
|
+
: result.status === 'success'
|
|
51
|
+
? Translate.Render(`success-register-user`)
|
|
52
|
+
: Translate.Render(`no-valid-register`),
|
|
53
|
+
status: result.status,
|
|
54
|
+
});
|
|
55
|
+
if (result.status === 'success') {
|
|
56
|
+
await this.Trigger(result.data);
|
|
57
|
+
await LogIn.Trigger(result.data);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
s(`.btn-sign-up-i-have-account`).onclick = () => {
|
|
61
|
+
s(`.main-btn-log-in`).click();
|
|
62
|
+
};
|
|
63
|
+
});
|
|
64
|
+
return html`
|
|
65
|
+
${await BtnIcon.Render({
|
|
66
|
+
class: 'section-mp form-button btn-sign-up-i-have-account',
|
|
67
|
+
label: html`<i class="fas fa-sign-in-alt"></i> ${Translate.Render('i-have-account')}<br />${Translate.Render(
|
|
68
|
+
'log-in',
|
|
69
|
+
)}`,
|
|
70
|
+
type: 'button',
|
|
71
|
+
})}
|
|
72
|
+
<form class="in">
|
|
73
|
+
<div class="in">
|
|
74
|
+
${await Input.Render({
|
|
75
|
+
id: `sign-up-username`,
|
|
76
|
+
type: 'text',
|
|
77
|
+
label: html`<i class="fa-solid fa-pen-to-square"></i> ${Translate.Render('username')}`,
|
|
78
|
+
containerClass: 'inl section-mp width-mini-box input-container',
|
|
79
|
+
placeholder: true,
|
|
80
|
+
})}
|
|
81
|
+
</div>
|
|
82
|
+
<div class="in">
|
|
83
|
+
${await Input.Render({
|
|
84
|
+
id: `sign-up-email`,
|
|
85
|
+
type: 'email',
|
|
86
|
+
label: html`<i class="fa-solid fa-envelope"></i> ${Translate.Render('email')}`,
|
|
87
|
+
containerClass: 'inl section-mp width-mini-box input-container',
|
|
88
|
+
placeholder: true,
|
|
89
|
+
autocomplete: 'email',
|
|
90
|
+
})}
|
|
91
|
+
</div>
|
|
92
|
+
<div class="in">
|
|
93
|
+
${await Input.Render({
|
|
94
|
+
id: `sign-up-password`,
|
|
95
|
+
type: 'password',
|
|
96
|
+
autocomplete: 'new-password',
|
|
97
|
+
label: html`<i class="fa-solid fa-lock"></i> ${Translate.Render('password')}`,
|
|
98
|
+
containerClass: 'inl section-mp width-mini-box input-container',
|
|
99
|
+
placeholder: true,
|
|
100
|
+
})}
|
|
101
|
+
</div>
|
|
102
|
+
<div class="in">
|
|
103
|
+
${await Input.Render({
|
|
104
|
+
id: `sign-up-repeat-password`,
|
|
105
|
+
type: 'password',
|
|
106
|
+
autocomplete: 'new-password',
|
|
107
|
+
label: html`<i class="fa-solid fa-lock"></i> ${Translate.Render('repeat')} ${Translate.Render('password')}`,
|
|
108
|
+
containerClass: 'inl section-mp width-mini-box input-container',
|
|
109
|
+
placeholder: true,
|
|
110
|
+
})}
|
|
111
|
+
</div>
|
|
112
|
+
${options?.bottomRender ? await options.bottomRender() : ``}
|
|
113
|
+
<div class="in">
|
|
114
|
+
${await BtnIcon.Render({
|
|
115
|
+
class: 'section-mp form-button btn-sign-up',
|
|
116
|
+
label: Translate.Render('sign-up'),
|
|
117
|
+
type: 'submit',
|
|
118
|
+
})}
|
|
119
|
+
</div>
|
|
120
|
+
</form>
|
|
121
|
+
`;
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
export { SignUp };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { io } from 'socket.io/client-dist/socket.io.esm.min.js';
|
|
2
|
+
import { loggerFactory } from './Logger.js';
|
|
3
|
+
import { getWsBasePath, getWsBaseUrl } from '../../services/core/core.service.js';
|
|
4
|
+
|
|
5
|
+
const logger = loggerFactory(import.meta);
|
|
6
|
+
|
|
7
|
+
const SocketIo = {
|
|
8
|
+
Event: {
|
|
9
|
+
connect: {},
|
|
10
|
+
connect_error: {},
|
|
11
|
+
disconnect: {},
|
|
12
|
+
},
|
|
13
|
+
/** @type {import('socket.io').Socket} */
|
|
14
|
+
socket: null,
|
|
15
|
+
Emit: function (channel = '', payload = {}) {
|
|
16
|
+
try {
|
|
17
|
+
this.socket.emit(channel, JSON.stringify(payload));
|
|
18
|
+
} catch (error) {
|
|
19
|
+
logger.error(error);
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
Init: async function (options) {
|
|
23
|
+
if (this.socket) this.socket.disconnect();
|
|
24
|
+
this.host = getWsBaseUrl({ wsBasePath: '' });
|
|
25
|
+
logger.info(`ws host:`, this.host);
|
|
26
|
+
const path = getWsBasePath();
|
|
27
|
+
const connectOptions = {
|
|
28
|
+
path,
|
|
29
|
+
// auth: {
|
|
30
|
+
// token: '',
|
|
31
|
+
// },
|
|
32
|
+
// query: {
|
|
33
|
+
// 'my-key': 'my-value',
|
|
34
|
+
// },
|
|
35
|
+
// forceNew: true,
|
|
36
|
+
// reconnectionAttempts: 'Infinity',
|
|
37
|
+
// timeout: 10000,
|
|
38
|
+
transports: ['websocket', 'polling', 'flashsocket'],
|
|
39
|
+
};
|
|
40
|
+
// logger.error(`connect options:`, JSON.stringify(connectOptions, null, 4));
|
|
41
|
+
this.socket = io(this.host, connectOptions);
|
|
42
|
+
|
|
43
|
+
this.socket.on('connect', () => {
|
|
44
|
+
logger.info(`event: connect | session id: ${this.socket.id}`);
|
|
45
|
+
Object.keys(this.Event.connect).map((keyEvent) => this.Event.connect[keyEvent]());
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
this.socket.on('connect_error', (err) => {
|
|
49
|
+
logger.info(`event: connect_error | reason: ${err.message}`);
|
|
50
|
+
Object.keys(this.Event.connect_error).map((keyEvent) => this.Event.connect_error[keyEvent](err));
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
this.socket.on('disconnect', (reason) => {
|
|
54
|
+
logger.info(`event: disconnect | reason: ${reason}`);
|
|
55
|
+
Object.keys(this.Event.disconnect).map((keyEvent) => this.Event.disconnect[keyEvent](reason));
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
if (options && 'channels' in options) this.setChannels(options.channels);
|
|
59
|
+
},
|
|
60
|
+
setChannels: function (channels) {
|
|
61
|
+
Object.keys(channels).map((type) => {
|
|
62
|
+
logger.info(`load chanel`, type);
|
|
63
|
+
this.Event[type] = {};
|
|
64
|
+
this.socket.on(type, (...args) => {
|
|
65
|
+
// logger.info(`event: ${type} | ${JSON.stringify(args, null, 4)}`);
|
|
66
|
+
Object.keys(this.Event[type]).map((keyEvent) => this.Event[type][keyEvent](args));
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export { SocketIo };
|