@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/parse-navigation.js
CHANGED
|
@@ -24,7 +24,9 @@ const getGroups = (navigation) => {
|
|
|
24
24
|
if (!groups[sec]) {
|
|
25
25
|
groups[sec] = [];
|
|
26
26
|
}
|
|
27
|
-
const item =
|
|
27
|
+
const item = {
|
|
28
|
+
...nav,
|
|
29
|
+
};
|
|
28
30
|
if (nav.section) {
|
|
29
31
|
item.section = sec === '__undefined__' ? [] : [sec];
|
|
30
32
|
}
|
|
@@ -37,9 +39,8 @@ const getChildName = (nav) => nav.component || nav.child;
|
|
|
37
39
|
const doParseNavigation = (navigation, blocklet, prefix = '/', _level = 1) => {
|
|
38
40
|
const result = [];
|
|
39
41
|
(navigation || []).forEach((nav) => {
|
|
40
|
-
var _a, _b;
|
|
41
42
|
if (!getChildName(nav)) {
|
|
42
|
-
if (_level > 1 &&
|
|
43
|
+
if (_level > 1 && nav.items?.length) {
|
|
43
44
|
const list = doParseNavigation(nav.items, blocklet, prefix, _level + 1);
|
|
44
45
|
result.push(...list);
|
|
45
46
|
return;
|
|
@@ -63,7 +64,7 @@ const doParseNavigation = (navigation, blocklet, prefix = '/', _level = 1) => {
|
|
|
63
64
|
if (nav.role) {
|
|
64
65
|
item.role = nav.role;
|
|
65
66
|
}
|
|
66
|
-
if (
|
|
67
|
+
if (nav.items?.length) {
|
|
67
68
|
const list = doParseNavigation(nav.items, blocklet, prefix, _level + 1);
|
|
68
69
|
if (list.length) {
|
|
69
70
|
item.items = list;
|
|
@@ -124,7 +125,10 @@ const doParseNavigation = (navigation, blocklet, prefix = '/', _level = 1) => {
|
|
|
124
125
|
if (list.length > 1) {
|
|
125
126
|
// more than 1 child nav
|
|
126
127
|
delete item.link;
|
|
127
|
-
result.push(
|
|
128
|
+
result.push({
|
|
129
|
+
...item,
|
|
130
|
+
items: list,
|
|
131
|
+
});
|
|
128
132
|
}
|
|
129
133
|
else {
|
|
130
134
|
// only 1 child nav
|
|
@@ -143,7 +147,10 @@ const doParseNavigation = (navigation, blocklet, prefix = '/', _level = 1) => {
|
|
|
143
147
|
item.section = item.section || groupSection;
|
|
144
148
|
}
|
|
145
149
|
item.items = list;
|
|
146
|
-
result.push(
|
|
150
|
+
result.push({
|
|
151
|
+
...item,
|
|
152
|
+
items: list,
|
|
153
|
+
});
|
|
147
154
|
}
|
|
148
155
|
else {
|
|
149
156
|
// secondary menu
|
package/lib/parse.js
CHANGED
|
@@ -22,7 +22,6 @@ const { BLOCKLET_META_FILE, BLOCKLET_META_FILE_ALT } = constants_1.default;
|
|
|
22
22
|
* @param {boolean} options.ensureFiles should we verify that logo and files exists
|
|
23
23
|
*/
|
|
24
24
|
const parse = (dir, { ensureMain = false, ensureFiles = false, ensureDist = false, ensureComponentStore = true, extraRawAttrs = {}, schemaOptions = {}, defaultStoreUrl, fix = true, } = {}) => {
|
|
25
|
-
var _a;
|
|
26
25
|
let result;
|
|
27
26
|
const blockletMetaFile = path_1.default.join(dir, BLOCKLET_META_FILE);
|
|
28
27
|
const blockletMetaFileAlt = path_1.default.join(dir, BLOCKLET_META_FILE_ALT);
|
|
@@ -61,9 +60,10 @@ const parse = (dir, { ensureMain = false, ensureFiles = false, ensureDist = fals
|
|
|
61
60
|
(0, fix_1.fixFiles)(result);
|
|
62
61
|
(0, fix_1.fixKeywords)(result);
|
|
63
62
|
(0, fix_1.fixTags)(result);
|
|
63
|
+
(0, fix_1.fixName)(result);
|
|
64
64
|
(0, fix_1.fixPerson)(result);
|
|
65
65
|
(0, fix_1.fixService)(result);
|
|
66
|
-
if (defaultStoreUrl &&
|
|
66
|
+
if (defaultStoreUrl && result.components?.length) {
|
|
67
67
|
result.components.forEach((x) => {
|
|
68
68
|
if ('name' in x.source) {
|
|
69
69
|
if (!x.source.store) {
|
|
@@ -81,10 +81,13 @@ const parse = (dir, { ensureMain = false, ensureFiles = false, ensureDist = fals
|
|
|
81
81
|
}, {});
|
|
82
82
|
debug('fix', result);
|
|
83
83
|
// Validate and cleanup
|
|
84
|
-
const schema = (0, schema_1.createBlockletSchema)(dir,
|
|
84
|
+
const schema = (0, schema_1.createBlockletSchema)(dir, {
|
|
85
|
+
ensureMain,
|
|
85
86
|
ensureFiles,
|
|
86
87
|
ensureDist,
|
|
87
|
-
ensureComponentStore
|
|
88
|
+
ensureComponentStore,
|
|
89
|
+
...schemaOptions,
|
|
90
|
+
});
|
|
88
91
|
const { value, error } = schema.validate(result);
|
|
89
92
|
if (error) {
|
|
90
93
|
throw new Error(`Invalid blocklet.yml: ${error.details
|
|
@@ -95,7 +98,7 @@ const parse = (dir, { ensureMain = false, ensureFiles = false, ensureDist = fals
|
|
|
95
98
|
return `${x.message}: ${x.context.value.id}`;
|
|
96
99
|
}
|
|
97
100
|
}
|
|
98
|
-
catch
|
|
101
|
+
catch {
|
|
99
102
|
//
|
|
100
103
|
}
|
|
101
104
|
return x.message;
|
package/lib/payment/v2.js
CHANGED
|
@@ -22,15 +22,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
27
|
};
|
|
@@ -68,11 +59,11 @@ const safeMul = (a, b) => Number((0, util_1.fromUnitToToken)((0, util_1.fromToke
|
|
|
68
59
|
.mul(new util_1.BN(b * defaultDecimals))
|
|
69
60
|
.div(defaultDecimalsBN)));
|
|
70
61
|
const md5 = (str) => crypto_1.default.createHash('md5').update(str).digest('hex');
|
|
71
|
-
const getStoreInfo = (url) =>
|
|
62
|
+
const getStoreInfo = async (url) => {
|
|
72
63
|
const storeMetaUrl = (0, url_join_1.default)(new URL(url).origin, BLOCKLET_STORE_META_PATH);
|
|
73
|
-
const { data: info } =
|
|
64
|
+
const { data: info } = await axios_1.default.get(storeMetaUrl, { timeout: 8000 });
|
|
74
65
|
return info;
|
|
75
|
-
}
|
|
66
|
+
};
|
|
76
67
|
/**
|
|
77
68
|
* @typedef {{
|
|
78
69
|
* meta: Object
|
|
@@ -91,7 +82,7 @@ const getStoreInfo = (url) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
91
82
|
*
|
|
92
83
|
* @returns {Array<Component>}
|
|
93
84
|
*/
|
|
94
|
-
const innerGetComponents = (inputMeta, context = {}) =>
|
|
85
|
+
const innerGetComponents = async (inputMeta, context = {}) => {
|
|
95
86
|
// FIXME 是否需要验证: 在同一个链上; 重复的 component
|
|
96
87
|
const { ancestors = [], bundles = {} } = context;
|
|
97
88
|
// check ancestor length
|
|
@@ -109,7 +100,7 @@ const innerGetComponents = (inputMeta, context = {}) => __awaiter(void 0, void 0
|
|
|
109
100
|
let meta;
|
|
110
101
|
let url;
|
|
111
102
|
try {
|
|
112
|
-
const res =
|
|
103
|
+
const res = await (0, util_meta_1.getBlockletMetaFromUrls)(urls, {
|
|
113
104
|
returnUrl: true,
|
|
114
105
|
validateFn: (m) => (0, validate_1.validateMeta)(m),
|
|
115
106
|
ensureTarball: false,
|
|
@@ -125,7 +116,7 @@ const innerGetComponents = (inputMeta, context = {}) => __awaiter(void 0, void 0
|
|
|
125
116
|
throw new Error(`The blocklet cannot be a component: ${meta.title}`);
|
|
126
117
|
}
|
|
127
118
|
// check circular dependencies
|
|
128
|
-
if (ancestors.map((x) =>
|
|
119
|
+
if (ancestors.map((x) => x.meta?.did).indexOf(meta.did) > -1) {
|
|
129
120
|
throw new Error('Blocklet components have circular dependencies');
|
|
130
121
|
}
|
|
131
122
|
// generate child
|
|
@@ -134,7 +125,7 @@ const innerGetComponents = (inputMeta, context = {}) => __awaiter(void 0, void 0
|
|
|
134
125
|
};
|
|
135
126
|
// child store info
|
|
136
127
|
if (config.source.store) {
|
|
137
|
-
const storeInfo =
|
|
128
|
+
const storeInfo = await getStoreInfo(url);
|
|
138
129
|
// check uniq bundle did in different stores
|
|
139
130
|
if (!bundles[child.meta.did]) {
|
|
140
131
|
bundles[child.meta.did] = storeInfo.id;
|
|
@@ -146,14 +137,14 @@ const innerGetComponents = (inputMeta, context = {}) => __awaiter(void 0, void 0
|
|
|
146
137
|
child.storeUrl = new URL(url).origin;
|
|
147
138
|
}
|
|
148
139
|
// child children
|
|
149
|
-
child.children =
|
|
140
|
+
child.children = await innerGetComponents(meta, {
|
|
150
141
|
ancestors: [...ancestors, { meta }],
|
|
151
142
|
bundles,
|
|
152
143
|
});
|
|
153
144
|
children.push(child);
|
|
154
145
|
}
|
|
155
146
|
return children;
|
|
156
|
-
}
|
|
147
|
+
};
|
|
157
148
|
/**
|
|
158
149
|
* @param {Array<Component>} components
|
|
159
150
|
* @param {Array<Store>} _stores
|
|
@@ -181,26 +172,25 @@ const getStores = (components, _stores = []) => {
|
|
|
181
172
|
}
|
|
182
173
|
return _stores;
|
|
183
174
|
};
|
|
184
|
-
const getComponents = (inputMeta) =>
|
|
185
|
-
const components =
|
|
186
|
-
const stores =
|
|
175
|
+
const getComponents = async (inputMeta) => {
|
|
176
|
+
const components = await innerGetComponents(inputMeta);
|
|
177
|
+
const stores = await getStores(components);
|
|
187
178
|
return { components, stores };
|
|
188
|
-
}
|
|
189
|
-
const getPriceTokens = (meta, ocapClient) =>
|
|
179
|
+
};
|
|
180
|
+
const getPriceTokens = async (meta, ocapClient) => {
|
|
190
181
|
const priceTokens = (0, cloneDeep_1.default)((0, get_1.default)(meta, 'payment.price', []));
|
|
191
182
|
for (const token of priceTokens) {
|
|
192
183
|
// eslint-disable-next-line no-await-in-loop
|
|
193
|
-
const { state } =
|
|
184
|
+
const { state } = await ocapClient.getTokenState({ address: token.address });
|
|
194
185
|
if (!state) {
|
|
195
186
|
throw new Error(`Token specified in blocklet meta was not found on chain: ${token.address}`);
|
|
196
187
|
}
|
|
197
188
|
token.decimal = state.decimal;
|
|
198
189
|
}
|
|
199
190
|
return priceTokens;
|
|
200
|
-
}
|
|
191
|
+
};
|
|
201
192
|
const getChildShare = (childMeta, parentPrice) => {
|
|
202
|
-
|
|
203
|
-
if (!((_a = childMeta === null || childMeta === void 0 ? void 0 : childMeta.payment) === null || _a === void 0 ? void 0 : _a.componentPrice)) {
|
|
193
|
+
if (!childMeta?.payment?.componentPrice) {
|
|
204
194
|
return 0;
|
|
205
195
|
}
|
|
206
196
|
const priceList = childMeta.payment.componentPrice;
|
|
@@ -246,7 +236,7 @@ const getTokenTransfers = ({ priceToken, shares = [], components = [], }) => {
|
|
|
246
236
|
const childShare = getChildShare(child.meta, price);
|
|
247
237
|
parentShareBN = parentShareBN.sub((0, util_1.fromTokenToUnit)(childShare, priceToken.decimal));
|
|
248
238
|
const componentContracts = getTokenTransfers({
|
|
249
|
-
priceToken:
|
|
239
|
+
priceToken: { ...priceToken, value: childShare },
|
|
250
240
|
shares: child.meta.payment.share,
|
|
251
241
|
components: child.children || [],
|
|
252
242
|
});
|
|
@@ -277,19 +267,22 @@ const getTokenTransfers = ({ priceToken, shares = [], components = [], }) => {
|
|
|
277
267
|
});
|
|
278
268
|
return mergedContracts;
|
|
279
269
|
};
|
|
280
|
-
const getContract = ({ meta, priceTokens, components, }) =>
|
|
270
|
+
const getContract = async ({ meta, priceTokens, components, }) => {
|
|
281
271
|
const shares = meta.payment.share || [];
|
|
282
272
|
const [priceToken] = priceTokens;
|
|
283
273
|
const contracts = getTokenTransfers({ priceToken, shares, components });
|
|
284
274
|
const code = contracts
|
|
285
275
|
.map((x) => `transferToken('${x.tokenAddress}','${x.accountAddress}','${x.amount.toString()}')`)
|
|
286
276
|
.join(';\n');
|
|
287
|
-
const shareList = contracts.map((x) => (
|
|
277
|
+
const shareList = contracts.map((x) => ({
|
|
278
|
+
...x,
|
|
279
|
+
amount: (0, util_1.fromUnitToToken)(x.amount, priceToken.decimal),
|
|
280
|
+
}));
|
|
288
281
|
return {
|
|
289
282
|
code,
|
|
290
283
|
shares: shareList,
|
|
291
284
|
};
|
|
292
|
-
}
|
|
285
|
+
};
|
|
293
286
|
/**
|
|
294
287
|
* we need to ensure that blocklet purchase factory does not change across changes
|
|
295
288
|
*
|
|
@@ -373,17 +366,17 @@ const getFactoryInput = (inputTokens, { formatToken = true } = {}) => {
|
|
|
373
366
|
variables: [],
|
|
374
367
|
};
|
|
375
368
|
};
|
|
376
|
-
const getPaymentIntegrity = ({ contract, factoryInput, storeComponents, meta, client, storeId, }) =>
|
|
369
|
+
const getPaymentIntegrity = async ({ contract, factoryInput, storeComponents, meta, client, storeId, }) => {
|
|
377
370
|
if (!contract && !factoryInput && !storeComponents) {
|
|
378
|
-
const priceTokens =
|
|
379
|
-
const { components, stores } =
|
|
371
|
+
const priceTokens = await getPriceTokens(meta, client);
|
|
372
|
+
const { components, stores } = await getComponents(meta);
|
|
380
373
|
const store = stores.find((x) => x.id === storeId);
|
|
381
374
|
// eslint-disable-next-line no-param-reassign
|
|
382
|
-
contract = (
|
|
375
|
+
contract = (await getContract({ meta, components, priceTokens })).code;
|
|
383
376
|
// eslint-disable-next-line no-param-reassign
|
|
384
|
-
factoryInput =
|
|
377
|
+
factoryInput = await getFactoryInput(priceTokens);
|
|
385
378
|
// eslint-disable-next-line no-param-reassign
|
|
386
|
-
storeComponents =
|
|
379
|
+
storeComponents = store?.components || [];
|
|
387
380
|
}
|
|
388
381
|
const paymentData = {
|
|
389
382
|
factoryInput,
|
|
@@ -392,19 +385,19 @@ const getPaymentIntegrity = ({ contract, factoryInput, storeComponents, meta, cl
|
|
|
392
385
|
};
|
|
393
386
|
const integrity = md5((0, json_stable_stringify_1.default)(paymentData));
|
|
394
387
|
return integrity;
|
|
395
|
-
}
|
|
396
|
-
const getStoreSignatures = ({ meta, stores, factoryInput, contract, }) =>
|
|
388
|
+
};
|
|
389
|
+
const getStoreSignatures = async ({ meta, stores, factoryInput, contract, }) => {
|
|
397
390
|
const storeSignatures = [];
|
|
398
391
|
for (const store of stores) {
|
|
399
392
|
const { id, url, pk, components: storeComponents } = store;
|
|
400
|
-
const paymentIntegrity =
|
|
393
|
+
const paymentIntegrity = await getPaymentIntegrity({ factoryInput, contract, storeComponents });
|
|
401
394
|
/**
|
|
402
395
|
* protocol: /api/payment/signature
|
|
403
396
|
* method: POST
|
|
404
397
|
* body: { blockletMeta, paymentIntegrity, paymentVersion }
|
|
405
398
|
* return: { signer, pk, signature}
|
|
406
399
|
*/
|
|
407
|
-
const { data: res } =
|
|
400
|
+
const { data: res } = await axios_1.default.post(`${url}/api/payment/signature`, {
|
|
408
401
|
blockletMeta: meta,
|
|
409
402
|
paymentIntegrity,
|
|
410
403
|
paymentVersion: VERSION,
|
|
@@ -434,7 +427,7 @@ const getStoreSignatures = ({ meta, stores, factoryInput, contract, }) => __awai
|
|
|
434
427
|
return {
|
|
435
428
|
storeSignatures,
|
|
436
429
|
};
|
|
437
|
-
}
|
|
430
|
+
};
|
|
438
431
|
/**
|
|
439
432
|
* Used by CLI and Store to independent compute factory itx
|
|
440
433
|
*
|
|
@@ -455,16 +448,16 @@ const getStoreSignatures = ({ meta, stores, factoryInput, contract, }) => __awai
|
|
|
455
448
|
* }>
|
|
456
449
|
* }}
|
|
457
450
|
*/
|
|
458
|
-
const createNftFactoryItx = ({ blockletMeta, ocapClient, issuers, storeUrl, }) =>
|
|
459
|
-
const priceTokens =
|
|
460
|
-
const { components, stores } =
|
|
451
|
+
const createNftFactoryItx = async ({ blockletMeta, ocapClient, issuers, storeUrl, }) => {
|
|
452
|
+
const priceTokens = await getPriceTokens(blockletMeta, ocapClient);
|
|
453
|
+
const { components, stores } = await getComponents(blockletMeta);
|
|
461
454
|
const factoryInput = getFactoryInput(priceTokens);
|
|
462
|
-
const { code: contract, shares } =
|
|
455
|
+
const { code: contract, shares } = await getContract({
|
|
463
456
|
meta: blockletMeta,
|
|
464
457
|
priceTokens,
|
|
465
458
|
components,
|
|
466
459
|
});
|
|
467
|
-
const { storeSignatures } =
|
|
460
|
+
const { storeSignatures } = await getStoreSignatures({
|
|
468
461
|
meta: blockletMeta,
|
|
469
462
|
stores,
|
|
470
463
|
factoryInput,
|
|
@@ -482,7 +475,7 @@ const createNftFactoryItx = ({ blockletMeta, ocapClient, issuers, storeUrl, }) =
|
|
|
482
475
|
stores: storeSignatures.map((x) => ({ id: x.signer, url: x.storeUrl })),
|
|
483
476
|
shares,
|
|
484
477
|
};
|
|
485
|
-
}
|
|
478
|
+
};
|
|
486
479
|
exports.createNftFactoryItx = createNftFactoryItx;
|
|
487
480
|
/**
|
|
488
481
|
* Used by Store before generating payment signature
|
|
@@ -495,13 +488,13 @@ exports.createNftFactoryItx = createNftFactoryItx;
|
|
|
495
488
|
* }}
|
|
496
489
|
* @returns {string} integrity
|
|
497
490
|
*/
|
|
498
|
-
const verifyPaymentIntegrity = ({ integrity: expected, blockletMeta, ocapClient, storeId, }) =>
|
|
499
|
-
const actual =
|
|
491
|
+
const verifyPaymentIntegrity = async ({ integrity: expected, blockletMeta, ocapClient, storeId, }) => {
|
|
492
|
+
const actual = await getPaymentIntegrity({ meta: blockletMeta, client: ocapClient, storeId });
|
|
500
493
|
if (actual !== expected) {
|
|
501
494
|
throw new Error('verify payment integrity failed');
|
|
502
495
|
}
|
|
503
496
|
return expected;
|
|
504
|
-
}
|
|
497
|
+
};
|
|
505
498
|
exports.verifyPaymentIntegrity = verifyPaymentIntegrity;
|
|
506
499
|
/**
|
|
507
500
|
* Used by Store before generating downloadToken
|
|
@@ -515,10 +508,9 @@ exports.verifyPaymentIntegrity = verifyPaymentIntegrity;
|
|
|
515
508
|
* components: Array<{did: string, version: string}>
|
|
516
509
|
* }}
|
|
517
510
|
*/
|
|
518
|
-
const verifyNftFactory = ({ factoryState, signerWallet, }) =>
|
|
519
|
-
|
|
520
|
-
const
|
|
521
|
-
const stores = (data === null || data === void 0 ? void 0 : data.stores) || [];
|
|
511
|
+
const verifyNftFactory = async ({ factoryState, signerWallet, }) => {
|
|
512
|
+
const data = JSON.parse(factoryState?.data?.value);
|
|
513
|
+
const stores = data?.stores || [];
|
|
522
514
|
const store = stores.find((x) => x.signer === signerWallet.address);
|
|
523
515
|
if (!store) {
|
|
524
516
|
throw new Error(`Signer does not found in factory. factory: ${factoryState.address}, signer: ${signerWallet.address}`);
|
|
@@ -527,7 +519,7 @@ const verifyNftFactory = ({ factoryState, signerWallet, }) => __awaiter(void 0,
|
|
|
527
519
|
const { components } = store;
|
|
528
520
|
// Token 的字段和 factory 中的字段不一致
|
|
529
521
|
const factoryInput = getFactoryInput(factoryState.input.tokens.map((x) => (0, pick_1.default)(x, ['address', 'value'])), { formatToken: false });
|
|
530
|
-
const integrity =
|
|
522
|
+
const integrity = await getPaymentIntegrity({
|
|
531
523
|
contract: c.hook,
|
|
532
524
|
factoryInput,
|
|
533
525
|
storeComponents: components,
|
|
@@ -537,7 +529,7 @@ const verifyNftFactory = ({ factoryState, signerWallet, }) => __awaiter(void 0,
|
|
|
537
529
|
throw new Error(`verify nft factory failed: ${factoryState.address}`);
|
|
538
530
|
}
|
|
539
531
|
return { components };
|
|
540
|
-
}
|
|
532
|
+
};
|
|
541
533
|
exports.verifyNftFactory = verifyNftFactory;
|
|
542
534
|
/**
|
|
543
535
|
* Check blocklet and all of components are free
|
|
@@ -545,11 +537,11 @@ exports.verifyNftFactory = verifyNftFactory;
|
|
|
545
537
|
*
|
|
546
538
|
* @param {TBlockletMeta} meta
|
|
547
539
|
*/
|
|
548
|
-
const checkFreeBlocklet = (blockletMeta) =>
|
|
540
|
+
const checkFreeBlocklet = async (blockletMeta) => {
|
|
549
541
|
if (!(0, util_2.isFreeBlocklet)(blockletMeta)) {
|
|
550
542
|
return Promise.reject(new Error('blocklet is not free'));
|
|
551
543
|
}
|
|
552
|
-
const { components } =
|
|
544
|
+
const { components } = await getComponents(blockletMeta);
|
|
553
545
|
const shouldAllComponentFree = (arr) => {
|
|
554
546
|
arr.forEach(({ meta, children }) => {
|
|
555
547
|
if (!(0, util_2.isFreeBlocklet)(meta) || !(0, util_2.isFreeComponent)(meta)) {
|
|
@@ -561,7 +553,7 @@ const checkFreeBlocklet = (blockletMeta) => __awaiter(void 0, void 0, void 0, fu
|
|
|
561
553
|
};
|
|
562
554
|
shouldAllComponentFree(components);
|
|
563
555
|
return true;
|
|
564
|
-
}
|
|
556
|
+
};
|
|
565
557
|
exports.checkFreeBlocklet = checkFreeBlocklet;
|
|
566
558
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
567
559
|
exports._test = {
|
package/lib/schema.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ declare const titleSchema: JOI.StringSchema<string>;
|
|
|
3
3
|
declare const descriptionSchema: JOI.StringSchema<string>;
|
|
4
4
|
declare const logoSchema: JOI.StringSchema<string>;
|
|
5
5
|
declare const mountPointSchema: JOI.StringSchema<string>;
|
|
6
|
+
declare const updateMountPointSchema: JOI.StringSchema<string>;
|
|
6
7
|
declare const blockletNameSchema: JOI.StringSchema<string>;
|
|
7
8
|
declare const environmentNameSchema: JOI.StringSchema<string>;
|
|
8
9
|
declare const environmentSchema: JOI.ObjectSchema<any>;
|
|
@@ -28,7 +29,7 @@ declare const createBlockletSchema: (baseDir: string, { ensureMain, ensureFiles,
|
|
|
28
29
|
ensureDist?: boolean;
|
|
29
30
|
ensureComponentStore?: boolean;
|
|
30
31
|
}) => JOI.ObjectSchema;
|
|
31
|
-
export { blockletMetaSchema, blockletNameSchema, componentSchema, createBlockletSchema, descriptionSchema, distSchema, endpointSchema, engineSchema, environmentSchema, environmentNameSchema, interfaceSchema, logoSchema, mountPointSchema, navigationItemSchema, navigationSchema, personSchema, scriptsSchema, serviceSchema, signatureSchema, themeSchema, titleSchema, statsSchema, cacheableSchema, authConfigSchema, };
|
|
32
|
+
export { blockletMetaSchema, blockletNameSchema, componentSchema, createBlockletSchema, descriptionSchema, distSchema, endpointSchema, engineSchema, environmentSchema, environmentNameSchema, interfaceSchema, logoSchema, mountPointSchema, updateMountPointSchema, navigationItemSchema, navigationSchema, personSchema, scriptsSchema, serviceSchema, signatureSchema, themeSchema, titleSchema, statsSchema, cacheableSchema, authConfigSchema, };
|
|
32
33
|
declare const _default: {
|
|
33
34
|
blockletNameSchema: JOI.StringSchema<string>;
|
|
34
35
|
componentSchema: JOI.ObjectSchema<any>;
|
|
@@ -52,6 +53,7 @@ declare const _default: {
|
|
|
52
53
|
navigationSchema: JOI.ArraySchema<any[]>;
|
|
53
54
|
themeSchema: JOI.ObjectSchema<any>;
|
|
54
55
|
mountPointSchema: JOI.StringSchema<string>;
|
|
56
|
+
updateMountPointSchema: JOI.StringSchema<string>;
|
|
55
57
|
authConfigSchema: JOI.ObjectSchema<any>;
|
|
56
58
|
};
|
|
57
59
|
export default _default;
|
package/lib/schema.js
CHANGED
|
@@ -1,39 +1,50 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
12
24
|
};
|
|
13
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
27
|
};
|
|
16
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.authConfigSchema = exports.cacheableSchema = exports.statsSchema = exports.titleSchema = exports.themeSchema = exports.signatureSchema = exports.serviceSchema = exports.scriptsSchema = exports.personSchema = exports.navigationSchema = exports.navigationItemSchema = exports.mountPointSchema = exports.logoSchema = exports.interfaceSchema = exports.environmentNameSchema = exports.environmentSchema = exports.engineSchema = exports.endpointSchema = exports.distSchema = exports.descriptionSchema = exports.createBlockletSchema = exports.componentSchema = exports.blockletNameSchema = exports.blockletMetaSchema = void 0;
|
|
29
|
+
exports.authConfigSchema = exports.cacheableSchema = exports.statsSchema = exports.titleSchema = exports.themeSchema = exports.signatureSchema = exports.serviceSchema = exports.scriptsSchema = exports.personSchema = exports.navigationSchema = exports.navigationItemSchema = exports.updateMountPointSchema = exports.mountPointSchema = exports.logoSchema = exports.interfaceSchema = exports.environmentNameSchema = exports.environmentSchema = exports.engineSchema = exports.endpointSchema = exports.distSchema = exports.descriptionSchema = exports.createBlockletSchema = exports.componentSchema = exports.blockletNameSchema = exports.blockletMetaSchema = void 0;
|
|
18
30
|
const fs_1 = __importDefault(require("fs"));
|
|
19
31
|
const joi_1 = __importDefault(require("joi"));
|
|
20
|
-
// eslint-disable-next-line import/no-named-default
|
|
21
32
|
const cjk_length_1 = __importDefault(require("cjk-length"));
|
|
22
33
|
const is_glob_1 = __importDefault(require("is-glob"));
|
|
23
34
|
const joi_extension_semver_1 = require("joi-extension-semver");
|
|
24
35
|
const is_var_name_1 = __importDefault(require("is-var-name"));
|
|
25
36
|
const constant_1 = require("@abtnode/constant");
|
|
26
|
-
const did_1 =
|
|
37
|
+
const did_1 = require("@arcblock/did");
|
|
38
|
+
const did_2 = __importDefault(require("./did"));
|
|
27
39
|
const extension_1 = require("./extension");
|
|
28
40
|
const name_1 = require("./name");
|
|
29
41
|
const constants_1 = __importDefault(require("./constants"));
|
|
30
42
|
const parse_navigation_from_blocklet_1 = require("./parse-navigation-from-blocklet");
|
|
31
|
-
const url_friendly_1 =
|
|
43
|
+
const url_friendly_1 = __importStar(require("./url-friendly"));
|
|
32
44
|
const cjkLength = cjk_length_1.default.default;
|
|
33
45
|
const { BLOCKLET_GROUPS, BLOCKLET_PLATFORMS, BLOCKLET_ARCHITECTURES, BLOCKLET_INTERFACE_TYPES, BLOCKLET_INTERFACE_PROTOCOLS, BLOCKLET_ENTRY_FILE, BLOCKLET_BUNDLE_FILE, BLOCKLET_DEFAULT_PORT_NAME, BLOCKLET_DYNAMIC_PATH_PREFIX, BlockletGroup, BLOCKLET_LATEST_REQUIREMENT_SERVER, BLOCKLET_INTERFACE_TYPE_WEB, BLOCKLET_INTERFACE_TYPE_WELLKNOWN, BLOCKLET_APP_SPACE_ENDPOINTS, BLOCKLET_CONFIGURABLE_KEY, } = constants_1.default;
|
|
34
46
|
const WELLKNOWN_PATH_PREFIX = '/.well-known';
|
|
35
47
|
const MAX_TITLE_LENGTH = 24;
|
|
36
|
-
const MAX_NAME_LENGTH = 32;
|
|
37
48
|
const Joi = joi_1.default.extend(joi_extension_semver_1.semver)
|
|
38
49
|
.extend(joi_extension_semver_1.semverRange)
|
|
39
50
|
.extend(extension_1.fileExtension)
|
|
@@ -89,18 +100,26 @@ const logoSchema = Joi.string()
|
|
|
89
100
|
})
|
|
90
101
|
.meta({ className: 'TLogo' });
|
|
91
102
|
exports.logoSchema = logoSchema;
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
.min(1)
|
|
103
|
+
const baseMountPointSchema = Joi.string().trim().min(1);
|
|
104
|
+
const mountPointSchema = baseMountPointSchema
|
|
95
105
|
.meta({ className: 'TMountPoint' })
|
|
96
|
-
.custom((value) =>
|
|
106
|
+
.custom((value, helper) => {
|
|
107
|
+
if ((0, url_friendly_1.isValidUrl)(value)) {
|
|
108
|
+
return value;
|
|
109
|
+
}
|
|
110
|
+
// @ts-expect-error
|
|
111
|
+
return helper.message('mountPoint cannot contain such characters space $*_+~.()\'"!:@\\');
|
|
112
|
+
});
|
|
97
113
|
exports.mountPointSchema = mountPointSchema;
|
|
114
|
+
const updateMountPointSchema = baseMountPointSchema
|
|
115
|
+
.meta({ className: 'TUpdateMountPoint' })
|
|
116
|
+
.custom((value) => (0, url_friendly_1.default)(value));
|
|
117
|
+
exports.updateMountPointSchema = updateMountPointSchema;
|
|
98
118
|
const blockletNameSchema = Joi.string()
|
|
99
119
|
.custom((value) => {
|
|
100
120
|
(0, name_1.validateName)(value);
|
|
101
121
|
return value;
|
|
102
122
|
})
|
|
103
|
-
.max(MAX_NAME_LENGTH)
|
|
104
123
|
.meta({ className: 'TBlockletName' });
|
|
105
124
|
exports.blockletNameSchema = blockletNameSchema;
|
|
106
125
|
const ENV_NAME_WHITE_LIST = [BLOCKLET_CONFIGURABLE_KEY.BLOCKLET_WALLET_TYPE];
|
|
@@ -382,7 +401,10 @@ const navigationItemProps = {
|
|
|
382
401
|
icon: Joi.string().min(1),
|
|
383
402
|
visible: Joi.boolean(),
|
|
384
403
|
};
|
|
385
|
-
const navigationItemSchema = Joi.object(
|
|
404
|
+
const navigationItemSchema = Joi.object({
|
|
405
|
+
...navigationItemProps,
|
|
406
|
+
items: Joi.array().items(Joi.object({ ...navigationItemProps }).rename('child', 'component')),
|
|
407
|
+
})
|
|
386
408
|
.rename('child', 'component')
|
|
387
409
|
.meta({
|
|
388
410
|
className: 'TNavigationItem',
|
|
@@ -430,7 +452,7 @@ exports.authConfigSchema = authConfigSchema;
|
|
|
430
452
|
const blockletMetaProps = {
|
|
431
453
|
did: Joi.DID().trim().required(),
|
|
432
454
|
version: Joi.semver().valid().required(),
|
|
433
|
-
name: blockletNameSchema.
|
|
455
|
+
name: blockletNameSchema.optional(),
|
|
434
456
|
description: descriptionSchema.required(),
|
|
435
457
|
group: Joi.string()
|
|
436
458
|
.valid(...BLOCKLET_GROUPS)
|
|
@@ -630,32 +652,56 @@ const blockletMetaSchema = Joi.object(blockletMetaProps).options({ stripUnknown:
|
|
|
630
652
|
unknownType: 'any',
|
|
631
653
|
});
|
|
632
654
|
exports.blockletMetaSchema = blockletMetaSchema;
|
|
633
|
-
const createBlockletSchema = (baseDir,
|
|
634
|
-
var { ensureMain = false, ensureFiles = false, ensureDist = false, ensureComponentStore = true } = _a, schemaOptions = __rest(_a, ["ensureMain", "ensureFiles", "ensureDist", "ensureComponentStore"]);
|
|
655
|
+
const createBlockletSchema = (baseDir, { ensureMain = false, ensureFiles = false, ensureDist = false, ensureComponentStore = true, ...schemaOptions } = {}) => {
|
|
635
656
|
if (!baseDir || !fs_1.default.existsSync(baseDir)) {
|
|
636
657
|
// eslint-disable-next-line no-param-reassign
|
|
637
658
|
ensureFiles = false;
|
|
638
659
|
}
|
|
639
|
-
return Joi.object(
|
|
660
|
+
return Joi.object({
|
|
661
|
+
...blockletMetaProps,
|
|
662
|
+
main: Joi.when('group', {
|
|
640
663
|
is: Joi.valid(BlockletGroup.gateway),
|
|
641
664
|
then: Joi.forbidden(),
|
|
642
665
|
otherwise: ensureMain ? Joi.file().exists({ baseDir }).required() : Joi.string().trim().required(),
|
|
643
|
-
}),
|
|
666
|
+
}),
|
|
667
|
+
logo: ensureFiles ? Joi.file().trim().exists({ baseDir }).optional() : Joi.string().trim().optional(),
|
|
644
668
|
// Other contents to be included in the bundle
|
|
645
669
|
files: Joi.array()
|
|
646
670
|
.items(ensureFiles
|
|
647
671
|
? // eslint-disable-next-line
|
|
648
672
|
Joi.file().exists({ baseDir, canSkip: (dir, name) => [BLOCKLET_ENTRY_FILE, BLOCKLET_BUNDLE_FILE].includes(name) || (0, is_glob_1.default)(name) }) // prettier-ignore
|
|
649
673
|
: Joi.string().trim())
|
|
650
|
-
.optional(),
|
|
651
|
-
|
|
674
|
+
.optional(),
|
|
675
|
+
dist: ensureDist ? distSchema.required() : distSchema.optional(),
|
|
676
|
+
components: componentsSchema(ensureComponentStore),
|
|
677
|
+
})
|
|
678
|
+
.options({ stripUnknown: true, noDefaults: false, ...schemaOptions })
|
|
652
679
|
.rename('children', 'components')
|
|
653
680
|
.custom((data, helper) => {
|
|
654
681
|
const { did, name } = data;
|
|
655
|
-
|
|
656
|
-
if (
|
|
657
|
-
|
|
658
|
-
|
|
682
|
+
let cacheError;
|
|
683
|
+
if ((0, did_1.isValid)(did)) {
|
|
684
|
+
try {
|
|
685
|
+
(0, name_1.validateNewDid)(did);
|
|
686
|
+
return data;
|
|
687
|
+
}
|
|
688
|
+
catch (e) {
|
|
689
|
+
cacheError = e;
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
/* ------------- 兼容旧的逻辑,旧逻辑使用 name 生成一个 did ------------- */
|
|
693
|
+
// 此时 name 必须存在
|
|
694
|
+
if (name) {
|
|
695
|
+
const expectDid = (0, did_2.default)(name);
|
|
696
|
+
if (expectDid !== did) {
|
|
697
|
+
// @ts-ignore
|
|
698
|
+
return helper.message(`The did of name "${name}" should be "${expectDid}"`);
|
|
699
|
+
}
|
|
700
|
+
return data;
|
|
701
|
+
/* ------------------------------------------------------ */
|
|
702
|
+
}
|
|
703
|
+
if (cacheError) {
|
|
704
|
+
return helper.message(cacheError.message);
|
|
659
705
|
}
|
|
660
706
|
return data;
|
|
661
707
|
});
|
|
@@ -679,5 +725,6 @@ exports.default = {
|
|
|
679
725
|
navigationSchema,
|
|
680
726
|
themeSchema,
|
|
681
727
|
mountPointSchema,
|
|
728
|
+
updateMountPointSchema,
|
|
682
729
|
authConfigSchema,
|
|
683
730
|
};
|
package/lib/service.js
CHANGED
|
@@ -22,7 +22,13 @@ setService({
|
|
|
22
22
|
default: {},
|
|
23
23
|
});
|
|
24
24
|
// backward compatible
|
|
25
|
-
SERVICES[NODE_SERVICES.AUTH_SERVICE] =
|
|
25
|
+
SERVICES[NODE_SERVICES.AUTH_SERVICE] = {
|
|
26
|
+
...SERVICES[NODE_SERVICES.AUTH],
|
|
27
|
+
meta: {
|
|
28
|
+
...SERVICES[NODE_SERVICES.AUTH].meta,
|
|
29
|
+
name: NODE_SERVICES.AUTH_SERVICE,
|
|
30
|
+
},
|
|
31
|
+
};
|
|
26
32
|
const getService = (serviceName) => {
|
|
27
33
|
if (!serviceName) {
|
|
28
34
|
throw new Error('service name should not be empty');
|
package/lib/types/schema.d.ts
CHANGED
|
@@ -66,7 +66,7 @@ export interface TBlockletMeta {
|
|
|
66
66
|
logoUrl?: string;
|
|
67
67
|
main: string;
|
|
68
68
|
maintainers?: TPerson[];
|
|
69
|
-
name
|
|
69
|
+
name?: TBlockletName;
|
|
70
70
|
navigation?: TNavigation;
|
|
71
71
|
nftFactory?: string;
|
|
72
72
|
path?: string;
|
|
@@ -287,3 +287,4 @@ export interface TTheme {
|
|
|
287
287
|
};
|
|
288
288
|
}
|
|
289
289
|
export type TTitle = string;
|
|
290
|
+
export type TUpdateMountPoint = string;
|