@blocklet/meta 1.7.4 → 1.7.7

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/lib/did.js CHANGED
@@ -3,7 +3,7 @@ const { toHex } = require('@ocap/util');
3
3
  const { fromPublicKey } = require('@arcblock/did');
4
4
 
5
5
  const toBlockletDid = (name) => {
6
- const pk = toHex(name);
6
+ const pk = toHex(Buffer.from(typeof name === 'string' ? name.trim() : name));
7
7
  return fromPublicKey(pk, { role: types.RoleType.ROLE_ANY });
8
8
  };
9
9
 
@@ -0,0 +1,78 @@
1
+ const get = require('lodash/get');
2
+ const normalizePathPrefix = require('@abtnode/util/lib/normalize-path-prefix');
3
+
4
+ /**
5
+ * @param {*} navigation src
6
+ * @param {*} blocklet
7
+ * @param {*} prefix prefix of link
8
+ * @param {*} level 1 or 2. primary menu or secondary menu
9
+ */
10
+ const parseNavigation = (navigation, blocklet, prefix = '/', level = 1) => {
11
+ const result = [];
12
+
13
+ (navigation || []).forEach((nav) => {
14
+ if (!nav.child) {
15
+ const item = {
16
+ title: nav.title,
17
+ };
18
+
19
+ if (nav.link) {
20
+ item.link = normalizePathPrefix(`${prefix}${nav.link || '/'}`);
21
+ }
22
+
23
+ if (level === 1) {
24
+ const list = parseNavigation(nav.items, blocklet, prefix, 2);
25
+ if (list.length) {
26
+ item.items = list;
27
+ }
28
+ }
29
+
30
+ result.push(item);
31
+ return;
32
+ }
33
+
34
+ if (!blocklet) {
35
+ return;
36
+ }
37
+
38
+ // parse child
39
+ const child = (blocklet.children || []).find((x) => [x.meta.name, x.meta.did].includes(nav.child));
40
+ if (!child) {
41
+ return;
42
+ }
43
+ const childTitle = child.meta.title || child.meta.name;
44
+
45
+ const childNavigation = get(child, 'meta.navigation', []);
46
+ if (!childNavigation.length) {
47
+ // child does not declares menu
48
+ result.push({
49
+ title: nav.title || childTitle,
50
+ link: normalizePathPrefix(`${prefix}${child.mountPoint || '/'}`),
51
+ });
52
+ } else if (childNavigation.length === 1) {
53
+ // child declares one menu
54
+ result.push({
55
+ title: nav.title || childNavigation[0].title || childTitle,
56
+ link: normalizePathPrefix(`${prefix}${child.mountPoint}${childNavigation[0].link || '/'}`),
57
+ });
58
+ } else {
59
+ // child declares multiple menus
60
+ if (level === 1) { // eslint-disable-line
61
+ // primary menu
62
+ const item = {
63
+ title: nav.title || child.meta.title || child.meta.name,
64
+ items: parseNavigation(childNavigation, null, normalizePathPrefix(`${prefix}${child.mountPoint}`), 2),
65
+ };
66
+ result.push(item);
67
+ } else {
68
+ // secondary menu
69
+ const list = parseNavigation(childNavigation, null, normalizePathPrefix(`${prefix}${child.mountPoint}`), 2);
70
+ result.push(...list);
71
+ }
72
+ }
73
+ });
74
+
75
+ return result;
76
+ };
77
+
78
+ module.exports = parseNavigation;
package/lib/schema.js CHANGED
@@ -37,6 +37,12 @@ const environmentSchema = Joi.object({
37
37
  secure: Joi.boolean().default(false),
38
38
  validation: Joi.string().optional(),
39
39
  shared: Joi.boolean().default((parent) => !parent.secure),
40
+ }).custom((x, helper) => {
41
+ if (x.secure && x.default) {
42
+ return helper.message(`Cannot declare default value for secure env ${x.name}`);
43
+ }
44
+
45
+ return x;
40
46
  });
41
47
 
42
48
  const scriptsSchema = Joi.object({
@@ -155,8 +161,7 @@ const childrenSchema = Joi.object({
155
161
  services: Joi.array().items(serviceSchema).unique('name'),
156
162
  })
157
163
  )
158
- .optional()
159
- .default([]),
164
+ .optional(),
160
165
  mountPoint: Joi.string().trim().min(1), // added in 1.2.3
161
166
  services: Joi.array().items(serviceSchema).unique('name'), // added in 1.2.3
162
167
  }).custom((value) => {
@@ -190,6 +195,22 @@ const titleSchema = Joi.string()
190
195
  });
191
196
  const descriptionSchema = Joi.string().trim().min(3).max(160);
192
197
 
198
+ const navigationItemSchema = Joi.object({
199
+ title: Joi.string().required(),
200
+ link: Joi.string(),
201
+ child: Joi.string(), // child name or child did
202
+ });
203
+
204
+ const navigationSchema = Joi.array().items(
205
+ navigationItemSchema.append({
206
+ items: Joi.array().items(navigationItemSchema),
207
+ })
208
+ );
209
+
210
+ const themeSchema = Joi.object({
211
+ background: Joi.string(),
212
+ });
213
+
193
214
  const createBlockletSchema = (
194
215
  baseDir,
195
216
  { ensureMain = false, ensureFiles = false, ensureDist = false, ...schemaOptions } = {}
@@ -391,6 +412,10 @@ const createBlockletSchema = (
391
412
 
392
413
  // blocklet component support
393
414
  children: Joi.array().items(childrenSchema).optional().default([]),
415
+
416
+ // navigation & theme
417
+ navigation: navigationSchema,
418
+ theme: themeSchema,
394
419
  })
395
420
  .rename('public_url', 'publicUrl', { ignoreUndefined: true, override: true })
396
421
  .rename('admin_url', 'adminUrl', { ignoreUndefined: true, override: true })
@@ -409,4 +434,6 @@ module.exports = {
409
434
  distSchema,
410
435
  titleSchema,
411
436
  descriptionSchema,
437
+ navigationSchema,
438
+ themeSchema,
412
439
  };
package/lib/util.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable no-await-in-loop */
2
2
  const get = require('lodash/get');
3
3
 
4
- const { NODE_SERVICES } = require('@abtnode/constant');
4
+ const { NODE_SERVICES, SLOT_FOR_IP_DNS_SITE } = require('@abtnode/constant');
5
5
 
6
6
  const { BlockletGroup, fromBlockletStatus, fromBlockletSource, BLOCKLET_INTERFACE_TYPE_WEB } = require('./constants');
7
7
 
@@ -213,6 +213,8 @@ const isInvitedUserOnlyInMeta = (blocklet) => {
213
213
  return service && service.config && ['yes', 'not-first'].includes(service.config.invitedUserOnly);
214
214
  };
215
215
 
216
+ const replaceSlotToIp = (url, ip) => (url || '').replace(SLOT_FOR_IP_DNS_SITE, (ip || '').replace(/\./g, '-'));
217
+
216
218
  module.exports = {
217
219
  isFreeBlocklet,
218
220
  isComponentBlocklet,
@@ -227,4 +229,5 @@ module.exports = {
227
229
  findWebInterface,
228
230
  findServiceFromMeta,
229
231
  isInvitedUserOnlyInMeta,
232
+ replaceSlotToIp,
230
233
  };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.7.4",
6
+ "version": "1.7.7",
7
7
  "description": "Library to parse/validate/fix blocklet meta",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -18,19 +18,20 @@
18
18
  "author": "wangshijun <wangshijun2020@gmail.com> (http://github.com/wangshijun)",
19
19
  "license": "MIT",
20
20
  "dependencies": {
21
- "@abtnode/constant": "1.7.4",
22
- "@arcblock/did": "^1.15.3",
23
- "@arcblock/did-ext": "^1.15.3",
24
- "@arcblock/did-util": "^1.15.3",
25
- "@arcblock/nft": "^1.15.3",
26
- "@ocap/asset": "^1.15.3",
27
- "@ocap/mcrypto": "^1.15.3",
28
- "@ocap/util": "^1.15.3",
29
- "@ocap/wallet": "^1.15.3",
21
+ "@abtnode/constant": "1.7.7",
22
+ "@abtnode/util": "1.7.7",
23
+ "@arcblock/did": "^1.16.0",
24
+ "@arcblock/did-ext": "^1.16.0",
25
+ "@arcblock/did-util": "^1.16.0",
26
+ "@arcblock/nft": "^1.16.0",
27
+ "@ocap/asset": "^1.16.0",
28
+ "@ocap/mcrypto": "^1.16.0",
29
+ "@ocap/util": "^1.16.0",
30
+ "@ocap/wallet": "^1.16.0",
30
31
  "ajv": "^7.0.3",
31
32
  "cjk-length": "^1.0.0",
32
33
  "debug": "^4.3.3",
33
- "fs-extra": "^10.0.0",
34
+ "fs-extra": "^10.0.1",
34
35
  "hosted-git-info": "3.0.8",
35
36
  "is-glob": "^4.0.3",
36
37
  "joi": "^17.6.0",
@@ -44,5 +45,5 @@
44
45
  "devDependencies": {
45
46
  "jest": "^27.4.5"
46
47
  },
47
- "gitHead": "02b25a877e5b56b389ab318a851bea01212e10df"
48
+ "gitHead": "619db37ea7a91c64a9bf30836a55c70d55325e73"
48
49
  }