@ocap/asset
Advanced tools
Comparing version 1.9.21 to 1.10.0
@@ -5,2 +5,3 @@ /* eslint-disable no-restricted-syntax */ | ||
const uniq = require('lodash/uniq'); | ||
const uniqBy = require('lodash/uniqBy'); | ||
const flatten = require('flat'); | ||
@@ -24,2 +25,3 @@ const mustache = require('mustache'); | ||
// eslint-disable-next-line consistent-return | ||
const isValidHook = (hook, quota) => { | ||
@@ -33,4 +35,4 @@ if (SUPPORTED_HOOK_TYPES.includes(hook.type) === false) { | ||
if (hook.type === 'url' && isAbsoluteUrl(hook.hook) === false) { | ||
return false; | ||
if (hook.type === 'url') { | ||
return isAbsoluteUrl(hook.hook); | ||
} | ||
@@ -42,2 +44,3 @@ | ||
validate(compiled, quota); | ||
return true; | ||
} catch (err) { | ||
@@ -48,8 +51,9 @@ console.error('invalid contract hook', err.message); | ||
} | ||
return true; | ||
}; | ||
const isValidFactory = (props) => { | ||
const isValidFactory = (props, throwOnError = false) => { | ||
if (!props) { | ||
if (throwOnError) { | ||
throw new Error('Factory props should not be empty'); | ||
} | ||
return false; | ||
@@ -60,2 +64,5 @@ } | ||
if (['name', 'description', 'input', 'output'].some((x) => !props[x])) { | ||
if (throwOnError) { | ||
throw new Error('Factory name/description/input/output should not be empty'); | ||
} | ||
return false; | ||
@@ -66,12 +73,30 @@ } | ||
if (['value', 'tokens', 'assets'].every((x) => isEmpty(props.input[x]))) { | ||
if (throwOnError) { | ||
throw new Error('Factory input should contain at least one token or asset'); | ||
} | ||
return false; | ||
} | ||
if (uniqBy(props.input.tokens, 'address').length !== props.input.tokens.length) { | ||
if (throwOnError) { | ||
throw new Error('Factory token input should not contains duplicate address'); | ||
} | ||
return false; | ||
} | ||
if (uniq(props.input.assets).length !== props.input.assets.length) { | ||
if (throwOnError) { | ||
throw new Error('Factory asset input should not contains duplicate address'); | ||
} | ||
return false; | ||
} | ||
// validate output | ||
if (!props.output || typeof props.output !== 'object') { | ||
if (throwOnError) { | ||
throw new Error('Factory output should be an object'); | ||
} | ||
return false; | ||
} | ||
try { | ||
// should be an object | ||
if (!props.output || typeof props.output !== 'object') { | ||
return false; | ||
} | ||
// should be a valid mustache template when serialized as json | ||
@@ -82,2 +107,5 @@ const template = JSON.stringify(props.output); | ||
// console.error('Invalid asset factory output', err); | ||
if (throwOnError) { | ||
throw new Error('Factory output should be a valid mustache template when serialized as json'); | ||
} | ||
return false; | ||
@@ -89,2 +117,5 @@ } | ||
if (Array.isArray(props.hooks) && props.hooks.some((x) => isValidHook(x, quota) === false)) { | ||
if (throwOnError) { | ||
throw new Error('Factory hooks is not valid'); | ||
} | ||
return false; | ||
@@ -91,0 +122,0 @@ } |
{ | ||
"name": "@ocap/asset", | ||
"description": "Utility to work with asset and factory on ArcBlock blockchain", | ||
"version": "1.9.21", | ||
"version": "1.10.0", | ||
"author": { | ||
@@ -18,9 +18,9 @@ "name": "wangshijun", | ||
"dependencies": { | ||
"@arcblock/did": "^1.9.21", | ||
"@arcblock/did-util": "^1.9.21", | ||
"@arcblock/vc": "^1.9.21", | ||
"@ocap/contract": "^1.9.21", | ||
"@ocap/mcrypto": "^1.9.21", | ||
"@ocap/util": "^1.9.21", | ||
"@ocap/wallet": "^1.9.21", | ||
"@arcblock/did": "^1.10.0", | ||
"@arcblock/did-util": "^1.10.0", | ||
"@arcblock/vc": "^1.10.0", | ||
"@ocap/contract": "^1.10.0", | ||
"@ocap/mcrypto": "^1.10.0", | ||
"@ocap/util": "^1.10.0", | ||
"@ocap/wallet": "^1.10.0", | ||
"debug": "^4.3.1", | ||
@@ -77,3 +77,3 @@ "empty-value": "^1.0.1", | ||
}, | ||
"gitHead": "fba08716938ca74c8a12b6ae76203f07c9ee495f" | ||
"gitHead": "e400e75721990b40d0ac351ef8e379d81fe357ba" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13288
284
Updated@arcblock/did@^1.10.0
Updated@arcblock/did-util@^1.10.0
Updated@arcblock/vc@^1.10.0
Updated@ocap/contract@^1.10.0
Updated@ocap/mcrypto@^1.10.0
Updated@ocap/util@^1.10.0
Updated@ocap/wallet@^1.10.0