@blocklet/meta 1.8.65 → 1.8.66-beta-7f4224af
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/channel.d.ts +9 -4
- package/lib/channel.js +19 -4
- package/lib/did.js +3 -0
- package/lib/extension.d.ts +4 -0
- package/lib/extension.js +4 -0
- package/lib/file.d.ts +2 -0
- package/lib/file.js +6 -1
- package/lib/fix.d.ts +3 -0
- package/lib/fix.js +15 -1
- package/lib/index.d.ts +6 -2
- package/lib/index.js +5 -1
- package/lib/name.d.ts +6 -0
- package/lib/name.js +28 -4
- package/lib/parse.js +1 -0
- package/lib/schema.js +26 -9
- package/lib/types/schema.d.ts +1 -1
- package/lib/util.d.ts +32 -6
- package/lib/util.js +31 -8
- package/package.json +16 -16
package/lib/channel.d.ts
CHANGED
|
@@ -1,27 +1,32 @@
|
|
|
1
1
|
declare const getAppPublicChannelRegex: () => RegExp;
|
|
2
|
+
declare const getRelayChannelRegex: () => RegExp;
|
|
2
3
|
declare const getAppPublicChannel: (appDid: string) => string;
|
|
4
|
+
declare const getRelayChannel: (appDid: string, topic: string) => string;
|
|
3
5
|
declare const CHANNEL_TYPE: {
|
|
4
6
|
DID: string;
|
|
5
7
|
APP: string;
|
|
8
|
+
RELAY: string;
|
|
6
9
|
};
|
|
7
10
|
declare const parseChannel: (channel: string) => {
|
|
8
11
|
type: string;
|
|
9
12
|
appDid?: string;
|
|
13
|
+
topic?: string;
|
|
10
14
|
};
|
|
11
|
-
export { CHANNEL_TYPE };
|
|
12
|
-
export { getAppPublicChannel };
|
|
13
|
-
export { getAppPublicChannelRegex };
|
|
14
|
-
export { parseChannel };
|
|
15
|
+
export { CHANNEL_TYPE, getAppPublicChannel, getAppPublicChannelRegex, getRelayChannel, getRelayChannelRegex, parseChannel, };
|
|
15
16
|
declare const _default: {
|
|
16
17
|
CHANNEL_TYPE: {
|
|
17
18
|
DID: string;
|
|
18
19
|
APP: string;
|
|
20
|
+
RELAY: string;
|
|
19
21
|
};
|
|
20
22
|
getAppPublicChannel: (appDid: string) => string;
|
|
21
23
|
getAppPublicChannelRegex: () => RegExp;
|
|
24
|
+
getRelayChannel: (appDid: string, topic: string) => string;
|
|
25
|
+
getRelayChannelRegex: () => RegExp;
|
|
22
26
|
parseChannel: (channel: string) => {
|
|
23
27
|
type: string;
|
|
24
28
|
appDid?: string;
|
|
29
|
+
topic?: string;
|
|
25
30
|
};
|
|
26
31
|
};
|
|
27
32
|
export default _default;
|
package/lib/channel.js
CHANGED
|
@@ -1,26 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseChannel = exports.getAppPublicChannelRegex = exports.getAppPublicChannel = exports.CHANNEL_TYPE = void 0;
|
|
3
|
+
exports.parseChannel = exports.getRelayChannelRegex = exports.getRelayChannel = exports.getAppPublicChannelRegex = exports.getAppPublicChannel = exports.CHANNEL_TYPE = void 0;
|
|
4
4
|
/* eslint-disable @typescript-eslint/indent */
|
|
5
5
|
const did_1 = require("@arcblock/did");
|
|
6
6
|
const getAppPublicChannelRegex = () => /app:(\w+):public/;
|
|
7
7
|
exports.getAppPublicChannelRegex = getAppPublicChannelRegex;
|
|
8
|
+
const getRelayChannelRegex = () => /relay:(\w+):(\w+)/;
|
|
9
|
+
exports.getRelayChannelRegex = getRelayChannelRegex;
|
|
8
10
|
const getAppPublicChannel = (appDid) => `app:${appDid}:public`;
|
|
9
11
|
exports.getAppPublicChannel = getAppPublicChannel;
|
|
12
|
+
const getRelayChannel = (appDid, topic) => `relay:${appDid}:${topic}`;
|
|
13
|
+
exports.getRelayChannel = getRelayChannel;
|
|
10
14
|
const CHANNEL_TYPE = {
|
|
11
15
|
DID: 'DID',
|
|
12
16
|
APP: 'APP',
|
|
17
|
+
RELAY: 'RELAY',
|
|
13
18
|
};
|
|
14
19
|
exports.CHANNEL_TYPE = CHANNEL_TYPE;
|
|
15
20
|
const parseChannel = (channel) => {
|
|
16
21
|
if (!channel) {
|
|
17
22
|
throw new Error('Channel should not be empty');
|
|
18
23
|
}
|
|
19
|
-
|
|
20
|
-
if (
|
|
24
|
+
let match = getRelayChannelRegex().exec(channel);
|
|
25
|
+
if (match && (0, did_1.isValid)(match[1])) {
|
|
26
|
+
return {
|
|
27
|
+
type: CHANNEL_TYPE.RELAY,
|
|
28
|
+
appDid: match[1],
|
|
29
|
+
topic: match[2],
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
match = getAppPublicChannelRegex().exec(channel);
|
|
33
|
+
if (match && (0, did_1.isValid)(match[1])) {
|
|
21
34
|
return {
|
|
22
35
|
type: CHANNEL_TYPE.APP,
|
|
23
|
-
appDid:
|
|
36
|
+
appDid: match[1],
|
|
24
37
|
};
|
|
25
38
|
}
|
|
26
39
|
if ((0, did_1.isValid)(channel)) {
|
|
@@ -35,5 +48,7 @@ exports.default = {
|
|
|
35
48
|
CHANNEL_TYPE,
|
|
36
49
|
getAppPublicChannel,
|
|
37
50
|
getAppPublicChannelRegex,
|
|
51
|
+
getRelayChannel,
|
|
52
|
+
getRelayChannelRegex,
|
|
38
53
|
parseChannel,
|
|
39
54
|
};
|
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
|
};
|
package/lib/extension.d.ts
CHANGED
|
@@ -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
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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 =
|
|
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.
|
|
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
|
-
|
|
651
|
-
if (
|
|
652
|
-
|
|
653
|
-
|
|
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
|
});
|
package/lib/types/schema.d.ts
CHANGED
package/lib/util.d.ts
CHANGED
|
@@ -54,10 +54,21 @@ declare const forEachBlocklet: (blocklet: BlockletState | ComponentState, cb: Fu
|
|
|
54
54
|
declare const forEachBlockletSync: (blocklet: any, cb: Function) => Promise<unknown>;
|
|
55
55
|
declare const forEachChild: (blocklet: any, cb: Function, params?: any) => Promise<any>;
|
|
56
56
|
declare const forEachChildSync: (blocklet: BlockletState, cb: Function) => Promise<any>;
|
|
57
|
-
declare const
|
|
58
|
-
|
|
57
|
+
declare const findComponent: (blocklet: BlockletState | ComponentState, isEqualFn: (component: ComponentState, context: {
|
|
58
|
+
ancestors: Array<ComponentState>;
|
|
59
|
+
}) => boolean, { _ancestors, returnAncestors, }?: {
|
|
60
|
+
_ancestors?: Array<ComponentState>;
|
|
61
|
+
returnAncestors?: boolean;
|
|
62
|
+
}) => ComponentState | {
|
|
63
|
+
component: ComponentState;
|
|
64
|
+
ancestors: Array<ComponentState>;
|
|
65
|
+
};
|
|
66
|
+
declare const findComponentById: (blocklet: BlockletState | ComponentState, componentId: string | Array<string>, { returnAncestors, }?: {
|
|
59
67
|
returnAncestors?: boolean;
|
|
60
|
-
}) =>
|
|
68
|
+
}) => ComponentState | {
|
|
69
|
+
component: ComponentState;
|
|
70
|
+
ancestors: Array<ComponentState>;
|
|
71
|
+
};
|
|
61
72
|
declare const isEnvShareable: (env?: TConfig) => boolean;
|
|
62
73
|
declare const getSharedConfigObj: (component: BlockletState, ancestors?: any[]) => any;
|
|
63
74
|
declare const isPreferenceKey: (x: TConfig) => Boolean;
|
|
@@ -78,6 +89,7 @@ declare const hasRunnableComponent: (blocklet: BlockletState) => boolean;
|
|
|
78
89
|
declare const getDisplayName: (blocklet: BlockletState, onlyUseMeta?: boolean) => string;
|
|
79
90
|
declare const fixBlockletStatus: (blocklet?: BlockletState) => void;
|
|
80
91
|
declare const findWebInterface: (blocklet?: BlockletState | TBlockletMeta) => any;
|
|
92
|
+
declare const findWebInterfacePort: (blocklet?: BlockletState) => any;
|
|
81
93
|
declare const findServiceFromMeta: (meta?: TBlockletMeta, ServiceName?: string) => any;
|
|
82
94
|
declare const getWhoCanAccess: (blocklet?: BlockletState) => any;
|
|
83
95
|
declare const getConnectAppUrl: ({ request, baseUrl }: {
|
|
@@ -108,6 +120,7 @@ export { hasRunnableComponent };
|
|
|
108
120
|
export { getDisplayName };
|
|
109
121
|
export { fixBlockletStatus };
|
|
110
122
|
export { findWebInterface };
|
|
123
|
+
export { findWebInterfacePort };
|
|
111
124
|
export { findServiceFromMeta };
|
|
112
125
|
export { getWhoCanAccess };
|
|
113
126
|
export { replaceSlotToIp };
|
|
@@ -115,6 +128,7 @@ export { urlFriendly };
|
|
|
115
128
|
export { getComponentId };
|
|
116
129
|
export { getComponentName };
|
|
117
130
|
export { getComponentBundleId };
|
|
131
|
+
export { findComponent };
|
|
118
132
|
export { findComponentById };
|
|
119
133
|
export { getParentComponentName };
|
|
120
134
|
export { getConnectAppUrl };
|
|
@@ -151,6 +165,7 @@ declare const _default: {
|
|
|
151
165
|
getDisplayName: (blocklet: BlockletState, onlyUseMeta?: boolean) => string;
|
|
152
166
|
fixBlockletStatus: (blocklet?: BlockletState) => void;
|
|
153
167
|
findWebInterface: (blocklet?: TBlockletMeta | BlockletState) => any;
|
|
168
|
+
findWebInterfacePort: (blocklet?: BlockletState) => any;
|
|
154
169
|
findServiceFromMeta: (meta?: TBlockletMeta, ServiceName?: string) => any;
|
|
155
170
|
getWhoCanAccess: (blocklet?: BlockletState) => any;
|
|
156
171
|
replaceSlotToIp: (url?: string, ip?: string) => string;
|
|
@@ -179,10 +194,21 @@ declare const _default: {
|
|
|
179
194
|
version: string;
|
|
180
195
|
};
|
|
181
196
|
}) => string;
|
|
182
|
-
|
|
183
|
-
|
|
197
|
+
findComponent: (blocklet: BlockletState | ComponentState, isEqualFn: (component: ComponentState, context: {
|
|
198
|
+
ancestors: ComponentState[];
|
|
199
|
+
}) => boolean, { _ancestors, returnAncestors, }?: {
|
|
200
|
+
_ancestors?: ComponentState[];
|
|
201
|
+
returnAncestors?: boolean;
|
|
202
|
+
}) => ComponentState | {
|
|
203
|
+
component: ComponentState;
|
|
204
|
+
ancestors: ComponentState[];
|
|
205
|
+
};
|
|
206
|
+
findComponentById: (blocklet: BlockletState | ComponentState, componentId: string | string[], { returnAncestors, }?: {
|
|
184
207
|
returnAncestors?: boolean;
|
|
185
|
-
}) =>
|
|
208
|
+
}) => ComponentState | {
|
|
209
|
+
component: ComponentState;
|
|
210
|
+
ancestors: ComponentState[];
|
|
211
|
+
};
|
|
186
212
|
getParentComponentName: (name?: string) => string;
|
|
187
213
|
getConnectAppUrl: ({ request, baseUrl }: {
|
|
188
214
|
request: Partial<Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>>;
|
package/lib/util.js
CHANGED
|
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.getRolesFromAuthConfig = exports.isPreferenceKey = exports.isExternalBlocklet = exports.getChainInfo = exports.getConnectAppUrl = exports.getParentComponentName = exports.findComponentById = exports.getComponentBundleId = exports.getComponentName = exports.getComponentId = exports.urlFriendly = exports.replaceSlotToIp = exports.getWhoCanAccess = exports.findServiceFromMeta = exports.findWebInterface = exports.fixBlockletStatus = exports.getDisplayName = exports.hasRunnableComponent = exports.wipeSensitiveData = exports.isEnvShareable = exports.getComponentMissingConfigs = exports.getAppMissingConfigs = exports.getSharedConfigObj = exports.isDeletableBlocklet = exports.forEachChildSync = exports.forEachChild = exports.forEachBlockletSync = exports.forEachBlocklet = exports.isComponentBlocklet = exports.isFreeComponent = exports.isFreeBlocklet = void 0;
|
|
15
|
+
exports.getRolesFromAuthConfig = exports.isPreferenceKey = exports.isExternalBlocklet = exports.getChainInfo = exports.getConnectAppUrl = exports.getParentComponentName = exports.findComponentById = exports.findComponent = exports.getComponentBundleId = exports.getComponentName = exports.getComponentId = exports.urlFriendly = exports.replaceSlotToIp = exports.getWhoCanAccess = exports.findServiceFromMeta = exports.findWebInterfacePort = exports.findWebInterface = exports.fixBlockletStatus = exports.getDisplayName = exports.hasRunnableComponent = exports.wipeSensitiveData = exports.isEnvShareable = exports.getComponentMissingConfigs = exports.getAppMissingConfigs = exports.getSharedConfigObj = exports.isDeletableBlocklet = exports.forEachChildSync = exports.forEachChild = exports.forEachBlockletSync = exports.forEachBlocklet = exports.isComponentBlocklet = exports.isFreeComponent = exports.isFreeBlocklet = void 0;
|
|
16
16
|
/* eslint-disable no-await-in-loop */
|
|
17
17
|
const get_1 = __importDefault(require("lodash/get"));
|
|
18
18
|
const slugify_1 = __importDefault(require("slugify"));
|
|
@@ -153,13 +153,11 @@ exports.forEachChild = forEachChild;
|
|
|
153
153
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
154
154
|
const forEachChildSync = (blocklet, cb) => forEachChild(blocklet, cb, { sync: true });
|
|
155
155
|
exports.forEachChildSync = forEachChildSync;
|
|
156
|
-
const
|
|
157
|
-
if (
|
|
158
|
-
|
|
159
|
-
componentId = componentId.join('/');
|
|
156
|
+
const findComponent = (blocklet, isEqualFn, { _ancestors = [], returnAncestors = false, } = {}) => {
|
|
157
|
+
if (!isEqualFn) {
|
|
158
|
+
return null;
|
|
160
159
|
}
|
|
161
|
-
|
|
162
|
-
if (componentId === id) {
|
|
160
|
+
if (isEqualFn(blocklet, { ancestors: _ancestors })) {
|
|
163
161
|
if (returnAncestors) {
|
|
164
162
|
return {
|
|
165
163
|
component: blocklet,
|
|
@@ -170,13 +168,24 @@ const findComponentById = (blocklet, componentId, { _ancestors = [], returnAnces
|
|
|
170
168
|
}
|
|
171
169
|
for (const child of blocklet.children || []) {
|
|
172
170
|
const ancestors = _ancestors.concat(blocklet);
|
|
173
|
-
const component =
|
|
171
|
+
const component = findComponent(child, isEqualFn, { _ancestors: ancestors, returnAncestors });
|
|
174
172
|
if (component) {
|
|
175
173
|
return component;
|
|
176
174
|
}
|
|
177
175
|
}
|
|
178
176
|
return null;
|
|
179
177
|
};
|
|
178
|
+
exports.findComponent = findComponent;
|
|
179
|
+
const findComponentById = (blocklet, componentId, { returnAncestors = false, } = {}) => {
|
|
180
|
+
if (Array.isArray(componentId)) {
|
|
181
|
+
// eslint-disable-next-line no-param-reassign
|
|
182
|
+
componentId = componentId.join('/');
|
|
183
|
+
}
|
|
184
|
+
return findComponent(blocklet, (component, { ancestors }) => {
|
|
185
|
+
const id = getComponentId(component, ancestors);
|
|
186
|
+
return componentId === id;
|
|
187
|
+
}, { returnAncestors });
|
|
188
|
+
};
|
|
180
189
|
exports.findComponentById = findComponentById;
|
|
181
190
|
const isEnvShareable = (env) => {
|
|
182
191
|
return (!!env &&
|
|
@@ -365,6 +374,18 @@ const findWebInterface = (blocklet) => {
|
|
|
365
374
|
return interfaces.find((x) => x.type === BLOCKLET_INTERFACE_TYPE_WEB);
|
|
366
375
|
};
|
|
367
376
|
exports.findWebInterface = findWebInterface;
|
|
377
|
+
const findWebInterfacePort = (blocklet) => {
|
|
378
|
+
if (!blocklet) {
|
|
379
|
+
return null;
|
|
380
|
+
}
|
|
381
|
+
const webInterface = findWebInterface(blocklet);
|
|
382
|
+
const { ports } = blocklet;
|
|
383
|
+
if (!webInterface || !ports) {
|
|
384
|
+
return null;
|
|
385
|
+
}
|
|
386
|
+
return ports[webInterface.port];
|
|
387
|
+
};
|
|
388
|
+
exports.findWebInterfacePort = findWebInterfacePort;
|
|
368
389
|
const findServiceFromMeta = (meta, ServiceName) => {
|
|
369
390
|
const names = [ServiceName];
|
|
370
391
|
// backward compatible
|
|
@@ -445,6 +466,7 @@ exports.default = {
|
|
|
445
466
|
getDisplayName,
|
|
446
467
|
fixBlockletStatus,
|
|
447
468
|
findWebInterface,
|
|
469
|
+
findWebInterfacePort,
|
|
448
470
|
findServiceFromMeta,
|
|
449
471
|
getWhoCanAccess,
|
|
450
472
|
replaceSlotToIp,
|
|
@@ -452,6 +474,7 @@ exports.default = {
|
|
|
452
474
|
getComponentId,
|
|
453
475
|
getComponentName,
|
|
454
476
|
getComponentBundleId,
|
|
477
|
+
findComponent,
|
|
455
478
|
findComponentById,
|
|
456
479
|
getParentComponentName,
|
|
457
480
|
getConnectAppUrl,
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.8.
|
|
6
|
+
"version": "1.8.66-beta-7f4224af",
|
|
7
7
|
"description": "Library to parse/validate/fix blocklet meta",
|
|
8
8
|
"main": "./lib/index.js",
|
|
9
9
|
"typings": "./lib/index.d.ts",
|
|
@@ -24,19 +24,19 @@
|
|
|
24
24
|
"author": "wangshijun <wangshijun2020@gmail.com> (http://github.com/wangshijun)",
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@abtnode/client": "1.8.
|
|
28
|
-
"@abtnode/constant": "1.8.
|
|
29
|
-
"@abtnode/util": "1.8.
|
|
30
|
-
"@arcblock/did": "1.18.
|
|
31
|
-
"@arcblock/did-ext": "1.18.
|
|
32
|
-
"@arcblock/did-util": "1.18.
|
|
33
|
-
"@arcblock/jwt": "1.18.
|
|
34
|
-
"@blocklet/constant": "1.8.
|
|
35
|
-
"@ocap/asset": "1.18.
|
|
36
|
-
"@ocap/mcrypto": "1.18.
|
|
37
|
-
"@ocap/types": "1.18.
|
|
38
|
-
"@ocap/util": "1.18.
|
|
39
|
-
"@ocap/wallet": "1.18.
|
|
27
|
+
"@abtnode/client": "1.8.66-beta-7f4224af",
|
|
28
|
+
"@abtnode/constant": "1.8.66-beta-7f4224af",
|
|
29
|
+
"@abtnode/util": "1.8.66-beta-7f4224af",
|
|
30
|
+
"@arcblock/did": "1.18.47",
|
|
31
|
+
"@arcblock/did-ext": "1.18.47",
|
|
32
|
+
"@arcblock/did-util": "1.18.47",
|
|
33
|
+
"@arcblock/jwt": "1.18.47",
|
|
34
|
+
"@blocklet/constant": "1.8.66-beta-7f4224af",
|
|
35
|
+
"@ocap/asset": "1.18.47",
|
|
36
|
+
"@ocap/mcrypto": "1.18.47",
|
|
37
|
+
"@ocap/types": "1.18.47",
|
|
38
|
+
"@ocap/util": "1.18.47",
|
|
39
|
+
"@ocap/wallet": "1.18.47",
|
|
40
40
|
"ajv": "^8.11.0",
|
|
41
41
|
"axios": "^0.27.2",
|
|
42
42
|
"cjk-length": "^1.0.0",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"validate-npm-package-name": "^3.0.0"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
|
-
"@abtnode/client": "^1.8.
|
|
62
|
+
"@abtnode/client": "^1.8.65",
|
|
63
63
|
"@arcblock/eslint-config-ts": "^0.2.3",
|
|
64
64
|
"@types/express": "^4.17.14",
|
|
65
65
|
"@types/jest": "^29.2.2",
|
|
@@ -80,5 +80,5 @@
|
|
|
80
80
|
"ts-node": "^10.9.1",
|
|
81
81
|
"typescript": "^4.8.4"
|
|
82
82
|
},
|
|
83
|
-
"gitHead": "
|
|
83
|
+
"gitHead": "72d418f63ecb76b1d5d62edbcc5f336cb62bf308"
|
|
84
84
|
}
|