@blocklet/meta 1.8.25 → 1.8.27

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/constants.js CHANGED
@@ -1,191 +1,3 @@
1
- const fromEntry = (entries) => (v) => {
2
- const match = Object.entries(entries).find((x) => x[1] === Number(v));
3
- return match ? match[0] : 'unknown';
4
- };
1
+ const constant = require('@blocklet/constant');
5
2
 
6
- const toEntry = (entries) => (v) => Object.keys(entries).find((x) => entries[x] === Number(v));
7
-
8
- // Blocklet Status
9
-
10
- const BlockletStatus = Object.freeze({
11
- added: 0,
12
- downloading: 1,
13
- downloaded: 2, // Deprecated
14
- installing: 3,
15
- installed: 4,
16
- starting: 5,
17
- running: 6,
18
- stopping: 7,
19
- stopped: 8,
20
- error: 9,
21
- upgrading: 10,
22
- restarting: 11, // Deprecated
23
- corrupted: 12,
24
- waiting: 13,
25
- deleted: 14,
26
- });
27
-
28
- const fromBlockletStatus = fromEntry(BlockletStatus);
29
- const toBlockletStatus = toEntry(BlockletStatus);
30
-
31
- // Blocklet Source
32
-
33
- const BlockletSource = Object.freeze({
34
- // Installed from Blocklet Store
35
- registry: 0,
36
-
37
- // Installed from local development source folder
38
- local: 1,
39
-
40
- // Installed from uploading bundle directly
41
- upload: 2,
42
-
43
- // Installed from a url (similar to Blocklet Store)
44
- url: 3,
45
-
46
- // Installed by custom creation
47
- custom: 4,
48
- });
49
-
50
- const fromBlockletSource = fromEntry(BlockletSource);
51
- const toBlockletSource = toEntry(BlockletSource);
52
-
53
- // Blocklet Group(Type)
54
-
55
- const BlockletGroup = Object.freeze({
56
- // Only static website
57
- // The website is served by by Blocklet Server at runtime
58
- static: 'static',
59
-
60
- // The runtime instance is provided by its own backend server
61
- dapp: 'dapp',
62
-
63
- starter: false, // deprecated
64
-
65
- // This type is used to combine other component blocklets
66
- // No instance will be spawned at runtime
67
- gateway: 'gateway',
68
- });
69
-
70
- const BLOCKLET_GROUPS = ['dapp', 'static', 'gateway'];
71
-
72
- // Blocklet Events
73
-
74
- const BlockletEvents = Object.freeze({
75
- added: 'blocklet.added',
76
- downloadFailed: 'blocklet.downloadFailed',
77
- installed: 'blocklet.installed',
78
- installFailed: 'blocklet.installFailed',
79
- upgraded: 'blocklet.upgraded',
80
- upgradeFailed: 'blocklet.upgradedFailed',
81
- downgraded: 'blocklet.downgraded',
82
- downgradeFailed: 'blocklet.downgradedFailed',
83
- updated: 'blocklet.updated',
84
- statusChange: 'blocklet.statusChange',
85
- removed: 'blocklet.removed',
86
- started: 'blocklet.started',
87
- startFailed: 'blocklet.startFailed',
88
- stopped: 'blocklet.stopped',
89
- reloaded: 'blocklet.reloaded', // Deprecated
90
- purchaseChange: 'blocklet.purchaseChange',
91
- });
92
-
93
- // Blocklet Interface
94
-
95
- const BLOCKLET_INTERFACE_TYPE_WEB = 'web';
96
- const BLOCKLET_INTERFACE_TYPE_SERVICE = 'service';
97
-
98
- // Wellknown interface declares an sub-interface under web interface
99
- // The path of the wellknown interface must starts with /.well-known, e.g. /.well-known/acme-challenge)
100
- // The wellknown interface can be mounted to every endpoint of the abtnode and all blocklets on the abtnode
101
- const BLOCKLET_INTERFACE_TYPE_WELLKNOWN = 'wellknown';
102
- const BLOCKLET_INTERFACE_TYPES = [
103
- BLOCKLET_INTERFACE_TYPE_WEB,
104
- BLOCKLET_INTERFACE_TYPE_SERVICE,
105
- BLOCKLET_INTERFACE_TYPE_WELLKNOWN,
106
- ];
107
-
108
- const BLOCKLET_INTERFACE_PUBLIC = 'publicUrl';
109
- const BLOCKLET_INTERFACE_WELLKNOWN = 'wellknownUrl'; // Deprecated
110
- const BLOCKLET_UI_INTERFACES = [BLOCKLET_INTERFACE_PUBLIC];
111
- const BLOCKLET_STANDARD_INTERFACES = [BLOCKLET_INTERFACE_PUBLIC, BLOCKLET_INTERFACE_WELLKNOWN];
112
-
113
- const BLOCKLET_INTERFACE_PROTOCOL_HTTP = 'http';
114
- const BLOCKLET_INTERFACE_PROTOCOL_TCP = 'tcp';
115
- const BLOCKLET_INTERFACE_PROTOCOL_UDP = 'udp';
116
- const BLOCKLET_INTERFACE_PROTOCOLS = [
117
- BLOCKLET_INTERFACE_PROTOCOL_TCP,
118
- BLOCKLET_INTERFACE_PROTOCOL_UDP,
119
- BLOCKLET_INTERFACE_PROTOCOL_HTTP,
120
- ];
121
-
122
- module.exports = Object.freeze({
123
- BlockletStatus,
124
- fromBlockletStatus,
125
- toBlockletStatus,
126
-
127
- BlockletSource,
128
- fromBlockletSource,
129
- toBlockletSource,
130
-
131
- BlockletGroup,
132
- BLOCKLET_GROUPS,
133
-
134
- BlockletEvents,
135
-
136
- BLOCKLET_PLATFORMS: ['aix', 'darwin', 'freebsd', 'linux', 'openbsd', 'sunos', 'win32'],
137
- BLOCKLET_ARCHITECTURES: ['arm', 'arm64', 'ia32', 'mips', 'mipsel', 'ppc', 'ppc64', 's390', 's390x', 'x32', 'x64'],
138
-
139
- BLOCKLET_MODES: Object.freeze({
140
- PRODUCTION: 'production',
141
- DEVELOPMENT: 'development',
142
- }),
143
-
144
- BLOCKLET_FACTORY_SHARES: { developer: 0.7, store: 0.3 },
145
-
146
- // interface
147
- BLOCKLET_INTERFACE_PUBLIC,
148
- BLOCKLET_INTERFACE_WELLKNOWN, // Deprecated
149
- BLOCKLET_UI_INTERFACES,
150
- BLOCKLET_STANDARD_INTERFACES,
151
-
152
- BLOCKLET_INTERFACE_TYPE_WEB,
153
- BLOCKLET_INTERFACE_TYPE_SERVICE,
154
- BLOCKLET_INTERFACE_TYPE_WELLKNOWN,
155
- BLOCKLET_INTERFACE_TYPES,
156
-
157
- BLOCKLET_INTERFACE_PROTOCOL_HTTP,
158
- BLOCKLET_INTERFACE_PROTOCOL_TCP,
159
- BLOCKLET_INTERFACE_PROTOCOL_UDP,
160
- BLOCKLET_INTERFACE_PROTOCOLS,
161
-
162
- BLOCKLET_DYNAMIC_PATH_PREFIX: '*',
163
- BLOCKLET_DEFAULT_PORT_NAME: 'BLOCKLET_PORT',
164
- BLOCKLET_DEFAULT_PATH_REWRITE: '/',
165
-
166
- // bundle
167
- BLOCKLET_RELEASE_FOLDER: '.blocklet/release',
168
- BLOCKLET_RELEASE_FILE: 'blocklet.json',
169
- BLOCKLET_BUNDLE_FOLDER: '.blocklet/bundle',
170
- BLOCKLET_BUNDLE_FILE: 'blocklet.zip',
171
- BLOCKLET_ENTRY_FILE: 'blocklet.js',
172
- BLOCKLET_META_FILE: 'blocklet.yml',
173
- BLOCKLET_META_FILE_ALT: 'blocklet.yaml',
174
-
175
- BLOCKLET_DEFAULT_VERSION: '1.0.0',
176
-
177
- BLOCKLET_LATEST_SPEC_VERSION: '1.2.7',
178
- BLOCKLET_LATEST_REQUIREMENT_SERVER: '>=1.7.0',
179
- BLOCKLET_LATEST_REQUIREMENT_ABTNODE: '>=1.5.15', // Deprecated
180
-
181
- BLOCKLET_CONFIGURABLE_KEY: {
182
- BLOCKLET_CLUSTER_SIZE: 'BLOCKLET_CLUSTER_SIZE',
183
- BLOCKLET_APP_NAME: 'BLOCKLET_APP_NAME',
184
- BLOCKLET_APP_DESCRIPTION: 'BLOCKLET_APP_DESCRIPTION',
185
- BLOCKLET_APP_SK: 'BLOCKLET_APP_SK',
186
- BLOCKLET_APP_URL: 'BLOCKLET_APP_URL',
187
- BLOCKLET_PASSPORT_COLOR: 'BLOCKLET_PASSPORT_COLOR',
188
- BLOCKLET_WALLET_TYPE: 'BLOCKLET_WALLET_TYPE',
189
- BLOCKLET_DELETABLE: 'BLOCKLET_DELETABLE',
190
- },
191
- });
3
+ module.exports = constant;
package/lib/file.js CHANGED
@@ -21,7 +21,12 @@ const select = (dir, { throwOnError = true } = {}) => {
21
21
  return metaToUpdate;
22
22
  };
23
23
 
24
- const update = (file, meta) => {
24
+ const update = (file, meta, { fix = true } = {}) => {
25
+ if (!fix) {
26
+ fs.writeFileSync(file, yaml.dump(meta, { sortKeys: false, skipInvalid: true }));
27
+ return;
28
+ }
29
+
25
30
  delete meta.path;
26
31
  delete meta.folder;
27
32
  delete meta.htmlAst;
@@ -40,6 +40,8 @@ const getGroups = (navigation) => {
40
40
  return Object.values(groups);
41
41
  };
42
42
 
43
+ const getChildName = (nav) => nav.component || nav.child;
44
+
43
45
  /**
44
46
  * @param {*} navigation src
45
47
  * @param {*} blocklet
@@ -50,7 +52,7 @@ const doParseNavigation = (navigation, blocklet, prefix = '/', _level = 1) => {
50
52
  const result = [];
51
53
 
52
54
  (navigation || []).forEach((nav) => {
53
- if (!nav.child) {
55
+ if (!getChildName(nav)) {
54
56
  if (_level > 1 && nav.items?.length) {
55
57
  const list = doParseNavigation(nav.items, blocklet, prefix, _level + 1);
56
58
  result.push(...list);
@@ -95,7 +97,7 @@ const doParseNavigation = (navigation, blocklet, prefix = '/', _level = 1) => {
95
97
  }
96
98
 
97
99
  // parse child
98
- const child = (blocklet.children || []).find((x) => [x.meta.name, x.meta.did].includes(nav.child));
100
+ const child = (blocklet.children || []).find((x) => [x.meta.name, x.meta.did].includes(getChildName(nav)));
99
101
  if (!child) {
100
102
  return;
101
103
  }
package/lib/parse.js CHANGED
@@ -28,6 +28,7 @@ const parse = (
28
28
  extraRawAttrs = {},
29
29
  serviceMetas,
30
30
  schemaOptions = {},
31
+ fix = true,
31
32
  } = {}
32
33
  ) => {
33
34
  let result = {};
@@ -57,6 +58,10 @@ const parse = (
57
58
  result = Object.assign(result, extraRawAttrs);
58
59
  }
59
60
 
61
+ if (!fix) {
62
+ return result;
63
+ }
64
+
60
65
  // Fix
61
66
  fixRequired(result, dir);
62
67
  fixRepository(result);
package/lib/payment/v2.js CHANGED
@@ -24,6 +24,8 @@ const ZeroBN = new BN(0);
24
24
  const defaultDecimals = 1e6; // we only support 6 decimals on share ratio
25
25
  const defaultDecimalsBN = new BN(defaultDecimals);
26
26
 
27
+ const getComponentConfig = (meta) => meta.components || meta.children;
28
+
27
29
  const safeMul = (a, b) =>
28
30
  Number(
29
31
  fromUnitToToken(
@@ -68,7 +70,7 @@ const _getComponents = async (inputMeta, context = {}) => {
68
70
  throw new Error('The depth of component should not exceed 40');
69
71
  }
70
72
 
71
- const configs = inputMeta.children || [];
73
+ const configs = getComponentConfig(inputMeta);
72
74
 
73
75
  if (!configs || !configs.length) {
74
76
  return [];
package/lib/schema.js CHANGED
@@ -42,6 +42,9 @@ const titleSchema = Joi.string()
42
42
  return value;
43
43
  });
44
44
  const descriptionSchema = Joi.string().trim().min(3).max(160);
45
+ const logoSchema = Joi.string()
46
+ .uri({ scheme: ['http', 'https'], allowRelative: true })
47
+ .allow('');
45
48
  const mountPointSchema = Joi.string().trim().min(1);
46
49
 
47
50
  const blockletNameSchema = Joi.string()
@@ -245,11 +248,11 @@ const navigationItemSchema = Joi.object({
245
248
  en: Joi.string(),
246
249
  }).min(1)
247
250
  ),
248
- child: Joi.string().min(1), // child name or child did
251
+ component: Joi.string().min(1), // child name or child did
249
252
  section: Joi.array().items(Joi.string().min(1)).single(),
250
253
  role: Joi.array().items(Joi.string().min(1)).single(),
251
254
  icon: Joi.string().min(1),
252
- });
255
+ }).rename('child', 'component');
253
256
 
254
257
  const navigationSchema = Joi.array().items(
255
258
  navigationItemSchema.append({
@@ -487,7 +490,7 @@ const createBlockletSchema = (
487
490
  lastPublishedAt: Joi.string().isoDate().optional(),
488
491
 
489
492
  // blocklet component support
490
- children: Joi.array().items(childrenSchema).unique('name').optional().default([]),
493
+ components: Joi.array().items(childrenSchema).unique('name').optional().default([]),
491
494
 
492
495
  // navigation & theme
493
496
  navigation: navigationSchema,
@@ -501,7 +504,9 @@ const createBlockletSchema = (
501
504
  bundleName: Joi.string(),
502
505
  bundleDid: Joi.DID().trim(),
503
506
  storeId: Joi.string(),
504
- }).options({ stripUnknown: true, noDefaults: false, ...schemaOptions });
507
+ })
508
+ .options({ stripUnknown: true, noDefaults: false, ...schemaOptions })
509
+ .rename('children', 'components');
505
510
  };
506
511
 
507
512
  module.exports = {
@@ -513,6 +518,7 @@ module.exports = {
513
518
  distSchema,
514
519
  titleSchema,
515
520
  descriptionSchema,
521
+ logoSchema,
516
522
  navigationSchema,
517
523
  themeSchema,
518
524
  mountPointSchema,
package/lib/util.js CHANGED
@@ -334,6 +334,10 @@ const hasRunnableComponent = (blocklet) => {
334
334
  * @returns blocklet display name
335
335
  */
336
336
  const getDisplayName = (blocklet, onlyUseMeta = false) => {
337
+ if (!blocklet) {
338
+ return '';
339
+ }
340
+
337
341
  const { meta } = blocklet;
338
342
  let displayName;
339
343
 
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.8.25",
6
+ "version": "1.8.27",
7
7
  "description": "Library to parse/validate/fix blocklet meta",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -18,16 +18,17 @@
18
18
  "author": "wangshijun <wangshijun2020@gmail.com> (http://github.com/wangshijun)",
19
19
  "license": "MIT",
20
20
  "dependencies": {
21
- "@abtnode/constant": "1.8.25",
22
- "@abtnode/util": "1.8.25",
23
- "@arcblock/did": "1.17.19",
24
- "@arcblock/did-ext": "1.17.19",
25
- "@arcblock/did-util": "1.17.19",
26
- "@arcblock/jwt": "1.17.19",
27
- "@ocap/asset": "1.17.19",
28
- "@ocap/mcrypto": "1.17.19",
29
- "@ocap/util": "1.17.19",
30
- "@ocap/wallet": "1.17.19",
21
+ "@abtnode/constant": "1.8.27",
22
+ "@abtnode/util": "1.8.27",
23
+ "@arcblock/did": "1.17.20",
24
+ "@arcblock/did-ext": "1.17.20",
25
+ "@arcblock/did-util": "1.17.20",
26
+ "@arcblock/jwt": "1.17.20",
27
+ "@blocklet/constant": "1.8.27",
28
+ "@ocap/asset": "1.17.20",
29
+ "@ocap/mcrypto": "1.17.20",
30
+ "@ocap/util": "1.17.20",
31
+ "@ocap/wallet": "1.17.20",
31
32
  "ajv": "^8.11.0",
32
33
  "axios": "^0.27.2",
33
34
  "cjk-length": "^1.0.0",
@@ -53,5 +54,5 @@
53
54
  "express": "^4.18.1",
54
55
  "jest": "^27.5.1"
55
56
  },
56
- "gitHead": "ea34dcd0037c63cb63b31744efcf169edf8aa776"
57
+ "gitHead": "84b2cb3ee703479f17e88c91650ecf3015cbf6af"
57
58
  }