@abtnode/webapp 1.8.63-beta-a36b5e1a → 1.8.63

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 (198) hide show
  1. package/blocklet.yml +6 -3
  2. package/build/asset-manifest.json +93 -0
  3. package/build/favicon.ico +0 -0
  4. package/build/icons/css/all.css +5919 -0
  5. package/build/icons/css/brands.css +14 -0
  6. package/build/icons/css/brands.min.css +12 -0
  7. package/build/icons/css/fontawesome.css +7816 -0
  8. package/build/icons/css/fontawesome.min.css +5864 -0
  9. package/build/icons/css/light.css +15 -0
  10. package/build/icons/css/light.min.css +13 -0
  11. package/build/icons/webfonts/fa-brands-400.eot +0 -0
  12. package/build/icons/webfonts/fa-brands-400.svg +1256 -0
  13. package/build/icons/webfonts/fa-brands-400.ttf +0 -0
  14. package/build/icons/webfonts/fa-brands-400.woff +0 -0
  15. package/build/icons/webfonts/fa-brands-400.woff2 +0 -0
  16. package/build/icons/webfonts/fa-light-300.eot +0 -0
  17. package/build/icons/webfonts/fa-light-300.svg +4445 -0
  18. package/build/icons/webfonts/fa-light-300.ttf +0 -0
  19. package/build/icons/webfonts/fa-light-300.woff +0 -0
  20. package/build/icons/webfonts/fa-light-300.woff2 +0 -0
  21. package/build/images/blocklet.png +0 -0
  22. package/build/images/blocklets-00c2c4.png +0 -0
  23. package/build/images/blocklets-222222.png +0 -0
  24. package/build/images/celebrate.png +0 -0
  25. package/build/images/community.svg +6 -0
  26. package/build/images/console-00c2c4.png +0 -0
  27. package/build/images/console-222222.png +0 -0
  28. package/build/images/dashboard-00c2c4.png +0 -0
  29. package/build/images/dashboard-222222.png +0 -0
  30. package/build/images/doc-222222.png +0 -0
  31. package/build/images/hourglass-222222.png +0 -0
  32. package/build/images/https-certificate-icon.png +0 -0
  33. package/build/images/labs-00c2c4.png +0 -0
  34. package/build/images/labs-222222.png +0 -0
  35. package/build/images/log-00c2c4.png +0 -0
  36. package/build/images/log-222222.png +0 -0
  37. package/build/images/member-222222.png +0 -0
  38. package/build/images/node.png +0 -0
  39. package/build/images/official.svg +1 -0
  40. package/build/images/private-222222.png +0 -0
  41. package/build/images/public-222222.png +0 -0
  42. package/build/images/public_avatar.png +0 -0
  43. package/build/images/router-00c2c4.png +0 -0
  44. package/build/images/router-222222.png +0 -0
  45. package/build/images/settings-00c2c4.png +0 -0
  46. package/build/images/settings-222222.png +0 -0
  47. package/build/images/slack.png +0 -0
  48. package/build/images/storage-222222.png +0 -0
  49. package/build/images/store-00c2c4.png +0 -0
  50. package/build/images/store-222222.png +0 -0
  51. package/build/images/team-00c2c4.png +0 -0
  52. package/build/images/team-222222.png +0 -0
  53. package/build/images/time-222222.png +0 -0
  54. package/build/images/upgrade.png +0 -0
  55. package/build/index.html +1 -0
  56. package/build/manifest.json +15 -0
  57. package/build/static/css/4381.5ade355d.chunk.css +1 -0
  58. package/build/static/css/4691.56c2f951.chunk.css +1 -0
  59. package/build/static/css/5245.5d6e9197.chunk.css +1 -0
  60. package/build/static/css/8213.f696fdbf.chunk.css +1 -0
  61. package/build/static/css/9779.f696fdbf.chunk.css +1 -0
  62. package/build/static/css/main.c9e90622.css +1 -0
  63. package/build/static/images/logo.png +0 -0
  64. package/build/static/js/1057.8280393f.chunk.js +1 -0
  65. package/build/static/js/1361.85e46159.chunk.js +1 -0
  66. package/build/static/js/1366.2f174c9b.chunk.js +2 -0
  67. package/build/static/js/1366.2f174c9b.chunk.js.LICENSE.txt +37 -0
  68. package/build/static/js/154.94956824.chunk.js +1 -0
  69. package/build/static/js/1826.07c285de.chunk.js +1 -0
  70. package/build/static/js/2129.120e36ae.chunk.js +1 -0
  71. package/build/static/js/2308.b65bc299.chunk.js +1 -0
  72. package/build/static/js/2564.eef717f3.chunk.js +1 -0
  73. package/build/static/js/2657.d3c62d57.chunk.js +1 -0
  74. package/build/static/js/2720.26eb1788.chunk.js +1 -0
  75. package/build/static/js/2828.4f318970.chunk.js +1 -0
  76. package/build/static/js/2878.5626558d.chunk.js +1 -0
  77. package/build/static/js/3111.84e02823.chunk.js +1 -0
  78. package/build/static/js/3476.c0b3411b.chunk.js +1 -0
  79. package/build/static/js/3633.8c7cf02d.chunk.js +1 -0
  80. package/build/static/js/3732.f5d8b39b.chunk.js +1 -0
  81. package/build/static/js/3776.1490b0f7.chunk.js +1 -0
  82. package/build/static/js/3829.b6d6cf45.chunk.js +1 -0
  83. package/build/static/js/4074.19db40ec.chunk.js +1 -0
  84. package/build/static/js/4104.b47ae0e1.chunk.js +1 -0
  85. package/build/static/js/4241.83e4f741.chunk.js +1 -0
  86. package/build/static/js/4274.e18ffddd.chunk.js +1 -0
  87. package/build/static/js/4349.7c2f6507.chunk.js +1 -0
  88. package/build/static/js/4381.631ef61d.chunk.js +2 -0
  89. package/build/static/js/4381.631ef61d.chunk.js.LICENSE.txt +22 -0
  90. package/build/static/js/4557.3907550e.chunk.js +1 -0
  91. package/build/static/js/4590.5a14012c.chunk.js +1 -0
  92. package/build/static/js/4633.9f946ed5.chunk.js +1 -0
  93. package/build/static/js/4691.550fcb40.chunk.js +2 -0
  94. package/build/static/js/4691.550fcb40.chunk.js.LICENSE.txt +8 -0
  95. package/build/static/js/5074.9ea094a9.chunk.js +1 -0
  96. package/build/static/js/5082.18d16cb9.chunk.js +1 -0
  97. package/build/static/js/519.adae6e43.chunk.js +1 -0
  98. package/build/static/js/556.381dcbd8.chunk.js +1 -0
  99. package/build/static/js/5984.25af6288.chunk.js +1 -0
  100. package/build/static/js/6158.8a43296d.chunk.js +1 -0
  101. package/build/static/js/6189.d6d74d14.chunk.js +1 -0
  102. package/build/static/js/6239.5a873a03.chunk.js +2 -0
  103. package/build/static/js/6239.5a873a03.chunk.js.LICENSE.txt +14 -0
  104. package/build/static/js/629.1a7f2553.chunk.js +1 -0
  105. package/build/static/js/6413.ab4a8e01.chunk.js +1 -0
  106. package/build/static/js/6602.c417a217.chunk.js +1 -0
  107. package/build/static/js/6780.64314507.chunk.js +1 -0
  108. package/build/static/js/6830.88b993a0.chunk.js +1 -0
  109. package/build/static/js/6866.2131ea60.chunk.js +2 -0
  110. package/build/static/js/6866.2131ea60.chunk.js.LICENSE.txt +8 -0
  111. package/build/static/js/6898.6fe0c32d.chunk.js +2 -0
  112. package/build/static/js/6898.6fe0c32d.chunk.js.LICENSE.txt +5 -0
  113. package/build/static/js/7016.835958ef.chunk.js +1 -0
  114. package/build/static/js/7298.a7286c09.chunk.js +1 -0
  115. package/build/static/js/7327.56a5e016.chunk.js +1 -0
  116. package/build/static/js/744.8b656dd2.chunk.js +1 -0
  117. package/build/static/js/7652.722b9180.chunk.js +1 -0
  118. package/build/static/js/8034.c4dcdeff.chunk.js +1 -0
  119. package/build/static/js/8058.0b2d4727.chunk.js +1 -0
  120. package/build/static/js/8213.09f25083.chunk.js +1 -0
  121. package/build/static/js/8235.add24931.chunk.js +1 -0
  122. package/build/static/js/8249.63c55b3a.chunk.js +1 -0
  123. package/build/static/js/8262.869cc799.chunk.js +1 -0
  124. package/build/static/js/8352.b57b0e44.chunk.js +1 -0
  125. package/build/static/js/8464.b4b82828.chunk.js +1 -0
  126. package/build/static/js/8606.66db67e2.chunk.js +1 -0
  127. package/build/static/js/9038.2908c176.chunk.js +1 -0
  128. package/build/static/js/9076.c77366bc.chunk.js +1 -0
  129. package/build/static/js/9301.a65db324.chunk.js +2 -0
  130. package/build/static/js/9301.a65db324.chunk.js.LICENSE.txt +8 -0
  131. package/build/static/js/9575.36f3de5b.chunk.js +2 -0
  132. package/build/static/js/9575.36f3de5b.chunk.js.LICENSE.txt +194 -0
  133. package/build/static/js/9779.bbf0dd81.chunk.js +1 -0
  134. package/build/static/js/main.cb5d8d67.js +2 -0
  135. package/build/static/js/main.cb5d8d67.js.LICENSE.txt +159 -0
  136. package/build/static/media/iconify.32b54549e843e448ee9b.cjs +2 -0
  137. package/build/static/media/iconify.32b54549e843e448ee9b.cjs.LICENSE.txt +13 -0
  138. package/build/static/media/lato-all-400-normal.3dc1eff492ab1f598560.woff +0 -0
  139. package/build/static/media/lato-all-700-normal.1e7707c9ec98d9b97e7f.woff +0 -0
  140. package/build/static/media/lato-latin-400-normal.be36596da218e1eec01c.woff2 +0 -0
  141. package/build/static/media/lato-latin-700-normal.8f28e0e1fdb195149f1c.woff2 +0 -0
  142. package/build/static/media/lato-latin-ext-400-normal.361f3dbb9db6a5980326.woff2 +0 -0
  143. package/build/static/media/lato-latin-ext-700-normal.9c8812eaec45956201e1.woff2 +0 -0
  144. package/build/static/media/logo.60f66bbe1ce9674a4df4e374c9d97fc4.svg +16 -0
  145. package/build/static/media/ubuntu-mono-all-400-normal.c879328bc62e9c68268f.woff +0 -0
  146. package/build/static/media/ubuntu-mono-cyrillic-400-normal.c367f416832eb8f1b846.woff2 +0 -0
  147. package/build/static/media/ubuntu-mono-cyrillic-ext-400-normal.eda1c4946b1f7bf58386.woff2 +0 -0
  148. package/build/static/media/ubuntu-mono-greek-400-normal.22f3bfc91f79c342bdf4.woff2 +0 -0
  149. package/build/static/media/ubuntu-mono-greek-ext-400-normal.b3459900ea8a25d1f7c2.woff2 +0 -0
  150. package/build/static/media/ubuntu-mono-latin-400-normal.18e32d9d743af28f913e.woff2 +0 -0
  151. package/build/static/media/ubuntu-mono-latin-ext-400-normal.b56e2315611d10838ad5.woff2 +0 -0
  152. package/package.json +1 -1
  153. package/api/gql/config.js +0 -392
  154. package/api/gql/index.js +0 -102
  155. package/api/gql/middlewares/create-audit-log.js +0 -3
  156. package/api/gql/middlewares/get-blocklet-list.js +0 -14
  157. package/api/gql/middlewares/install-blocklet.js +0 -13
  158. package/api/gql/middlewares/verify-blocklet.js +0 -21
  159. package/api/gql/middlewares/verify-team.js +0 -9
  160. package/api/index.js +0 -249
  161. package/api/libs/auth.js +0 -78
  162. package/api/libs/env.js +0 -3
  163. package/api/libs/login.js +0 -212
  164. package/api/libs/security.js +0 -90
  165. package/api/libs/storage.js +0 -69
  166. package/api/middlewares/mutate-blocklet-permission.js +0 -18
  167. package/api/routes/auth/accept-server.js +0 -28
  168. package/api/routes/auth/connect-owner.js +0 -143
  169. package/api/routes/auth/delegate-transfer-owner-nft.js +0 -86
  170. package/api/routes/auth/invite.js +0 -93
  171. package/api/routes/auth/issue-passport.js +0 -61
  172. package/api/routes/auth/launch-free-blocklet-by-nft.js +0 -9
  173. package/api/routes/auth/launch-free-blocklet.js +0 -9
  174. package/api/routes/auth/launch-paid-blocklet-by-nft.js +0 -9
  175. package/api/routes/auth/launch-paid-blocklet.js +0 -9
  176. package/api/routes/auth/login.js +0 -63
  177. package/api/routes/auth/lost-passport-issue.js +0 -5
  178. package/api/routes/auth/lost-passport-list.js +0 -5
  179. package/api/routes/auth/switch-passport.js +0 -47
  180. package/api/routes/auth/switch-profile.js +0 -69
  181. package/api/routes/auth/util.js +0 -135
  182. package/api/routes/auth/verify-owner.js +0 -39
  183. package/api/routes/auth/verify-purchase.js +0 -185
  184. package/api/routes/blocklet-info.js +0 -246
  185. package/api/routes/blocklet-preference.js +0 -161
  186. package/api/routes/blocklet-proxy.js +0 -220
  187. package/api/routes/did-resolver.js +0 -38
  188. package/api/routes/dns-resolver.js +0 -73
  189. package/api/routes/log.js +0 -31
  190. package/api/routes/passport.js +0 -19
  191. package/api/routes/session.js +0 -61
  192. package/api/routes/user.js +0 -38
  193. package/api/util/find-routing-rule.js +0 -95
  194. package/api/util/get-configs.js +0 -31
  195. package/api/util/index.js +0 -5
  196. package/api/util/navigation.js +0 -84
  197. package/api/webpack.blocklet.js +0 -43
  198. package/api/ws/index.js +0 -146
@@ -1,95 +0,0 @@
1
- const {
2
- DOMAIN_FOR_IP_SITE_REGEXP,
3
- DOMAIN_FOR_DEFAULT_SITE,
4
- ROUTING_RULE_TYPES,
5
- SLOT_FOR_IP_DNS_SITE,
6
- } = require('@abtnode/constant');
7
- const checkDomainMatch = require('@abtnode/util/lib/check-domain-match');
8
-
9
- const LOCALHOST = 'localhost';
10
-
11
- const findSite = (sites, req) => {
12
- const site = sites.find(x => {
13
- if (x.domain === DOMAIN_FOR_IP_SITE_REGEXP || x.domain === DOMAIN_FOR_DEFAULT_SITE) {
14
- return false;
15
- }
16
- if (checkDomainMatch(req.hostname, x.domain)) {
17
- return true;
18
- }
19
- if ((x.domainAliases || []).some(y => checkDomainMatch(req.hostname, y.value))) {
20
- return true;
21
- }
22
-
23
- const ipDomain = (x.domainAliases || []).find(y => (y.value || '').includes(SLOT_FOR_IP_DNS_SITE));
24
- if (ipDomain && ipDomain.value) {
25
- const [startWith, endWith] = ipDomain.value.split(SLOT_FOR_IP_DNS_SITE);
26
- if (req.hostname.startsWith(startWith) && req.hostname.endsWith(endWith)) {
27
- return true;
28
- }
29
- }
30
-
31
- if (x.domain.includes(SLOT_FOR_IP_DNS_SITE)) {
32
- const [startWith, endWith] = x.domain.split(SLOT_FOR_IP_DNS_SITE);
33
- if (req.hostname.startsWith(startWith) && req.hostname.endsWith(endWith)) {
34
- return true;
35
- }
36
- }
37
- return false;
38
- });
39
- if (site) {
40
- return site;
41
- }
42
-
43
- const dashboardSite = sites.find(x => {
44
- if (x.domain === DOMAIN_FOR_IP_SITE_REGEXP) {
45
- if (req.hostname === LOCALHOST) {
46
- return true;
47
- }
48
- // eslint-disable-next-line prefer-regex-literals
49
- if (new RegExp('^\\d+.\\d+.\\d+.\\d+$').test(req.hostname)) {
50
- return true;
51
- }
52
- }
53
- return (x.domainAliases || []).some(y => checkDomainMatch(req.hostname, y.value));
54
- });
55
- if (dashboardSite) {
56
- return dashboardSite;
57
- }
58
-
59
- const defaultSite = sites.find(x => x.domain === DOMAIN_FOR_DEFAULT_SITE);
60
- const mergeDashboardSite = sites.find(x => x.domain === DOMAIN_FOR_IP_SITE_REGEXP);
61
- if (defaultSite) {
62
- const x = Object.assign({}, defaultSite);
63
- if (mergeDashboardSite) {
64
- x.rules = [...x.rules, ...mergeDashboardSite.rules];
65
- }
66
- return x;
67
- }
68
-
69
- return null;
70
- };
71
-
72
- module.exports = function findRoutingRule(sites, req, urlPrefix = '') {
73
- if (!req || !req.hostname || !req.headers || !req.headers.referer) {
74
- return null;
75
- }
76
-
77
- const site = findSite(sites, req);
78
-
79
- if (!site) {
80
- return null;
81
- }
82
-
83
- const rules = (site.rules || [])
84
- .filter(x => x.to.type === ROUTING_RULE_TYPES.BLOCKLET)
85
- .sort((a, b) => (a.from.pathPrefix.length > b.from.pathPrefix.length ? -1 : 1));
86
-
87
- const refererPath = new URL(req.headers.referer).pathname;
88
-
89
- // return root blocklet's rule (usually last in sorted rules) for favicon
90
- if (req.url.startsWith(`${urlPrefix}/favicon`)) {
91
- return rules[rules.length - 1];
92
- }
93
-
94
- return rules.find(x => refererPath.startsWith(x.from.pathPrefix.replace(/\/+$/, '')));
95
- };
@@ -1,31 +0,0 @@
1
- const { forEachBlockletSync, getSharedConfigObj, isEnvShareable } = require('@blocklet/meta/lib/util');
2
-
3
- /**
4
- * Get configs of root blocklet or child blocklet
5
- * @param {*} blocklet
6
- * @param {*} componentId
7
- * @returns
8
- */
9
- module.exports = (blocklet, componentId) => {
10
- let res = {};
11
- forEachBlockletSync(blocklet, (component, { id, ancestors }) => {
12
- if (id !== componentId) {
13
- return;
14
- }
15
-
16
- const configs = component.configs.filter(x => isEnvShareable(x));
17
- const configObj = configs.reduce((o, x) => {
18
- o[x.key] = x.value;
19
- return o;
20
- }, {});
21
-
22
- const sharedObj = getSharedConfigObj(component, ancestors);
23
- for (const [key, value] of Object.entries(sharedObj)) {
24
- configObj[key] = value;
25
- }
26
-
27
- res = configObj;
28
- });
29
-
30
- return Object.entries(res).map(([key, value]) => ({ key, value }));
31
- };
package/api/util/index.js DELETED
@@ -1,5 +0,0 @@
1
- const joinUrl = require('url-join');
2
-
3
- const getBlockletUrl = (registryUrl, did) => joinUrl(registryUrl, `/api/blocklets/${did}/blocklet.json`);
4
-
5
- module.exports = { getBlockletUrl };
@@ -1,84 +0,0 @@
1
- const { WELLKNOWN_SERVICE_PATH_PREFIX } = require('@abtnode/constant');
2
-
3
- const fillDashboardNavigation = navigation => {
4
- if (!navigation.some(x => x.id === '/access')) {
5
- navigation.push({
6
- id: '/access',
7
- from: 'tmpl',
8
- title: {
9
- en: 'Access',
10
- zh: '访问控制',
11
- },
12
- role: ['owner', 'admin', 'member'],
13
- section: ['dashboard'],
14
- link: '',
15
- items: [
16
- {
17
- id: 'member',
18
- from: 'tmpl',
19
- title: {
20
- en: 'Members',
21
- zh: '成员',
22
- },
23
- icon: 'ant-design:user-outlined',
24
- link: `${WELLKNOWN_SERVICE_PATH_PREFIX}/admin/members`,
25
- },
26
- {
27
- id: 'passport',
28
- from: 'tmpl',
29
- title: {
30
- en: 'Passport',
31
- zh: '通行证',
32
- },
33
- icon: 'icon-park-outline:passport',
34
- link: `${WELLKNOWN_SERVICE_PATH_PREFIX}/admin/passports`,
35
- },
36
- ],
37
- });
38
- }
39
-
40
- if (!navigation.some(x => x.id === '/dashboard')) {
41
- navigation.push({
42
- id: '/dashboard',
43
- from: 'tmpl',
44
- title: 'Blocklet',
45
- role: ['owner', 'admin'],
46
- section: ['dashboard'],
47
- link: '',
48
- items: [
49
- {
50
- id: 'dashboard',
51
- from: 'tmpl',
52
- title: {
53
- en: 'Dashboard',
54
- zh: '仪表盘',
55
- },
56
- icon: 'ant-design:dashboard-outlined',
57
- link: `${WELLKNOWN_SERVICE_PATH_PREFIX}/admin`,
58
- },
59
- ],
60
- });
61
- }
62
- };
63
-
64
- const ensureSessionManagerNavigation = navigation => {
65
- if (!navigation.some(x => (x.section || []).includes('sessionManager'))) {
66
- navigation.push({
67
- id: '/sessionManager',
68
- from: 'tmpl',
69
- title: {
70
- en: 'Manage',
71
- zh: '管理',
72
- },
73
- section: ['sessionManager'],
74
- icon: 'ion:settings-outline',
75
- link: `${WELLKNOWN_SERVICE_PATH_PREFIX}/admin`,
76
- role: ['owner', 'admin'],
77
- });
78
- }
79
- };
80
-
81
- module.exports = {
82
- fillDashboardNavigation,
83
- ensureSessionManagerNavigation,
84
- };
@@ -1,43 +0,0 @@
1
- const fs = require('fs');
2
- // eslint-disable-next-line import/no-extraneous-dependencies
3
- const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
4
-
5
- const env = process.env.NODE_ENV || 'development';
6
-
7
- const extraPlugins = [];
8
- if (process.env.ANALYZE_BUNDLE) {
9
- extraPlugins.push(new BundleAnalyzerPlugin({ analyzerMode: 'static' }));
10
- }
11
-
12
- const extraAliases = {};
13
- if (process.env.NODE_ENV === 'production') {
14
- const targetPath = require.resolve('express-graphql/renderGraphiQL');
15
- const sourcePath = require.resolve('@abtnode/mocks/lib/graphiql');
16
- fs.unlinkSync(targetPath);
17
- fs.copyFileSync(sourcePath, targetPath);
18
- }
19
-
20
- module.exports = webpack => ({
21
- optimization: {
22
- nodeEnv: env, // @link https://github.com/webpack/webpack/issues/7470#issuecomment-394259698
23
- },
24
- resolve: {
25
- alias: {
26
- axios: require.resolve('axios'),
27
- debug: require.resolve('debug'),
28
- jspdf: require.resolve('@abtnode/mocks/lib/jspdf'),
29
- isobject: require.resolve('@abtnode/mocks/lib/isobject'),
30
- 'vue-template-compiler': require.resolve('@abtnode/mocks/lib/vue-template-compiler'),
31
- 'bn.js': require.resolve('bn.js'),
32
- 'mime-db': require.resolve('mime-db'),
33
- ...extraAliases,
34
- },
35
- },
36
- plugins: [
37
- new webpack.DefinePlugin({
38
- 'process.env.NODE_ENV': JSON.stringify(env),
39
- 'process.env.TEST_BUILD': JSON.stringify(process.env.TEST_BUILD),
40
- }),
41
- ...extraPlugins,
42
- ],
43
- });
package/api/ws/index.js DELETED
@@ -1,146 +0,0 @@
1
- const { WsServer } = require('@arcblock/ws');
2
- const { types } = require('@ocap/mcrypto');
3
- const { fromSecretKey, WalletType } = require('@ocap/wallet');
4
-
5
- const { BlockletEvents } = require('@blocklet/constant');
6
- const { EVENTS } = require('@abtnode/constant');
7
- const { createStreamLogManager, getLogFiles } = require('@abtnode/util/lib/log');
8
-
9
- // eslint-disable-next-line global-require
10
- const logger = require('@abtnode/logger')(`${require('../../package.json').name}:ws`);
11
-
12
- const { authWithJwt } = require('../libs/login');
13
-
14
- logger.debug = () => null;
15
-
16
- module.exports = function createWebsocketServer(node) {
17
- const wsServer = new WsServer({
18
- logger,
19
- pathname: '/websocket',
20
- authenticate: (req, cb) => {
21
- const { searchParams } = new URL(req.url, `http://${req.headers.host || 'unknown'}`);
22
- const token = searchParams.get('token');
23
- const timestamp = searchParams.get('timestamp');
24
- if (!token) {
25
- cb(new Error('token not found'), null);
26
- return;
27
- }
28
-
29
- // Authentication CLI: who knows the SK of the node
30
- if (token && timestamp) {
31
- node.getNodeInfo().then(info => {
32
- const wallet = fromSecretKey(
33
- info.sk,
34
- WalletType({
35
- role: types.RoleType.ROLE_APPLICATION,
36
- pk: types.KeyType.ED25519,
37
- hash: types.HashType.SHA3,
38
- })
39
- );
40
-
41
- if (wallet.verify(timestamp, token)) {
42
- cb(null, { did: info.did });
43
- } else {
44
- cb(new Error('Signature is invalid'), null);
45
- }
46
- });
47
- } else {
48
- // Authentication web users
49
- authWithJwt(token, node)
50
- .then(user => {
51
- cb(null, { did: user.did });
52
- })
53
- .catch(() => {
54
- cb(new Error('token parse fail'), null);
55
- });
56
- }
57
- },
58
- hooks: {
59
- receiveMessage: ({ socket, topic, event, payload }) => {
60
- wsServer.emit(`${topic}/${event}`, { socket, topic, event, payload });
61
- logger.info('client pushed socket message', { topic, event });
62
- },
63
- },
64
- });
65
-
66
- // Publish CLI generated events to web dashboard clients
67
- const onCLIEvent = ({ event, payload }) => {
68
- if (event) {
69
- if (Object.values(BlockletEvents).includes(event) && typeof node.handleBlockletEvent === 'function') {
70
- node.handleBlockletEvent(event, payload);
71
- return;
72
- }
73
-
74
- if ([EVENTS.NODE_STARTED, EVENTS.NODE_STOPPED].includes(event) && typeof node.handleServerEvent === 'function') {
75
- node.handleServerEvent(event, payload);
76
- return;
77
- }
78
-
79
- wsServer.broadcast(event, payload);
80
- }
81
- };
82
- wsServer.on('cli/blocklet.installed', onCLIEvent);
83
- wsServer.on('cli/blocklet.upgraded', onCLIEvent);
84
- wsServer.on('cli/blocklet.statusChange', onCLIEvent);
85
- wsServer.on('cli/blocklet.started', onCLIEvent);
86
- wsServer.on('cli/blocklet.removed', onCLIEvent);
87
- wsServer.on('cli/blocklet.updated', onCLIEvent);
88
- wsServer.on('cli/routing.updated', onCLIEvent);
89
- wsServer.on('cli/node.stopped', onCLIEvent);
90
- wsServer.on('cli/node.started', onCLIEvent);
91
- wsServer.on('cli/node.upgrading', onCLIEvent);
92
-
93
- const streamLogManager = createStreamLogManager({
94
- onGetLogFiles: name => getLogFiles({ name, node }),
95
- onLog: ({ topic, level, logFiles, data }) => {
96
- wsServer.broadcast(topic, topic, { level, logFiles, data }, { enableLog: false });
97
- },
98
- });
99
-
100
- const onChannelEvent = async (eventName, { socket, topic }) => {
101
- const [type, ...names] = topic.split('.');
102
- if (type === 'log') {
103
- const name = names.join('.');
104
- if (eventName === 'channel.join') {
105
- streamLogManager.add(name, topic, (level, data, logFiles) => {
106
- wsServer.send(socket, topic, topic, { level, data, logFiles }, { enableLog: false });
107
- });
108
- }
109
-
110
- if (eventName === 'channel.destroy') {
111
- streamLogManager.destroy(name);
112
- }
113
- }
114
-
115
- if (topic === EVENTS.NODE_RUNTIME_INFO) {
116
- if (eventName === 'channel.join') {
117
- const info = node.getNodeRuntimeInfo();
118
- wsServer.send(socket, topic, topic, info, { enableLog: false });
119
- }
120
- }
121
- };
122
-
123
- ['channel.join', 'channel.leave', 'channel.destroy'].forEach(name => {
124
- wsServer.on(name, payload => onChannelEvent(name, payload));
125
- });
126
-
127
- node.setEventHandler(({ name, data }) => {
128
- if (name === BlockletEvents.removed) {
129
- // remove blocklet log stream
130
- try {
131
- const { did } = data.meta;
132
- const logName = `blocklet-${did}`;
133
- logger.info('destroy blocklet log stream', { name: logName });
134
- streamLogManager.destroy(logName);
135
- } catch (error) {
136
- logger.error('destroy blocklet log stream error', { error });
137
- }
138
- }
139
-
140
- if (name) {
141
- wsServer.broadcast(name, data);
142
- }
143
- });
144
-
145
- return wsServer;
146
- };