@abtnode/util
Advanced tools
Comparing version 1.0.24 to 1.0.25
@@ -9,4 +9,23 @@ module.exports = Object.freeze({ | ||
}), | ||
NODE_UPGRADE_PROGRESS: Object.freeze({ | ||
SETUP: 'setup', // backup | ||
INSTALLING: 'installing', | ||
RESTARTING: 'restarting', | ||
CLEANUP: 'cleanup', | ||
COMPLETE: 'complete', | ||
ROLLBACK: 'rollback', | ||
}), | ||
NODE_PACKAGE_NAME: '@abtnode/cli', | ||
PROCESS_NAME_DAEMON: 'abt-node-daemon', | ||
PROCESS_NAME_PROXY: 'abt-node-db-hub', | ||
PROCESS_NAME_UPDATER: 'abt-node-updater', | ||
NODE_REGISTER_URL: 'https://install.arcblock.io/', | ||
CONFIG_FILENAME: 'abtnode.yml', | ||
CONFIG_FOLDER_NAME: '.abtnode', | ||
StatusCode: Object.freeze({ | ||
@@ -22,2 +41,3 @@ ok: 0, | ||
}), | ||
// Blocklet | ||
@@ -39,2 +59,3 @@ BlockletStatus: Object.freeze({ | ||
}), | ||
BlockletSource: Object.freeze({ | ||
@@ -51,2 +72,3 @@ registry: 0, | ||
}), | ||
BLOCKLET_GROUPS: ['dapp', 'static'], | ||
@@ -58,6 +80,9 @@ BLOCKLET_COLORS: ['primary', 'secondary', 'error'], | ||
}), | ||
BLOCKLET_BUNDLE_FOLDER: '_blocklet', | ||
BLOCKLET_BUNDLE_FOLDER: '.blocklet/bundle', | ||
BLOCKLET_BUNDLE_FILE: 'blocklet.zip', | ||
BLOCKLET_ENTRY_FILE: 'blocklet.js', | ||
BLOCKLET_META_FILE: 'blocklet.json', | ||
BLOCKLET_DEFAULT_VERSION: '1.0.0', | ||
// Service Gateway | ||
@@ -68,4 +93,3 @@ DEFAULT_ROUTER_PROVIDER: 'none', | ||
DOMAIN_FOR_DEFAULT_SITE: '*', | ||
PROCESS_NAME_DAEMON: 'abt-node-daemon', | ||
PROCESS_NAME_PROXY: 'abt-node-db-hub', | ||
DEFAULT_ADMIN_PATH: '/admin', | ||
@@ -72,0 +96,0 @@ DEFAULT_HTTP_PORT: 80, |
@@ -7,27 +7,24 @@ const axios = require('axios'); | ||
const ensureStarted = (endpoint, maxRetry = 10) => | ||
new Promise((resolve, reject) => { | ||
let counter = 0; | ||
const ensureStarted = async (endpoint, timeout = 10 * 1000) => { | ||
const startTime = Date.now(); | ||
try { | ||
const res = await axios({ url: endpoint, method: 'HEAD', timeout }); | ||
debug('ping if started result:', { endpoint, status: res.status }); | ||
return true; | ||
} catch (err) { | ||
debug('ping error:', err.message, endpoint); | ||
if (err.response && err.response.status < 500) { | ||
return true; | ||
} | ||
await sleep(1000); | ||
const ttl = timeout - (Date.now() - startTime); | ||
if (ttl < 0) { | ||
throw new Error( | ||
`the service is not ready within ${Math.ceil(timeout / 1000)} seconds, please check your network` | ||
); | ||
} | ||
return ensureStarted(endpoint, ttl); | ||
} | ||
}; | ||
// eslint-disable-next-line | ||
const intervalId = setInterval(async () => { | ||
if (counter++ >= maxRetry) { | ||
clearInterval(intervalId); | ||
return reject(new Error(`the service is not ready within ${maxRetry} seconds, please check your network`)); | ||
} | ||
try { | ||
const res = await axios({ url: endpoint, method: 'HEAD', timeout: 1000 }); | ||
debug('ping if started result:', { endpoint, status: res.status }); | ||
clearInterval(intervalId); | ||
return resolve(true); | ||
} catch (err) { | ||
debug('ping error:', err.message, endpoint); | ||
if (err.response && err.response.status < 500) { | ||
return resolve(true); | ||
} | ||
} | ||
}, 1000); | ||
}); | ||
const ensureHealthy = async ({ endpoint, minConsecutiveTime = 5 * 1000 }) => { | ||
@@ -67,8 +64,6 @@ const checkInterval = 1000; | ||
const maxRetry = Math.ceil((timeout - minConsecutiveTime) / 1000); | ||
return tryWithTimeout(async () => { | ||
await ensureStarted(endpoint, maxRetry); | ||
await ensureStarted(endpoint, timeout - minConsecutiveTime); | ||
await ensureHealthy({ endpoint, minConsecutiveTime }); | ||
}, timeout); | ||
}; |
@@ -57,2 +57,3 @@ const { promisify } = require('util'); | ||
* @param {function(file): boolean} opts.filter | ||
* @param {number} opts.concurrentHash | ||
* @return {object} { files: { file1: hash, file2: hash, ... }} | ||
@@ -65,6 +66,6 @@ */ | ||
filter: defaultFilter, | ||
concurrentHash: 100, | ||
}, | ||
opts, | ||
{ | ||
concurrentHash: 100, | ||
assetType: 'file', | ||
@@ -71,0 +72,0 @@ } |
@@ -16,3 +16,4 @@ const pkg = require('../package.json'); | ||
const getEc2Meta = require('./get_ec2_meta'); | ||
const locateNpmGlobalPackage = require('./locate_npm_global_package'); | ||
const locateNpmGlobalByBinary = require('./locate_npm_global_by_binary'); | ||
const validateBlockletMeta = require('./validate_blocklet_meta'); | ||
@@ -45,3 +46,4 @@ const constants = require('./constants'); | ||
CustomError, | ||
locateNpmGlobalPackage, | ||
locateNpmGlobalByBinary, | ||
validateBlockletMeta, | ||
}; |
@@ -5,5 +5,7 @@ const fs = require('fs'); | ||
const camelCase = require('lodash/camelCase'); | ||
const padStart = require('lodash/padStart'); | ||
const debug = require('debug')('@abtnode/util:readBlockletConfig'); | ||
const { BLOCKLET_GROUPS } = require('./constants'); | ||
const { BLOCKLET_DEFAULT_VERSION } = require('./constants'); | ||
const defaultAttrSpec = { | ||
@@ -50,10 +52,2 @@ name: true, | ||
const getTimeAsVersion = () => { | ||
const date = new Date(); | ||
const major = date.getFullYear(); | ||
const minor = `${padStart(date.getMonth() + 1, 2, '0')}${padStart(date.getDate(), 2, '0')}`; | ||
const patch = `${padStart(date.getHours(), 2, '0')}${padStart(date.getMinutes(), 2, '0')}`; | ||
return [major, minor, patch].map(Number).join('.'); | ||
}; | ||
// Assign sensible defaults: name/description/main/group/provider/version/public_url | ||
@@ -70,3 +64,3 @@ const ensureRequiredAttrs = (attrs, dir) => { | ||
if (!attrs.version) { | ||
attrs.version = getTimeAsVersion(); | ||
attrs.version = BLOCKLET_DEFAULT_VERSION; | ||
} | ||
@@ -162,2 +156,6 @@ | ||
if (!BLOCKLET_GROUPS.includes(result.group)) { | ||
throw new Error(`Unsupported blocklet type ${result.group}`); | ||
} | ||
result.path = `/${result.group}/${result.name}`; | ||
@@ -193,2 +191,1 @@ result.folder = dir; | ||
module.exports = readBlockletConfig; | ||
module.exports.getTimeAsVersion = getTimeAsVersion; |
@@ -6,3 +6,3 @@ { | ||
}, | ||
"version": "1.0.24", | ||
"version": "1.0.25", | ||
"description": "ArcBlock's JavaScript utility", | ||
@@ -24,2 +24,3 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@arcblock/did": "^1.4.2", | ||
"axios": "^0.21.0", | ||
@@ -36,5 +37,7 @@ "debug": "^4.2.0", | ||
"pump": "^3.0.0", | ||
"semver-sort": "^0.0.4", | ||
"shelljs": "^0.8.4", | ||
"through2-filter": "^3.0.0", | ||
"through2-map": "^3.0.0" | ||
"through2-map": "^3.0.0", | ||
"to-semver": "^2.0.0" | ||
}, | ||
@@ -47,3 +50,3 @@ "devDependencies": { | ||
}, | ||
"gitHead": "4ce533cd14c8bfaf876247d32676e6fbfa2d0a48" | ||
"gitHead": "6bc5d3b4c9123f94ce389c5de143b32bf86578c5" | ||
} |
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
26238
27
747
17
6
+ Added@arcblock/did@^1.4.2
+ Addedsemver-sort@^0.0.4
+ Addedto-semver@^2.0.0
+ Added@arcblock/did@1.18.162(transitive)
+ Added@ocap/mcrypto@1.18.162(transitive)
+ Added@ocap/util@1.18.162(transitive)
+ Addedbase-x@4.0.0(transitive)
+ Addedbase64-url@2.3.3(transitive)
+ Addedbn.js@4.12.15.2.1(transitive)
+ Addedbrorand@1.1.0(transitive)
+ Addedbs58@5.0.0(transitive)
+ Addedbuffer-to-arraybuffer@0.0.5(transitive)
+ Addedcrypto-js@4.2.0(transitive)
+ Addeddecode-uri-component@0.2.2(transitive)
+ Addeddom-walk@0.1.2(transitive)
+ Addedelliptic@6.6.1(transitive)
+ Addedeth-lib@0.2.8(transitive)
+ Addedglobal@4.4.0(transitive)
+ Addedhash.js@1.1.7(transitive)
+ Addedhmac-drbg@1.0.1(transitive)
+ Addedinterface@1.2.1(transitive)
+ Addedis-function@1.0.2(transitive)
+ Addedjs-sha3@0.8.0(transitive)
+ Addedmin-document@2.19.0(transitive)
+ Addedminimalistic-assert@1.0.1(transitive)
+ Addedminimalistic-crypto-utils@1.0.1(transitive)
+ Addedobject-assign@4.1.1(transitive)
+ Addedparse-headers@2.0.5(transitive)
+ Addedprocess@0.11.10(transitive)
+ Addedquery-string@5.1.1(transitive)
+ Addedrandombytes@2.1.0(transitive)
+ Addedsemver@5.7.26.3.1(transitive)
+ Addedsemver-regex@1.0.0(transitive)
+ Addedsemver-sort@0.0.4(transitive)
+ Addedsimple-concat@1.0.1(transitive)
+ Addedsimple-get@2.8.2(transitive)
+ Addedstrict-uri-encode@1.1.0(transitive)
+ Addedtimed-out@4.0.1(transitive)
+ Addedto-semver@2.0.0(transitive)
+ Addedtweetnacl@1.0.3(transitive)
+ Addedurl-set-query@1.0.0(transitive)
+ Addedutf8@3.0.0(transitive)
+ Addedxhr@2.6.0(transitive)
+ Addedxhr-request@1.1.0(transitive)
+ Addedxhr-request-promise@0.1.3(transitive)
+ Addedxtend@4.0.2(transitive)