@abtnode/blocklet-services 1.6.31 → 1.7.2
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/api/index.js +27 -15
- package/api/libs/auth.js +1 -1
- package/api/libs/jwt.js +4 -4
- package/api/middlewares/check-running.js +6 -2
- package/api/middlewares/proxy-to-daemon.js +42 -0
- package/api/routes/blocklet.js +101 -0
- package/api/routes/dns-resolver.js +39 -0
- package/api/routes/env.js +15 -5
- package/api/services/auth/connect/invite.js +4 -4
- package/api/services/auth/connect/login.js +68 -45
- package/api/services/auth/connect/setup.js +102 -0
- package/api/services/auth/index.js +21 -11
- package/api/services/notification/index.js +15 -19
- package/api/services/static.js +6 -26
- package/api/state/message.js +1 -1
- package/api/util/attach-shared-utils.js +21 -10
- package/api/util/get-dynamic-service-config.js +22 -0
- package/api/util/index.js +6 -2
- package/build/asset-manifest.json +34 -29
- package/build/index.html +1 -1
- package/build/precache-manifest.fc03dfbbf370fcf983cbef3f121b7584.js +186 -0
- package/build/service-worker.js +1 -1
- package/build/static/css/4.634341e0.chunk.css +2 -0
- package/build/static/css/4.634341e0.chunk.css.map +1 -0
- package/build/static/js/0.b6b3b23c.chunk.js +3 -0
- package/build/static/js/{3.94781068.chunk.js.LICENSE.txt → 0.b6b3b23c.chunk.js.LICENSE.txt} +0 -0
- package/build/static/js/0.b6b3b23c.chunk.js.map +1 -0
- package/build/static/js/1.0e83f63d.chunk.js +2 -0
- package/build/static/js/1.0e83f63d.chunk.js.map +1 -0
- package/build/static/js/10.4199ec3c.chunk.js +2 -0
- package/build/static/js/10.4199ec3c.chunk.js.map +1 -0
- package/build/static/js/4.0046a465.chunk.js +3 -0
- package/build/static/js/{2.ce8b1e12.chunk.js.LICENSE.txt → 4.0046a465.chunk.js.LICENSE.txt} +0 -9
- package/build/static/js/4.0046a465.chunk.js.map +1 -0
- package/build/static/js/5.4304d38f.chunk.js +2 -0
- package/build/static/js/5.4304d38f.chunk.js.map +1 -0
- package/build/static/js/6.08043dea.chunk.js +2 -0
- package/build/static/js/6.08043dea.chunk.js.map +1 -0
- package/build/static/js/7.165c3091.chunk.js +2 -0
- package/build/static/js/7.165c3091.chunk.js.map +1 -0
- package/build/static/js/8.49993466.chunk.js +2 -0
- package/build/static/js/8.49993466.chunk.js.map +1 -0
- package/build/static/js/9.69df4f05.chunk.js +2 -0
- package/build/static/js/9.69df4f05.chunk.js.map +1 -0
- package/build/static/js/main.af31d0af.chunk.js +2 -0
- package/build/static/js/main.af31d0af.chunk.js.map +1 -0
- package/build/static/js/runtime-main.aa0aaf4a.js +2 -0
- package/build/static/js/runtime-main.aa0aaf4a.js.map +1 -0
- package/build/static/media/lato-all-400-normal.a82dcb33.woff +0 -0
- package/build/static/media/lato-all-700-normal.8190ee0e.woff +0 -0
- package/build/static/media/lato-latin-400-normal.e1b3b590.woff2 +0 -0
- package/build/static/media/lato-latin-700-normal.de69cf9e.woff2 +0 -0
- package/build/static/media/lato-latin-ext-400-normal.4bde07f9.woff2 +0 -0
- package/build/static/media/lato-latin-ext-700-normal.a48b0f04.woff2 +0 -0
- package/build/static/media/rubik-cyrillic-400-normal.49f3ce37.woff2 +0 -0
- package/build/static/media/rubik-cyrillic-500-normal.0c1bd2ab.woff2 +0 -0
- package/build/static/media/rubik-cyrillic-600-normal.b76031ea.woff2 +0 -0
- package/build/static/media/rubik-cyrillic-ext-400-normal.d3902986.woff2 +0 -0
- package/build/static/media/rubik-cyrillic-ext-500-normal.7e493ee0.woff2 +0 -0
- package/build/static/media/rubik-cyrillic-ext-600-normal.f4b6c519.woff2 +0 -0
- package/build/static/media/rubik-hebrew-400-normal.0ebef856.woff2 +0 -0
- package/build/static/media/rubik-hebrew-500-normal.3664f2b5.woff2 +0 -0
- package/build/static/media/rubik-hebrew-600-normal.6207349a.woff2 +0 -0
- package/build/static/media/rubik-latin-400-normal.b836d2ed.woff2 +0 -0
- package/build/static/media/rubik-latin-500-normal.18984747.woff2 +0 -0
- package/build/static/media/rubik-latin-600-normal.b1216018.woff2 +0 -0
- package/build/static/media/rubik-latin-ext-400-normal.69a88832.woff2 +0 -0
- package/build/static/media/rubik-latin-ext-500-normal.21b63491.woff2 +0 -0
- package/build/static/media/rubik-latin-ext-600-normal.d0d90e83.woff2 +0 -0
- package/package.json +27 -22
- package/build/precache-manifest.73830a6f1727b9b71b878f92fe982c03.js +0 -154
- package/build/static/css/2.d49e994f.chunk.css +0 -2
- package/build/static/css/2.d49e994f.chunk.css.map +0 -1
- package/build/static/js/2.ce8b1e12.chunk.js +0 -3
- package/build/static/js/2.ce8b1e12.chunk.js.map +0 -1
- package/build/static/js/3.94781068.chunk.js +0 -3
- package/build/static/js/3.94781068.chunk.js.map +0 -1
- package/build/static/js/4.7ef421eb.chunk.js +0 -2
- package/build/static/js/4.7ef421eb.chunk.js.map +0 -1
- package/build/static/js/5.b556eada.chunk.js +0 -2
- package/build/static/js/5.b556eada.chunk.js.map +0 -1
- package/build/static/js/6.0c90a989.chunk.js +0 -2
- package/build/static/js/6.0c90a989.chunk.js.map +0 -1
- package/build/static/js/7.f511e135.chunk.js +0 -2
- package/build/static/js/7.f511e135.chunk.js.map +0 -1
- package/build/static/js/8.ea4e4666.chunk.js +0 -2
- package/build/static/js/8.ea4e4666.chunk.js.map +0 -1
- package/build/static/js/main.874efc69.chunk.js +0 -2
- package/build/static/js/main.874efc69.chunk.js.map +0 -1
- package/build/static/js/runtime-main.c4acdd90.js +0 -2
- package/build/static/js/runtime-main.c4acdd90.js.map +0 -1
- package/build/static/media/rubik-cyrillic-400-normal.aa383bbd.woff2 +0 -0
- package/build/static/media/rubik-cyrillic-500-normal.27a1ebd4.woff2 +0 -0
- package/build/static/media/rubik-cyrillic-600-normal.74d5cdba.woff2 +0 -0
- package/build/static/media/rubik-cyrillic-ext-400-normal.b8647475.woff2 +0 -0
- package/build/static/media/rubik-cyrillic-ext-500-normal.860932d9.woff2 +0 -0
- package/build/static/media/rubik-cyrillic-ext-600-normal.942f240f.woff2 +0 -0
- package/build/static/media/rubik-hebrew-400-normal.2c9e3c2a.woff2 +0 -0
- package/build/static/media/rubik-hebrew-500-normal.08d6e502.woff2 +0 -0
- package/build/static/media/rubik-hebrew-600-normal.bfa32e44.woff2 +0 -0
- package/build/static/media/rubik-latin-400-normal.b8fd53c5.woff2 +0 -0
- package/build/static/media/rubik-latin-500-normal.595f1a98.woff2 +0 -0
- package/build/static/media/rubik-latin-600-normal.5f06934f.woff2 +0 -0
- package/build/static/media/rubik-latin-ext-400-normal.3c5c378e.woff2 +0 -0
- package/build/static/media/rubik-latin-ext-500-normal.5663c731.woff2 +0 -0
- package/build/static/media/rubik-latin-ext-600-normal.ff159cb8.woff2 +0 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/* eslint-disable arrow-parens */
|
|
2
|
+
const { messages } = require('@abtnode/auth/lib/auth');
|
|
3
|
+
const logger = require('@abtnode/logger')(require('../../../../package.json').name);
|
|
4
|
+
|
|
5
|
+
const checkOwner = async ({ node, userDid, blocklet }) => {
|
|
6
|
+
const teamDid = blocklet.meta.did;
|
|
7
|
+
|
|
8
|
+
const count = await node.getUsersCount({ teamDid });
|
|
9
|
+
if (count > 1) {
|
|
10
|
+
logger.error(`The number of members should be at most 1, got ${count}`, {
|
|
11
|
+
name: blocklet.meta.name,
|
|
12
|
+
did: blocklet.meta.did,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const user = await node.getUser({ teamDid, user: { did: userDid } });
|
|
17
|
+
|
|
18
|
+
if (count === 1 && !user) {
|
|
19
|
+
throw new Error('You are not owner of the application');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return user;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
module.exports = function createRoutes(node, _authenticator, createSessionToken) {
|
|
26
|
+
return {
|
|
27
|
+
action: 'setup',
|
|
28
|
+
onConnect: async ({ req, userDid }) => {
|
|
29
|
+
const blocklet = await req.getBlocklet();
|
|
30
|
+
|
|
31
|
+
const claims = {
|
|
32
|
+
profile: async ({ extraParams }) => {
|
|
33
|
+
const { locale } = extraParams;
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
fields: ['fullName', 'avatar'],
|
|
37
|
+
description: messages.description[locale],
|
|
38
|
+
};
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
await checkOwner({ node, userDid, blocklet });
|
|
43
|
+
|
|
44
|
+
return claims;
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
// eslint-disable-next-line consistent-return
|
|
48
|
+
onAuth: async ({ claims, userDid, userPk, token, storage, extraParams, req, baseUrl }) => {
|
|
49
|
+
const { locale } = extraParams;
|
|
50
|
+
const blocklet = await req.getBlocklet();
|
|
51
|
+
const teamDid = blocklet.meta.did;
|
|
52
|
+
|
|
53
|
+
const user = await checkOwner({ node, userDid, blocklet });
|
|
54
|
+
|
|
55
|
+
try {
|
|
56
|
+
if (user) {
|
|
57
|
+
// Update user
|
|
58
|
+
await node.updateUser({
|
|
59
|
+
teamDid,
|
|
60
|
+
user: {
|
|
61
|
+
did: userDid,
|
|
62
|
+
pk: userPk,
|
|
63
|
+
approved: true,
|
|
64
|
+
locale,
|
|
65
|
+
lastLoginAt: new Date().toISOString(),
|
|
66
|
+
extra: {
|
|
67
|
+
baseUrl,
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
} else {
|
|
72
|
+
// Create user
|
|
73
|
+
const profile = claims.find((x) => x.type === 'profile');
|
|
74
|
+
await node.addUser({
|
|
75
|
+
teamDid,
|
|
76
|
+
user: {
|
|
77
|
+
...profile,
|
|
78
|
+
did: userDid,
|
|
79
|
+
pk: userPk,
|
|
80
|
+
approved: true,
|
|
81
|
+
locale,
|
|
82
|
+
passports: [],
|
|
83
|
+
firstLoginAt: new Date().toISOString(),
|
|
84
|
+
lastLoginAt: new Date().toISOString(),
|
|
85
|
+
extra: {
|
|
86
|
+
baseUrl,
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Generate new session token that client can save to localStorage
|
|
93
|
+
const sessionToken = await createSessionToken(userDid, { role: 'owner' });
|
|
94
|
+
await storage.update(token, { did: userDid, sessionToken });
|
|
95
|
+
logger.info('setup.connect.success', { userDid });
|
|
96
|
+
} catch (err) {
|
|
97
|
+
logger.error('setup.connect.error', { error: err, userDid });
|
|
98
|
+
throw new Error(err.message);
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
};
|
|
@@ -4,7 +4,7 @@ const minimatch = require('minimatch');
|
|
|
4
4
|
const bearerToken = require('express-bearer-token');
|
|
5
5
|
|
|
6
6
|
const validators = require('@blocklet/sdk/lib/validators');
|
|
7
|
-
const { genPermissionName, NODE_SERVICES } = require('@abtnode/constant');
|
|
7
|
+
const { genPermissionName, NODE_SERVICES, WHO_CAN_ACCESS, ROLES } = require('@abtnode/constant');
|
|
8
8
|
const { BLOCKLET_MODES } = require('@blocklet/meta/lib/constants');
|
|
9
9
|
const { setUserInfoHeaders } = require('@abtnode/auth/lib/auth');
|
|
10
10
|
|
|
@@ -16,6 +16,7 @@ const createInviteRoutes = require('./connect/invite');
|
|
|
16
16
|
const createIssuePassportAuth = require('./connect/issue-passport');
|
|
17
17
|
const createLostPassportListAuth = require('./connect/lost-passport-list');
|
|
18
18
|
const createLostPassportIssueAuth = require('./connect/lost-passport-issue');
|
|
19
|
+
const createSetupAuth = require('./connect/setup');
|
|
19
20
|
const createSessionRoutes = require('./session');
|
|
20
21
|
const createPassportRoutes = require('./passport');
|
|
21
22
|
const { getRedirectUrl } = require('../../util');
|
|
@@ -28,7 +29,7 @@ const init = ({ node, options }) => {
|
|
|
28
29
|
try {
|
|
29
30
|
if (token) {
|
|
30
31
|
const teamDid = req.getBlockletDid();
|
|
31
|
-
const result = await
|
|
32
|
+
const result = await verifySessionToken(token, teamDid);
|
|
32
33
|
req.user = result;
|
|
33
34
|
}
|
|
34
35
|
} catch {
|
|
@@ -52,6 +53,14 @@ const init = ({ node, options }) => {
|
|
|
52
53
|
return {};
|
|
53
54
|
}
|
|
54
55
|
|
|
56
|
+
if ([WHO_CAN_ACCESS.OWNER, WHO_CAN_ACCESS.INVITED].includes(config.whoCanAccess) && !req.user) {
|
|
57
|
+
return { blocked: true, authenticated: false };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (config.whoCanAccess === WHO_CAN_ACCESS.OWNER && req.user && req.user.role !== ROLES.OWNER) {
|
|
61
|
+
return { blocked: true, authenticated: true, authorized: false };
|
|
62
|
+
}
|
|
63
|
+
|
|
55
64
|
if (config.blockUnauthenticated === false) {
|
|
56
65
|
return {};
|
|
57
66
|
}
|
|
@@ -80,7 +89,7 @@ const init = ({ node, options }) => {
|
|
|
80
89
|
return {};
|
|
81
90
|
};
|
|
82
91
|
|
|
83
|
-
const {
|
|
92
|
+
const { createSessionToken, verifySessionToken } = initJwt(node, options);
|
|
84
93
|
const { authenticator, handlers } = initAuth(node, options);
|
|
85
94
|
|
|
86
95
|
const middlewares = {};
|
|
@@ -88,13 +97,13 @@ const init = ({ node, options }) => {
|
|
|
88
97
|
|
|
89
98
|
// auth middleware for http request
|
|
90
99
|
middlewares.bearerToken = bearerToken({
|
|
91
|
-
queryKey: options.
|
|
92
|
-
bodyKey: options.
|
|
100
|
+
queryKey: options.sessionTokenKey,
|
|
101
|
+
bodyKey: options.sessionTokenKey,
|
|
93
102
|
headerKey: 'Bearer',
|
|
94
103
|
cookie: {
|
|
95
104
|
signed: true,
|
|
96
105
|
secret: options.sessionSecret,
|
|
97
|
-
key: options.
|
|
106
|
+
key: options.sessionTokenKey,
|
|
98
107
|
},
|
|
99
108
|
});
|
|
100
109
|
|
|
@@ -111,11 +120,12 @@ const init = ({ node, options }) => {
|
|
|
111
120
|
// did-auth api
|
|
112
121
|
routes.attachDidAuthHandlers = (app) => {
|
|
113
122
|
handlers.forEach((handler) => {
|
|
114
|
-
handler.attach(Object.assign({ app }, createLoginRoutes(node, authenticator,
|
|
115
|
-
handler.attach(Object.assign({ app }, createInviteRoutes(node, authenticator,
|
|
116
|
-
handler.attach(Object.assign({ app }, createIssuePassportAuth(node, authenticator,
|
|
117
|
-
handler.attach(Object.assign({ app }, createLostPassportListAuth(node, authenticator,
|
|
118
|
-
handler.attach(Object.assign({ app }, createLostPassportIssueAuth(node, authenticator,
|
|
123
|
+
handler.attach(Object.assign({ app }, createLoginRoutes(node, authenticator, createSessionToken)));
|
|
124
|
+
handler.attach(Object.assign({ app }, createInviteRoutes(node, authenticator, createSessionToken)));
|
|
125
|
+
handler.attach(Object.assign({ app }, createIssuePassportAuth(node, authenticator, createSessionToken)));
|
|
126
|
+
handler.attach(Object.assign({ app }, createLostPassportListAuth(node, authenticator, createSessionToken)));
|
|
127
|
+
handler.attach(Object.assign({ app }, createLostPassportIssueAuth(node, authenticator, createSessionToken)));
|
|
128
|
+
handler.attach(Object.assign({ app }, createSetupAuth(node, authenticator, createSessionToken)));
|
|
119
129
|
});
|
|
120
130
|
};
|
|
121
131
|
|
|
@@ -51,7 +51,8 @@ const authenticate = (req, cb) => {
|
|
|
51
51
|
* @returns
|
|
52
52
|
*/
|
|
53
53
|
const onSendToUser = async (node, payload, wsServer) => {
|
|
54
|
-
const { sender, receiver, notification } = payload;
|
|
54
|
+
const { sender, receiver, notification, options } = payload;
|
|
55
|
+
const { keepForOfflineUser = true } = options || {};
|
|
55
56
|
|
|
56
57
|
await validateReceiver(receiver);
|
|
57
58
|
|
|
@@ -108,24 +109,18 @@ const onSendToUser = async (node, payload, wsServer) => {
|
|
|
108
109
|
const EVENT_NAME = 'message';
|
|
109
110
|
const createTask = async (did, data) => {
|
|
110
111
|
try {
|
|
111
|
-
await new Promise((resolve
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
logger.info('Online client for the user was not found', { userDid: did });
|
|
116
|
-
reject(new Error('Online client for the user was not found'));
|
|
117
|
-
} else {
|
|
118
|
-
resolve();
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
} catch (error) {
|
|
122
|
-
logger.error('Failed on broadcast message', { error });
|
|
123
|
-
reject(error);
|
|
124
|
-
}
|
|
112
|
+
const count = await new Promise((resolve) => {
|
|
113
|
+
wsServer.broadcast(did, EVENT_NAME, data, ({ count: c } = {}) => {
|
|
114
|
+
resolve(c);
|
|
115
|
+
});
|
|
125
116
|
});
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
117
|
+
|
|
118
|
+
if (count <= 0 && keepForOfflineUser) {
|
|
119
|
+
logger.info('Online client was not found', { userDid: did });
|
|
120
|
+
await states.message.insert({ did, event: EVENT_NAME, data });
|
|
121
|
+
}
|
|
122
|
+
} catch (error) {
|
|
123
|
+
logger.error('Failed on broadcast message', { error });
|
|
129
124
|
}
|
|
130
125
|
};
|
|
131
126
|
|
|
@@ -176,7 +171,7 @@ const receiveMessage = async ({ topic, event, payload, wsServer, node }) => {
|
|
|
176
171
|
// FIXME: use node.getBlocklet() when support index by appID
|
|
177
172
|
const blocklet = await node.getBlocklet({ did: receiver.did, attachConfig: false });
|
|
178
173
|
if (!blocklet) {
|
|
179
|
-
throw new Error(
|
|
174
|
+
throw new Error(`App is not installed in the server. receiver: ${receiver.did}`);
|
|
180
175
|
}
|
|
181
176
|
|
|
182
177
|
logger.info('send message to blocklet', { sender: topic, receiver });
|
|
@@ -261,6 +256,7 @@ const init = ({ node }) => {
|
|
|
261
256
|
app.post(`${prefix}/api/sendToUser`, sendToUser);
|
|
262
257
|
});
|
|
263
258
|
},
|
|
259
|
+
exec: (data) => onSendToUser(node, data, wsServer),
|
|
264
260
|
},
|
|
265
261
|
attach: (wsRouter) => {
|
|
266
262
|
PREFIXES.forEach((prefix) => {
|
package/api/services/static.js
CHANGED
|
@@ -11,19 +11,9 @@ const devDir = path.resolve(__dirname, '../../public');
|
|
|
11
11
|
const attachUtils = ({ req, res, proxy }) => {
|
|
12
12
|
res.sendWebPage = () => {
|
|
13
13
|
if (isFeDevelopment) {
|
|
14
|
-
proxy.
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
{
|
|
18
|
-
target: `http://127.0.0.1:${process.env.ABT_NODE_SERVICE_FE_PORT}`,
|
|
19
|
-
},
|
|
20
|
-
(error) => {
|
|
21
|
-
if (error) {
|
|
22
|
-
console.error(error);
|
|
23
|
-
res.status(502).send(error.message);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
);
|
|
14
|
+
proxy.safeWeb(req, res, {
|
|
15
|
+
target: `http://127.0.0.1:${process.env.ABT_NODE_SERVICE_FE_PORT}`,
|
|
16
|
+
});
|
|
27
17
|
} else {
|
|
28
18
|
res.sendFile(path.join(distDir, 'index.html'));
|
|
29
19
|
}
|
|
@@ -41,19 +31,9 @@ const attachUtils = ({ req, res, proxy }) => {
|
|
|
41
31
|
const attachStaticResources = ({ app, proxy }) => {
|
|
42
32
|
if (isFeDevelopment) {
|
|
43
33
|
app.use('/static', (req, res) => {
|
|
44
|
-
proxy.
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
{
|
|
48
|
-
target: `http://127.0.0.1:${process.env.ABT_NODE_SERVICE_FE_PORT}/static`,
|
|
49
|
-
},
|
|
50
|
-
(error) => {
|
|
51
|
-
if (error) {
|
|
52
|
-
console.error(error);
|
|
53
|
-
res.status(502).send(error.message);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
);
|
|
34
|
+
proxy.safeWeb(req, res, {
|
|
35
|
+
target: `http://127.0.0.1:${process.env.ABT_NODE_SERVICE_FE_PORT}/static`,
|
|
36
|
+
});
|
|
57
37
|
});
|
|
58
38
|
} else {
|
|
59
39
|
app.use(`${WELLKNOWN_SERVICE_PATH_PREFIX}/static`, serveStatic(distDir, { index: false }));
|
package/api/state/message.js
CHANGED
|
@@ -6,6 +6,7 @@ const logger = require('@abtnode/logger')(require('../../package.json').name);
|
|
|
6
6
|
const cache = require('../cache');
|
|
7
7
|
|
|
8
8
|
const formatContext = require('./format-context');
|
|
9
|
+
const getDynamicServiceConfig = require('./get-dynamic-service-config');
|
|
9
10
|
|
|
10
11
|
module.exports = ({ node, req, options }) => {
|
|
11
12
|
req.getBlockletUrl = () => req.headers['x-blocklet-url'] || get(options, 'blockletUrl', '');
|
|
@@ -70,12 +71,17 @@ module.exports = ({ node, req, options }) => {
|
|
|
70
71
|
return defaultConfig;
|
|
71
72
|
}
|
|
72
73
|
|
|
74
|
+
const dynamicConfig = getDynamicServiceConfig(serviceName, blocklet);
|
|
75
|
+
|
|
76
|
+
const defaultConfigWithDynamic = { ...defaultConfig, ...dynamicConfig };
|
|
77
|
+
|
|
73
78
|
const realDid = req.getBlockletRealDid();
|
|
74
79
|
if (realDid && blocklet.meta.did !== realDid) {
|
|
75
80
|
blocklet = (blocklet.children || []).find((x) => x.meta.did === realDid);
|
|
76
81
|
}
|
|
82
|
+
|
|
77
83
|
if (!blocklet) {
|
|
78
|
-
return
|
|
84
|
+
return defaultConfigWithDynamic;
|
|
79
85
|
}
|
|
80
86
|
|
|
81
87
|
// find interface
|
|
@@ -91,35 +97,40 @@ module.exports = ({ node, req, options }) => {
|
|
|
91
97
|
|
|
92
98
|
const _interface = blocklet.meta.interfaces.find((x) => x.name === interfaceName);
|
|
93
99
|
if (!_interface) {
|
|
94
|
-
return
|
|
100
|
+
return defaultConfigWithDynamic;
|
|
95
101
|
}
|
|
96
102
|
|
|
97
103
|
// find service
|
|
98
104
|
const service = findService(_interface.services, serviceName);
|
|
99
105
|
|
|
100
106
|
if (!service) {
|
|
101
|
-
return
|
|
107
|
+
return defaultConfigWithDynamic;
|
|
102
108
|
}
|
|
103
109
|
|
|
104
|
-
return service.config;
|
|
110
|
+
return { ...service.config, ...defaultConfigWithDynamic };
|
|
105
111
|
};
|
|
106
112
|
|
|
107
|
-
req.getBlocklet = async () => {
|
|
113
|
+
req.getBlocklet = async ({ useCache = true } = {}) => {
|
|
108
114
|
const did = req.getBlockletDid();
|
|
109
115
|
if (!did) {
|
|
110
116
|
return null;
|
|
111
117
|
}
|
|
112
118
|
|
|
113
119
|
const cacheKey = cache.keyFns.blocklet(did);
|
|
114
|
-
|
|
115
|
-
if (
|
|
116
|
-
const
|
|
117
|
-
blocklet = await node.getBlocklet({ did, attachRuntimeInfo: false }, context);
|
|
120
|
+
|
|
121
|
+
if (useCache) {
|
|
122
|
+
const blocklet = cache.get(cacheKey);
|
|
118
123
|
if (blocklet) {
|
|
119
|
-
|
|
124
|
+
return blocklet;
|
|
120
125
|
}
|
|
121
126
|
}
|
|
122
127
|
|
|
128
|
+
const context = req.getServiceContext();
|
|
129
|
+
const blocklet = await node.getBlocklet({ did, attachRuntimeInfo: false }, context);
|
|
130
|
+
if (blocklet) {
|
|
131
|
+
cache.set(cacheKey, blocklet);
|
|
132
|
+
}
|
|
133
|
+
|
|
123
134
|
return blocklet;
|
|
124
135
|
};
|
|
125
136
|
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const get = require('lodash/get');
|
|
2
|
+
|
|
3
|
+
const getAuthConfig = (blocklet) => {
|
|
4
|
+
const whoCanAccess = get(blocklet, 'settings.whoCanAccess');
|
|
5
|
+
if (whoCanAccess) {
|
|
6
|
+
return {
|
|
7
|
+
whoCanAccess,
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return null;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const getDynamicServiceConfig = (serviceName, blocklet) => {
|
|
15
|
+
if (serviceName === 'auth') {
|
|
16
|
+
return getAuthConfig(blocklet);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
throw new Error(`Invalid service name: ${serviceName}`);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
module.exports = getDynamicServiceConfig;
|
package/api/util/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const joinUrl = require('url-join');
|
|
2
2
|
const { ROLES } = require('@abtnode/constant');
|
|
3
|
-
const { BlockletSource } = require('@blocklet/meta/lib/constants');
|
|
3
|
+
const { BlockletSource, BLOCKLET_MODES } = require('@blocklet/meta/lib/constants');
|
|
4
4
|
const { WELLKNOWN_SERVICE_PATH_PREFIX } = require('@abtnode/constant');
|
|
5
5
|
const { getBaseUrl } = require('@abtnode/router-adapter');
|
|
6
6
|
|
|
@@ -34,7 +34,11 @@ const getBlockletLogo = ({ baseUrl, blocklet }) => {
|
|
|
34
34
|
return logo;
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
-
const shouldGotoStartPage = (req) => {
|
|
37
|
+
const shouldGotoStartPage = (req, blocklet) => {
|
|
38
|
+
if (blocklet && blocklet.mode === BLOCKLET_MODES.DEVELOPMENT) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
|
|
38
42
|
if (req.user && [ROLES.OWNER, ROLES.ADMIN].includes(req.user.role)) {
|
|
39
43
|
return true;
|
|
40
44
|
}
|
|
@@ -1,38 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"files": {
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"static/
|
|
12
|
-
"static/js/4.
|
|
13
|
-
"static/js/4.
|
|
14
|
-
"static/js/5.
|
|
15
|
-
"static/js/5.
|
|
16
|
-
"static/js/6.
|
|
17
|
-
"static/js/6.
|
|
18
|
-
"static/js/7.
|
|
19
|
-
"static/js/7.
|
|
20
|
-
"static/js/8.
|
|
21
|
-
"static/js/8.
|
|
3
|
+
"static/js/0.b6b3b23c.chunk.js": "/.blocklet/proxy/blocklet-service/static/js/0.b6b3b23c.chunk.js",
|
|
4
|
+
"static/js/0.b6b3b23c.chunk.js.map": "/.blocklet/proxy/blocklet-service/static/js/0.b6b3b23c.chunk.js.map",
|
|
5
|
+
"static/js/1.0e83f63d.chunk.js": "/.blocklet/proxy/blocklet-service/static/js/1.0e83f63d.chunk.js",
|
|
6
|
+
"static/js/1.0e83f63d.chunk.js.map": "/.blocklet/proxy/blocklet-service/static/js/1.0e83f63d.chunk.js.map",
|
|
7
|
+
"main.js": "/.blocklet/proxy/blocklet-service/static/js/main.af31d0af.chunk.js",
|
|
8
|
+
"main.js.map": "/.blocklet/proxy/blocklet-service/static/js/main.af31d0af.chunk.js.map",
|
|
9
|
+
"runtime-main.js": "/.blocklet/proxy/blocklet-service/static/js/runtime-main.aa0aaf4a.js",
|
|
10
|
+
"runtime-main.js.map": "/.blocklet/proxy/blocklet-service/static/js/runtime-main.aa0aaf4a.js.map",
|
|
11
|
+
"static/css/4.634341e0.chunk.css": "/.blocklet/proxy/blocklet-service/static/css/4.634341e0.chunk.css",
|
|
12
|
+
"static/js/4.0046a465.chunk.js": "/.blocklet/proxy/blocklet-service/static/js/4.0046a465.chunk.js",
|
|
13
|
+
"static/js/4.0046a465.chunk.js.map": "/.blocklet/proxy/blocklet-service/static/js/4.0046a465.chunk.js.map",
|
|
14
|
+
"static/js/5.4304d38f.chunk.js": "/.blocklet/proxy/blocklet-service/static/js/5.4304d38f.chunk.js",
|
|
15
|
+
"static/js/5.4304d38f.chunk.js.map": "/.blocklet/proxy/blocklet-service/static/js/5.4304d38f.chunk.js.map",
|
|
16
|
+
"static/js/6.08043dea.chunk.js": "/.blocklet/proxy/blocklet-service/static/js/6.08043dea.chunk.js",
|
|
17
|
+
"static/js/6.08043dea.chunk.js.map": "/.blocklet/proxy/blocklet-service/static/js/6.08043dea.chunk.js.map",
|
|
18
|
+
"static/js/7.165c3091.chunk.js": "/.blocklet/proxy/blocklet-service/static/js/7.165c3091.chunk.js",
|
|
19
|
+
"static/js/7.165c3091.chunk.js.map": "/.blocklet/proxy/blocklet-service/static/js/7.165c3091.chunk.js.map",
|
|
20
|
+
"static/js/8.49993466.chunk.js": "/.blocklet/proxy/blocklet-service/static/js/8.49993466.chunk.js",
|
|
21
|
+
"static/js/8.49993466.chunk.js.map": "/.blocklet/proxy/blocklet-service/static/js/8.49993466.chunk.js.map",
|
|
22
|
+
"static/js/9.69df4f05.chunk.js": "/.blocklet/proxy/blocklet-service/static/js/9.69df4f05.chunk.js",
|
|
23
|
+
"static/js/9.69df4f05.chunk.js.map": "/.blocklet/proxy/blocklet-service/static/js/9.69df4f05.chunk.js.map",
|
|
24
|
+
"static/js/10.4199ec3c.chunk.js": "/.blocklet/proxy/blocklet-service/static/js/10.4199ec3c.chunk.js",
|
|
25
|
+
"static/js/10.4199ec3c.chunk.js.map": "/.blocklet/proxy/blocklet-service/static/js/10.4199ec3c.chunk.js.map",
|
|
22
26
|
"index.html": "/.blocklet/proxy/blocklet-service/index.html",
|
|
23
|
-
"precache-manifest.
|
|
27
|
+
"precache-manifest.fc03dfbbf370fcf983cbef3f121b7584.js": "/.blocklet/proxy/blocklet-service/precache-manifest.fc03dfbbf370fcf983cbef3f121b7584.js",
|
|
24
28
|
"service-worker.js": "/.blocklet/proxy/blocklet-service/service-worker.js",
|
|
25
|
-
"static/css/
|
|
26
|
-
"static/js/
|
|
27
|
-
"static/js/
|
|
29
|
+
"static/css/4.634341e0.chunk.css.map": "/.blocklet/proxy/blocklet-service/static/css/4.634341e0.chunk.css.map",
|
|
30
|
+
"static/js/0.b6b3b23c.chunk.js.LICENSE.txt": "/.blocklet/proxy/blocklet-service/static/js/0.b6b3b23c.chunk.js.LICENSE.txt",
|
|
31
|
+
"static/js/4.0046a465.chunk.js.LICENSE.txt": "/.blocklet/proxy/blocklet-service/static/js/4.0046a465.chunk.js.LICENSE.txt",
|
|
28
32
|
"static/media/400.css": "/.blocklet/proxy/blocklet-service/static/media/ubuntu-mono-latin-ext-400-normal.84fa8bc1.woff2",
|
|
29
|
-
"static/media/
|
|
30
|
-
"static/media/
|
|
33
|
+
"static/media/700.css": "/.blocklet/proxy/blocklet-service/static/media/lato-latin-ext-700-normal.a48b0f04.woff2",
|
|
34
|
+
"static/media/500.css": "/.blocklet/proxy/blocklet-service/static/media/rubik-latin-ext-500-normal.21b63491.woff2",
|
|
35
|
+
"static/media/600.css": "/.blocklet/proxy/blocklet-service/static/media/rubik-latin-ext-600-normal.d0d90e83.woff2"
|
|
31
36
|
},
|
|
32
37
|
"entrypoints": [
|
|
33
|
-
"static/js/runtime-main.
|
|
34
|
-
"static/css/
|
|
35
|
-
"static/js/
|
|
36
|
-
"static/js/main.
|
|
38
|
+
"static/js/runtime-main.aa0aaf4a.js",
|
|
39
|
+
"static/css/4.634341e0.chunk.css",
|
|
40
|
+
"static/js/4.0046a465.chunk.js",
|
|
41
|
+
"static/js/main.af31d0af.chunk.js"
|
|
37
42
|
]
|
|
38
43
|
}
|
package/build/index.html
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="shortcut icon" href="/.well-known/service/static/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=0"/><meta name="theme-color" content="#000000"/><title>Blocklet Service</title><script src="/.well-known/service/api/env"></script><link href="/.blocklet/proxy/blocklet-service/static/css/
|
|
1
|
+
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="shortcut icon" href="/.well-known/service/static/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=0"/><meta name="theme-color" content="#000000"/><title>Blocklet Service</title><script src="/.well-known/service/api/env"></script><link href="/.blocklet/proxy/blocklet-service/static/css/4.634341e0.chunk.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div><script>!function(e){function t(t){for(var n,i,a=t[0],l=t[1],f=t[2],s=t[3]||[],d=0,h=[];d<a.length;d++)i=a[d],Object.prototype.hasOwnProperty.call(o,i)&&o[i]&&h.push(o[i][0]),o[i]=0;for(n in l)Object.prototype.hasOwnProperty.call(l,n)&&(e[n]=l[n]);for(p&&p(t),u.push.apply(u,s);h.length;)h.shift()();return c.push.apply(c,f||[]),r()}function r(){for(var e,t=0;t<c.length;t++){for(var r=c[t],n=!0,l=1;l<r.length;l++){var f=r[l];0!==o[f]&&(n=!1)}n&&(c.splice(t--,1),e=a(a.s=r[0]))}return 0===c.length&&(u.forEach((function(e){if(void 0===o[e]){o[e]=null;var t=document.createElement("link");a.nc&&t.setAttribute("nonce",a.nc),t.rel="prefetch",t.as="script",t.href=i(e),document.head.appendChild(t)}})),u.length=0),e}var n={},o={3:0},c=[],u=[];function i(e){return a.p+"static/js/"+({}[e]||e)+"."+{0:"b6b3b23c",1:"0e83f63d",5:"4304d38f",6:"08043dea",7:"165c3091",8:"49993466",9:"69df4f05",10:"4199ec3c"}[e]+".chunk.js"}function a(t){if(n[t])return n[t].exports;var r=n[t]={i:t,l:!1,exports:{}};return e[t].call(r.exports,r,r.exports,a),r.l=!0,r.exports}a.e=function(e){var t=[],r=o[e];if(0!==r)if(r)t.push(r[2]);else{var n=new Promise((function(t,n){r=o[e]=[t,n]}));t.push(r[2]=n);var c,u=document.createElement("script");u.charset="utf-8",u.timeout=120,a.nc&&u.setAttribute("nonce",a.nc),u.src=i(e);var l=new Error;c=function(t){u.onerror=u.onload=null,clearTimeout(f);var r=o[e];if(0!==r){if(r){var n=t&&("load"===t.type?"missing":t.type),c=t&&t.target&&t.target.src;l.message="Loading chunk "+e+" failed.\n("+n+": "+c+")",l.name="ChunkLoadError",l.type=n,l.request=c,r[1](l)}o[e]=void 0}};var f=setTimeout((function(){c({type:"timeout",target:u})}),12e4);u.onerror=u.onload=c,document.head.appendChild(u)}return Promise.all(t)},a.m=e,a.c=n,a.d=function(e,t,r){a.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},a.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},a.t=function(e,t){if(1&t&&(e=a(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(a.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)a.d(r,n,function(t){return e[t]}.bind(null,n));return r},a.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return a.d(t,"a",t),t},a.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},a.p="/.blocklet/proxy/blocklet-service/",a.oe=function(e){throw console.error(e),e};var l=this["webpackJsonp@abtnode/blocklet-services"]=this["webpackJsonp@abtnode/blocklet-services"]||[],f=l.push.bind(l);l.push=t,l=l.slice();for(var s=0;s<l.length;s++)t(l[s]);var p=f;r()}([])</script><script src="/.blocklet/proxy/blocklet-service/static/js/4.0046a465.chunk.js"></script><script src="/.blocklet/proxy/blocklet-service/static/js/main.af31d0af.chunk.js"></script></body></html>
|