@blocklet/meta 1.8.65 → 1.8.66-beta-ff281dd5

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,6 +3,9 @@ const mcrypto_1 = require("@ocap/mcrypto");
3
3
  const util_1 = require("@ocap/util");
4
4
  const did_1 = require("@arcblock/did");
5
5
  const toBlockletDid = (name) => {
6
+ if ((0, did_1.isValid)(name)) {
7
+ return name;
8
+ }
6
9
  const pk = (0, util_1.toHex)(Buffer.from(typeof name === 'string' ? name.trim() : name));
7
10
  return (0, did_1.fromPublicKey)(pk, { role: mcrypto_1.types.RoleType.ROLE_ANY });
8
11
  };
@@ -1,5 +1,9 @@
1
1
  import { Extension, Root } from 'joi';
2
2
  declare const fileExtension: (joi: Root) => Extension;
3
+ /**
4
+ * joi extend did 判断
5
+ * 由于需要兼容新旧两种 did 模式判断,所以这里不能做 role 类型判断
6
+ */
3
7
  declare const didExtension: (joi: Root) => Extension;
4
8
  export { fileExtension };
5
9
  export { didExtension };
package/lib/extension.js CHANGED
@@ -60,6 +60,10 @@ const fileExtension = (joi) => ({
60
60
  },
61
61
  });
62
62
  exports.fileExtension = fileExtension;
63
+ /**
64
+ * joi extend did 判断
65
+ * 由于需要兼容新旧两种 did 模式判断,所以这里不能做 role 类型判断
66
+ */
63
67
  const didExtension = (joi) => ({
64
68
  type: 'DID',
65
69
  base: joi.string(),
package/lib/file.d.ts CHANGED
@@ -6,7 +6,9 @@ declare const select: (dir: string, { throwOnError }?: {
6
6
  declare const update: (file: string, meta: TBlockletMeta, { fix }?: {
7
7
  fix?: boolean;
8
8
  }) => void;
9
+ declare const read: (file: string) => unknown;
9
10
  export { list };
11
+ export { read };
10
12
  export { select };
11
13
  export { update };
12
14
  declare const _default: {
package/lib/file.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.update = exports.select = exports.list = void 0;
6
+ exports.update = exports.select = exports.read = exports.list = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const js_yaml_1 = __importDefault(require("js-yaml"));
9
9
  const fs_extra_1 = __importDefault(require("fs-extra"));
@@ -43,6 +43,11 @@ const update = (file, meta, { fix = true } = {}) => {
43
43
  fs_extra_1.default.writeFileSync(file, js_yaml_1.default.dump(meta, { sortKeys: false, skipInvalid: true }));
44
44
  };
45
45
  exports.update = update;
46
+ const read = (file) => {
47
+ const fileContent = fs_extra_1.default.readFileSync(file, 'utf8').toString();
48
+ return js_yaml_1.default.load(fileContent);
49
+ };
50
+ exports.read = read;
46
51
  exports.default = {
47
52
  list,
48
53
  select,
package/lib/fix.d.ts CHANGED
@@ -8,12 +8,14 @@ declare const formatPerson: (person: string | Record<string, any>) => string;
8
8
  declare const parsePerson: (person: string) => any;
9
9
  declare const fixPerson: (data: any) => any;
10
10
  declare const fixInterfaces: (meta: any, removeMerged?: boolean) => any;
11
+ declare const fixName: (meta: any) => any;
11
12
  export { fixRequired };
12
13
  export { fixRepository };
13
14
  export { fixFiles };
14
15
  export { fixKeywords };
15
16
  export { fixPerson };
16
17
  export { fixTags };
18
+ export { fixName };
17
19
  export { formatPerson };
18
20
  export { parsePerson };
19
21
  export { fixInterfaces };
@@ -25,6 +27,7 @@ declare const _default: {
25
27
  fixKeywords: (data: any) => void;
26
28
  fixPerson: (data: any) => any;
27
29
  fixTags: (data: any) => void;
30
+ fixName: (meta: any) => any;
28
31
  formatPerson: (person: string | Record<string, any>) => string;
29
32
  parsePerson: (person: string) => any;
30
33
  fixInterfaces: (meta: any, removeMerged?: boolean) => any;
package/lib/fix.js CHANGED
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.fixService = exports.fixInterfaces = exports.parsePerson = exports.formatPerson = exports.fixTags = exports.fixPerson = exports.fixKeywords = exports.fixFiles = exports.fixRepository = exports.fixRequired = void 0;
29
+ exports.fixService = exports.fixInterfaces = exports.parsePerson = exports.formatPerson = exports.fixName = exports.fixTags = exports.fixPerson = exports.fixKeywords = exports.fixFiles = exports.fixRepository = exports.fixRequired = void 0;
30
30
  const fs_1 = __importDefault(require("fs"));
31
31
  const path_1 = __importDefault(require("path"));
32
32
  const get_1 = __importDefault(require("lodash/get"));
@@ -35,6 +35,7 @@ const debug_1 = __importDefault(require("debug"));
35
35
  const validate_1 = require("./validate");
36
36
  Object.defineProperty(exports, "fixService", { enumerable: true, get: function () { return validate_1.fixAndValidateService; } });
37
37
  const constants_1 = __importDefault(require("./constants"));
38
+ const name_1 = require("./name");
38
39
  const debug = (0, debug_1.default)('@blocklet/meta:fix');
39
40
  const { BLOCKLET_DEFAULT_VERSION, BLOCKLET_DEFAULT_PORT_NAME, BLOCKLET_DYNAMIC_PATH_PREFIX, BLOCKLET_INTERFACE_TYPE_WEB, BLOCKLET_INTERFACE_PUBLIC, } = constants_1.default;
40
41
  // Assign sensible defaults: description/main/group/version/public_url
@@ -228,6 +229,18 @@ const fixInterfaces = (meta, removeMerged = true) => {
228
229
  return meta;
229
230
  };
230
231
  exports.fixInterfaces = fixInterfaces;
232
+ const fixName = (meta) => {
233
+ const { did } = meta;
234
+ try {
235
+ (0, name_1.validateNewDid)(did);
236
+ meta.name = did;
237
+ }
238
+ catch (_a) {
239
+ /* empty */
240
+ }
241
+ return meta;
242
+ };
243
+ exports.fixName = fixName;
231
244
  exports.default = {
232
245
  fixRequired,
233
246
  fixRepository,
@@ -235,6 +248,7 @@ exports.default = {
235
248
  fixKeywords,
236
249
  fixPerson,
237
250
  fixTags,
251
+ fixName,
238
252
  formatPerson,
239
253
  parsePerson,
240
254
  fixInterfaces,
package/lib/index.d.ts CHANGED
@@ -6,13 +6,14 @@ import getBlockletWallet from './wallet';
6
6
  import getBlockletInfo from './info';
7
7
  import getBlockletEngine from './engine';
8
8
  import { validateMeta, fixAndValidateService } from './validate';
9
- import { formatPerson, parsePerson, fixPerson, fixInterfaces, fixService } from './fix';
10
- import { list, select, update } from './file';
9
+ import { formatPerson, parsePerson, fixPerson, fixInterfaces, fixService, fixName } from './fix';
10
+ import { list, select, update, read } from './file';
11
11
  import verifyMultiSig from './verify-multi-sig';
12
12
  export { constants };
13
13
  export { list };
14
14
  export { select };
15
15
  export { update };
16
+ export { read };
16
17
  export { parse };
17
18
  export { validateMeta };
18
19
  export { fixAndValidateService };
@@ -21,6 +22,7 @@ export { parsePerson };
21
22
  export { fixPerson };
22
23
  export { fixInterfaces };
23
24
  export { fixService };
25
+ export { fixName };
24
26
  export { toBlockletDid };
25
27
  export { getBlockletWallet };
26
28
  export { getBlockletInfo };
@@ -35,6 +37,7 @@ declare const _default: {
35
37
  update: (file: string, meta: import("./types").TBlockletMeta, { fix }?: {
36
38
  fix?: boolean;
37
39
  }) => void;
40
+ read: (file: string) => unknown;
38
41
  parse: (dir: string, { ensureMain, ensureFiles, ensureDist, ensureComponentStore, extraRawAttrs, schemaOptions, defaultStoreUrl, fix, }?: {
39
42
  ensureMain?: boolean;
40
43
  ensureFiles?: boolean;
@@ -59,6 +62,7 @@ declare const _default: {
59
62
  parsePerson: (person: string) => any;
60
63
  fixPerson: (data: any) => any;
61
64
  fixInterfaces: (meta: any, removeMerged?: boolean) => any;
65
+ fixName: (meta: any) => any;
62
66
  fixService: (meta: import("./types").TBlockletMeta) => import("./types").TBlockletMeta;
63
67
  toBlockletDid: {
64
68
  (name: string | Buffer): string;
package/lib/index.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.verifyMultiSig = exports.getBlockletEngine = exports.getBlockletInfo = exports.getBlockletWallet = exports.toBlockletDid = exports.fixService = exports.fixInterfaces = exports.fixPerson = exports.parsePerson = exports.formatPerson = exports.fixAndValidateService = exports.validateMeta = exports.parse = exports.update = exports.select = exports.list = exports.constants = void 0;
6
+ exports.verifyMultiSig = exports.getBlockletEngine = exports.getBlockletInfo = exports.getBlockletWallet = exports.toBlockletDid = exports.fixName = exports.fixService = exports.fixInterfaces = exports.fixPerson = exports.parsePerson = exports.formatPerson = exports.fixAndValidateService = exports.validateMeta = exports.parse = exports.read = exports.update = exports.select = exports.list = exports.constants = void 0;
7
7
  const constants_1 = __importDefault(require("./constants"));
8
8
  exports.constants = constants_1.default;
9
9
  const parse_1 = __importDefault(require("./parse"));
@@ -25,10 +25,12 @@ Object.defineProperty(exports, "parsePerson", { enumerable: true, get: function
25
25
  Object.defineProperty(exports, "fixPerson", { enumerable: true, get: function () { return fix_1.fixPerson; } });
26
26
  Object.defineProperty(exports, "fixInterfaces", { enumerable: true, get: function () { return fix_1.fixInterfaces; } });
27
27
  Object.defineProperty(exports, "fixService", { enumerable: true, get: function () { return fix_1.fixService; } });
28
+ Object.defineProperty(exports, "fixName", { enumerable: true, get: function () { return fix_1.fixName; } });
28
29
  const file_1 = require("./file");
29
30
  Object.defineProperty(exports, "list", { enumerable: true, get: function () { return file_1.list; } });
30
31
  Object.defineProperty(exports, "select", { enumerable: true, get: function () { return file_1.select; } });
31
32
  Object.defineProperty(exports, "update", { enumerable: true, get: function () { return file_1.update; } });
33
+ Object.defineProperty(exports, "read", { enumerable: true, get: function () { return file_1.read; } });
32
34
  const verify_multi_sig_1 = __importDefault(require("./verify-multi-sig"));
33
35
  exports.verifyMultiSig = verify_multi_sig_1.default;
34
36
  exports.default = {
@@ -36,6 +38,7 @@ exports.default = {
36
38
  list: file_1.list,
37
39
  select: file_1.select,
38
40
  update: file_1.update,
41
+ read: file_1.read,
39
42
  parse: parse_1.default,
40
43
  validateMeta: validate_1.validateMeta,
41
44
  fixAndValidateService: validate_1.fixAndValidateService,
@@ -43,6 +46,7 @@ exports.default = {
43
46
  parsePerson: fix_1.parsePerson,
44
47
  fixPerson: fix_1.fixPerson,
45
48
  fixInterfaces: fix_1.fixInterfaces,
49
+ fixName: fix_1.fixName,
46
50
  fixService: fix_1.fixService,
47
51
  toBlockletDid: did_1.default,
48
52
  getBlockletWallet: wallet_1.default,
package/lib/name.d.ts CHANGED
@@ -1,5 +1,11 @@
1
+ /**
2
+ * 检查一个 did 是否为新版 blocklet-did(这里只需要判断是否为 ROLE_BLOCKLET 即可)
3
+ * @param did 需要检查是否为新版 did 的值
4
+ */
5
+ export declare const validateNewDid: (did: string) => void;
1
6
  export declare const validateName: (name: string) => void;
2
7
  declare const _default: {
3
8
  validateName: (name: string) => void;
9
+ validateNewDid: (did: string) => void;
4
10
  };
5
11
  export default _default;
package/lib/name.js CHANGED
@@ -3,15 +3,39 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.validateName = void 0;
6
+ exports.validateName = exports.validateNewDid = void 0;
7
+ const did_1 = require("@arcblock/did");
7
8
  const validate_npm_package_name_1 = __importDefault(require("validate-npm-package-name"));
9
+ const MAX_NAME_LENGTH = 32;
10
+ /**
11
+ * 检查一个 did 是否为新版 blocklet-did(这里只需要判断是否为 ROLE_BLOCKLET 即可)
12
+ * @param did 需要检查是否为新版 did 的值
13
+ */
14
+ const validateNewDid = (did) => {
15
+ const typeInfo = (0, did_1.toTypeInfo)(did);
16
+ if (typeInfo.role !== did_1.types.RoleType.ROLE_BLOCKLET) {
17
+ throw new Error("Blocklet DID's type must be ROLE_BLOCKLET");
18
+ }
19
+ };
20
+ exports.validateNewDid = validateNewDid;
8
21
  const validateName = (name) => {
9
- const { validForNewPackages, errors = [], warnings = [] } = (0, validate_npm_package_name_1.default)(name);
10
- if (!validForNewPackages) {
11
- throw new Error(errors[0] || warnings[0]);
22
+ if ((0, did_1.isValid)(name)) {
23
+ // new did mode
24
+ (0, exports.validateNewDid)(name);
25
+ }
26
+ else {
27
+ // old did mode
28
+ const { validForNewPackages, errors = [], warnings = [] } = (0, validate_npm_package_name_1.default)(name);
29
+ if (!validForNewPackages) {
30
+ throw new Error(errors[0] || warnings[0]);
31
+ }
32
+ if (name.length > MAX_NAME_LENGTH) {
33
+ throw new Error('Blocklet name is too long');
34
+ }
12
35
  }
13
36
  };
14
37
  exports.validateName = validateName;
15
38
  exports.default = {
16
39
  validateName: exports.validateName,
40
+ validateNewDid: exports.validateNewDid,
17
41
  };
package/lib/parse.js CHANGED
@@ -61,6 +61,7 @@ const parse = (dir, { ensureMain = false, ensureFiles = false, ensureDist = fals
61
61
  (0, fix_1.fixFiles)(result);
62
62
  (0, fix_1.fixKeywords)(result);
63
63
  (0, fix_1.fixTags)(result);
64
+ (0, fix_1.fixName)(result);
64
65
  (0, fix_1.fixPerson)(result);
65
66
  (0, fix_1.fixService)(result);
66
67
  if (defaultStoreUrl && ((_a = result.components) === null || _a === void 0 ? void 0 : _a.length)) {
package/lib/schema.js CHANGED
@@ -17,13 +17,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.authConfigSchema = exports.cacheableSchema = exports.statsSchema = exports.titleSchema = exports.themeSchema = exports.signatureSchema = exports.serviceSchema = exports.scriptsSchema = exports.personSchema = exports.navigationSchema = exports.navigationItemSchema = exports.mountPointSchema = exports.logoSchema = exports.interfaceSchema = exports.environmentNameSchema = exports.environmentSchema = exports.engineSchema = exports.endpointSchema = exports.distSchema = exports.descriptionSchema = exports.createBlockletSchema = exports.componentSchema = exports.blockletNameSchema = exports.blockletMetaSchema = void 0;
18
18
  const fs_1 = __importDefault(require("fs"));
19
19
  const joi_1 = __importDefault(require("joi"));
20
- // eslint-disable-next-line import/no-named-default
21
20
  const cjk_length_1 = __importDefault(require("cjk-length"));
22
21
  const is_glob_1 = __importDefault(require("is-glob"));
23
22
  const joi_extension_semver_1 = require("joi-extension-semver");
24
23
  const is_var_name_1 = __importDefault(require("is-var-name"));
25
24
  const constant_1 = require("@abtnode/constant");
26
- const did_1 = __importDefault(require("./did"));
25
+ const did_1 = require("@arcblock/did");
26
+ const did_2 = __importDefault(require("./did"));
27
27
  const extension_1 = require("./extension");
28
28
  const name_1 = require("./name");
29
29
  const constants_1 = __importDefault(require("./constants"));
@@ -32,7 +32,6 @@ const cjkLength = cjk_length_1.default.default;
32
32
  const { BLOCKLET_GROUPS, BLOCKLET_PLATFORMS, BLOCKLET_ARCHITECTURES, BLOCKLET_INTERFACE_TYPES, BLOCKLET_INTERFACE_PROTOCOLS, BLOCKLET_ENTRY_FILE, BLOCKLET_BUNDLE_FILE, BLOCKLET_DEFAULT_PORT_NAME, BLOCKLET_DYNAMIC_PATH_PREFIX, BlockletGroup, BLOCKLET_LATEST_REQUIREMENT_SERVER, BLOCKLET_INTERFACE_TYPE_WEB, BLOCKLET_INTERFACE_TYPE_WELLKNOWN, BLOCKLET_APP_SPACE_ENDPOINTS, BLOCKLET_CONFIGURABLE_KEY, } = constants_1.default;
33
33
  const WELLKNOWN_PATH_PREFIX = '/.well-known';
34
34
  const MAX_TITLE_LENGTH = 24;
35
- const MAX_NAME_LENGTH = 32;
36
35
  const Joi = joi_1.default.extend(joi_extension_semver_1.semver)
37
36
  .extend(joi_extension_semver_1.semverRange)
38
37
  .extend(extension_1.fileExtension)
@@ -95,7 +94,6 @@ const blockletNameSchema = Joi.string()
95
94
  (0, name_1.validateName)(value);
96
95
  return value;
97
96
  })
98
- .max(MAX_NAME_LENGTH)
99
97
  .meta({ className: 'TBlockletName' });
100
98
  exports.blockletNameSchema = blockletNameSchema;
101
99
  const ENV_NAME_WHITE_LIST = [BLOCKLET_CONFIGURABLE_KEY.BLOCKLET_WALLET_TYPE];
@@ -425,7 +423,7 @@ exports.authConfigSchema = authConfigSchema;
425
423
  const blockletMetaProps = {
426
424
  did: Joi.DID().trim().required(),
427
425
  version: Joi.semver().valid().required(),
428
- name: blockletNameSchema.required(),
426
+ name: blockletNameSchema.optional(),
429
427
  description: descriptionSchema.required(),
430
428
  group: Joi.string()
431
429
  .valid(...BLOCKLET_GROUPS)
@@ -647,10 +645,29 @@ const createBlockletSchema = (baseDir, _a = {}) => {
647
645
  .rename('children', 'components')
648
646
  .custom((data, helper) => {
649
647
  const { did, name } = data;
650
- const expectDid = (0, did_1.default)(name);
651
- if (expectDid !== did) {
652
- // @ts-expect-error
653
- return helper.message(`the did of name "${name}" should be "${expectDid}"`);
648
+ let cacheError;
649
+ if ((0, did_1.isValid)(did)) {
650
+ try {
651
+ (0, name_1.validateNewDid)(did);
652
+ return data;
653
+ }
654
+ catch (e) {
655
+ cacheError = e;
656
+ }
657
+ }
658
+ /* ------------- 兼容旧的逻辑,旧逻辑使用 name 生成一个 did ------------- */
659
+ // 此时 name 必须存在
660
+ if (name) {
661
+ const expectDid = (0, did_2.default)(name);
662
+ if (expectDid !== did) {
663
+ // @ts-ignore
664
+ return helper.message(`The did of name "${name}" should be "${expectDid}"`);
665
+ }
666
+ return data;
667
+ /* ------------------------------------------------------ */
668
+ }
669
+ if (cacheError) {
670
+ return helper.message(cacheError.message);
654
671
  }
655
672
  return data;
656
673
  });
@@ -66,7 +66,7 @@ export interface TBlockletMeta {
66
66
  logoUrl?: string;
67
67
  main: string;
68
68
  maintainers?: TPerson[];
69
- name: TBlockletName;
69
+ name?: TBlockletName;
70
70
  navigation?: TNavigation;
71
71
  nftFactory?: string;
72
72
  path?: string;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.8.65",
6
+ "version": "1.8.66-beta-ff281dd5",
7
7
  "description": "Library to parse/validate/fix blocklet meta",
8
8
  "main": "./lib/index.js",
9
9
  "typings": "./lib/index.d.ts",
@@ -24,14 +24,14 @@
24
24
  "author": "wangshijun <wangshijun2020@gmail.com> (http://github.com/wangshijun)",
25
25
  "license": "MIT",
26
26
  "dependencies": {
27
- "@abtnode/client": "1.8.65",
28
- "@abtnode/constant": "1.8.65",
29
- "@abtnode/util": "1.8.65",
27
+ "@abtnode/client": "1.8.66-beta-ff281dd5",
28
+ "@abtnode/constant": "1.8.66-beta-ff281dd5",
29
+ "@abtnode/util": "1.8.66-beta-ff281dd5",
30
30
  "@arcblock/did": "1.18.42",
31
31
  "@arcblock/did-ext": "1.18.42",
32
32
  "@arcblock/did-util": "1.18.42",
33
33
  "@arcblock/jwt": "1.18.42",
34
- "@blocklet/constant": "1.8.65",
34
+ "@blocklet/constant": "1.8.66-beta-ff281dd5",
35
35
  "@ocap/asset": "1.18.42",
36
36
  "@ocap/mcrypto": "1.18.42",
37
37
  "@ocap/types": "1.18.42",
@@ -80,5 +80,5 @@
80
80
  "ts-node": "^10.9.1",
81
81
  "typescript": "^4.8.4"
82
82
  },
83
- "gitHead": "69b608353fbbdb7c61f9ccb10965a1d0c55c45f2"
83
+ "gitHead": "92edfc81679a4749b30a7f8195d487afa148e26b"
84
84
  }