@blocklet/meta 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/lib/constants.js CHANGED
@@ -173,7 +173,7 @@ module.exports = Object.freeze({
173
173
 
174
174
  BLOCKLET_DEFAULT_VERSION: '1.0.0',
175
175
 
176
- BLOCKLET_LATEST_SPEC_VERSION: '1.2.3',
176
+ BLOCKLET_LATEST_SPEC_VERSION: '1.2.4',
177
177
  BLOCKLET_LATEST_REQUIREMENT_SERVER: '>=1.6.2',
178
178
  BLOCKLET_LATEST_REQUIREMENT_ABTNODE: '>=1.5.15', // Deprecated
179
179
 
package/lib/schema.js CHANGED
@@ -36,6 +36,7 @@ const environmentSchema = Joi.object({
36
36
  required: Joi.boolean().default(false),
37
37
  secure: Joi.boolean().default(false),
38
38
  validation: Joi.string().optional(),
39
+ shared: Joi.boolean().default((parent) => !parent.secure),
39
40
  });
40
41
 
41
42
  const scriptsSchema = Joi.object({
@@ -177,6 +178,18 @@ const signatureSchema = Joi.object({
177
178
  appended: Joi.array().items(Joi.string()).optional(),
178
179
  });
179
180
 
181
+ const titleSchema = Joi.string()
182
+ .trim()
183
+ .min(3)
184
+ .custom((value) => {
185
+ if (cjkLength(value) > MAX_TITLE_LENGTH) {
186
+ throw new Error(`Blocklet title is too long. Max length is ${MAX_TITLE_LENGTH}`);
187
+ }
188
+
189
+ return value;
190
+ });
191
+ const descriptionSchema = Joi.string().trim().min(3).max(160);
192
+
180
193
  const createBlockletSchema = (
181
194
  baseDir,
182
195
  { ensureMain = false, ensureFiles = false, ensureDist = false, ...schemaOptions } = {}
@@ -196,25 +209,14 @@ const createBlockletSchema = (
196
209
  })
197
210
  .max(MAX_NAME_LENGTH)
198
211
  .required(),
199
- description: Joi.string().trim().min(3).max(512).required(),
212
+ description: descriptionSchema.required(),
200
213
  group: Joi.string().valid(...BLOCKLET_GROUPS).required(), // prettier-ignore
201
214
  main: Joi.when('group', {
202
215
  is: Joi.valid(BlockletGroup.gateway),
203
216
  then: Joi.forbidden(),
204
217
  otherwise: ensureMain ? Joi.file().exists({ baseDir }).required() : Joi.string().trim().required(),
205
218
  }),
206
- title: Joi.string()
207
- .trim()
208
- .min(3)
209
- .custom((value) => {
210
- if (cjkLength(value) > MAX_TITLE_LENGTH) {
211
- throw new Error(`Blocklet title is too long. Max length is ${MAX_TITLE_LENGTH}`);
212
- }
213
-
214
- return value;
215
- })
216
- .optional()
217
- .allow(''),
219
+ title: titleSchema.optional().allow(''),
218
220
  logo: ensureFiles ? Joi.file().trim().exists({ baseDir }).optional() : Joi.string().trim().optional(),
219
221
  specVersion: Joi.semver().valid().gte('1.0.0').optional(),
220
222
 
@@ -309,6 +311,14 @@ const createBlockletSchema = (
309
311
  .items(Joi.string().valid(...BLOCKLET_ARCHITECTURES))
310
312
  .min(1)
311
313
  ),
314
+ fuels: Joi.array().items(
315
+ Joi.object({
316
+ endpoint: Joi.string().required(),
317
+ address: Joi.string().required(),
318
+ value: Joi.string().required(),
319
+ reason: Joi.string().required(),
320
+ })
321
+ ),
312
322
  }).default({ server: BLOCKLET_LATEST_REQUIREMENT_SERVER, os: '*', cpu: '*' }),
313
323
 
314
324
  // interfaces: https://github.com/blocklet/blocklet-specification/issues/2
@@ -397,4 +407,6 @@ module.exports = {
397
407
  scriptsSchema,
398
408
  personSchema,
399
409
  distSchema,
410
+ titleSchema,
411
+ descriptionSchema,
400
412
  };
package/lib/util.js CHANGED
@@ -1,7 +1,9 @@
1
1
  /* eslint-disable no-await-in-loop */
2
2
  const get = require('lodash/get');
3
3
 
4
- const { BlockletGroup, fromBlockletStatus, fromBlockletSource } = require('./constants');
4
+ const { NODE_SERVICES } = require('@abtnode/constant');
5
+
6
+ const { BlockletGroup, fromBlockletStatus, fromBlockletSource, BLOCKLET_INTERFACE_TYPE_WEB } = require('./constants');
5
7
 
6
8
  const forEachBlocklet = (blocklet, cb, { parallel = false, sync } = {}) => {
7
9
  // sync
@@ -170,6 +172,47 @@ const fixBlockletStatus = (blocklet) => {
170
172
  });
171
173
  };
172
174
 
175
+ const findWebInterface = (blocklet) => {
176
+ if (!blocklet) {
177
+ return null;
178
+ }
179
+
180
+ const meta = blocklet.meta || blocklet || {};
181
+ const { interfaces = [] } = meta;
182
+
183
+ if (!Array.isArray(interfaces)) {
184
+ return null;
185
+ }
186
+
187
+ return interfaces.find((x) => x.type === BLOCKLET_INTERFACE_TYPE_WEB);
188
+ };
189
+
190
+ const findServiceFromMeta = (meta, ServiceName) => {
191
+ const names = [ServiceName];
192
+
193
+ // backward compatible
194
+ if (ServiceName === NODE_SERVICES.AUTH) {
195
+ names.push(NODE_SERVICES.AUTH_SERVICE);
196
+ }
197
+
198
+ const webInterface = findWebInterface(meta);
199
+
200
+ if (!webInterface) {
201
+ return null;
202
+ }
203
+
204
+ return (webInterface.services || []).find((x) => names.includes(x.name));
205
+ };
206
+
207
+ const isInvitedUserOnlyInMeta = (blocklet) => {
208
+ if (!blocklet) {
209
+ return false;
210
+ }
211
+
212
+ const service = findServiceFromMeta(blocklet.meta, NODE_SERVICES.AUTH);
213
+ return service && service.config && ['yes', 'not-first'].includes(service.config.invitedUserOnly);
214
+ };
215
+
173
216
  module.exports = {
174
217
  isFreeBlocklet,
175
218
  isComponentBlocklet,
@@ -181,4 +224,7 @@ module.exports = {
181
224
  hasRunnableComponent,
182
225
  getDisplayName,
183
226
  fixBlockletStatus,
227
+ findWebInterface,
228
+ findServiceFromMeta,
229
+ isInvitedUserOnlyInMeta,
184
230
  };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.6.31",
6
+ "version": "1.7.2",
7
7
  "description": "Library to parse/validate/fix blocklet meta",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -18,14 +18,15 @@
18
18
  "author": "wangshijun <wangshijun2020@gmail.com> (http://github.com/wangshijun)",
19
19
  "license": "MIT",
20
20
  "dependencies": {
21
- "@arcblock/did": "^1.14.24",
22
- "@arcblock/did-ext": "^1.14.24",
23
- "@arcblock/did-util": "^1.14.24",
24
- "@arcblock/nft": "^1.14.24",
25
- "@ocap/asset": "^1.14.24",
26
- "@ocap/mcrypto": "^1.14.24",
27
- "@ocap/util": "^1.14.24",
28
- "@ocap/wallet": "^1.14.24",
21
+ "@abtnode/constant": "1.7.2",
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",
29
30
  "ajv": "^7.0.3",
30
31
  "cjk-length": "^1.0.0",
31
32
  "debug": "^4.3.3",
@@ -43,5 +44,5 @@
43
44
  "devDependencies": {
44
45
  "jest": "^27.4.5"
45
46
  },
46
- "gitHead": "ccda31a16ac6b606d34336fcc6db0b2aff15c32e"
47
+ "gitHead": "b84e7406d84fb9c3be5bf7ce968cb7b6b661d550"
47
48
  }