@blocklet/meta 1.8.34 → 1.8.35
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 +27 -0
- package/lib/channel.js +32 -32
- package/lib/constants.d.ts +2 -0
- package/lib/constants.js +6 -3
- package/lib/did.d.ts +10 -0
- package/lib/did.js +18 -24
- package/lib/engine.d.ts +7 -0
- package/lib/engine.js +21 -25
- package/lib/entry.d.ts +3 -0
- package/lib/entry.js +51 -64
- package/lib/extension.d.ts +10 -0
- package/lib/extension.js +78 -77
- package/lib/file.d.ts +21 -0
- package/lib/file.js +44 -39
- package/lib/fix.d.ts +33 -0
- package/lib/fix.js +218 -208
- package/lib/get-component-process-id.d.ts +5 -0
- package/lib/get-component-process-id.js +13 -14
- package/lib/has-reserved-key.d.ts +3 -0
- package/lib/has-reserved-key.js +10 -9
- package/lib/index.d.ts +82 -0
- package/lib/index.js +51 -34
- package/lib/info.d.ts +13 -0
- package/lib/info.js +58 -60
- package/lib/name.d.ts +5 -0
- package/lib/name.js +14 -7
- package/lib/nft-templates.d.ts +86 -0
- package/lib/nft-templates.js +47 -42
- package/lib/parse-navigation.d.ts +3 -0
- package/lib/parse-navigation.js +167 -228
- package/lib/parse.d.ts +22 -0
- package/lib/parse.js +71 -82
- package/lib/payment/index.d.ts +254 -0
- package/lib/payment/index.js +13 -6
- package/lib/payment/v1.d.ts +185 -0
- package/lib/payment/v1.js +80 -81
- package/lib/payment/v2.d.ts +242 -0
- package/lib/payment/v2.js +453 -531
- package/lib/schema.d.ts +50 -0
- package/lib/schema.js +405 -402
- package/lib/service-configs/auth.json +61 -61
- package/lib/service.d.ts +26 -0
- package/lib/service.js +69 -85
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.js +18 -0
- package/lib/types/schema.d.ts +241 -0
- package/lib/types/schema.js +3 -0
- package/lib/util-meta.d.ts +42 -0
- package/lib/util-meta.js +138 -158
- package/lib/util.d.ts +185 -0
- package/lib/util.js +359 -414
- package/lib/validate.d.ts +10 -0
- package/lib/validate.js +28 -34
- package/lib/verify-multi-sig.d.ts +3 -0
- package/lib/verify-multi-sig.js +94 -101
- package/lib/wallet.d.ts +9 -0
- package/lib/wallet.js +17 -27
- package/package.json +40 -18
package/lib/channel.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
declare const getAppPublicChannelRegex: () => RegExp;
|
|
2
|
+
declare const getAppPublicChannel: (appDid: string) => string;
|
|
3
|
+
declare const CHANNEL_TYPE: {
|
|
4
|
+
DID: string;
|
|
5
|
+
APP: string;
|
|
6
|
+
};
|
|
7
|
+
declare const parseChannel: (channel: string) => {
|
|
8
|
+
type: string;
|
|
9
|
+
appDid?: string;
|
|
10
|
+
};
|
|
11
|
+
export { CHANNEL_TYPE };
|
|
12
|
+
export { getAppPublicChannel };
|
|
13
|
+
export { getAppPublicChannelRegex };
|
|
14
|
+
export { parseChannel };
|
|
15
|
+
declare const _default: {
|
|
16
|
+
CHANNEL_TYPE: {
|
|
17
|
+
DID: string;
|
|
18
|
+
APP: string;
|
|
19
|
+
};
|
|
20
|
+
getAppPublicChannel: (appDid: string) => string;
|
|
21
|
+
getAppPublicChannelRegex: () => RegExp;
|
|
22
|
+
parseChannel: (channel: string) => {
|
|
23
|
+
type: string;
|
|
24
|
+
appDid?: string;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
export default _default;
|
package/lib/channel.js
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseChannel = exports.getAppPublicChannelRegex = exports.getAppPublicChannel = exports.CHANNEL_TYPE = void 0;
|
|
4
|
+
/* eslint-disable @typescript-eslint/indent */
|
|
5
|
+
const did_1 = require("@arcblock/did");
|
|
3
6
|
const getAppPublicChannelRegex = () => /app:(\w+):public/;
|
|
4
|
-
|
|
7
|
+
exports.getAppPublicChannelRegex = getAppPublicChannelRegex;
|
|
5
8
|
const getAppPublicChannel = (appDid) => `app:${appDid}:public`;
|
|
6
|
-
|
|
9
|
+
exports.getAppPublicChannel = getAppPublicChannel;
|
|
7
10
|
const CHANNEL_TYPE = {
|
|
8
|
-
|
|
9
|
-
|
|
11
|
+
DID: 'DID',
|
|
12
|
+
APP: 'APP',
|
|
10
13
|
};
|
|
11
|
-
|
|
14
|
+
exports.CHANNEL_TYPE = CHANNEL_TYPE;
|
|
12
15
|
const parseChannel = (channel) => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
throw new Error(`Invalid channel format: ${channel}`);
|
|
16
|
+
if (!channel) {
|
|
17
|
+
throw new Error('Channel should not be empty');
|
|
18
|
+
}
|
|
19
|
+
const matchAppPublicChannel = getAppPublicChannelRegex().exec(channel);
|
|
20
|
+
if (matchAppPublicChannel) {
|
|
21
|
+
return {
|
|
22
|
+
type: CHANNEL_TYPE.APP,
|
|
23
|
+
appDid: matchAppPublicChannel[1],
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
if ((0, did_1.isValid)(channel)) {
|
|
27
|
+
return {
|
|
28
|
+
type: CHANNEL_TYPE.DID,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
throw new Error(`Invalid channel format: ${channel}`);
|
|
32
32
|
};
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
exports.parseChannel = parseChannel;
|
|
34
|
+
exports.default = {
|
|
35
|
+
CHANNEL_TYPE,
|
|
36
|
+
getAppPublicChannel,
|
|
37
|
+
getAppPublicChannelRegex,
|
|
38
|
+
parseChannel,
|
|
39
39
|
};
|
package/lib/constants.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
const constant_1 = __importDefault(require("@blocklet/constant"));
|
|
6
|
+
module.exports = constant_1.default;
|
package/lib/did.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { TBlockletMeta } from './types';
|
|
3
|
+
declare const toBlockletDid: {
|
|
4
|
+
(name: string | Buffer): string;
|
|
5
|
+
toExternalBlocklet(name: string, userDid: string, { didOnly, nameOnly }?: {
|
|
6
|
+
didOnly?: boolean;
|
|
7
|
+
nameOnly?: boolean;
|
|
8
|
+
}): Pick<TBlockletMeta, 'did' | 'name'> | string;
|
|
9
|
+
};
|
|
10
|
+
export = toBlockletDid;
|
package/lib/did.js
CHANGED
|
@@ -1,29 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
const mcrypto_1 = require("@ocap/mcrypto");
|
|
3
|
+
const util_1 = require("@ocap/util");
|
|
4
|
+
const did_1 = require("@arcblock/did");
|
|
5
5
|
const toBlockletDid = (name) => {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
const pk = (0, util_1.toHex)(Buffer.from(typeof name === 'string' ? name.trim() : name));
|
|
7
|
+
return (0, did_1.fromPublicKey)(pk, { role: mcrypto_1.types.RoleType.ROLE_ANY });
|
|
8
8
|
};
|
|
9
|
-
|
|
10
9
|
toBlockletDid.toExternalBlocklet = (name, userDid, { didOnly, nameOnly } = {}) => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return {
|
|
24
|
-
name: blockletName,
|
|
25
|
-
did: blockletDid,
|
|
26
|
-
};
|
|
10
|
+
const blockletName = `${name}-${userDid.toLowerCase().substring(userDid.length - 6)}`;
|
|
11
|
+
if (nameOnly) {
|
|
12
|
+
return blockletName;
|
|
13
|
+
}
|
|
14
|
+
const blockletDid = toBlockletDid(blockletName);
|
|
15
|
+
if (didOnly) {
|
|
16
|
+
return blockletDid;
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
name: blockletName,
|
|
20
|
+
did: blockletDid,
|
|
21
|
+
};
|
|
27
22
|
};
|
|
28
|
-
|
|
29
23
|
module.exports = toBlockletDid;
|
package/lib/engine.d.ts
ADDED
package/lib/engine.js
CHANGED
|
@@ -1,32 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
const os_1 = __importDefault(require("os"));
|
|
3
6
|
/**
|
|
4
7
|
* get blocklet engine info by platform
|
|
5
8
|
* @param {object} meta blocklet meta
|
|
6
9
|
*/
|
|
7
10
|
const getEngineByPlatform = (meta) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const tmpRuntime = engine.find((r) => r.platform === platform);
|
|
25
|
-
if (!tmpRuntime) {
|
|
26
|
-
throw new Error(`can not find a proper engine interpreter on ${platform}`);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return tmpRuntime;
|
|
11
|
+
if (meta === undefined) {
|
|
12
|
+
throw new Error('blocklet meta param is required');
|
|
13
|
+
}
|
|
14
|
+
const { engine } = meta;
|
|
15
|
+
if (!engine) {
|
|
16
|
+
return { interpreter: 'node', script: '' };
|
|
17
|
+
}
|
|
18
|
+
if (!Array.isArray(engine)) {
|
|
19
|
+
return engine;
|
|
20
|
+
}
|
|
21
|
+
const platform = os_1.default.platform();
|
|
22
|
+
const tmpRuntime = engine.find((r) => r.platform === platform);
|
|
23
|
+
if (!tmpRuntime) {
|
|
24
|
+
throw new Error(`can not find a proper engine interpreter on ${platform}`);
|
|
25
|
+
}
|
|
26
|
+
return tmpRuntime;
|
|
30
27
|
};
|
|
31
|
-
|
|
32
28
|
module.exports = getEngineByPlatform;
|
package/lib/entry.d.ts
ADDED
package/lib/entry.js
CHANGED
|
@@ -1,69 +1,56 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
throw new Error(`DApp blocklet may be corrupted or not properly configured: missing engine.${k}`);
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
const fs_1 = __importDefault(require("fs"));
|
|
6
|
+
const path_1 = __importDefault(require("path"));
|
|
7
|
+
const os_1 = __importDefault(require("os"));
|
|
8
|
+
const isEmpty_1 = __importDefault(require("lodash/isEmpty"));
|
|
9
|
+
const get_1 = __importDefault(require("lodash/get"));
|
|
10
|
+
const constants_1 = __importDefault(require("./constants"));
|
|
11
|
+
const { BLOCKLET_BUNDLE_FOLDER, BlockletGroup } = constants_1.default;
|
|
12
|
+
const validateBlockletEntry = (dir, meta) => {
|
|
13
|
+
const { main, group } = meta;
|
|
14
|
+
if (group === BlockletGroup.dapp) {
|
|
15
|
+
// backward compatible
|
|
16
|
+
if (!fs_1.default.existsSync(path_1.default.join(dir, 'blocklet.js')) &&
|
|
17
|
+
!fs_1.default.existsSync(path_1.default.join(dir, BLOCKLET_BUNDLE_FOLDER, 'blocklet.js'))) {
|
|
18
|
+
// backward compatible
|
|
19
|
+
if ((0, isEmpty_1.default)(meta.engine)) {
|
|
20
|
+
throw new Error('DApp blocklet may be corrupted or not properly bundled: missing blocklet.js');
|
|
21
|
+
}
|
|
22
|
+
const engine = (0, get_1.default)(meta, 'engine', null);
|
|
23
|
+
if (engine) {
|
|
24
|
+
if (!Array.isArray(engine)) {
|
|
25
|
+
if (!engine.interpreter) {
|
|
26
|
+
throw new Error('DApp blocklet may be corrupted or not properly configured: missing engine.interpreter');
|
|
27
|
+
}
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
engine.forEach((r) => {
|
|
31
|
+
['interpreter', 'platform'].forEach((k) => {
|
|
32
|
+
if (!(0, get_1.default)(r, k, null)) {
|
|
33
|
+
throw new Error(`DApp blocklet may be corrupted or not properly configured: missing engine.${k}`);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
const platform = os_1.default.platform();
|
|
38
|
+
if (!engine.find((r) => r.platform === platform)) {
|
|
39
|
+
throw new Error(`DApp blocklet may be corrupted or not properly configured: no engine run on ${platform}`);
|
|
40
|
+
}
|
|
42
41
|
}
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
const platform = os.platform();
|
|
47
|
-
|
|
48
|
-
if (!engine.find((r) => r.platform === platform)) {
|
|
49
|
-
throw new Error(`DApp blocklet may be corrupted or not properly configured: no engine run on ${platform}`);
|
|
50
42
|
}
|
|
51
|
-
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (group === BlockletGroup.static) {
|
|
46
|
+
if (!fs_1.default.existsSync(path_1.default.join(dir, main))) {
|
|
47
|
+
throw new Error('Static blocklet may be corrupted or not properly configured: missing main folder');
|
|
48
|
+
}
|
|
49
|
+
return;
|
|
52
50
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (group === BlockletGroup.static) {
|
|
58
|
-
if (!fs.existsSync(path.join(dir, main))) {
|
|
59
|
-
throw new Error('Static blocklet may be corrupted or not properly configured: missing main folder');
|
|
51
|
+
if (group === BlockletGroup.gateway) {
|
|
52
|
+
return;
|
|
60
53
|
}
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (group === BlockletGroup.gateway) {
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
throw new Error(`Unsupported blocklet type ${group}`);
|
|
54
|
+
throw new Error(`Unsupported blocklet type ${group}`);
|
|
69
55
|
};
|
|
56
|
+
module.exports = validateBlockletEntry;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Extension, Root } from 'joi';
|
|
2
|
+
declare const fileExtension: (joi: Root) => Extension;
|
|
3
|
+
declare const didExtension: (joi: Root) => Extension;
|
|
4
|
+
export { fileExtension };
|
|
5
|
+
export { didExtension };
|
|
6
|
+
declare const _default: {
|
|
7
|
+
fileExtension: (joi: Root) => Extension;
|
|
8
|
+
didExtension: (joi: Root) => Extension;
|
|
9
|
+
};
|
|
10
|
+
export default _default;
|
package/lib/extension.js
CHANGED
|
@@ -1,83 +1,84 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.didExtension = exports.fileExtension = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const did_1 = require("@arcblock/did");
|
|
7
10
|
const fileExtension = (joi) => ({
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
return { errors: error('file.empty', { file: value }) };
|
|
16
|
-
},
|
|
17
|
-
messages: {
|
|
18
|
-
'file.empty': 'file "{{#file}}" must be non-empty string',
|
|
19
|
-
'file.enoent': 'file "{{#file}}" does not exist',
|
|
20
|
-
'file.error.generic': 'file could not be read. message: "{{#message}}"',
|
|
21
|
-
},
|
|
22
|
-
|
|
23
|
-
rules: {
|
|
24
|
-
exists: {
|
|
25
|
-
multi: false,
|
|
26
|
-
method({ baseDir = null, canSkip } = {}) {
|
|
27
|
-
return this.$_addRule({ name: 'exists', args: { baseDir, canSkip } });
|
|
28
|
-
},
|
|
29
|
-
args: [
|
|
30
|
-
{
|
|
31
|
-
name: 'baseDir',
|
|
32
|
-
assert: (baseDir) => fs.existsSync(baseDir),
|
|
33
|
-
message: 'baseDir must exist',
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
name: 'canSkip',
|
|
37
|
-
assert: (canSkip) => typeof canSkip === 'function',
|
|
38
|
-
message: 'canSkip must be a function',
|
|
39
|
-
},
|
|
40
|
-
],
|
|
41
|
-
|
|
42
|
-
validate(value, { error }, { baseDir, canSkip } = {}) {
|
|
43
|
-
if (typeof canSkip === 'function' && canSkip(baseDir, value)) {
|
|
44
|
-
return value;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
try {
|
|
48
|
-
fs.statSync(path.join(baseDir, value));
|
|
49
|
-
return value;
|
|
50
|
-
} catch (e) {
|
|
51
|
-
switch (e.code) {
|
|
52
|
-
case 'ENOENT':
|
|
53
|
-
return error('file.enoent', { file: value });
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return error('file.error.generic', { message: e.message });
|
|
11
|
+
type: 'file',
|
|
12
|
+
base: joi.string(),
|
|
13
|
+
validate(value, { error }) {
|
|
14
|
+
if (value && typeof value === 'string') {
|
|
15
|
+
return { value };
|
|
57
16
|
}
|
|
58
|
-
|
|
17
|
+
return { errors: error('file.empty', { file: value }) };
|
|
18
|
+
},
|
|
19
|
+
messages: {
|
|
20
|
+
'file.empty': 'file "{{#file}}" must be non-empty string',
|
|
21
|
+
'file.enoent': 'file "{{#file}}" does not exist',
|
|
22
|
+
'file.error.generic': 'file could not be read. message: "{{#message}}"',
|
|
23
|
+
},
|
|
24
|
+
rules: {
|
|
25
|
+
exists: {
|
|
26
|
+
multi: false,
|
|
27
|
+
method({ baseDir = null, canSkip } = {}) {
|
|
28
|
+
return this.$_addRule({ name: 'exists', args: { baseDir, canSkip } });
|
|
29
|
+
},
|
|
30
|
+
args: [
|
|
31
|
+
{
|
|
32
|
+
name: 'baseDir',
|
|
33
|
+
assert: (baseDir) => fs_1.default.existsSync(baseDir),
|
|
34
|
+
message: 'baseDir must exist',
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
name: 'canSkip',
|
|
38
|
+
assert: (canSkip) => typeof canSkip === 'function',
|
|
39
|
+
message: 'canSkip must be a function',
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
validate(value, { error }, { baseDir, canSkip } = {}) {
|
|
43
|
+
if (typeof canSkip === 'function' && canSkip(baseDir, value)) {
|
|
44
|
+
return value;
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
fs_1.default.statSync(path_1.default.join(baseDir, value));
|
|
48
|
+
return value;
|
|
49
|
+
}
|
|
50
|
+
catch (e) {
|
|
51
|
+
switch (e.code) {
|
|
52
|
+
case 'ENOENT':
|
|
53
|
+
return error('file.enoent', { file: value });
|
|
54
|
+
default:
|
|
55
|
+
}
|
|
56
|
+
return error('file.error.generic', { message: e.message });
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
},
|
|
59
60
|
},
|
|
60
|
-
},
|
|
61
61
|
});
|
|
62
|
-
|
|
62
|
+
exports.fileExtension = fileExtension;
|
|
63
63
|
const didExtension = (joi) => ({
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
'did.invalid': 'did "{{#did}}" is not valid',
|
|
80
|
-
},
|
|
64
|
+
type: 'DID',
|
|
65
|
+
base: joi.string(),
|
|
66
|
+
validate(value, { error }) {
|
|
67
|
+
if (!value || typeof value !== 'string') {
|
|
68
|
+
return { errors: error('did.empty', { did: value }) };
|
|
69
|
+
}
|
|
70
|
+
if ((0, did_1.isValid)(value) === false) {
|
|
71
|
+
return { errors: error('did.invalid', { did: value }) };
|
|
72
|
+
}
|
|
73
|
+
return { value };
|
|
74
|
+
},
|
|
75
|
+
messages: {
|
|
76
|
+
'did.empty': 'did "{{#did}}" must be non-empty string',
|
|
77
|
+
'did.invalid': 'did "{{#did}}" is not valid',
|
|
78
|
+
},
|
|
81
79
|
});
|
|
82
|
-
|
|
83
|
-
|
|
80
|
+
exports.didExtension = didExtension;
|
|
81
|
+
exports.default = {
|
|
82
|
+
fileExtension,
|
|
83
|
+
didExtension,
|
|
84
|
+
};
|
package/lib/file.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { TBlockletMeta } from './types';
|
|
2
|
+
declare const list: any[];
|
|
3
|
+
declare const select: (dir: string, { throwOnError }?: {
|
|
4
|
+
throwOnError?: boolean;
|
|
5
|
+
}) => string;
|
|
6
|
+
declare const update: (file: string, meta: TBlockletMeta, { fix }?: {
|
|
7
|
+
fix?: boolean;
|
|
8
|
+
}) => void;
|
|
9
|
+
export { list };
|
|
10
|
+
export { select };
|
|
11
|
+
export { update };
|
|
12
|
+
declare const _default: {
|
|
13
|
+
list: any[];
|
|
14
|
+
select: (dir: string, { throwOnError }?: {
|
|
15
|
+
throwOnError?: boolean;
|
|
16
|
+
}) => string;
|
|
17
|
+
update: (file: string, meta: TBlockletMeta, { fix }?: {
|
|
18
|
+
fix?: boolean;
|
|
19
|
+
}) => void;
|
|
20
|
+
};
|
|
21
|
+
export default _default;
|
package/lib/file.js
CHANGED
|
@@ -1,45 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.update = exports.select = exports.list = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const js_yaml_1 = __importDefault(require("js-yaml"));
|
|
9
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
10
|
+
const constants_1 = __importDefault(require("./constants"));
|
|
11
|
+
const { BLOCKLET_META_FILE, BLOCKLET_META_FILE_ALT } = constants_1.default;
|
|
6
12
|
const list = [BLOCKLET_META_FILE, BLOCKLET_META_FILE_ALT];
|
|
7
|
-
|
|
13
|
+
exports.list = list;
|
|
8
14
|
const select = (dir, { throwOnError = true } = {}) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
const metaFile = path_1.default.join(dir, BLOCKLET_META_FILE);
|
|
16
|
+
const metaFileAlt = path_1.default.join(dir, BLOCKLET_META_FILE_ALT);
|
|
17
|
+
if (fs_extra_1.default.existsSync(metaFile) === false && fs_extra_1.default.existsSync(metaFileAlt) === false) {
|
|
18
|
+
if (throwOnError) {
|
|
19
|
+
throw new Error('blocklet.yml not found, please migrate your blocklet meta by run `abtnode blocklet:migrate`');
|
|
20
|
+
}
|
|
21
|
+
return '';
|
|
15
22
|
}
|
|
16
|
-
|
|
17
|
-
return
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const metaToUpdate = fs.existsSync(metaFile) ? metaFile : fs.existsSync(metaFileAlt) ? metaFileAlt : null; // eslint-disable-line
|
|
21
|
-
return metaToUpdate;
|
|
23
|
+
const metaToUpdate = fs_extra_1.default.existsSync(metaFile) ? metaFile : fs_extra_1.default.existsSync(metaFileAlt) ? metaFileAlt : null; // eslint-disable-line
|
|
24
|
+
return metaToUpdate;
|
|
22
25
|
};
|
|
23
|
-
|
|
26
|
+
exports.select = select;
|
|
24
27
|
const update = (file, meta, { fix = true } = {}) => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
28
|
+
if (!fix) {
|
|
29
|
+
fs_extra_1.default.writeFileSync(file, js_yaml_1.default.dump(meta, { sortKeys: false, skipInvalid: true }));
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
delete meta.path;
|
|
33
|
+
// @ts-ignore
|
|
34
|
+
delete meta.folder;
|
|
35
|
+
delete meta.htmlAst;
|
|
36
|
+
delete meta.stats;
|
|
37
|
+
delete meta.nftFactory;
|
|
38
|
+
delete meta.signatures;
|
|
39
|
+
delete meta.lastPublishedAt;
|
|
40
|
+
if (!meta.specVersion) {
|
|
41
|
+
meta.specVersion = '1.0.0';
|
|
42
|
+
}
|
|
43
|
+
fs_extra_1.default.writeFileSync(file, js_yaml_1.default.dump(meta, { sortKeys: false, skipInvalid: true }));
|
|
44
|
+
};
|
|
45
|
+
exports.update = update;
|
|
46
|
+
exports.default = {
|
|
47
|
+
list,
|
|
48
|
+
select,
|
|
49
|
+
update,
|
|
43
50
|
};
|
|
44
|
-
|
|
45
|
-
module.exports = { list, select, update };
|