@blocklet/meta 1.7.0 → 1.7.3

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 (3) hide show
  1. package/lib/schema.js +25 -14
  2. package/lib/util.js +47 -1
  3. package/package.json +11 -10
package/lib/schema.js CHANGED
@@ -36,7 +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(true),
39
+ shared: Joi.boolean().default((parent) => !parent.secure),
40
40
  });
41
41
 
42
42
  const scriptsSchema = Joi.object({
@@ -178,6 +178,18 @@ const signatureSchema = Joi.object({
178
178
  appended: Joi.array().items(Joi.string()).optional(),
179
179
  });
180
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
+
181
193
  const createBlockletSchema = (
182
194
  baseDir,
183
195
  { ensureMain = false, ensureFiles = false, ensureDist = false, ...schemaOptions } = {}
@@ -197,25 +209,14 @@ const createBlockletSchema = (
197
209
  })
198
210
  .max(MAX_NAME_LENGTH)
199
211
  .required(),
200
- description: Joi.string().trim().min(3).max(512).required(),
212
+ description: descriptionSchema.required(),
201
213
  group: Joi.string().valid(...BLOCKLET_GROUPS).required(), // prettier-ignore
202
214
  main: Joi.when('group', {
203
215
  is: Joi.valid(BlockletGroup.gateway),
204
216
  then: Joi.forbidden(),
205
217
  otherwise: ensureMain ? Joi.file().exists({ baseDir }).required() : Joi.string().trim().required(),
206
218
  }),
207
- title: Joi.string()
208
- .trim()
209
- .min(3)
210
- .custom((value) => {
211
- if (cjkLength(value) > MAX_TITLE_LENGTH) {
212
- throw new Error(`Blocklet title is too long. Max length is ${MAX_TITLE_LENGTH}`);
213
- }
214
-
215
- return value;
216
- })
217
- .optional()
218
- .allow(''),
219
+ title: titleSchema.optional().allow(''),
219
220
  logo: ensureFiles ? Joi.file().trim().exists({ baseDir }).optional() : Joi.string().trim().optional(),
220
221
  specVersion: Joi.semver().valid().gte('1.0.0').optional(),
221
222
 
@@ -310,6 +311,14 @@ const createBlockletSchema = (
310
311
  .items(Joi.string().valid(...BLOCKLET_ARCHITECTURES))
311
312
  .min(1)
312
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
+ ),
313
322
  }).default({ server: BLOCKLET_LATEST_REQUIREMENT_SERVER, os: '*', cpu: '*' }),
314
323
 
315
324
  // interfaces: https://github.com/blocklet/blocklet-specification/issues/2
@@ -398,4 +407,6 @@ module.exports = {
398
407
  scriptsSchema,
399
408
  personSchema,
400
409
  distSchema,
410
+ titleSchema,
411
+ descriptionSchema,
401
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.7.0",
6
+ "version": "1.7.3",
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.25",
22
- "@arcblock/did-ext": "^1.14.25",
23
- "@arcblock/did-util": "^1.14.25",
24
- "@arcblock/nft": "^1.14.25",
25
- "@ocap/asset": "^1.14.25",
26
- "@ocap/mcrypto": "^1.14.25",
27
- "@ocap/util": "^1.14.25",
28
- "@ocap/wallet": "^1.14.25",
21
+ "@abtnode/constant": "1.7.3",
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": "fc949a5e8a1017fbe17533d3bd78b166c7dad132"
47
+ "gitHead": "2b965b42a59a2d98642018749a6afb6e4014a698"
47
48
  }