@blocklet/meta 1.8.1 → 1.8.4
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.js +39 -0
- package/lib/constants.js +2 -1
- package/lib/file.js +2 -2
- package/lib/nft-templates.js +47 -0
- package/lib/parse-navigation.js +42 -4
- package/lib/parse.js +11 -25
- package/lib/payment.js +1 -1
- package/lib/util.js +51 -0
- package/package.json +12 -13
package/lib/channel.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const { isValid: isValidDid } = require('@arcblock/did');
|
|
2
|
+
|
|
3
|
+
const getAppPublicChannelRegex = () => /app:(\w+):public/;
|
|
4
|
+
|
|
5
|
+
const getAppPublicChannel = (appDid) => `app:${appDid}:public`;
|
|
6
|
+
|
|
7
|
+
const CHANNEL_TYPE = {
|
|
8
|
+
DID: 'DID',
|
|
9
|
+
APP: 'APP',
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const parseChannel = (channel) => {
|
|
13
|
+
if (!channel) {
|
|
14
|
+
throw new Error('Channel should not be empty');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const matchAppPublicChannel = getAppPublicChannelRegex().exec(channel);
|
|
18
|
+
if (matchAppPublicChannel) {
|
|
19
|
+
return {
|
|
20
|
+
type: CHANNEL_TYPE.APP,
|
|
21
|
+
appDid: matchAppPublicChannel[1],
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (isValidDid(channel)) {
|
|
26
|
+
return {
|
|
27
|
+
type: CHANNEL_TYPE.DID,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
throw new Error(`Invalid channel format: ${channel}`);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
module.exports = {
|
|
35
|
+
CHANNEL_TYPE,
|
|
36
|
+
getAppPublicChannel,
|
|
37
|
+
getAppPublicChannelRegex,
|
|
38
|
+
parseChannel,
|
|
39
|
+
};
|
package/lib/constants.js
CHANGED
|
@@ -77,7 +77,9 @@ const BlockletEvents = Object.freeze({
|
|
|
77
77
|
installed: 'blocklet.installed',
|
|
78
78
|
installFailed: 'blocklet.installFailed',
|
|
79
79
|
upgraded: 'blocklet.upgraded',
|
|
80
|
+
upgradeFailed: 'blocklet.upgradedFailed',
|
|
80
81
|
downgraded: 'blocklet.downgraded',
|
|
82
|
+
downgradeFailed: 'blocklet.downgradedFailed',
|
|
81
83
|
deployed: 'blocklet.deployed',
|
|
82
84
|
updated: 'blocklet.updated',
|
|
83
85
|
statusChange: 'blocklet.statusChange',
|
|
@@ -170,7 +172,6 @@ module.exports = Object.freeze({
|
|
|
170
172
|
BLOCKLET_ENTRY_FILE: 'blocklet.js',
|
|
171
173
|
BLOCKLET_META_FILE: 'blocklet.yml',
|
|
172
174
|
BLOCKLET_META_FILE_ALT: 'blocklet.yaml',
|
|
173
|
-
BLOCKLET_META_FILE_OLD: 'blocklet.json',
|
|
174
175
|
|
|
175
176
|
BLOCKLET_DEFAULT_VERSION: '1.0.0',
|
|
176
177
|
|
package/lib/file.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
const path = require('path');
|
|
2
2
|
const yaml = require('js-yaml');
|
|
3
3
|
const fs = require('fs-extra');
|
|
4
|
-
const { BLOCKLET_META_FILE, BLOCKLET_META_FILE_ALT
|
|
4
|
+
const { BLOCKLET_META_FILE, BLOCKLET_META_FILE_ALT } = require('./constants');
|
|
5
5
|
|
|
6
|
-
const list = [BLOCKLET_META_FILE, BLOCKLET_META_FILE_ALT
|
|
6
|
+
const list = [BLOCKLET_META_FILE, BLOCKLET_META_FILE_ALT];
|
|
7
7
|
|
|
8
8
|
const select = (dir, { throwOnError = true } = {}) => {
|
|
9
9
|
const metaFile = path.join(dir, BLOCKLET_META_FILE);
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const joinUrl = require('url-join');
|
|
2
|
+
|
|
3
|
+
const getBlockletPurchaseTemplate = (serviceUrl = 'https://registry.arcblock.io') => ({
|
|
4
|
+
type: 'vc',
|
|
5
|
+
value: {
|
|
6
|
+
'@context': 'https://schema.arcblock.io/v0.1/context.jsonld',
|
|
7
|
+
id: '{{input.id}}',
|
|
8
|
+
tag: ['{{data.did}}'],
|
|
9
|
+
type: ['VerifiableCredential', 'PurchaseCredential', 'NFTCertificate', 'BlockletPurchaseCredential'],
|
|
10
|
+
issuer: {
|
|
11
|
+
id: '{{ctx.issuer.id}}',
|
|
12
|
+
pk: '{{ctx.issuer.pk}}',
|
|
13
|
+
name: '{{ctx.issuer.name}}',
|
|
14
|
+
},
|
|
15
|
+
issuanceDate: '{{input.issuanceDate}}', // does not expire
|
|
16
|
+
credentialSubject: {
|
|
17
|
+
id: '{{ctx.owner}}',
|
|
18
|
+
sn: '{{ctx.id}}',
|
|
19
|
+
purchased: {
|
|
20
|
+
blocklet: {
|
|
21
|
+
id: '{{data.did}}',
|
|
22
|
+
url: '{{{data.url}}}',
|
|
23
|
+
name: '{{data.name}}',
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
display: {
|
|
27
|
+
type: 'url',
|
|
28
|
+
content: joinUrl(serviceUrl, '/api/nft/display'), // accept asset-did in query param
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
credentialStatus: {
|
|
32
|
+
id: joinUrl(serviceUrl, '/api/nft/status'),
|
|
33
|
+
type: 'NFTStatusList2021',
|
|
34
|
+
scope: 'public',
|
|
35
|
+
},
|
|
36
|
+
proof: {
|
|
37
|
+
type: '{{input.proofType}}',
|
|
38
|
+
created: '{{input.issuanceDate}}',
|
|
39
|
+
proofPurpose: 'assertionMethod',
|
|
40
|
+
jws: '{{input.signature}}',
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
module.exports = {
|
|
46
|
+
getBlockletPurchaseTemplate,
|
|
47
|
+
};
|
package/lib/parse-navigation.js
CHANGED
|
@@ -7,13 +7,13 @@ const normalizePathPrefix = require('@abtnode/util/lib/normalize-path-prefix');
|
|
|
7
7
|
* @param {*} prefix prefix of link
|
|
8
8
|
* @param {*} _level 1: primary menu, >2: secondary menu
|
|
9
9
|
*/
|
|
10
|
-
const
|
|
10
|
+
const doParseNavigation = (navigation, blocklet, prefix = '/', _level = 1) => {
|
|
11
11
|
const result = [];
|
|
12
12
|
|
|
13
13
|
(navigation || []).forEach((nav) => {
|
|
14
14
|
if (!nav.child) {
|
|
15
15
|
if (_level > 1 && nav.items?.length) {
|
|
16
|
-
const list =
|
|
16
|
+
const list = doParseNavigation(nav.items, blocklet, prefix, _level + 1);
|
|
17
17
|
result.push(...list);
|
|
18
18
|
return;
|
|
19
19
|
}
|
|
@@ -37,7 +37,7 @@ const parseNavigation = (navigation, blocklet, prefix = '/', _level = 1) => {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
if (nav.items?.length) {
|
|
40
|
-
const list =
|
|
40
|
+
const list = doParseNavigation(nav.items, blocklet, prefix, _level + 1);
|
|
41
41
|
if (list.length) {
|
|
42
42
|
item.items = list;
|
|
43
43
|
}
|
|
@@ -82,7 +82,7 @@ const parseNavigation = (navigation, blocklet, prefix = '/', _level = 1) => {
|
|
|
82
82
|
result.push(item);
|
|
83
83
|
} else {
|
|
84
84
|
// child declares multiple menus
|
|
85
|
-
const list =
|
|
85
|
+
const list = doParseNavigation(
|
|
86
86
|
childNavigation,
|
|
87
87
|
child,
|
|
88
88
|
normalizePathPrefix(`${prefix}${child.mountPoint}`),
|
|
@@ -105,4 +105,42 @@ const parseNavigation = (navigation, blocklet, prefix = '/', _level = 1) => {
|
|
|
105
105
|
return result;
|
|
106
106
|
};
|
|
107
107
|
|
|
108
|
+
const markDuplicate = (navigation, urls = []) => {
|
|
109
|
+
navigation.forEach((item) => {
|
|
110
|
+
if (item.link && urls.includes(item.link)) {
|
|
111
|
+
item.duplicate = true;
|
|
112
|
+
}
|
|
113
|
+
if (item.link) {
|
|
114
|
+
urls.push(item.link);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (item.items) {
|
|
118
|
+
markDuplicate(item.items, urls);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
return navigation;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const filterDuplicate = (navigation) => {
|
|
126
|
+
const res = navigation.filter((x) => !x.duplicate);
|
|
127
|
+
res.forEach((item) => {
|
|
128
|
+
if (item.items) {
|
|
129
|
+
item.items = filterDuplicate(item.items);
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
return res;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
const uniq = (navigation) => {
|
|
137
|
+
return filterDuplicate(markDuplicate(navigation));
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const parseNavigation = (...args) => {
|
|
141
|
+
const res = doParseNavigation(...args);
|
|
142
|
+
|
|
143
|
+
return uniq(res);
|
|
144
|
+
};
|
|
145
|
+
|
|
108
146
|
module.exports = parseNavigation;
|
package/lib/parse.js
CHANGED
|
@@ -4,14 +4,14 @@ const yaml = require('js-yaml');
|
|
|
4
4
|
const camelCase = require('lodash/camelCase');
|
|
5
5
|
const debug = require('debug')('@blocklet/meta:parse');
|
|
6
6
|
|
|
7
|
-
const { BLOCKLET_META_FILE, BLOCKLET_META_FILE_ALT
|
|
7
|
+
const { BLOCKLET_META_FILE, BLOCKLET_META_FILE_ALT } = require('./constants');
|
|
8
8
|
|
|
9
9
|
const toBlockletDid = require('./did');
|
|
10
10
|
const { createBlockletSchema } = require('./schema');
|
|
11
11
|
const { fixRequired, fixRepository, fixFiles, fixPerson, fixKeywords, fixTags, fixService } = require('./fix');
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
|
-
* Get blocklet meta from blocklet.yml
|
|
14
|
+
* Get blocklet meta from blocklet.yml
|
|
15
15
|
* @param {string} dir blocklet directory
|
|
16
16
|
* @param {object} options.extraRawAttrs extra attributes, will be used as base attributes
|
|
17
17
|
* @param {boolean} options.ensureMain should we verify that main exists
|
|
@@ -21,30 +21,16 @@ const { fixRequired, fixRepository, fixFiles, fixPerson, fixKeywords, fixTags, f
|
|
|
21
21
|
*/
|
|
22
22
|
const parse = (
|
|
23
23
|
dir,
|
|
24
|
-
{
|
|
24
|
+
{
|
|
25
|
+
ensureMain = false,
|
|
26
|
+
ensureFiles = false,
|
|
27
|
+
ensureDist = false,
|
|
28
|
+
extraRawAttrs = {},
|
|
29
|
+
serviceMetas,
|
|
30
|
+
schemaOptions = {},
|
|
31
|
+
} = {}
|
|
25
32
|
) => {
|
|
26
33
|
let result = {};
|
|
27
|
-
const packageFile = path.join(dir, 'package.json');
|
|
28
|
-
if (fs.existsSync(packageFile)) {
|
|
29
|
-
try {
|
|
30
|
-
const packageJson = JSON.parse(fs.readFileSync(packageFile).toString());
|
|
31
|
-
delete packageJson.scripts;
|
|
32
|
-
result = Object.assign(result, packageJson, packageJson.blocklet || {});
|
|
33
|
-
debug('parse package.json', result);
|
|
34
|
-
} catch (err) {
|
|
35
|
-
console.error('parse_blocklet_meta from package.json failed', err);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const blockletMetaFileOld = path.join(dir, BLOCKLET_META_FILE_OLD);
|
|
40
|
-
if (fs.existsSync(blockletMetaFileOld)) {
|
|
41
|
-
try {
|
|
42
|
-
result = Object.assign(result, JSON.parse(fs.readFileSync(blockletMetaFileOld).toString()));
|
|
43
|
-
debug(`parse ${BLOCKLET_META_FILE_OLD}`, result);
|
|
44
|
-
} catch (err) {
|
|
45
|
-
console.error(`parse_blocklet_meta from ${BLOCKLET_META_FILE_OLD} failed`, err);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
34
|
|
|
49
35
|
const blockletMetaFile = path.join(dir, BLOCKLET_META_FILE);
|
|
50
36
|
const blockletMetaFileAlt = path.join(dir, BLOCKLET_META_FILE_ALT);
|
|
@@ -90,7 +76,7 @@ const parse = (
|
|
|
90
76
|
}, {});
|
|
91
77
|
|
|
92
78
|
// Validate and cleanup
|
|
93
|
-
const schema = createBlockletSchema(dir, { ensureMain, ensureFiles, ensureDist });
|
|
79
|
+
const schema = createBlockletSchema(dir, { ensureMain, ensureFiles, ensureDist, ...schemaOptions });
|
|
94
80
|
const { value, error } = schema.validate(result);
|
|
95
81
|
if (error) {
|
|
96
82
|
throw new Error(`Invalid blocklet meta: ${error.details.map((x) => x.message).join(', ')}`);
|
package/lib/payment.js
CHANGED
|
@@ -3,7 +3,7 @@ const joinURL = require('url-join');
|
|
|
3
3
|
const { BN } = require('@ocap/util');
|
|
4
4
|
const { isValidFactory } = require('@ocap/asset');
|
|
5
5
|
const { toFactoryAddress } = require('@arcblock/did-util');
|
|
6
|
-
const { getBlockletPurchaseTemplate } = require('
|
|
6
|
+
const { getBlockletPurchaseTemplate } = require('./nft-templates');
|
|
7
7
|
|
|
8
8
|
const createShareContract = ({ tokens = [], shares = [] }) => {
|
|
9
9
|
const zeroBN = new BN(0);
|
package/lib/util.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/* eslint-disable no-await-in-loop */
|
|
2
2
|
const get = require('lodash/get');
|
|
3
3
|
const slugify = require('slugify');
|
|
4
|
+
const joinUrl = require('url-join');
|
|
4
5
|
|
|
5
6
|
const { NODE_SERVICES, SLOT_FOR_IP_DNS_SITE, WHO_CAN_ACCESS } = require('@abtnode/constant');
|
|
6
7
|
|
|
@@ -24,6 +25,39 @@ const getComponentName = (component, ancestors = []) =>
|
|
|
24
25
|
|
|
25
26
|
const getComponentBundleId = (component) => `${component.meta.bundleName}@${component.meta.version}`;
|
|
26
27
|
|
|
28
|
+
/**
|
|
29
|
+
* a => ''
|
|
30
|
+
* @a/b => ''
|
|
31
|
+
* a/b => a
|
|
32
|
+
* @a/b/c => @a/b
|
|
33
|
+
* a/@b/c => a
|
|
34
|
+
* @a/b/@c/d => @a/b
|
|
35
|
+
* @a/b/@c/d/e => @a/b/@c/d
|
|
36
|
+
* @a/b/@c/d/@e/f => @a/b/@c/d
|
|
37
|
+
*/
|
|
38
|
+
const getParentComponentName = (name) => {
|
|
39
|
+
if (!name) {
|
|
40
|
+
return '';
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const arr = name.split('/');
|
|
44
|
+
arr.pop();
|
|
45
|
+
|
|
46
|
+
if (!arr.length) {
|
|
47
|
+
return '';
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (arr[arr.length - 1].startsWith('@')) {
|
|
51
|
+
arr.pop();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (!arr.length) {
|
|
55
|
+
return '';
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return arr.join('/');
|
|
59
|
+
};
|
|
60
|
+
|
|
27
61
|
const forEachBlocklet = (
|
|
28
62
|
blocklet,
|
|
29
63
|
cb,
|
|
@@ -374,6 +408,21 @@ const getWhoCanAccess = (blocklet) => {
|
|
|
374
408
|
return WHO_CAN_ACCESS.ALL;
|
|
375
409
|
};
|
|
376
410
|
|
|
411
|
+
const getConnectAppUrl = ({ request, baseUrl }) => {
|
|
412
|
+
const blockletDid = request.headers['x-blocklet-did'] || '';
|
|
413
|
+
const blockletRealDid = request.headers['x-blocklet-real-did'] || '';
|
|
414
|
+
const pathPrefix = request.headers['x-path-prefix'] || '/';
|
|
415
|
+
const groupPathPrefix = request.headers['x-group-path-prefix'] || '/';
|
|
416
|
+
|
|
417
|
+
// Child blocklets should set appInfo.link to exactly the same path as the root blocklet
|
|
418
|
+
let appUrl = baseUrl;
|
|
419
|
+
if (blockletDid !== blockletRealDid && pathPrefix !== groupPathPrefix) {
|
|
420
|
+
appUrl = joinUrl(joinUrl(appUrl, '/').replace(pathPrefix, groupPathPrefix), '');
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
return appUrl;
|
|
424
|
+
};
|
|
425
|
+
|
|
377
426
|
const replaceSlotToIp = (url, ip) => (url || '').replace(SLOT_FOR_IP_DNS_SITE, (ip || '').replace(/\./g, '-'));
|
|
378
427
|
|
|
379
428
|
const urlFriendly = (name) => slugify(name.replace(/^[@./-]/, '').replace(/[@./_]/g, '-'));
|
|
@@ -402,4 +451,6 @@ module.exports = {
|
|
|
402
451
|
getComponentName,
|
|
403
452
|
getComponentBundleId,
|
|
404
453
|
findComponentById,
|
|
454
|
+
getParentComponentName,
|
|
455
|
+
getConnectAppUrl,
|
|
405
456
|
};
|
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.4",
|
|
7
7
|
"description": "Library to parse/validate/fix blocklet meta",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -18,17 +18,16 @@
|
|
|
18
18
|
"author": "wangshijun <wangshijun2020@gmail.com> (http://github.com/wangshijun)",
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@abtnode/constant": "1.8.
|
|
22
|
-
"@abtnode/util": "1.8.
|
|
23
|
-
"@arcblock/did": "1.17.
|
|
24
|
-
"@arcblock/did-ext": "1.17.
|
|
25
|
-
"@arcblock/did-util": "1.17.
|
|
26
|
-
"@arcblock/jwt": "1.17.
|
|
27
|
-
"@
|
|
28
|
-
"@ocap/
|
|
29
|
-
"@ocap/
|
|
30
|
-
"@ocap/
|
|
31
|
-
"@ocap/wallet": "1.17.0",
|
|
21
|
+
"@abtnode/constant": "1.8.4",
|
|
22
|
+
"@abtnode/util": "1.8.4",
|
|
23
|
+
"@arcblock/did": "1.17.5",
|
|
24
|
+
"@arcblock/did-ext": "1.17.5",
|
|
25
|
+
"@arcblock/did-util": "1.17.5",
|
|
26
|
+
"@arcblock/jwt": "1.17.5",
|
|
27
|
+
"@ocap/asset": "1.17.5",
|
|
28
|
+
"@ocap/mcrypto": "1.17.5",
|
|
29
|
+
"@ocap/util": "1.17.5",
|
|
30
|
+
"@ocap/wallet": "1.17.5",
|
|
32
31
|
"ajv": "^8.11.0",
|
|
33
32
|
"cjk-length": "^1.0.0",
|
|
34
33
|
"debug": "^4.3.3",
|
|
@@ -47,5 +46,5 @@
|
|
|
47
46
|
"devDependencies": {
|
|
48
47
|
"jest": "^27.4.5"
|
|
49
48
|
},
|
|
50
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "c42fb1bb84c5eef0f753fd5397d8007c7a6eee19"
|
|
51
50
|
}
|