@blocklet/meta 1.15.17 → 1.16.0-beta-b16cb035
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 +32 -0
- package/lib/channel.js +54 -0
- package/lib/constants.d.ts +2 -0
- package/lib/constants.js +5 -152
- package/lib/did.d.ts +3 -0
- package/lib/did.js +9 -9
- 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 +14 -0
- package/lib/extension.js +82 -77
- package/lib/file.d.ts +23 -0
- package/lib/file.js +51 -36
- package/lib/fix.d.ts +36 -0
- package/lib/fix.js +231 -228
- package/lib/get-component-process-id.d.ts +5 -0
- package/lib/get-component-process-id.js +16 -0
- package/lib/has-reserved-key.d.ts +3 -0
- package/lib/has-reserved-key.js +15 -0
- package/lib/index.d.ts +86 -0
- package/lib/index.js +55 -34
- package/lib/info.d.ts +15 -0
- package/lib/info.js +70 -38
- package/lib/name.d.ts +15 -0
- package/lib/name.js +41 -8
- package/lib/nft-templates.d.ts +86 -0
- package/lib/nft-templates.js +52 -0
- package/lib/parse-navigation-from-blocklet.d.ts +92 -0
- package/lib/parse-navigation-from-blocklet.js +539 -0
- package/lib/parse-navigation.d.ts +3 -0
- package/lib/parse-navigation.js +197 -0
- package/lib/parse.d.ts +22 -0
- package/lib/parse.js +100 -89
- package/lib/payment/index.d.ts +254 -0
- package/lib/payment/index.js +14 -0
- package/lib/payment/v1.d.ts +185 -0
- package/lib/payment/v1.js +84 -0
- package/lib/payment/v2.d.ts +242 -0
- package/lib/payment/v2.js +576 -0
- package/lib/schema.d.ts +63 -0
- package/lib/schema.js +669 -283
- package/lib/service.d.ts +27 -0
- package/lib/service.js +71 -0
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.js +18 -0
- package/lib/types/schema.d.ts +284 -0
- package/lib/types/schema.js +3 -0
- package/lib/url-friendly.d.ts +6 -0
- package/lib/url-friendly.js +20 -0
- package/lib/util-meta.d.ts +42 -0
- package/lib/util-meta.js +146 -0
- package/lib/util.d.ts +201 -0
- package/lib/util.js +501 -82
- package/lib/validate.d.ts +13 -0
- package/lib/validate.js +37 -61
- package/lib/verify-multi-sig.d.ts +3 -0
- package/lib/verify-multi-sig.js +86 -59
- package/lib/wallet.d.ts +9 -0
- package/lib/wallet.js +19 -30
- package/package.json +59 -20
- package/lib/payment.js +0 -114
package/lib/channel.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
declare const getAppPublicChannelRegex: () => RegExp;
|
|
2
|
+
declare const getRelayChannelRegex: () => RegExp;
|
|
3
|
+
declare const getAppPublicChannel: (appDid: string) => string;
|
|
4
|
+
declare const getRelayChannel: (appDid: string, topic: string) => string;
|
|
5
|
+
declare const CHANNEL_TYPE: {
|
|
6
|
+
DID: string;
|
|
7
|
+
APP: string;
|
|
8
|
+
RELAY: string;
|
|
9
|
+
};
|
|
10
|
+
declare const parseChannel: (channel: string) => {
|
|
11
|
+
type: string;
|
|
12
|
+
appDid?: string;
|
|
13
|
+
topic?: string;
|
|
14
|
+
};
|
|
15
|
+
export { CHANNEL_TYPE, getAppPublicChannel, getAppPublicChannelRegex, getRelayChannel, getRelayChannelRegex, parseChannel, };
|
|
16
|
+
declare const _default: {
|
|
17
|
+
CHANNEL_TYPE: {
|
|
18
|
+
DID: string;
|
|
19
|
+
APP: string;
|
|
20
|
+
RELAY: string;
|
|
21
|
+
};
|
|
22
|
+
getAppPublicChannel: (appDid: string) => string;
|
|
23
|
+
getAppPublicChannelRegex: () => RegExp;
|
|
24
|
+
getRelayChannel: (appDid: string, topic: string) => string;
|
|
25
|
+
getRelayChannelRegex: () => RegExp;
|
|
26
|
+
parseChannel: (channel: string) => {
|
|
27
|
+
type: string;
|
|
28
|
+
appDid?: string;
|
|
29
|
+
topic?: string;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
export default _default;
|
package/lib/channel.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseChannel = exports.getRelayChannelRegex = exports.getRelayChannel = exports.getAppPublicChannelRegex = exports.getAppPublicChannel = exports.CHANNEL_TYPE = void 0;
|
|
4
|
+
/* eslint-disable @typescript-eslint/indent */
|
|
5
|
+
const did_1 = require("@arcblock/did");
|
|
6
|
+
const getAppPublicChannelRegex = () => /app:(\w+):public/;
|
|
7
|
+
exports.getAppPublicChannelRegex = getAppPublicChannelRegex;
|
|
8
|
+
const getRelayChannelRegex = () => /relay:(\w+):(\w+)/;
|
|
9
|
+
exports.getRelayChannelRegex = getRelayChannelRegex;
|
|
10
|
+
const getAppPublicChannel = (appDid) => `app:${appDid}:public`;
|
|
11
|
+
exports.getAppPublicChannel = getAppPublicChannel;
|
|
12
|
+
const getRelayChannel = (appDid, topic) => `relay:${appDid}:${topic}`;
|
|
13
|
+
exports.getRelayChannel = getRelayChannel;
|
|
14
|
+
const CHANNEL_TYPE = {
|
|
15
|
+
DID: 'DID',
|
|
16
|
+
APP: 'APP',
|
|
17
|
+
RELAY: 'RELAY',
|
|
18
|
+
};
|
|
19
|
+
exports.CHANNEL_TYPE = CHANNEL_TYPE;
|
|
20
|
+
const parseChannel = (channel) => {
|
|
21
|
+
if (!channel) {
|
|
22
|
+
throw new Error('Channel should not be empty');
|
|
23
|
+
}
|
|
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])) {
|
|
34
|
+
return {
|
|
35
|
+
type: CHANNEL_TYPE.APP,
|
|
36
|
+
appDid: match[1],
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
if ((0, did_1.isValid)(channel)) {
|
|
40
|
+
return {
|
|
41
|
+
type: CHANNEL_TYPE.DID,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
throw new Error(`Invalid channel format: ${channel}`);
|
|
45
|
+
};
|
|
46
|
+
exports.parseChannel = parseChannel;
|
|
47
|
+
exports.default = {
|
|
48
|
+
CHANNEL_TYPE,
|
|
49
|
+
getAppPublicChannel,
|
|
50
|
+
getAppPublicChannelRegex,
|
|
51
|
+
getRelayChannel,
|
|
52
|
+
getRelayChannelRegex,
|
|
53
|
+
parseChannel,
|
|
54
|
+
};
|
package/lib/constants.js
CHANGED
|
@@ -1,153 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
// Wellknown interface declares an sub-interface under web interface
|
|
5
|
-
// The path of the wellknown interface must starts with /.well-known, e.g. /.well-known/acme-challenge)
|
|
6
|
-
// The wellknown interface can be mounted to every endpoint of the abtnode and all blocklets on the abtnode
|
|
7
|
-
const BLOCKLET_INTERFACE_TYPE_WELLKNOWN = 'wellknown';
|
|
8
|
-
|
|
9
|
-
const BlockletStatus = Object.freeze({
|
|
10
|
-
added: 0,
|
|
11
|
-
downloading: 1,
|
|
12
|
-
downloaded: 2, // Deprecated
|
|
13
|
-
installing: 3,
|
|
14
|
-
installed: 4,
|
|
15
|
-
starting: 5,
|
|
16
|
-
running: 6,
|
|
17
|
-
stopping: 7,
|
|
18
|
-
stopped: 8,
|
|
19
|
-
error: 9,
|
|
20
|
-
upgrading: 10,
|
|
21
|
-
restarting: 11, // Deprecated
|
|
22
|
-
corrupted: 12,
|
|
23
|
-
waiting: 13,
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
const BlockletSource = Object.freeze({
|
|
27
|
-
registry: 0,
|
|
28
|
-
local: 1,
|
|
29
|
-
upload: 2,
|
|
30
|
-
url: 3,
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
const BlockletEvents = Object.freeze({
|
|
34
|
-
added: 'blocklet.added',
|
|
35
|
-
downloadFailed: 'blocklet.downloadFailed',
|
|
36
|
-
installed: 'blocklet.installed',
|
|
37
|
-
installFailed: 'blocklet.installFailed',
|
|
38
|
-
upgraded: 'blocklet.upgraded',
|
|
39
|
-
downgraded: 'blocklet.downgraded',
|
|
40
|
-
deployed: 'blocklet.deployed',
|
|
41
|
-
updated: 'blocklet.updated',
|
|
42
|
-
statusChange: 'blocklet.statusChange',
|
|
43
|
-
removed: 'blocklet.removed',
|
|
44
|
-
started: 'blocklet.started',
|
|
45
|
-
startFailed: 'blocklet.startFailed',
|
|
46
|
-
stopped: 'blocklet.stopped',
|
|
47
|
-
reloaded: 'blocklet.reloaded', // Deprecated
|
|
48
|
-
purchaseChange: 'blocklet.purchaseChange',
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
const fromEntry = (entries) => (v) => {
|
|
52
|
-
const match = Object.entries(entries).find((x) => x[1] === Number(v));
|
|
53
|
-
return match ? match[0] : 'unknown';
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
54
4
|
};
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const fromBlockletStatus = fromEntry(BlockletStatus);
|
|
59
|
-
const toBlockletStatus = toEntry(BlockletStatus);
|
|
60
|
-
|
|
61
|
-
const fromBlockletSource = fromEntry(BlockletSource);
|
|
62
|
-
const toBlockletSource = toEntry(BlockletSource);
|
|
63
|
-
|
|
64
|
-
const BLOCKLET_INTERFACE_PUBLIC = 'publicUrl';
|
|
65
|
-
const BLOCKLET_INTERFACE_ADMIN = 'adminUrl';
|
|
66
|
-
const BLOCKLET_INTERFACE_CONFIG = 'configUrl';
|
|
67
|
-
const BLOCKLET_INTERFACE_DOC = 'docUrl';
|
|
68
|
-
const BLOCKLET_INTERFACE_WELLKNOWN = 'wellknownUrl'; // Deprecated
|
|
69
|
-
|
|
70
|
-
module.exports = Object.freeze({
|
|
71
|
-
BlockletStatus,
|
|
72
|
-
BlockletSource,
|
|
73
|
-
fromBlockletStatus,
|
|
74
|
-
toBlockletStatus,
|
|
75
|
-
fromBlockletSource,
|
|
76
|
-
toBlockletSource,
|
|
77
|
-
|
|
78
|
-
BlockletGroup: Object.freeze({
|
|
79
|
-
static: 'static',
|
|
80
|
-
dapp: 'dapp',
|
|
81
|
-
starter: false,
|
|
82
|
-
gateway: 'gateway',
|
|
83
|
-
}),
|
|
84
|
-
BLOCKLET_GROUPS: ['dapp', 'static', 'gateway'],
|
|
85
|
-
|
|
86
|
-
BlockletEvents,
|
|
87
|
-
|
|
88
|
-
BLOCKLET_PLATFORMS: ['aix', 'darwin', 'freebsd', 'linux', 'openbsd', 'sunos', 'win32'],
|
|
89
|
-
BLOCKLET_ARCHITECTURES: ['arm', 'arm64', 'ia32', 'mips', 'mipsel', 'ppc', 'ppc64', 's390', 's390x', 'x32', 'x64'],
|
|
90
|
-
BLOCKLET_MODES: Object.freeze({
|
|
91
|
-
PRODUCTION: 'production',
|
|
92
|
-
DEVELOPMENT: 'development',
|
|
93
|
-
}),
|
|
94
|
-
|
|
95
|
-
BLOCKLET_FACTORY_SHARES: { developer: 0.7, store: 0.3 },
|
|
96
|
-
|
|
97
|
-
BLOCKLET_DYNAMIC_PATH_PREFIX: '*',
|
|
98
|
-
|
|
99
|
-
BLOCKLET_INTERFACE_PUBLIC,
|
|
100
|
-
BLOCKLET_INTERFACE_ADMIN,
|
|
101
|
-
BLOCKLET_INTERFACE_CONFIG,
|
|
102
|
-
BLOCKLET_INTERFACE_DOC,
|
|
103
|
-
BLOCKLET_INTERFACE_WELLKNOWN,
|
|
104
|
-
|
|
105
|
-
BLOCKLET_UI_INTERFACES: [
|
|
106
|
-
BLOCKLET_INTERFACE_PUBLIC,
|
|
107
|
-
BLOCKLET_INTERFACE_ADMIN,
|
|
108
|
-
BLOCKLET_INTERFACE_CONFIG,
|
|
109
|
-
BLOCKLET_INTERFACE_DOC,
|
|
110
|
-
],
|
|
111
|
-
|
|
112
|
-
BLOCKLET_STANDARD_INTERFACES: [
|
|
113
|
-
BLOCKLET_INTERFACE_PUBLIC,
|
|
114
|
-
BLOCKLET_INTERFACE_ADMIN,
|
|
115
|
-
BLOCKLET_INTERFACE_CONFIG,
|
|
116
|
-
BLOCKLET_INTERFACE_DOC,
|
|
117
|
-
BLOCKLET_INTERFACE_WELLKNOWN,
|
|
118
|
-
],
|
|
119
|
-
|
|
120
|
-
BLOCKLET_INTERFACE_TYPE_WEB,
|
|
121
|
-
BLOCKLET_INTERFACE_TYPE_SERVICE,
|
|
122
|
-
BLOCKLET_INTERFACE_TYPE_WELLKNOWN,
|
|
123
|
-
BLOCKLET_INTERFACE_TYPES: [
|
|
124
|
-
BLOCKLET_INTERFACE_TYPE_WEB,
|
|
125
|
-
BLOCKLET_INTERFACE_TYPE_SERVICE,
|
|
126
|
-
BLOCKLET_INTERFACE_TYPE_WELLKNOWN,
|
|
127
|
-
],
|
|
128
|
-
|
|
129
|
-
BLOCKLET_INTERFACE_PROTOCOLS: ['tcp', 'udp', 'http'],
|
|
130
|
-
|
|
131
|
-
BLOCKLET_RELEASE_FOLDER: '.blocklet/release',
|
|
132
|
-
BLOCKLET_RELEASE_FILE: 'blocklet.json',
|
|
133
|
-
BLOCKLET_BUNDLE_FOLDER: '.blocklet/bundle',
|
|
134
|
-
BLOCKLET_BUNDLE_FILE: 'blocklet.zip',
|
|
135
|
-
BLOCKLET_ENTRY_FILE: 'blocklet.js',
|
|
136
|
-
BLOCKLET_META_FILE: 'blocklet.yml',
|
|
137
|
-
BLOCKLET_META_FILE_ALT: 'blocklet.yaml',
|
|
138
|
-
BLOCKLET_META_FILE_OLD: 'blocklet.json',
|
|
139
|
-
|
|
140
|
-
BLOCKLET_DEFAULT_VERSION: '1.0.0',
|
|
141
|
-
BLOCKLET_DEFAULT_PORT_NAME: 'BLOCKLET_PORT',
|
|
142
|
-
|
|
143
|
-
BLOCKLET_LATEST_SPEC_VERSION: '1.1.1',
|
|
144
|
-
BLOCKLET_LATEST_REQUIREMENT_ABTNODE: '>=1.2.0',
|
|
145
|
-
|
|
146
|
-
BLOCKLET_CONFIGURABLE_KEY: {
|
|
147
|
-
BLOCKLET_CLUSTER_SIZE: 'BLOCKLET_CLUSTER_SIZE',
|
|
148
|
-
BLOCKLET_APP_NAME: 'BLOCKLET_APP_NAME',
|
|
149
|
-
BLOCKLET_APP_DESCRIPTION: 'BLOCKLET_APP_DESCRIPTION',
|
|
150
|
-
BLOCKLET_APP_SK: 'BLOCKLET_APP_SK',
|
|
151
|
-
BLOCKLET_WALLET_TYPE: 'BLOCKLET_WALLET_TYPE',
|
|
152
|
-
},
|
|
153
|
-
});
|
|
5
|
+
const constant_1 = __importDefault(require("@blocklet/constant"));
|
|
6
|
+
module.exports = constant_1.default;
|
package/lib/did.d.ts
ADDED
package/lib/did.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
const { types } = Mcrypto;
|
|
6
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
const mcrypto_1 = require("@ocap/mcrypto");
|
|
3
|
+
const util_1 = require("@ocap/util");
|
|
4
|
+
const did_1 = require("@arcblock/did");
|
|
7
5
|
const toBlockletDid = (name) => {
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
if ((0, did_1.isValid)(name)) {
|
|
7
|
+
return name;
|
|
8
|
+
}
|
|
9
|
+
const pk = (0, util_1.toHex)(Buffer.from(typeof name === 'string' ? name.trim() : name));
|
|
10
|
+
return (0, did_1.fromPublicKey)(pk, { role: mcrypto_1.types.RoleType.ROLE_ANY });
|
|
10
11
|
};
|
|
11
|
-
|
|
12
12
|
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(`${meta.bundleName} 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(`${meta.bundleName} 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(`${meta.bundleName} 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(`${meta.bundleName} 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(`${meta.bundleName} 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(`${meta.bundleName} Unsupported blocklet type ${group}`);
|
|
69
55
|
};
|
|
56
|
+
module.exports = validateBlockletEntry;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Extension, Root } from 'joi';
|
|
2
|
+
declare const fileExtension: (joi: Root) => Extension;
|
|
3
|
+
/**
|
|
4
|
+
* joi extend did 判断
|
|
5
|
+
* 由于需要兼容新旧两种 did 模式判断,所以这里不能做 role 类型判断
|
|
6
|
+
*/
|
|
7
|
+
declare const didExtension: (joi: Root) => Extension;
|
|
8
|
+
export { fileExtension };
|
|
9
|
+
export { didExtension };
|
|
10
|
+
declare const _default: {
|
|
11
|
+
fileExtension: (joi: Root) => Extension;
|
|
12
|
+
didExtension: (joi: Root) => Extension;
|
|
13
|
+
};
|
|
14
|
+
export default _default;
|
package/lib/extension.js
CHANGED
|
@@ -1,83 +1,88 @@
|
|
|
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 = () => false } = {}) {
|
|
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
|
+
/**
|
|
64
|
+
* joi extend did 判断
|
|
65
|
+
* 由于需要兼容新旧两种 did 模式判断,所以这里不能做 role 类型判断
|
|
66
|
+
*/
|
|
63
67
|
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
|
-
},
|
|
68
|
+
type: 'DID',
|
|
69
|
+
base: joi.string(),
|
|
70
|
+
validate(value, { error }) {
|
|
71
|
+
if (!value || typeof value !== 'string') {
|
|
72
|
+
return { errors: error('did.empty', { did: value }) };
|
|
73
|
+
}
|
|
74
|
+
if ((0, did_1.isValid)(value) === false) {
|
|
75
|
+
return { errors: error('did.invalid', { did: value }) };
|
|
76
|
+
}
|
|
77
|
+
return { value };
|
|
78
|
+
},
|
|
79
|
+
messages: {
|
|
80
|
+
'did.empty': 'did "{{#did}}" must be non-empty string',
|
|
81
|
+
'did.invalid': 'did "{{#did}}" is not valid',
|
|
82
|
+
},
|
|
81
83
|
});
|
|
82
|
-
|
|
83
|
-
|
|
84
|
+
exports.didExtension = didExtension;
|
|
85
|
+
exports.default = {
|
|
86
|
+
fileExtension,
|
|
87
|
+
didExtension,
|
|
88
|
+
};
|
package/lib/file.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
declare const read: (file: string) => unknown;
|
|
10
|
+
export { list };
|
|
11
|
+
export { read };
|
|
12
|
+
export { select };
|
|
13
|
+
export { update };
|
|
14
|
+
declare const _default: {
|
|
15
|
+
list: any[];
|
|
16
|
+
select: (dir: string, { throwOnError }?: {
|
|
17
|
+
throwOnError?: boolean;
|
|
18
|
+
}) => string;
|
|
19
|
+
update: (file: string, meta: TBlockletMeta, { fix }?: {
|
|
20
|
+
fix?: boolean;
|
|
21
|
+
}) => void;
|
|
22
|
+
};
|
|
23
|
+
export default _default;
|