@blocklet/meta 1.8.68 → 1.8.69-beta-e0666d0d
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 +10 -5
- package/lib/index.js +5 -1
- package/lib/info.d.ts +3 -2
- package/lib/info.js +11 -5
- package/lib/name.d.ts +6 -0
- package/lib/name.js +28 -4
- package/lib/parse-navigation-from-blocklet.js +29 -25
- package/lib/parse-navigation.js +13 -6
- package/lib/parse.js +8 -5
- package/lib/payment/v2.js +52 -60
- package/lib/schema.d.ts +3 -1
- package/lib/schema.js +79 -32
- package/lib/service.js +7 -1
- package/lib/types/schema.d.ts +2 -1
- package/lib/url-friendly.d.ts +2 -0
- package/lib/url-friendly.js +7 -1
- package/lib/util-meta.js +14 -23
- package/lib/util.d.ts +45 -40
- package/lib/util.js +77 -30
- package/lib/validate.js +5 -2
- package/lib/verify-multi-sig.js +3 -14
- package/lib/wallet.d.ts +1 -1
- package/lib/wallet.js +4 -3
- package/package.json +17 -16
package/lib/url-friendly.d.ts
CHANGED
package/lib/url-friendly.js
CHANGED
|
@@ -3,12 +3,18 @@ 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.isValidUrl = void 0;
|
|
6
7
|
const toLower_1 = __importDefault(require("lodash/toLower"));
|
|
7
8
|
const slugify_1 = __importDefault(require("slugify"));
|
|
9
|
+
const isValidUrl = (name) => {
|
|
10
|
+
const regex = /[\s$*_+~.()'"!:@\\]+/g;
|
|
11
|
+
return !regex.test(name);
|
|
12
|
+
};
|
|
13
|
+
exports.isValidUrl = isValidUrl;
|
|
8
14
|
const urlFriendly = (name, { keepSlash = true } = { keepSlash: true }) => {
|
|
9
15
|
if (!keepSlash) {
|
|
10
16
|
return (0, toLower_1.default)((0, slugify_1.default)(name.replace(/^[@./-]/, '').replace(/[@./_]/g, '-')));
|
|
11
17
|
}
|
|
12
|
-
return (0, toLower_1.default)((0, slugify_1.default)(name.replace(/^[@.-]/, '').replace(/[@._]/g, '-'), { remove: /[^\w\s$*_+~.()'"
|
|
18
|
+
return (0, toLower_1.default)((0, slugify_1.default)(name.replace(/^[@.-]/, '').replace(/[@._]/g, '-'), { remove: /[^\w\s$*_+~.()'"!:@^/]+/g }));
|
|
13
19
|
};
|
|
14
20
|
exports.default = urlFriendly;
|
package/lib/util-meta.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -22,7 +13,7 @@ const constant_1 = __importDefault(require("@abtnode/constant"));
|
|
|
22
13
|
const did_1 = __importDefault(require("./did"));
|
|
23
14
|
const validate_1 = require("./validate");
|
|
24
15
|
const { BLOCKLET_STORE_API_BLOCKLET_PREFIX } = constant_1.default;
|
|
25
|
-
const validateUrl = (url, expectedHttpResTypes = ['application/json', 'text/plain']) =>
|
|
16
|
+
const validateUrl = async (url, expectedHttpResTypes = ['application/json', 'text/plain']) => {
|
|
26
17
|
const parsed = new URL(url);
|
|
27
18
|
const { protocol } = parsed;
|
|
28
19
|
// file
|
|
@@ -37,7 +28,7 @@ const validateUrl = (url, expectedHttpResTypes = ['application/json', 'text/plai
|
|
|
37
28
|
if (protocol.startsWith('http')) {
|
|
38
29
|
let res;
|
|
39
30
|
try {
|
|
40
|
-
res =
|
|
31
|
+
res = await (0, axios_1.default)({ url, method: 'HEAD', timeout: 1000 * 10 });
|
|
41
32
|
}
|
|
42
33
|
catch (err) {
|
|
43
34
|
throw new Error(`Cannot get content-type from ${url}: ${err.message}`);
|
|
@@ -49,36 +40,36 @@ const validateUrl = (url, expectedHttpResTypes = ['application/json', 'text/plai
|
|
|
49
40
|
return true;
|
|
50
41
|
}
|
|
51
42
|
throw new Error(`Invalid url protocol: ${protocol.replace(/:$/, '')}`);
|
|
52
|
-
}
|
|
43
|
+
};
|
|
53
44
|
exports.validateUrl = validateUrl;
|
|
54
45
|
const validateBlockletMeta = (meta, opts = {}) => {
|
|
55
46
|
(0, validate_1.fixAndValidateService)(meta);
|
|
56
47
|
return (0, validate_1.validateMeta)(meta, opts);
|
|
57
48
|
};
|
|
58
|
-
const getBlockletMetaByUrl = (url) =>
|
|
49
|
+
const getBlockletMetaByUrl = async (url) => {
|
|
59
50
|
const { protocol } = new URL(url);
|
|
60
51
|
if (protocol.startsWith('file')) {
|
|
61
52
|
const decoded = decodeURIComponent((0, url_1.fileURLToPath)(url));
|
|
62
53
|
if (!fs_1.default.existsSync(decoded)) {
|
|
63
54
|
throw new Error(`File does not exist: ${decoded}`);
|
|
64
55
|
}
|
|
65
|
-
const d =
|
|
56
|
+
const d = await fs_1.default.promises.readFile(decoded);
|
|
66
57
|
// @ts-expect-error TS(2345) FIXME: Argument of type 'Buffer' is not assignable to par... Remove this comment to see the full error message
|
|
67
58
|
const meta = JSON.parse(d);
|
|
68
59
|
return meta;
|
|
69
60
|
}
|
|
70
61
|
if (protocol.startsWith('http')) {
|
|
71
|
-
const { data: meta } =
|
|
62
|
+
const { data: meta } = await (0, axios_1.default)({ url, method: 'GET', timeout: 1000 * 20 });
|
|
72
63
|
if (Object.prototype.toString.call(meta) !== '[object Object]') {
|
|
73
64
|
throw new Error('Url is not valid');
|
|
74
65
|
}
|
|
75
66
|
return meta;
|
|
76
67
|
}
|
|
77
68
|
throw new Error(`Invalid url protocol: ${protocol.replace(/:$/, '')}`);
|
|
78
|
-
}
|
|
69
|
+
};
|
|
79
70
|
exports.getBlockletMetaByUrl = getBlockletMetaByUrl;
|
|
80
|
-
const getBlockletMetaFromUrl = (url, { validateFn = validateBlockletMeta, returnUrl = false, ensureTarball = true, logger, } = {}) =>
|
|
81
|
-
const meta =
|
|
71
|
+
const getBlockletMetaFromUrl = async (url, { validateFn = validateBlockletMeta, returnUrl = false, ensureTarball = true, logger, } = {}) => {
|
|
72
|
+
const meta = await getBlockletMetaByUrl(url);
|
|
82
73
|
delete meta.htmlAst;
|
|
83
74
|
const newMeta = validateFn(meta, { ensureDist: true });
|
|
84
75
|
if (ensureTarball) {
|
|
@@ -86,7 +77,7 @@ const getBlockletMetaFromUrl = (url, { validateFn = validateBlockletMeta, return
|
|
|
86
77
|
const { href } = new URL(newMeta.dist.tarball, url);
|
|
87
78
|
const tarball = decodeURIComponent(href);
|
|
88
79
|
try {
|
|
89
|
-
|
|
80
|
+
await validateUrl(tarball, ['application/octet-stream', 'application/x-gzip']);
|
|
90
81
|
}
|
|
91
82
|
catch (error) {
|
|
92
83
|
if (!error.message.startsWith('Cannot get content-type')) {
|
|
@@ -107,11 +98,11 @@ const getBlockletMetaFromUrl = (url, { validateFn = validateBlockletMeta, return
|
|
|
107
98
|
return { meta: newMeta, url };
|
|
108
99
|
}
|
|
109
100
|
return newMeta;
|
|
110
|
-
}
|
|
101
|
+
};
|
|
111
102
|
exports.getBlockletMetaFromUrl = getBlockletMetaFromUrl;
|
|
112
|
-
const getBlockletMetaFromUrls = (urls, { validateFn, returnUrl = false, ensureTarball = true, logger, } = {}) =>
|
|
103
|
+
const getBlockletMetaFromUrls = async (urls, { validateFn, returnUrl = false, ensureTarball = true, logger, } = {}) => {
|
|
113
104
|
try {
|
|
114
|
-
const res =
|
|
105
|
+
const res = await (0, promise_any_1.default)(urls.map((url) => getBlockletMetaFromUrl(url, { validateFn, returnUrl, ensureTarball, logger })));
|
|
115
106
|
return res;
|
|
116
107
|
}
|
|
117
108
|
catch (err) {
|
|
@@ -124,7 +115,7 @@ const getBlockletMetaFromUrls = (urls, { validateFn, returnUrl = false, ensureTa
|
|
|
124
115
|
}
|
|
125
116
|
throw new Error(message);
|
|
126
117
|
}
|
|
127
|
-
}
|
|
118
|
+
};
|
|
128
119
|
exports.getBlockletMetaFromUrls = getBlockletMetaFromUrls;
|
|
129
120
|
/**
|
|
130
121
|
* @param {*} config defined in componentSchema in blocklet meta schema
|
package/lib/util.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { BlockletState, ComponentState } from '@abtnode/client';
|
|
2
|
-
import { Request } from 'express';
|
|
3
|
-
import { TBlockletMeta, TEnvironment } from './types';
|
|
1
|
+
import type { BlockletState, ComponentState } from '@abtnode/client';
|
|
2
|
+
import type { Request } from 'express';
|
|
3
|
+
import type { TBlockletMeta, TEnvironment } from './types';
|
|
4
4
|
type TConfig = TEnvironment & {
|
|
5
5
|
key: string;
|
|
6
6
|
};
|
|
@@ -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;
|
|
@@ -75,9 +86,17 @@ declare const hasRunnableComponent: (blocklet: BlockletState) => boolean;
|
|
|
75
86
|
* @param {Boolean} onlyUseMeta 优先使用应用元数据的name
|
|
76
87
|
* @returns blocklet display name
|
|
77
88
|
*/
|
|
78
|
-
declare const
|
|
89
|
+
declare const getAppName: (blocklet: BlockletState, onlyUseMeta?: boolean) => string;
|
|
90
|
+
/**
|
|
91
|
+
* 获取 blocklet 的 description
|
|
92
|
+
* @param {Object} blocklet 应用数据
|
|
93
|
+
* @param {Boolean} onlyUseMeta 优先使用应用元数据的name
|
|
94
|
+
* @returns blocklet display description
|
|
95
|
+
*/
|
|
96
|
+
declare const getAppDescription: (blocklet: BlockletState, onlyUseMeta?: boolean) => string;
|
|
79
97
|
declare const fixBlockletStatus: (blocklet?: BlockletState) => void;
|
|
80
98
|
declare const findWebInterface: (blocklet?: BlockletState | TBlockletMeta) => any;
|
|
99
|
+
declare const findWebInterfacePort: (blocklet?: BlockletState) => any;
|
|
81
100
|
declare const findServiceFromMeta: (meta?: TBlockletMeta, ServiceName?: string) => any;
|
|
82
101
|
declare const getWhoCanAccess: (blocklet?: BlockletState) => any;
|
|
83
102
|
declare const getConnectAppUrl: ({ request, baseUrl }: {
|
|
@@ -90,36 +109,8 @@ declare const isExternalBlocklet: (blocklet?: BlockletState) => boolean;
|
|
|
90
109
|
declare const getRolesFromAuthConfig: (config: {
|
|
91
110
|
whoCanAccess: string;
|
|
92
111
|
}) => Array<string>;
|
|
93
|
-
|
|
94
|
-
export { isFreeComponent };
|
|
95
|
-
export { isComponentBlocklet };
|
|
96
|
-
export { forEachBlocklet };
|
|
97
|
-
export { forEachBlockletSync };
|
|
98
|
-
export { forEachChild };
|
|
99
|
-
export { forEachChildSync };
|
|
100
|
-
export { isDeletableBlocklet };
|
|
101
|
-
export { getSharedConfigObj };
|
|
102
|
-
export { getAppMissingConfigs };
|
|
103
|
-
export { getComponentMissingConfigs };
|
|
104
|
-
export { isEnvShareable };
|
|
105
|
-
export { wipeSensitiveData };
|
|
106
|
-
export { hasRunnableComponent };
|
|
107
|
-
export { getDisplayName };
|
|
108
|
-
export { fixBlockletStatus };
|
|
109
|
-
export { findWebInterface };
|
|
110
|
-
export { findServiceFromMeta };
|
|
111
|
-
export { getWhoCanAccess };
|
|
112
|
-
export { replaceSlotToIp };
|
|
113
|
-
export { getComponentId };
|
|
114
|
-
export { getComponentName };
|
|
115
|
-
export { getComponentBundleId };
|
|
116
|
-
export { findComponentById };
|
|
117
|
-
export { getParentComponentName };
|
|
118
|
-
export { getConnectAppUrl };
|
|
119
|
-
export { getChainInfo };
|
|
120
|
-
export { isExternalBlocklet };
|
|
121
|
-
export { isPreferenceKey };
|
|
122
|
-
export { getRolesFromAuthConfig };
|
|
112
|
+
declare const getBlockletAppIdList: (blocklet: Partial<BlockletState>) => string[];
|
|
113
|
+
export { isFreeBlocklet, isFreeComponent, isComponentBlocklet, forEachBlocklet, forEachBlockletSync, forEachChild, forEachChildSync, isDeletableBlocklet, getSharedConfigObj, getAppMissingConfigs, getComponentMissingConfigs, isEnvShareable, wipeSensitiveData, hasRunnableComponent, getAppName, getAppName as getDisplayName, getAppDescription, fixBlockletStatus, findWebInterface, findWebInterfacePort, findServiceFromMeta, getWhoCanAccess, replaceSlotToIp, getComponentId, getComponentName, getComponentBundleId, findComponent, findComponentById, getParentComponentName, getConnectAppUrl, getChainInfo, isExternalBlocklet, isPreferenceKey, getRolesFromAuthConfig, getBlockletAppIdList, };
|
|
123
114
|
declare const _default: {
|
|
124
115
|
isFreeBlocklet: (meta: TBlockletMeta) => boolean;
|
|
125
116
|
isFreeComponent: (meta: TBlockletMeta) => boolean;
|
|
@@ -146,9 +137,12 @@ declare const _default: {
|
|
|
146
137
|
isEnvShareable: (env?: TConfig) => boolean;
|
|
147
138
|
wipeSensitiveData: (blocklet?: BlockletState) => BlockletState;
|
|
148
139
|
hasRunnableComponent: (blocklet: BlockletState) => boolean;
|
|
140
|
+
getAppName: (blocklet: BlockletState, onlyUseMeta?: boolean) => string;
|
|
141
|
+
getAppDescription: (blocklet: BlockletState, onlyUseMeta?: boolean) => string;
|
|
149
142
|
getDisplayName: (blocklet: BlockletState, onlyUseMeta?: boolean) => string;
|
|
150
143
|
fixBlockletStatus: (blocklet?: BlockletState) => void;
|
|
151
144
|
findWebInterface: (blocklet?: TBlockletMeta | BlockletState) => any;
|
|
145
|
+
findWebInterfacePort: (blocklet?: BlockletState) => any;
|
|
152
146
|
findServiceFromMeta: (meta?: TBlockletMeta, ServiceName?: string) => any;
|
|
153
147
|
getWhoCanAccess: (blocklet?: BlockletState) => any;
|
|
154
148
|
replaceSlotToIp: (url?: string, ip?: string) => string;
|
|
@@ -176,10 +170,21 @@ declare const _default: {
|
|
|
176
170
|
version: string;
|
|
177
171
|
};
|
|
178
172
|
}) => string;
|
|
179
|
-
|
|
180
|
-
|
|
173
|
+
findComponent: (blocklet: BlockletState | ComponentState, isEqualFn: (component: ComponentState, context: {
|
|
174
|
+
ancestors: ComponentState[];
|
|
175
|
+
}) => boolean, { _ancestors, returnAncestors, }?: {
|
|
176
|
+
_ancestors?: ComponentState[];
|
|
181
177
|
returnAncestors?: boolean;
|
|
182
|
-
}) =>
|
|
178
|
+
}) => ComponentState | {
|
|
179
|
+
component: ComponentState;
|
|
180
|
+
ancestors: ComponentState[];
|
|
181
|
+
};
|
|
182
|
+
findComponentById: (blocklet: BlockletState | ComponentState, componentId: string | string[], { returnAncestors, }?: {
|
|
183
|
+
returnAncestors?: boolean;
|
|
184
|
+
}) => ComponentState | {
|
|
185
|
+
component: ComponentState;
|
|
186
|
+
ancestors: ComponentState[];
|
|
187
|
+
};
|
|
183
188
|
getParentComponentName: (name?: string) => string;
|
|
184
189
|
getConnectAppUrl: ({ request, baseUrl }: {
|
|
185
190
|
request: Partial<Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>>;
|
package/lib/util.js
CHANGED
|
@@ -1,20 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
14
5
|
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.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;
|
|
6
|
+
exports.getBlockletAppIdList = exports.getRolesFromAuthConfig = exports.isPreferenceKey = exports.isExternalBlocklet = exports.getChainInfo = exports.getConnectAppUrl = exports.getParentComponentName = exports.findComponentById = exports.findComponent = exports.getComponentBundleId = exports.getComponentName = exports.getComponentId = exports.replaceSlotToIp = exports.getWhoCanAccess = exports.findServiceFromMeta = exports.findWebInterfacePort = exports.findWebInterface = exports.fixBlockletStatus = exports.getAppDescription = exports.getDisplayName = exports.getAppName = 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
7
|
/* eslint-disable no-await-in-loop */
|
|
17
8
|
const get_1 = __importDefault(require("lodash/get"));
|
|
9
|
+
const uniq_1 = __importDefault(require("lodash/uniq"));
|
|
18
10
|
const url_join_1 = __importDefault(require("url-join"));
|
|
19
11
|
const p_limit_1 = __importDefault(require("p-limit"));
|
|
20
12
|
const constant_1 = __importDefault(require("@abtnode/constant"));
|
|
@@ -87,9 +79,9 @@ const forEachBlocklet = (blocklet, cb, { parallel = false, concurrencyLimit = 5,
|
|
|
87
79
|
// serial
|
|
88
80
|
if (!parallel) {
|
|
89
81
|
// eslint-disable-next-line no-async-promise-executor
|
|
90
|
-
return new Promise((resolve, reject) =>
|
|
82
|
+
return new Promise(async (resolve, reject) => {
|
|
91
83
|
try {
|
|
92
|
-
const params =
|
|
84
|
+
const params = await cb(blocklet, {
|
|
93
85
|
parent: _parent,
|
|
94
86
|
root,
|
|
95
87
|
level: _level,
|
|
@@ -99,7 +91,7 @@ const forEachBlocklet = (blocklet, cb, { parallel = false, concurrencyLimit = 5,
|
|
|
99
91
|
});
|
|
100
92
|
if (blocklet.children) {
|
|
101
93
|
for (const child of blocklet.children) {
|
|
102
|
-
|
|
94
|
+
await forEachBlocklet(child, cb, {
|
|
103
95
|
params,
|
|
104
96
|
_parent: blocklet,
|
|
105
97
|
_root: root,
|
|
@@ -113,7 +105,7 @@ const forEachBlocklet = (blocklet, cb, { parallel = false, concurrencyLimit = 5,
|
|
|
113
105
|
catch (err) {
|
|
114
106
|
reject(err);
|
|
115
107
|
}
|
|
116
|
-
})
|
|
108
|
+
});
|
|
117
109
|
}
|
|
118
110
|
// parallel
|
|
119
111
|
const limit = _limit || (0, p_limit_1.default)(concurrencyLimit);
|
|
@@ -152,13 +144,11 @@ exports.forEachChild = forEachChild;
|
|
|
152
144
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
153
145
|
const forEachChildSync = (blocklet, cb) => forEachChild(blocklet, cb, { sync: true });
|
|
154
146
|
exports.forEachChildSync = forEachChildSync;
|
|
155
|
-
const
|
|
156
|
-
if (
|
|
157
|
-
|
|
158
|
-
componentId = componentId.join('/');
|
|
147
|
+
const findComponent = (blocklet, isEqualFn, { _ancestors = [], returnAncestors = false, } = {}) => {
|
|
148
|
+
if (!isEqualFn) {
|
|
149
|
+
return null;
|
|
159
150
|
}
|
|
160
|
-
|
|
161
|
-
if (componentId === id) {
|
|
151
|
+
if (isEqualFn(blocklet, { ancestors: _ancestors })) {
|
|
162
152
|
if (returnAncestors) {
|
|
163
153
|
return {
|
|
164
154
|
component: blocklet,
|
|
@@ -169,13 +159,24 @@ const findComponentById = (blocklet, componentId, { _ancestors = [], returnAnces
|
|
|
169
159
|
}
|
|
170
160
|
for (const child of blocklet.children || []) {
|
|
171
161
|
const ancestors = _ancestors.concat(blocklet);
|
|
172
|
-
const component =
|
|
162
|
+
const component = findComponent(child, isEqualFn, { _ancestors: ancestors, returnAncestors });
|
|
173
163
|
if (component) {
|
|
174
164
|
return component;
|
|
175
165
|
}
|
|
176
166
|
}
|
|
177
167
|
return null;
|
|
178
168
|
};
|
|
169
|
+
exports.findComponent = findComponent;
|
|
170
|
+
const findComponentById = (blocklet, componentId, { returnAncestors = false, } = {}) => {
|
|
171
|
+
if (Array.isArray(componentId)) {
|
|
172
|
+
// eslint-disable-next-line no-param-reassign
|
|
173
|
+
componentId = componentId.join('/');
|
|
174
|
+
}
|
|
175
|
+
return findComponent(blocklet, (component, { ancestors }) => {
|
|
176
|
+
const id = getComponentId(component, ancestors);
|
|
177
|
+
return componentId === id;
|
|
178
|
+
}, { returnAncestors });
|
|
179
|
+
};
|
|
179
180
|
exports.findComponentById = findComponentById;
|
|
180
181
|
const isEnvShareable = (env) => {
|
|
181
182
|
return (!!env &&
|
|
@@ -204,7 +205,7 @@ const getSharedConfigObj = (component, ancestors) => {
|
|
|
204
205
|
if (config && config.value) {
|
|
205
206
|
return;
|
|
206
207
|
}
|
|
207
|
-
res[key] = value;
|
|
208
|
+
res[key] = (0, get_1.default)(ancestor, `configObj.${key}`) || value;
|
|
208
209
|
});
|
|
209
210
|
}
|
|
210
211
|
}
|
|
@@ -275,10 +276,13 @@ const wipeSensitiveData = (blocklet) => {
|
|
|
275
276
|
});
|
|
276
277
|
}
|
|
277
278
|
(d.environments || []).forEach((x) => {
|
|
278
|
-
if (['BLOCKLET_APP_SK'].includes(x.key)) {
|
|
279
|
+
if (['BLOCKLET_APP_SK', 'BLOCKLET_APP_PSK'].includes(x.key)) {
|
|
279
280
|
x.value = '__encrypted__';
|
|
280
281
|
}
|
|
281
282
|
});
|
|
283
|
+
(d.migratedFrom || []).forEach((x) => {
|
|
284
|
+
x.appSk = '__encrypted__';
|
|
285
|
+
});
|
|
282
286
|
// @ts-ignore
|
|
283
287
|
delete blocklet.configObj;
|
|
284
288
|
// @ts-ignore
|
|
@@ -314,21 +318,43 @@ exports.hasRunnableComponent = hasRunnableComponent;
|
|
|
314
318
|
* @param {Boolean} onlyUseMeta 优先使用应用元数据的name
|
|
315
319
|
* @returns blocklet display name
|
|
316
320
|
*/
|
|
317
|
-
const
|
|
321
|
+
const getAppName = (blocklet, onlyUseMeta = false) => {
|
|
318
322
|
if (!blocklet) {
|
|
319
323
|
return '';
|
|
320
324
|
}
|
|
321
325
|
const { meta } = blocklet;
|
|
322
|
-
let
|
|
326
|
+
let name;
|
|
323
327
|
if (!onlyUseMeta && blocklet.environments) {
|
|
324
328
|
const target = blocklet.environments.find((e) => e.key === 'BLOCKLET_APP_NAME');
|
|
325
329
|
if (target && target.value) {
|
|
326
|
-
|
|
330
|
+
name = target.value;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
return name || meta.title || meta.name;
|
|
334
|
+
};
|
|
335
|
+
exports.getAppName = getAppName;
|
|
336
|
+
exports.getDisplayName = getAppName;
|
|
337
|
+
/**
|
|
338
|
+
* 获取 blocklet 的 description
|
|
339
|
+
* @param {Object} blocklet 应用数据
|
|
340
|
+
* @param {Boolean} onlyUseMeta 优先使用应用元数据的name
|
|
341
|
+
* @returns blocklet display description
|
|
342
|
+
*/
|
|
343
|
+
const getAppDescription = (blocklet, onlyUseMeta = false) => {
|
|
344
|
+
if (!blocklet) {
|
|
345
|
+
return '';
|
|
346
|
+
}
|
|
347
|
+
const { meta } = blocklet;
|
|
348
|
+
let description;
|
|
349
|
+
if (!onlyUseMeta && blocklet.environments) {
|
|
350
|
+
const target = blocklet.environments.find((e) => e.key === 'BLOCKLET_APP_DESCRIPTION');
|
|
351
|
+
if (target && target.value) {
|
|
352
|
+
description = target.value;
|
|
327
353
|
}
|
|
328
354
|
}
|
|
329
|
-
return
|
|
355
|
+
return description || meta.description || meta.name;
|
|
330
356
|
};
|
|
331
|
-
exports.
|
|
357
|
+
exports.getAppDescription = getAppDescription;
|
|
332
358
|
const fixBlockletStatus = (blocklet) => {
|
|
333
359
|
if (!blocklet) {
|
|
334
360
|
return;
|
|
@@ -364,6 +390,18 @@ const findWebInterface = (blocklet) => {
|
|
|
364
390
|
return interfaces.find((x) => x.type === BLOCKLET_INTERFACE_TYPE_WEB);
|
|
365
391
|
};
|
|
366
392
|
exports.findWebInterface = findWebInterface;
|
|
393
|
+
const findWebInterfacePort = (blocklet) => {
|
|
394
|
+
if (!blocklet) {
|
|
395
|
+
return null;
|
|
396
|
+
}
|
|
397
|
+
const webInterface = findWebInterface(blocklet);
|
|
398
|
+
const { ports } = blocklet;
|
|
399
|
+
if (!webInterface || !ports) {
|
|
400
|
+
return null;
|
|
401
|
+
}
|
|
402
|
+
return ports[webInterface.port];
|
|
403
|
+
};
|
|
404
|
+
exports.findWebInterfacePort = findWebInterfacePort;
|
|
367
405
|
const findServiceFromMeta = (meta, ServiceName) => {
|
|
368
406
|
const names = [ServiceName];
|
|
369
407
|
// backward compatible
|
|
@@ -415,7 +453,7 @@ const getChainInfo = (env) => Object.entries(CHAIN_INFO_CONFIG).reduce((info, x)
|
|
|
415
453
|
return info;
|
|
416
454
|
}, {});
|
|
417
455
|
exports.getChainInfo = getChainInfo;
|
|
418
|
-
const isExternalBlocklet = (blocklet) => !!
|
|
456
|
+
const isExternalBlocklet = (blocklet) => !!blocklet?.controller;
|
|
419
457
|
exports.isExternalBlocklet = isExternalBlocklet;
|
|
420
458
|
const getRolesFromAuthConfig = (config) => {
|
|
421
459
|
if (!config.whoCanAccess.startsWith(WHO_CAN_ACCESS_PREFIX_ROLES)) {
|
|
@@ -424,6 +462,11 @@ const getRolesFromAuthConfig = (config) => {
|
|
|
424
462
|
return config.whoCanAccess.substring(WHO_CAN_ACCESS_PREFIX_ROLES.length).split(',');
|
|
425
463
|
};
|
|
426
464
|
exports.getRolesFromAuthConfig = getRolesFromAuthConfig;
|
|
465
|
+
const getBlockletAppIdList = (blocklet) => {
|
|
466
|
+
const migratedFrom = Array.isArray(blocklet.migratedFrom) ? blocklet.migratedFrom.map((x) => x.appDid) : [];
|
|
467
|
+
return (0, uniq_1.default)([blocklet.appDid, blocklet.appPid, ...migratedFrom].filter(Boolean));
|
|
468
|
+
};
|
|
469
|
+
exports.getBlockletAppIdList = getBlockletAppIdList;
|
|
427
470
|
exports.default = {
|
|
428
471
|
isFreeBlocklet,
|
|
429
472
|
isFreeComponent,
|
|
@@ -439,15 +482,19 @@ exports.default = {
|
|
|
439
482
|
isEnvShareable,
|
|
440
483
|
wipeSensitiveData,
|
|
441
484
|
hasRunnableComponent,
|
|
442
|
-
|
|
485
|
+
getAppName,
|
|
486
|
+
getAppDescription,
|
|
487
|
+
getDisplayName: getAppName,
|
|
443
488
|
fixBlockletStatus,
|
|
444
489
|
findWebInterface,
|
|
490
|
+
findWebInterfacePort,
|
|
445
491
|
findServiceFromMeta,
|
|
446
492
|
getWhoCanAccess,
|
|
447
493
|
replaceSlotToIp,
|
|
448
494
|
getComponentId,
|
|
449
495
|
getComponentName,
|
|
450
496
|
getComponentBundleId,
|
|
497
|
+
findComponent,
|
|
451
498
|
findComponentById,
|
|
452
499
|
getParentComponentName,
|
|
453
500
|
getConnectAppUrl,
|
package/lib/validate.js
CHANGED
|
@@ -21,10 +21,13 @@ const fixAndValidateService = (meta) => {
|
|
|
21
21
|
};
|
|
22
22
|
exports.fixAndValidateService = fixAndValidateService;
|
|
23
23
|
const validateMeta = (meta, { ensureMain = false, ensureFiles = false, ensureDist = false, ensureComponentStore = true, schemaOptions = {}, } = {}) => {
|
|
24
|
-
const schema = (0, schema_1.createBlockletSchema)(null,
|
|
24
|
+
const schema = (0, schema_1.createBlockletSchema)(null, {
|
|
25
|
+
ensureMain,
|
|
25
26
|
ensureFiles,
|
|
26
27
|
ensureDist,
|
|
27
|
-
ensureComponentStore
|
|
28
|
+
ensureComponentStore,
|
|
29
|
+
...schemaOptions,
|
|
30
|
+
});
|
|
28
31
|
const { value, error } = schema.validate(meta);
|
|
29
32
|
if (error) {
|
|
30
33
|
throw new Error(`Invalid blocklet meta: ${error.details.map((x) => x.message).join(', ')}`);
|
package/lib/verify-multi-sig.js
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
-
var t = {};
|
|
4
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
-
t[p] = s[p];
|
|
6
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
-
t[p[i]] = s[p[i]];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
4
|
};
|
|
@@ -49,7 +38,7 @@ function verifyDelegationToken(signature) {
|
|
|
49
38
|
return true;
|
|
50
39
|
}
|
|
51
40
|
const verifyMultiSig = (blockletMeta) => {
|
|
52
|
-
const { signatures: tmpSignatures
|
|
41
|
+
const { signatures: tmpSignatures, ...meta } = blockletMeta;
|
|
53
42
|
const signatures = (0, cloneDeep_1.default)(tmpSignatures);
|
|
54
43
|
if (!Array.isArray(signatures)) {
|
|
55
44
|
throw new Error('Invalid signatures, signatures should be an array');
|
|
@@ -74,7 +63,7 @@ const verifyMultiSig = (blockletMeta) => {
|
|
|
74
63
|
: signature;
|
|
75
64
|
delete signature.sig;
|
|
76
65
|
debug('verify', { signer });
|
|
77
|
-
let toBeVerifiedMeta =
|
|
66
|
+
let toBeVerifiedMeta = { ...meta };
|
|
78
67
|
if (lastSignature && lastSignature.appended) {
|
|
79
68
|
debug('appended fields', { signer, appended: lastSignature.appended });
|
|
80
69
|
lastSignature.appended.forEach((field) => {
|
|
@@ -89,7 +78,7 @@ const verifyMultiSig = (blockletMeta) => {
|
|
|
89
78
|
}
|
|
90
79
|
const type = (0, did_1.toTypeInfo)(signer);
|
|
91
80
|
const wallet = (0, wallet_1.fromPublicKey)(pk, type);
|
|
92
|
-
const verifyRes = wallet.verify((0, json_stable_stringify_1.default)(
|
|
81
|
+
const verifyRes = wallet.verify((0, json_stable_stringify_1.default)({ ...toBeVerifiedMeta, signatures: [signature, ...signatures] }), sig);
|
|
93
82
|
if (verifyRes !== true) {
|
|
94
83
|
debug('verify failed', { signer });
|
|
95
84
|
return verifyRes;
|
package/lib/wallet.d.ts
CHANGED
|
@@ -5,5 +5,5 @@ import { DIDType } from '@arcblock/did';
|
|
|
5
5
|
*
|
|
6
6
|
* Spec: https://github.com/ArcBlock/ABT-DID-Protocol#request-did-authentication
|
|
7
7
|
*/
|
|
8
|
-
declare const getBlockletWallet: (blockletDid: string, nodeSk?: string, type?: DIDType, index?: number) => WalletObject;
|
|
8
|
+
declare const getBlockletWallet: (blockletDid: string, nodeSk?: string, type?: DIDType | string, index?: number) => WalletObject;
|
|
9
9
|
export = getBlockletWallet;
|
package/lib/wallet.js
CHANGED
|
@@ -8,10 +8,11 @@ const did_ext_1 = require("@arcblock/did-ext");
|
|
|
8
8
|
*
|
|
9
9
|
* Spec: https://github.com/ArcBlock/ABT-DID-Protocol#request-did-authentication
|
|
10
10
|
*/
|
|
11
|
-
const getBlockletWallet = (blockletDid, nodeSk, type
|
|
11
|
+
const getBlockletWallet = (blockletDid, nodeSk, type, index) => {
|
|
12
|
+
const t = type || { role: mcrypto_1.types.RoleType.ROLE_APPLICATION };
|
|
12
13
|
if (!(0, did_1.isValid)(blockletDid)) {
|
|
13
14
|
try {
|
|
14
|
-
return (0, wallet_1.fromSecretKey)(blockletDid,
|
|
15
|
+
return (0, wallet_1.fromSecretKey)(blockletDid, t);
|
|
15
16
|
}
|
|
16
17
|
catch (err) {
|
|
17
18
|
throw new Error(`Cannot get blocklet wallet with invalid blocklet did or custom sk: ${err.message}`);
|
|
@@ -20,6 +21,6 @@ const getBlockletWallet = (blockletDid, nodeSk, type = { role: mcrypto_1.types.R
|
|
|
20
21
|
if (!nodeSk) {
|
|
21
22
|
throw new Error('Cannot get blocklet wallet with empty node sk');
|
|
22
23
|
}
|
|
23
|
-
return (0, did_ext_1.fromAppDid)(blockletDid, nodeSk,
|
|
24
|
+
return (0, did_ext_1.fromAppDid)(blockletDid, nodeSk, t, index || 0);
|
|
24
25
|
};
|
|
25
26
|
module.exports = getBlockletWallet;
|
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.69-beta-e0666d0d",
|
|
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.69-beta-e0666d0d",
|
|
28
|
+
"@abtnode/constant": "1.8.69-beta-e0666d0d",
|
|
29
|
+
"@abtnode/util": "1.8.69-beta-e0666d0d",
|
|
30
|
+
"@arcblock/did": "1.18.57",
|
|
31
|
+
"@arcblock/did-ext": "1.18.57",
|
|
32
|
+
"@arcblock/did-util": "1.18.57",
|
|
33
|
+
"@arcblock/jwt": "1.18.57",
|
|
34
|
+
"@blocklet/constant": "1.8.69-beta-e0666d0d",
|
|
35
|
+
"@ocap/asset": "1.18.57",
|
|
36
|
+
"@ocap/mcrypto": "1.18.57",
|
|
37
|
+
"@ocap/types": "1.18.57",
|
|
38
|
+
"@ocap/util": "1.18.57",
|
|
39
|
+
"@ocap/wallet": "1.18.57",
|
|
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.68",
|
|
63
63
|
"@arcblock/eslint-config-ts": "^0.2.3",
|
|
64
64
|
"@types/express": "^4.17.14",
|
|
65
65
|
"@types/jest": "^29.2.2",
|
|
@@ -75,10 +75,11 @@
|
|
|
75
75
|
"expand-tilde": "^2.0.2",
|
|
76
76
|
"express": "^4.18.2",
|
|
77
77
|
"jest": "^29.3.0",
|
|
78
|
+
"joi-to-typescript": "^4.0.7",
|
|
78
79
|
"prettier": "^2.7.1",
|
|
79
80
|
"ts-jest": "^29.0.3",
|
|
80
81
|
"ts-node": "^10.9.1",
|
|
81
82
|
"typescript": "^4.8.4"
|
|
82
83
|
},
|
|
83
|
-
"gitHead": "
|
|
84
|
+
"gitHead": "acf0373591eaa3aff76483edc4e648afc543f1f7"
|
|
84
85
|
}
|