@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,59 @@
|
|
|
1
|
+
import { loggerFactory } from '../../server/logger.js';
|
|
2
|
+
import { TestService } from './test.service.js';
|
|
3
|
+
|
|
4
|
+
const logger = loggerFactory(import.meta);
|
|
5
|
+
|
|
6
|
+
const TestController = {
|
|
7
|
+
post: async (req, res, options) => {
|
|
8
|
+
try {
|
|
9
|
+
return res.status(200).json({
|
|
10
|
+
status: 'success',
|
|
11
|
+
data: await TestService.post(req, res, options),
|
|
12
|
+
});
|
|
13
|
+
} catch (error) {
|
|
14
|
+
logger.error(error, error.stack);
|
|
15
|
+
return res.status(400).json({
|
|
16
|
+
status: 'error',
|
|
17
|
+
message: error.message,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
get: async (req, res, options) => {
|
|
22
|
+
try {
|
|
23
|
+
const result = await TestService.get(req, res, options);
|
|
24
|
+
if (result)
|
|
25
|
+
return res.status(200).json({
|
|
26
|
+
status: 'success',
|
|
27
|
+
data: result,
|
|
28
|
+
});
|
|
29
|
+
else
|
|
30
|
+
return res.status(400).json({
|
|
31
|
+
status: 'error',
|
|
32
|
+
});
|
|
33
|
+
} catch (error) {
|
|
34
|
+
logger.error(error, error.stack);
|
|
35
|
+
return res.status(400).json({
|
|
36
|
+
status: 'error',
|
|
37
|
+
message: error.message,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
delete: async (req, res, options) => {
|
|
42
|
+
try {
|
|
43
|
+
const result = await TestService.delete(req, res, options);
|
|
44
|
+
|
|
45
|
+
return res.status(200).json({
|
|
46
|
+
status: 'success',
|
|
47
|
+
data: result,
|
|
48
|
+
});
|
|
49
|
+
} catch (error) {
|
|
50
|
+
logger.error(error, error.stack);
|
|
51
|
+
return res.status(400).json({
|
|
52
|
+
status: 'error',
|
|
53
|
+
message: error.message,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export { TestController };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Schema, model, Types } from 'mongoose';
|
|
2
|
+
|
|
3
|
+
// https://mongoosejs.com/docs/2.7.x/docs/schematypes.html
|
|
4
|
+
|
|
5
|
+
const TestSchema = new Schema({
|
|
6
|
+
testId: { type: String, required: true, immutable: true },
|
|
7
|
+
value: { type: String, required: true, immutable: true },
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
const TestModel = model('Test', TestSchema);
|
|
11
|
+
|
|
12
|
+
const ProviderSchema = TestSchema;
|
|
13
|
+
|
|
14
|
+
export { TestSchema, TestModel, ProviderSchema };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { authMiddleware } from '../../server/auth.js';
|
|
2
|
+
import { loggerFactory } from '../../server/logger.js';
|
|
3
|
+
import { TestController } from './test.controller.js';
|
|
4
|
+
import express from 'express';
|
|
5
|
+
|
|
6
|
+
const logger = loggerFactory(import.meta);
|
|
7
|
+
|
|
8
|
+
const TestRouter = (options) => {
|
|
9
|
+
const router = express.Router();
|
|
10
|
+
router.post(`/:id`, async (req, res) => await TestController.post(req, res, options));
|
|
11
|
+
router.post(`/`, authMiddleware, async (req, res) => await TestController.post(req, res, options));
|
|
12
|
+
router.get(`/:id`, async (req, res) => await TestController.get(req, res, options));
|
|
13
|
+
router.get(`/`, async (req, res) => await TestController.get(req, res, options));
|
|
14
|
+
router.delete(`/:id`, async (req, res) => await TestController.delete(req, res, options));
|
|
15
|
+
router.delete(`/`, async (req, res) => await TestController.delete(req, res, options));
|
|
16
|
+
return router;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const ApiRouter = TestRouter;
|
|
20
|
+
|
|
21
|
+
export { ApiRouter, TestRouter };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import validator from 'validator';
|
|
2
|
+
import { loggerFactory } from '../../server/logger.js';
|
|
3
|
+
import { TestModel } from './test.model.js';
|
|
4
|
+
import { getYouTubeID, validatePassword } from '../../client/components/core/CommonJs.js';
|
|
5
|
+
|
|
6
|
+
const logger = loggerFactory(import.meta);
|
|
7
|
+
|
|
8
|
+
const TestService = {
|
|
9
|
+
post: async (req, res, options) => {
|
|
10
|
+
switch (req.params.id) {
|
|
11
|
+
default:
|
|
12
|
+
break;
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
get: async (req, res, options) => {
|
|
16
|
+
switch (req.params.id) {
|
|
17
|
+
case 'verify-email':
|
|
18
|
+
return validator.isEmail(req.query.email);
|
|
19
|
+
case 'youtube-id':
|
|
20
|
+
return getYouTubeID(req.query.url);
|
|
21
|
+
case 'is-strong-password':
|
|
22
|
+
return validatePassword(req.query.password);
|
|
23
|
+
|
|
24
|
+
default:
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
delete: async (req, res, options) => {
|
|
28
|
+
switch (req.params.id) {
|
|
29
|
+
default:
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export { TestService };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import { faBase64Png, getBufferPngText } from '../../server/client-icons.js';
|
|
3
|
+
|
|
4
|
+
process.exit(0);
|
|
5
|
+
|
|
6
|
+
fs.writeFileSync(
|
|
7
|
+
'./tmp/api-user-invalid-token.png',
|
|
8
|
+
await getBufferPngText({ text: 'Invalid token', textColor: '#ff0000' }),
|
|
9
|
+
'utf8',
|
|
10
|
+
);
|
|
11
|
+
fs.writeFileSync(
|
|
12
|
+
'./tmp/api-user-recover.png',
|
|
13
|
+
Buffer.from(faBase64Png('rotate-left', 50, 50, '#ffffff'), 'base64'),
|
|
14
|
+
'utf8',
|
|
15
|
+
);
|
|
16
|
+
fs.writeFileSync('./tmp/api-user-check.png', Buffer.from(faBase64Png('check', 50, 50), 'base64'), 'utf8');
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { loggerFactory } from '../../server/logger.js';
|
|
2
|
+
import { UserService } from './user.service.js';
|
|
3
|
+
|
|
4
|
+
const logger = loggerFactory(import.meta);
|
|
5
|
+
|
|
6
|
+
const UserController = {
|
|
7
|
+
post: async (req, res, options) => {
|
|
8
|
+
try {
|
|
9
|
+
const result = await UserService.post(req, res, options);
|
|
10
|
+
return res.status(200).json({
|
|
11
|
+
status: 'success',
|
|
12
|
+
data: result,
|
|
13
|
+
});
|
|
14
|
+
} catch (error) {
|
|
15
|
+
logger.error(error, error.stack);
|
|
16
|
+
return res.status(400).json({
|
|
17
|
+
status: 'error',
|
|
18
|
+
message: error.message,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
get: async (req, res, options) => {
|
|
23
|
+
try {
|
|
24
|
+
const result = await UserService.get(req, res, options);
|
|
25
|
+
if (result instanceof Buffer) return res.status(200).end(result);
|
|
26
|
+
return res.status(200).json({
|
|
27
|
+
status: 'success',
|
|
28
|
+
data: result,
|
|
29
|
+
});
|
|
30
|
+
} catch (error) {
|
|
31
|
+
logger.error(error, error.stack);
|
|
32
|
+
return res.status(400).json({
|
|
33
|
+
status: 'error',
|
|
34
|
+
message: error.message,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
delete: async (req, res, options) => {
|
|
39
|
+
try {
|
|
40
|
+
const result = await UserService.delete(req, res, options);
|
|
41
|
+
return res.status(200).json({
|
|
42
|
+
status: 'success',
|
|
43
|
+
data: result,
|
|
44
|
+
});
|
|
45
|
+
} catch (error) {
|
|
46
|
+
logger.error(error, error.stack);
|
|
47
|
+
return res.status(400).json({
|
|
48
|
+
status: 'error',
|
|
49
|
+
message: error.message,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
put: async (req, res, options) => {
|
|
54
|
+
try {
|
|
55
|
+
const result = await UserService.put(req, res, options);
|
|
56
|
+
return res.status(200).json({
|
|
57
|
+
status: 'success',
|
|
58
|
+
data: result,
|
|
59
|
+
});
|
|
60
|
+
} catch (error) {
|
|
61
|
+
logger.error(error, error.stack);
|
|
62
|
+
return res.status(400).json({
|
|
63
|
+
status: 'error',
|
|
64
|
+
message: error.message,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export { UserController };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Schema, model } from 'mongoose';
|
|
2
|
+
import validator from 'validator';
|
|
3
|
+
|
|
4
|
+
// https://mongoosejs.com/docs/2.7.x/docs/schematypes.html
|
|
5
|
+
|
|
6
|
+
const userRoleEnum = ['admin', 'moderator', 'user', 'guest'];
|
|
7
|
+
|
|
8
|
+
const UserSchema = new Schema(
|
|
9
|
+
{
|
|
10
|
+
email: {
|
|
11
|
+
type: String,
|
|
12
|
+
trim: true,
|
|
13
|
+
lowercase: true,
|
|
14
|
+
unique: true,
|
|
15
|
+
required: 'Email address is required',
|
|
16
|
+
validate: [validator.isEmail, 'Please fill a valid email address'],
|
|
17
|
+
// match: [/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/, 'Please fill a valid email address'],
|
|
18
|
+
},
|
|
19
|
+
emailConfirmed: { type: Boolean, default: false },
|
|
20
|
+
recoverTimeOut: { type: Date },
|
|
21
|
+
lastLoginDate: { type: Date },
|
|
22
|
+
failedLoginAttempts: { type: Number, default: 0 },
|
|
23
|
+
password: { type: String, trim: true, required: 'Password is required' },
|
|
24
|
+
username: { type: String, trim: true, unique: true, required: 'Username is required' },
|
|
25
|
+
role: { type: String, enum: userRoleEnum, default: 'guest' },
|
|
26
|
+
profileImageId: { type: Schema.Types.ObjectId, ref: 'File' },
|
|
27
|
+
phoneNumbers: [
|
|
28
|
+
{
|
|
29
|
+
type: { type: String, enum: ['office', 'home', 'private'], number: { type: String } },
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
publicKey: {
|
|
33
|
+
type: [
|
|
34
|
+
{
|
|
35
|
+
type: Schema.Types.ObjectId,
|
|
36
|
+
ref: 'Crypto',
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
default: [],
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
timestamps: true,
|
|
44
|
+
},
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
const UserModel = model('User', UserSchema);
|
|
48
|
+
|
|
49
|
+
const ProviderSchema = UserSchema;
|
|
50
|
+
|
|
51
|
+
const UserDto = {
|
|
52
|
+
select: {
|
|
53
|
+
get: () => {
|
|
54
|
+
return { _id: 1, username: 1, email: 1, role: 1, emailConfirmed: 1, profileImageId: 1 };
|
|
55
|
+
},
|
|
56
|
+
getAll: () => {
|
|
57
|
+
return { _id: 1, name: 1 };
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
auth: {
|
|
61
|
+
payload: (user) => ({ _id: user._id.toString(), role: user.role }),
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export { UserSchema, UserModel, userRoleEnum, ProviderSchema, UserDto };
|
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
import { authMiddleware } from '../../server/auth.js';
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
|
+
import { loggerFactory } from '../../server/logger.js';
|
|
4
|
+
import { UserController } from './user.controller.js';
|
|
5
|
+
import express from 'express';
|
|
6
|
+
|
|
7
|
+
const logger = loggerFactory(import.meta);
|
|
8
|
+
|
|
9
|
+
const UserRouter = (options) => {
|
|
10
|
+
const router = express.Router();
|
|
11
|
+
|
|
12
|
+
(async () => {
|
|
13
|
+
options.png = {
|
|
14
|
+
buffer: {
|
|
15
|
+
'invalid-token': fs.readFileSync(`./src/client/public/default/assets/mailer/api-user-invalid-token.png`),
|
|
16
|
+
recover: fs.readFileSync(`./src/client/public/default/assets/mailer/api-user-recover.png`),
|
|
17
|
+
check: fs.readFileSync(`./src/client/public/default/assets/mailer/api-user-check.png`),
|
|
18
|
+
},
|
|
19
|
+
header: (res) => {
|
|
20
|
+
res.set('Content-Type', 'image/png');
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
|
|
25
|
+
router.post(`/mailer/:id`, authMiddleware, async (req, res) => {
|
|
26
|
+
/*
|
|
27
|
+
#swagger.ignore = true
|
|
28
|
+
*/
|
|
29
|
+
return await UserController.post(req, res, options);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
router.get(`/mailer/:id`, async (req, res) => {
|
|
33
|
+
/*
|
|
34
|
+
#swagger.ignore = true
|
|
35
|
+
*/
|
|
36
|
+
return await UserController.get(req, res, options);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
router.get(`/email/:email`, authMiddleware, async (req, res) => {
|
|
40
|
+
/*
|
|
41
|
+
#swagger.ignore = true
|
|
42
|
+
*/
|
|
43
|
+
return await UserController.get(req, res, options);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
router.post(`/:id`, async (req, res) => {
|
|
47
|
+
/*
|
|
48
|
+
#swagger.ignore = true
|
|
49
|
+
*/
|
|
50
|
+
return await UserController.post(req, res, options);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// #swagger.start
|
|
54
|
+
|
|
55
|
+
/*
|
|
56
|
+
#swagger.auto = false
|
|
57
|
+
#swagger.tags = ['user']
|
|
58
|
+
#swagger.summary = 'Log in'
|
|
59
|
+
#swagger.description = 'This endpoint get a JWT for authenticated user'
|
|
60
|
+
#swagger.path = '/user/auth'
|
|
61
|
+
#swagger.method = 'post'
|
|
62
|
+
#swagger.produces = ['application/json']
|
|
63
|
+
#swagger.consumes = ['application/json']
|
|
64
|
+
|
|
65
|
+
#swagger.requestBody = {
|
|
66
|
+
in: 'body',
|
|
67
|
+
description: 'User data',
|
|
68
|
+
required: true,
|
|
69
|
+
content: {
|
|
70
|
+
'application/json': {
|
|
71
|
+
schema: {
|
|
72
|
+
$ref: '#/components/schemas/userLogInRequest'
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
#swagger.responses[200] = {
|
|
79
|
+
description: 'User created successfully',
|
|
80
|
+
content: {
|
|
81
|
+
'application/json': {
|
|
82
|
+
schema: {
|
|
83
|
+
$ref: '#/components/schemas/userResponse'
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
#swagger.responses[400] = {
|
|
90
|
+
description: 'Bad request. Please check the input data',
|
|
91
|
+
content: {
|
|
92
|
+
'application/json': {
|
|
93
|
+
schema: {
|
|
94
|
+
$ref: '#/components/schemas/userBadRequestResponse'
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
*/
|
|
100
|
+
|
|
101
|
+
// #swagger.end
|
|
102
|
+
|
|
103
|
+
router.post(`/`, async (req, res) => {
|
|
104
|
+
/*
|
|
105
|
+
#swagger.auto = false
|
|
106
|
+
#swagger.tags = ['user']
|
|
107
|
+
#swagger.summary = 'Create user'
|
|
108
|
+
#swagger.description = 'This endpoint will create a new user account'
|
|
109
|
+
#swagger.path = '/user'
|
|
110
|
+
#swagger.method = 'post'
|
|
111
|
+
#swagger.produces = ['application/json']
|
|
112
|
+
#swagger.consumes = ['application/json']
|
|
113
|
+
|
|
114
|
+
#swagger.requestBody = {
|
|
115
|
+
in: 'body',
|
|
116
|
+
description: 'User data',
|
|
117
|
+
required: true,
|
|
118
|
+
content: {
|
|
119
|
+
'application/json': {
|
|
120
|
+
schema: {
|
|
121
|
+
$ref: '#/components/schemas/userRequest'
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
#swagger.responses[200] = {
|
|
128
|
+
description: 'User created successfully',
|
|
129
|
+
content: {
|
|
130
|
+
'application/json': {
|
|
131
|
+
schema: {
|
|
132
|
+
$ref: '#/components/schemas/userResponse'
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
#swagger.responses[400] = {
|
|
139
|
+
description: 'Bad request. Please check the input data',
|
|
140
|
+
content: {
|
|
141
|
+
'application/json': {
|
|
142
|
+
schema: {
|
|
143
|
+
$ref: '#/components/schemas/userBadRequestResponse'
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
*/
|
|
149
|
+
return await UserController.post(req, res, options);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
router.get(`/recover/:id`, async (req, res) => {
|
|
153
|
+
/*
|
|
154
|
+
#swagger.ignore = true
|
|
155
|
+
*/
|
|
156
|
+
return await UserController.get(req, res, options);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
router.get(`/:id`, authMiddleware, async (req, res) => {
|
|
160
|
+
/*
|
|
161
|
+
#swagger.auto = false
|
|
162
|
+
#swagger.tags = ['user']
|
|
163
|
+
#swagger.summary = 'Get user data by ID'
|
|
164
|
+
#swagger.description = 'This endpoint get user data by ID'
|
|
165
|
+
#swagger.path = '/user/{id}'
|
|
166
|
+
#swagger.method = 'get'
|
|
167
|
+
#swagger.produces = ['application/json']
|
|
168
|
+
#swagger.consumes = ['application/json']
|
|
169
|
+
#swagger.security = [{
|
|
170
|
+
'bearerAuth': []
|
|
171
|
+
}]
|
|
172
|
+
|
|
173
|
+
#swagger.parameters['id'] = {
|
|
174
|
+
in: 'path',
|
|
175
|
+
description: 'User ID',
|
|
176
|
+
required: true,
|
|
177
|
+
type: 'string'
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
#swagger.responses[200] = {
|
|
181
|
+
description: 'get user successfully',
|
|
182
|
+
content: {
|
|
183
|
+
'application/json': {
|
|
184
|
+
schema: {
|
|
185
|
+
$ref: '#/components/schemas/userGetResponse'
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
#swagger.responses[400] = {
|
|
192
|
+
description: 'Bad request. Please check the input data',
|
|
193
|
+
content: {
|
|
194
|
+
'application/json': {
|
|
195
|
+
schema: {
|
|
196
|
+
$ref: '#/components/schemas/userBadRequestResponse'
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
*/
|
|
202
|
+
return await UserController.get(req, res, options);
|
|
203
|
+
});
|
|
204
|
+
router.get(`/`, authMiddleware, async (req, res) => {
|
|
205
|
+
/*
|
|
206
|
+
#swagger.ignore = true
|
|
207
|
+
*/
|
|
208
|
+
return await UserController.get(req, res, options);
|
|
209
|
+
});
|
|
210
|
+
router.put(`/recover/:id`, async (req, res) => {
|
|
211
|
+
/*
|
|
212
|
+
#swagger.ignore = true
|
|
213
|
+
*/
|
|
214
|
+
return await UserController.put(req, res, options);
|
|
215
|
+
});
|
|
216
|
+
router.put(`/profile-image/:id`, authMiddleware, async (req, res) => {
|
|
217
|
+
/*
|
|
218
|
+
#swagger.ignore = true
|
|
219
|
+
*/
|
|
220
|
+
return await UserController.put(req, res, options);
|
|
221
|
+
});
|
|
222
|
+
router.put(`/:id`, authMiddleware, async (req, res) => {
|
|
223
|
+
/*
|
|
224
|
+
#swagger.auto = false
|
|
225
|
+
#swagger.tags = ['user']
|
|
226
|
+
#swagger.summary = 'Update user data by ID'
|
|
227
|
+
#swagger.description = 'This endpoint will update user data by ID'
|
|
228
|
+
#swagger.path = '/user/{id}'
|
|
229
|
+
#swagger.method = 'put'
|
|
230
|
+
#swagger.produces = ['application/json']
|
|
231
|
+
#swagger.consumes = ['application/json']
|
|
232
|
+
#swagger.security = [{
|
|
233
|
+
'bearerAuth': []
|
|
234
|
+
}]
|
|
235
|
+
|
|
236
|
+
#swagger.parameters['id'] = {
|
|
237
|
+
in: 'path',
|
|
238
|
+
description: 'User ID',
|
|
239
|
+
required: true,
|
|
240
|
+
type: 'string'
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
#swagger.requestBody = {
|
|
244
|
+
in: 'body',
|
|
245
|
+
description: 'User data',
|
|
246
|
+
required: true,
|
|
247
|
+
content: {
|
|
248
|
+
'application/json': {
|
|
249
|
+
schema: {
|
|
250
|
+
$ref: '#/components/schemas/userRequest'
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
#swagger.responses[200] = {
|
|
257
|
+
description: 'User updated successfully',
|
|
258
|
+
content: {
|
|
259
|
+
'application/json': {
|
|
260
|
+
schema: {
|
|
261
|
+
$ref: '#/components/schemas/userUpdateResponse'
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
#swagger.responses[400] = {
|
|
268
|
+
description: 'Bad request. Please check the input data',
|
|
269
|
+
content: {
|
|
270
|
+
'application/json': {
|
|
271
|
+
schema: {
|
|
272
|
+
$ref: '#/components/schemas/userBadRequestResponse'
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
*/
|
|
278
|
+
return await UserController.put(req, res, options);
|
|
279
|
+
});
|
|
280
|
+
router.put(`/`, authMiddleware, async (req, res) => {
|
|
281
|
+
/*
|
|
282
|
+
#swagger.ignore = true
|
|
283
|
+
*/
|
|
284
|
+
return await UserController.put(req, res, options);
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
router.delete(`/:id`, authMiddleware, async (req, res) => {
|
|
288
|
+
/*
|
|
289
|
+
#swagger.auto = false
|
|
290
|
+
#swagger.tags = ['user']
|
|
291
|
+
#swagger.summary = 'Delete user data by ID'
|
|
292
|
+
#swagger.description = 'This endpoint deletes user data by ID, the path ID must match with the ID of the authenticated user'
|
|
293
|
+
#swagger.path = '/user/{id}'
|
|
294
|
+
#swagger.method = 'delete'
|
|
295
|
+
#swagger.produces = ['application/json']
|
|
296
|
+
#swagger.consumes = ['application/json']
|
|
297
|
+
#swagger.security = [{
|
|
298
|
+
'bearerAuth': []
|
|
299
|
+
}]
|
|
300
|
+
|
|
301
|
+
#swagger.parameters['id'] = {
|
|
302
|
+
in: 'path',
|
|
303
|
+
description: 'User ID',
|
|
304
|
+
required: true,
|
|
305
|
+
type: 'string'
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
#swagger.responses[200] = {
|
|
309
|
+
description: 'get user successfully',
|
|
310
|
+
content: {
|
|
311
|
+
'application/json': {
|
|
312
|
+
schema: {
|
|
313
|
+
$ref: '#/components/schemas/userGetResponse'
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
#swagger.responses[400] = {
|
|
320
|
+
description: 'Bad request. Please check the input data',
|
|
321
|
+
content: {
|
|
322
|
+
'application/json': {
|
|
323
|
+
schema: {
|
|
324
|
+
$ref: '#/components/schemas/userBadRequestResponse'
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
*/
|
|
330
|
+
return await UserController.delete(req, res, options);
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
router.delete(`/`, authMiddleware, async (req, res) => {
|
|
334
|
+
/*
|
|
335
|
+
#swagger.ignore = true
|
|
336
|
+
*/
|
|
337
|
+
return await UserController.delete(req, res, options);
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
return router;
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
const ApiRouter = UserRouter;
|
|
344
|
+
|
|
345
|
+
export { ApiRouter, UserRouter };
|