@underpostnet/underpost 2.7.82

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (290) hide show
  1. package/.dockerignore +14 -0
  2. package/.env.development +6 -0
  3. package/.env.production +6 -0
  4. package/.env.test +6 -0
  5. package/.github/workflows/ghpkg.yml +75 -0
  6. package/.github/workflows/publish.yml +84 -0
  7. package/.github/workflows/pwa-microservices-template.test.yml +30 -0
  8. package/.nycrc +9 -0
  9. package/.prettierignore +13 -0
  10. package/.prettierrc +9 -0
  11. package/.vscode/extensions.json +72 -0
  12. package/.vscode/settings.json +100 -0
  13. package/AUTHORS.md +10 -0
  14. package/CHANGELOG.md +37 -0
  15. package/Dockerfile +90 -0
  16. package/LICENSE +21 -0
  17. package/README.md +96 -0
  18. package/bin/db.js +172 -0
  19. package/bin/deploy.js +674 -0
  20. package/bin/file.js +93 -0
  21. package/bin/index.js +82 -0
  22. package/bin/ssl.js +55 -0
  23. package/bin/util.js +182 -0
  24. package/bin/vs.js +35 -0
  25. package/conf.js +251 -0
  26. package/docker-compose.yml +67 -0
  27. package/jsconfig.json +7 -0
  28. package/jsdoc.json +32 -0
  29. package/nodemon.json +6 -0
  30. package/package.json +134 -0
  31. package/prometheus.yml +36 -0
  32. package/src/api/core/core.controller.js +69 -0
  33. package/src/api/core/core.model.js +11 -0
  34. package/src/api/core/core.router.js +23 -0
  35. package/src/api/core/core.service.js +29 -0
  36. package/src/api/crypto/crypto.controller.js +51 -0
  37. package/src/api/crypto/crypto.model.js +23 -0
  38. package/src/api/crypto/crypto.router.js +20 -0
  39. package/src/api/crypto/crypto.service.js +64 -0
  40. package/src/api/default/default.controller.js +69 -0
  41. package/src/api/default/default.model.js +20 -0
  42. package/src/api/default/default.router.js +23 -0
  43. package/src/api/default/default.service.js +31 -0
  44. package/src/api/file/file.controller.js +53 -0
  45. package/src/api/file/file.model.js +19 -0
  46. package/src/api/file/file.router.js +21 -0
  47. package/src/api/file/file.service.js +80 -0
  48. package/src/api/instance/instance.controller.js +69 -0
  49. package/src/api/instance/instance.model.js +36 -0
  50. package/src/api/instance/instance.router.js +33 -0
  51. package/src/api/instance/instance.service.js +48 -0
  52. package/src/api/test/test.controller.js +59 -0
  53. package/src/api/test/test.model.js +14 -0
  54. package/src/api/test/test.router.js +21 -0
  55. package/src/api/test/test.service.js +35 -0
  56. package/src/api/user/user.build.js +16 -0
  57. package/src/api/user/user.controller.js +70 -0
  58. package/src/api/user/user.model.js +65 -0
  59. package/src/api/user/user.router.js +345 -0
  60. package/src/api/user/user.service.js +479 -0
  61. package/src/api.js +23 -0
  62. package/src/client/Default.index.js +40 -0
  63. package/src/client/components/core/Account.js +290 -0
  64. package/src/client/components/core/AgGrid.js +160 -0
  65. package/src/client/components/core/Auth.js +19 -0
  66. package/src/client/components/core/Badge.js +32 -0
  67. package/src/client/components/core/Blockchain.js +41 -0
  68. package/src/client/components/core/Blog.js +9 -0
  69. package/src/client/components/core/BtnIcon.js +101 -0
  70. package/src/client/components/core/CalendarCore.js +458 -0
  71. package/src/client/components/core/Chat.js +64 -0
  72. package/src/client/components/core/ColorPalette.js +5267 -0
  73. package/src/client/components/core/CommonJs.js +742 -0
  74. package/src/client/components/core/Content.js +193 -0
  75. package/src/client/components/core/Css.js +846 -0
  76. package/src/client/components/core/CssCore.js +817 -0
  77. package/src/client/components/core/D3Chart.js +44 -0
  78. package/src/client/components/core/Docs.js +231 -0
  79. package/src/client/components/core/DropDown.js +164 -0
  80. package/src/client/components/core/EventsUI.js +46 -0
  81. package/src/client/components/core/FileExplorer.js +699 -0
  82. package/src/client/components/core/FullScreen.js +45 -0
  83. package/src/client/components/core/Input.js +346 -0
  84. package/src/client/components/core/JoyStick.js +77 -0
  85. package/src/client/components/core/Keyboard.js +73 -0
  86. package/src/client/components/core/LoadingAnimation.js +178 -0
  87. package/src/client/components/core/LogIn.js +187 -0
  88. package/src/client/components/core/LogOut.js +58 -0
  89. package/src/client/components/core/Logger.js +26 -0
  90. package/src/client/components/core/Modal.js +1612 -0
  91. package/src/client/components/core/NotificationManager.js +84 -0
  92. package/src/client/components/core/Panel.js +613 -0
  93. package/src/client/components/core/PanelForm.js +468 -0
  94. package/src/client/components/core/Polyhedron.js +162 -0
  95. package/src/client/components/core/Recover.js +204 -0
  96. package/src/client/components/core/Responsive.js +53 -0
  97. package/src/client/components/core/RichText.js +51 -0
  98. package/src/client/components/core/Router.js +76 -0
  99. package/src/client/components/core/Scroll.js +34 -0
  100. package/src/client/components/core/SignUp.js +125 -0
  101. package/src/client/components/core/SocketIo.js +72 -0
  102. package/src/client/components/core/Stream.js +113 -0
  103. package/src/client/components/core/ToggleSwitch.js +87 -0
  104. package/src/client/components/core/ToolTip.js +26 -0
  105. package/src/client/components/core/Translate.js +446 -0
  106. package/src/client/components/core/Validator.js +100 -0
  107. package/src/client/components/core/VanillaJs.js +463 -0
  108. package/src/client/components/core/Wallet.js +106 -0
  109. package/src/client/components/core/Webhook.js +25 -0
  110. package/src/client/components/core/Worker.js +282 -0
  111. package/src/client/components/default/CommonDefault.js +29 -0
  112. package/src/client/components/default/CssDefault.js +13 -0
  113. package/src/client/components/default/ElementsDefault.js +38 -0
  114. package/src/client/components/default/LogInDefault.js +41 -0
  115. package/src/client/components/default/LogOutDefault.js +28 -0
  116. package/src/client/components/default/MenuDefault.js +389 -0
  117. package/src/client/components/default/RoutesDefault.js +48 -0
  118. package/src/client/components/default/SettingsDefault.js +16 -0
  119. package/src/client/components/default/SignUpDefault.js +9 -0
  120. package/src/client/components/default/SocketIoDefault.js +54 -0
  121. package/src/client/components/default/TranslateDefault.js +7 -0
  122. package/src/client/public/default/android-chrome-144x144.png +0 -0
  123. package/src/client/public/default/android-chrome-192x192.png +0 -0
  124. package/src/client/public/default/android-chrome-256x256.png +0 -0
  125. package/src/client/public/default/android-chrome-36x36.png +0 -0
  126. package/src/client/public/default/android-chrome-384x384.png +0 -0
  127. package/src/client/public/default/android-chrome-48x48.png +0 -0
  128. package/src/client/public/default/android-chrome-512x512.png +0 -0
  129. package/src/client/public/default/android-chrome-72x72.png +0 -0
  130. package/src/client/public/default/android-chrome-96x96.png +0 -0
  131. package/src/client/public/default/apple-touch-icon-1024x1024.png +0 -0
  132. package/src/client/public/default/apple-touch-icon-114x114.png +0 -0
  133. package/src/client/public/default/apple-touch-icon-120x120.png +0 -0
  134. package/src/client/public/default/apple-touch-icon-144x144.png +0 -0
  135. package/src/client/public/default/apple-touch-icon-152x152.png +0 -0
  136. package/src/client/public/default/apple-touch-icon-167x167.png +0 -0
  137. package/src/client/public/default/apple-touch-icon-180x180.png +0 -0
  138. package/src/client/public/default/apple-touch-icon-57x57.png +0 -0
  139. package/src/client/public/default/apple-touch-icon-60x60.png +0 -0
  140. package/src/client/public/default/apple-touch-icon-72x72.png +0 -0
  141. package/src/client/public/default/apple-touch-icon-76x76.png +0 -0
  142. package/src/client/public/default/apple-touch-icon-precomposed.png +0 -0
  143. package/src/client/public/default/apple-touch-icon.png +0 -0
  144. package/src/client/public/default/apple-touch-startup-image-1125x2436.png +0 -0
  145. package/src/client/public/default/apple-touch-startup-image-1136x640.png +0 -0
  146. package/src/client/public/default/apple-touch-startup-image-1170x2532.png +0 -0
  147. package/src/client/public/default/apple-touch-startup-image-1179x2556.png +0 -0
  148. package/src/client/public/default/apple-touch-startup-image-1242x2208.png +0 -0
  149. package/src/client/public/default/apple-touch-startup-image-1242x2688.png +0 -0
  150. package/src/client/public/default/apple-touch-startup-image-1284x2778.png +0 -0
  151. package/src/client/public/default/apple-touch-startup-image-1290x2796.png +0 -0
  152. package/src/client/public/default/apple-touch-startup-image-1334x750.png +0 -0
  153. package/src/client/public/default/apple-touch-startup-image-1488x2266.png +0 -0
  154. package/src/client/public/default/apple-touch-startup-image-1536x2048.png +0 -0
  155. package/src/client/public/default/apple-touch-startup-image-1620x2160.png +0 -0
  156. package/src/client/public/default/apple-touch-startup-image-1640x2160.png +0 -0
  157. package/src/client/public/default/apple-touch-startup-image-1668x2224.png +0 -0
  158. package/src/client/public/default/apple-touch-startup-image-1668x2388.png +0 -0
  159. package/src/client/public/default/apple-touch-startup-image-1792x828.png +0 -0
  160. package/src/client/public/default/apple-touch-startup-image-2048x1536.png +0 -0
  161. package/src/client/public/default/apple-touch-startup-image-2048x2732.png +0 -0
  162. package/src/client/public/default/apple-touch-startup-image-2160x1620.png +0 -0
  163. package/src/client/public/default/apple-touch-startup-image-2160x1640.png +0 -0
  164. package/src/client/public/default/apple-touch-startup-image-2208x1242.png +0 -0
  165. package/src/client/public/default/apple-touch-startup-image-2224x1668.png +0 -0
  166. package/src/client/public/default/apple-touch-startup-image-2266x1488.png +0 -0
  167. package/src/client/public/default/apple-touch-startup-image-2388x1668.png +0 -0
  168. package/src/client/public/default/apple-touch-startup-image-2436x1125.png +0 -0
  169. package/src/client/public/default/apple-touch-startup-image-2532x1170.png +0 -0
  170. package/src/client/public/default/apple-touch-startup-image-2556x1179.png +0 -0
  171. package/src/client/public/default/apple-touch-startup-image-2688x1242.png +0 -0
  172. package/src/client/public/default/apple-touch-startup-image-2732x2048.png +0 -0
  173. package/src/client/public/default/apple-touch-startup-image-2778x1284.png +0 -0
  174. package/src/client/public/default/apple-touch-startup-image-2796x1290.png +0 -0
  175. package/src/client/public/default/apple-touch-startup-image-640x1136.png +0 -0
  176. package/src/client/public/default/apple-touch-startup-image-750x1334.png +0 -0
  177. package/src/client/public/default/apple-touch-startup-image-828x1792.png +0 -0
  178. package/src/client/public/default/assets/background/white.jpg +0 -0
  179. package/src/client/public/default/assets/background/white0-min.jpg +0 -0
  180. package/src/client/public/default/assets/background/white0.jpg +0 -0
  181. package/src/client/public/default/assets/logo/base-icon.png +0 -0
  182. package/src/client/public/default/assets/mailer/api-user-check.png +0 -0
  183. package/src/client/public/default/assets/mailer/api-user-invalid-token.png +0 -0
  184. package/src/client/public/default/assets/mailer/api-user-recover.png +0 -0
  185. package/src/client/public/default/browserconfig.xml +12 -0
  186. package/src/client/public/default/favicon-16x16.png +0 -0
  187. package/src/client/public/default/favicon-32x32.png +0 -0
  188. package/src/client/public/default/favicon-48x48.png +0 -0
  189. package/src/client/public/default/favicon.ico +0 -0
  190. package/src/client/public/default/manifest.webmanifest +69 -0
  191. package/src/client/public/default/mstile-144x144.png +0 -0
  192. package/src/client/public/default/mstile-150x150.png +0 -0
  193. package/src/client/public/default/mstile-310x150.png +0 -0
  194. package/src/client/public/default/mstile-310x310.png +0 -0
  195. package/src/client/public/default/mstile-70x70.png +0 -0
  196. package/src/client/public/default/plantuml/client-conf.svg +1 -0
  197. package/src/client/public/default/plantuml/client-schema.svg +1 -0
  198. package/src/client/public/default/plantuml/cron-conf.svg +1 -0
  199. package/src/client/public/default/plantuml/cron-schema.svg +1 -0
  200. package/src/client/public/default/plantuml/server-conf.svg +1 -0
  201. package/src/client/public/default/plantuml/server-schema.svg +1 -0
  202. package/src/client/public/default/plantuml/ssr-conf.svg +1 -0
  203. package/src/client/public/default/plantuml/ssr-schema.svg +1 -0
  204. package/src/client/public/default/sitemap +148 -0
  205. package/src/client/public/default/yandex-browser-50x50.png +0 -0
  206. package/src/client/public/default/yandex-browser-manifest.json +9 -0
  207. package/src/client/public/doc/favicon.ico +0 -0
  208. package/src/client/public/doc/sitemap +148 -0
  209. package/src/client/public/test/favicon.ico +0 -0
  210. package/src/client/public/test/sitemap +148 -0
  211. package/src/client/services/core/core.service.js +170 -0
  212. package/src/client/services/crypto/crypto.service.js +70 -0
  213. package/src/client/services/default/default.management.js +343 -0
  214. package/src/client/services/default/default.service.js +89 -0
  215. package/src/client/services/file/file.service.js +70 -0
  216. package/src/client/services/instance/instance.management.js +74 -0
  217. package/src/client/services/instance/instance.service.js +89 -0
  218. package/src/client/services/test/test.service.js +70 -0
  219. package/src/client/services/user/user.management.js +50 -0
  220. package/src/client/services/user/user.service.js +89 -0
  221. package/src/client/ssr/Render.js +237 -0
  222. package/src/client/ssr/common/Alert.js +75 -0
  223. package/src/client/ssr/common/SsrCore.js +91 -0
  224. package/src/client/ssr/common/Translate.js +26 -0
  225. package/src/client/ssr/common/Worker.js +28 -0
  226. package/src/client/ssr/components/body/CacheControl.js +114 -0
  227. package/src/client/ssr/components/body/DefaultSplashScreen.js +90 -0
  228. package/src/client/ssr/components/email/DefaultRecoverEmail.js +21 -0
  229. package/src/client/ssr/components/email/DefaultVerifyEmail.js +17 -0
  230. package/src/client/ssr/components/head/Css.js +241 -0
  231. package/src/client/ssr/components/head/DefaultScripts.js +3 -0
  232. package/src/client/ssr/components/head/PwaDefault.js +60 -0
  233. package/src/client/ssr/offline/default.index.js +31 -0
  234. package/src/client/ssr/pages/404.js +12 -0
  235. package/src/client/ssr/pages/500.js +12 -0
  236. package/src/client/sw/default.sw.js +203 -0
  237. package/src/client/sw/template.sw.js +84 -0
  238. package/src/client.build.js +22 -0
  239. package/src/client.dev.js +21 -0
  240. package/src/cron.js +30 -0
  241. package/src/db/DataBaseProvider.js +34 -0
  242. package/src/db/mariadb/MariaDB.js +33 -0
  243. package/src/db/mongo/MongooseDB.js +125 -0
  244. package/src/dns.js +22 -0
  245. package/src/index.js +43 -0
  246. package/src/mailer/EmailRender.js +69 -0
  247. package/src/mailer/MailerProvider.js +96 -0
  248. package/src/proxy.js +22 -0
  249. package/src/runtime/lampp/Lampp.js +115 -0
  250. package/src/runtime/nginx/Nginx.js +3 -0
  251. package/src/runtime/xampp/Xampp.js +49 -0
  252. package/src/server/auth.js +235 -0
  253. package/src/server/backup.js +108 -0
  254. package/src/server/client-build-live.js +98 -0
  255. package/src/server/client-build.js +821 -0
  256. package/src/server/client-dev-server.js +60 -0
  257. package/src/server/client-formatted.js +58 -0
  258. package/src/server/client-icons.js +151 -0
  259. package/src/server/conf.js +883 -0
  260. package/src/server/cron.js +35 -0
  261. package/src/server/dns.js +89 -0
  262. package/src/server/downloader.js +42 -0
  263. package/src/server/logger.js +190 -0
  264. package/src/server/network.js +122 -0
  265. package/src/server/peer.js +33 -0
  266. package/src/server/process.js +66 -0
  267. package/src/server/prompt-optimizer.js +28 -0
  268. package/src/server/proxy.js +118 -0
  269. package/src/server/runtime.js +461 -0
  270. package/src/server/ssl.js +120 -0
  271. package/src/server.js +25 -0
  272. package/src/ws/IoInterface.js +45 -0
  273. package/src/ws/IoServer.js +39 -0
  274. package/src/ws/core/channels/core.ws.chat.js +23 -0
  275. package/src/ws/core/channels/core.ws.mailer.js +35 -0
  276. package/src/ws/core/channels/core.ws.stream.js +31 -0
  277. package/src/ws/core/core.ws.connection.js +28 -0
  278. package/src/ws/core/core.ws.emit.js +14 -0
  279. package/src/ws/core/core.ws.server.js +24 -0
  280. package/src/ws/core/management/core.ws.chat.js +8 -0
  281. package/src/ws/core/management/core.ws.mailer.js +16 -0
  282. package/src/ws/core/management/core.ws.stream.js +8 -0
  283. package/src/ws/default/channels/default.ws.main.js +16 -0
  284. package/src/ws/default/default.ws.connection.js +22 -0
  285. package/src/ws/default/default.ws.emit.js +14 -0
  286. package/src/ws/default/default.ws.server.js +20 -0
  287. package/src/ws/default/management/default.ws.main.js +8 -0
  288. package/startup.js +11 -0
  289. package/supervisord-openssh-server.conf +5 -0
  290. package/test/api.test.js +60 -0
@@ -0,0 +1,60 @@
1
+ import fs from 'fs-extra';
2
+ import nodemon from 'nodemon';
3
+ import { shellExec } from './process.js';
4
+ import { loggerFactory } from './logger.js';
5
+
6
+ const logger = loggerFactory(import.meta);
7
+
8
+ const createClientDevServer = () => {
9
+ // process.argv.slice(2).join(' ')
10
+ shellExec(`env-cmd -f .env.development node bin/deploy build-full-client ${process.argv.slice(2).join(' ')} l`);
11
+ shellExec(
12
+ `env-cmd -f .env.development node src/api ${process.argv[2]}${process.argv[5] ? ` ${process.argv[5]}` : ''}${
13
+ process.argv.includes('static') ? ' static' : ''
14
+ }`,
15
+ { async: true },
16
+ );
17
+
18
+ // https://github.com/remy/nodemon/blob/main/doc/events.md
19
+
20
+ // States
21
+ // start - child process has started
22
+ // crash - child process has crashed (nodemon will not emit exit)
23
+ // exit - child process has cleanly exited (ie. no crash)
24
+ // restart([ array of files triggering the restart ]) - child process has restarted
25
+ // config:update - nodemon's config has changed
26
+
27
+ if (fs.existsSync(`./tmp/client.build.json`)) fs.removeSync(`./tmp/client.build.json`);
28
+
29
+ let buildPathScope = [];
30
+
31
+ const nodemonOptions = { script: './src/client.build', args: process.argv.slice(2), watch: 'src/client' };
32
+ logger.info('nodemon option', { nodemonOptions });
33
+ nodemon(nodemonOptions)
34
+ .on('start', function (...args) {
35
+ logger.info(args, 'nodemon started');
36
+ })
37
+ .on('restart', function (...args) {
38
+ logger.info(args, 'nodemon restart');
39
+ const eventPath = args[0][0];
40
+ const indexPath = buildPathScope.findIndex((buildObjScope) => buildObjScope.path === eventPath);
41
+ const buildObj = {
42
+ timestamp: new Date().getTime(),
43
+ path: eventPath,
44
+ };
45
+ if (indexPath > -1) {
46
+ buildPathScope[indexPath].timestamp = buildObj.timestamp;
47
+ } else buildPathScope.push(buildObj);
48
+ setTimeout(() => {
49
+ buildPathScope = buildPathScope.filter((buildObjScope) => buildObjScope.timestamp !== buildObj.timestamp);
50
+ }, 2500);
51
+ const buildPathScopeBuild = buildPathScope.map((o) => o.path);
52
+ logger.info('buildPathScopeBuild', buildPathScopeBuild);
53
+ fs.writeFileSync(`./tmp/client.build.json`, JSON.stringify(buildPathScopeBuild, null, 4));
54
+ })
55
+ .on('crash', function (error) {
56
+ logger.error(error, error.message);
57
+ });
58
+ };
59
+
60
+ export { createClientDevServer };
@@ -0,0 +1,58 @@
1
+ 'use strict';
2
+
3
+ import fs from 'fs-extra';
4
+
5
+ const srcFormatted = (src) =>
6
+ src
7
+ .replaceAll(' html`', '`')
8
+ .replaceAll(' css`', '`')
9
+ .replaceAll('{html`', '{`')
10
+ .replaceAll('{css`', '{`')
11
+ .replaceAll('(html`', '(`')
12
+ .replaceAll('(css`', '(`')
13
+ .replaceAll('[html`', '[`')
14
+ .replaceAll('[css`', '[`');
15
+
16
+ const JSONweb = (data) => 'JSON.parse(`' + JSON.stringify(data) + '`)';
17
+
18
+ const componentFormatted = (src, module, dists, proxyPath, componentBasePath = '', baseHost = '') => {
19
+ dists.map(
20
+ (dist) =>
21
+ (src = src.replaceAll(
22
+ `from '${dist.import_name}'`,
23
+ `from '${baseHost}${proxyPath !== '/' ? `${proxyPath}` : ''}${dist.import_name_build}'`,
24
+ )),
25
+ );
26
+ return src
27
+ .replaceAll(
28
+ `from '../`,
29
+ `from '${baseHost}${proxyPath !== '/' ? `${proxyPath}/` : '/'}${
30
+ componentBasePath === '' ? `` : `${componentBasePath}/`
31
+ }`,
32
+ )
33
+ .replaceAll(
34
+ `from './`,
35
+ `from '${baseHost}${proxyPath !== '/' ? `${proxyPath}/` : '/'}${
36
+ componentBasePath === '' ? `` : `${componentBasePath}/`
37
+ }${module}/`,
38
+ );
39
+ };
40
+
41
+ const viewFormatted = (src, dists, proxyPath, baseHost = '') => {
42
+ dists.map(
43
+ (dist) =>
44
+ (src = src.replaceAll(dist.import_name, `${proxyPath !== '/' ? `${proxyPath}` : ''}${dist.import_name_build}`)),
45
+ );
46
+ const componentFromFormatted = `from '${baseHost}${proxyPath !== '/' ? `${proxyPath}/` : '/'}`;
47
+ return src.replaceAll(`from './`, componentFromFormatted).replaceAll(`from '../`, componentFromFormatted);
48
+ };
49
+
50
+ const ssrFactory = async (componentPath = '', jsSsrCommonComponents) => {
51
+ let SrrComponent = () => {};
52
+ let render = await srcFormatted(fs.readFileSync(componentPath, 'utf8'));
53
+ if (render.split('/*imports*/')[1]) render = render.split('/*imports*/')[1];
54
+ eval(jsSsrCommonComponents + render);
55
+ return SrrComponent;
56
+ };
57
+
58
+ export { srcFormatted, JSONweb, componentFormatted, viewFormatted, ssrFactory };
@@ -0,0 +1,151 @@
1
+ import { favicons } from 'favicons';
2
+ // TODO: search alternatives
3
+ // import textToImage from 'text-to-image';
4
+ import { loggerFactory } from './logger.js';
5
+ import fs from 'fs-extra';
6
+ import { png3x } from 'font-awesome-assets';
7
+ import { getCapVariableName, s4 } from '../client/components/core/CommonJs.js';
8
+
9
+ const logger = loggerFactory(import.meta);
10
+
11
+ const faBase64Png = (faId = 'check', width = 100, height = 100, color = '#209e00') => {
12
+ const b64Src = png3x(faId, color, width, height);
13
+ return b64Src.split('src="data:image/png;base64,')[1].split('"')[0];
14
+ };
15
+
16
+ const defaultBaseTextImgOptions = {
17
+ debug: true,
18
+ fontFamily: 'Arial',
19
+ fontWeight: 'bold',
20
+ bgColor: 'black',
21
+ textColor: 'white',
22
+ debugFilename: 'src/client/public/text-image.png',
23
+ verticalAlign: 'center',
24
+ textAlign: 'center',
25
+ };
26
+
27
+ const defaultBaseTextImgOptionsSizes = {
28
+ '70x70': {
29
+ maxWidth: 70,
30
+ customHeight: 70,
31
+ fontSize: 25,
32
+ margin: 10,
33
+ },
34
+ '100x100': {
35
+ maxWidth: 100,
36
+ customHeight: 100,
37
+ fontSize: 30,
38
+ margin: 12,
39
+ },
40
+ '100x300': {
41
+ maxWidth: 300,
42
+ customHeight: 100,
43
+ fontSize: 30,
44
+ margin: 12,
45
+ },
46
+ '1200x1200': {
47
+ maxWidth: 1200,
48
+ customHeight: 1200,
49
+ fontSize: 500,
50
+ margin: 50,
51
+ },
52
+ };
53
+
54
+ const buildTextImg = async (text = 'APP', options, size = '1200x1200') => {
55
+ options = { ...defaultBaseTextImgOptions, ...defaultBaseTextImgOptionsSizes[size], ...options };
56
+ // await textToImage.generate(text, options);
57
+ };
58
+
59
+ const getBufferPngText = async ({ text, textColor, bgColor, size, debugFilename }) => {
60
+ if (!text) text = 'Hello World!';
61
+ if (!textColor) textColor = '#000000';
62
+ if (!bgColor) bgColor = '#ffffff';
63
+ if (!size) size = '100x300';
64
+ if (!debugFilename) debugFilename = `./${s4()}${s4()}${s4()}.png`;
65
+ await buildTextImg(text, { textColor, bgColor, size, debugFilename }, size);
66
+ if (!fs.existsSync(debugFilename)) return Buffer.alloc(0); // Return empty buffer if file not found
67
+ const bufferImage = fs.readFileSync(debugFilename);
68
+ fs.removeSync(debugFilename);
69
+ return bufferImage;
70
+ };
71
+
72
+ const buildIcons = async ({
73
+ publicClientId,
74
+ metadata: { title, description, keywords, author, thumbnail, themeColor },
75
+ }) => {
76
+ const source = `src/client/public/${publicClientId}/assets/logo/base-icon.png`; // Source image(s). `string`, `buffer` or array of `string`
77
+
78
+ const configuration = {
79
+ path: '/', // Path for overriding default icons path. `string`
80
+ appName: title ? title : null, // Your application's name. `string`
81
+ appShortName: title ? title : null, // Your application's short_name. `string`. Optional. If not set, appName will be used
82
+ appDescription: description ? description : null, // Your application's description. `string`
83
+ developerName: author ? author : null, // Your (or your developer's) name. `string`
84
+ developerURL: author ? author : null, // Your (or your developer's) URL. `string`
85
+ cacheBustingQueryParam: null, // Query parameter added to all URLs that acts as a cache busting system. `string | null`
86
+ dir: 'auto', // Primary text direction for name, short_name, and description
87
+ lang: 'en-US', // Primary language for name and short_name
88
+ background: themeColor ? themeColor : '#fff', // Background colour for flattened icons. `string`
89
+ theme_color: themeColor ? themeColor : '#fff', // Theme color user for example in Android's task switcher. `string`
90
+ appleStatusBarStyle: 'black-translucent', // Style for Apple status bar: "black-translucent", "default", "black". `string`
91
+ display: 'standalone', // Preferred display mode: "fullscreen", "standalone", "minimal-ui" or "browser". `string`
92
+ orientation: 'any', // Default orientation: "any", "natural", "portrait" or "landscape". `string`
93
+ scope: '/', // set of URLs that the browser considers within your app
94
+ start_url: '/?homescreen=1', // Start URL when launching the application from a device. `string`
95
+ preferRelatedApplications: false, // Should the browser prompt the user to install the native companion app. `boolean`
96
+ relatedApplications: undefined, // Information about the native companion apps. This will only be used if `preferRelatedApplications` is `true`. `Array<{ id: string, url: string, platform: string }>`
97
+ version: '1.0', // Your application's version string. `string`
98
+ pixel_art: false, // Keeps pixels "sharp" when scaling up, for pixel art. Only supported in offline mode.
99
+ loadManifestWithCredentials: true, // Browsers don't send cookies when fetching a manifest, enable this to fix that. `boolean`
100
+ manifestMaskable: true, // Maskable source image(s) for manifest.json. "true" to use default source. More information at https://web.dev/maskable-icon/. `boolean`, `string`, `buffer` or array of `string`
101
+ icons: {
102
+ // Platform Options:
103
+ // - offset - offset in percentage
104
+ // - background:
105
+ // * false - use default
106
+ // * true - force use default, e.g. set background for Android icons
107
+ // * color - set background for the specified icons
108
+ //
109
+ android: true, // Create Android homescreen icon. `boolean` or `{ offset, background }` or an array of sources
110
+ appleIcon: true, // Create Apple touch icons. `boolean` or `{ offset, background }` or an array of sources
111
+ appleStartup: true, // Create Apple startup images. `boolean` or `{ offset, background }` or an array of sources
112
+ favicons: true, // Create regular favicons. `boolean` or `{ offset, background }` or an array of sources
113
+ windows: true, // Create Windows 8 tile icons. `boolean` or `{ offset, background }` or an array of sources
114
+ yandex: true, // Create Yandex browser icon. `boolean` or `{ offset, background }` or an array of sources
115
+ },
116
+ shortcuts: [
117
+ // Your applications's Shortcuts (see: https://developer.mozilla.org/docs/Web/Manifest/shortcuts)
118
+ // Array of shortcut objects:
119
+ // {
120
+ // name: 'View your Inbox', // The name of the shortcut. `string`
121
+ // short_name: 'inbox', // optionally, falls back to name. `string`
122
+ // description: 'View your inbox messages', // optionally, not used in any implemention yet. `string`
123
+ // url: '/inbox', // The URL this shortcut should lead to. `string`
124
+ // icon: 'test/inbox_shortcut.png', // source image(s) for that shortcut. `string`, `buffer` or array of `string`
125
+ // },
126
+ // more shortcuts objects
127
+ ],
128
+ };
129
+
130
+ try {
131
+ const response = await favicons(source, configuration);
132
+
133
+ // console.log(response.images); // Array of { name: string, contents: <buffer> }
134
+ // console.log(response.files); // Array of { name: string, contents: <string> }
135
+ // console.log(response.html); // Array of strings (html elements)
136
+
137
+ for (const image of response.images)
138
+ fs.writeFileSync(`./src/client/public/${publicClientId}/${image.name}`, image.contents);
139
+
140
+ for (const file of response.files)
141
+ fs.writeFileSync(`./src/client/public/${publicClientId}/${file.name}`, file.contents, 'utf8');
142
+
143
+ const ssrPath = `./src/client/ssr/components/head/Pwa${getCapVariableName(publicClientId)}.js`;
144
+ if (!fs.existsSync(ssrPath))
145
+ fs.writeFileSync(ssrPath, 'SrrComponent = () => html`' + response.html.join(`\n`) + '`;', 'utf8');
146
+ } catch (error) {
147
+ logger.error(error.message); // Error description e.g. "An unknown error has occurred"
148
+ }
149
+ };
150
+
151
+ export { buildIcons, buildTextImg, defaultBaseTextImgOptions, faBase64Png, getBufferPngText };