Comparing version 4.0.2 to 5.0.0-rc.0
module.exports = { | ||
// specify additional options here, especially http(s) | ||
// see https://github.com/request/request#readme for specifics | ||
ca: [ /* strings or binaries */], | ||
cert: [ /* strings or binaries */], | ||
key: [ /* strings or binaries */], | ||
// see https://nodejs.org/api/tls.html#tls_tls_connect_options_callback for specifics | ||
ca: [ | ||
/* strings or binaries */ | ||
], | ||
cert: [ | ||
/* strings or binaries */ | ||
], | ||
key: [ | ||
/* strings or binaries */ | ||
], | ||
passphrase: 'yourpassphrase', | ||
auth: { | ||
user: 'yourusername', | ||
pass: 'yourpassword' | ||
pass: 'yourpassword', | ||
}, | ||
httpSignature: { | ||
keyId: 'keyId', | ||
key: 'yourkey' | ||
}, | ||
strictSSL: false, | ||
followAllRedirects: false, | ||
followRedirect: false, | ||
headers: { | ||
'x-custom': 'headers' | ||
} | ||
'x-custom': 'headers', | ||
}, | ||
}; |
@@ -6,4 +6,6 @@ 'use strict'; | ||
const Joi = require('@hapi/joi'); | ||
const https = require('https'); | ||
const net = require('net'); | ||
const requestProm = require('request-promise-native'); | ||
const util = require('util'); | ||
const axios = require('axios').default; | ||
const { isBoolean, isEmpty, negate, noop, once, partial, pick, zip } = require('lodash/fp'); | ||
@@ -19,58 +21,30 @@ const { NEVER, combineLatest, from, merge, throwError, timer } = require('rxjs'); | ||
const HTTP_GET_RE = /^https?-get:/; | ||
const HTTP_UNIX_RE = /^http:\/\/unix:([^:]+):([^:]+)$/; | ||
const TIMEOUT_ERR_MSG = 'Timeout'; | ||
const WAIT_ON_SCHEMA = Joi.object({ | ||
resources: Joi.array() | ||
.items(Joi.string().required()) | ||
.required(), | ||
delay: Joi.number() | ||
.integer() | ||
.min(0) | ||
.default(0), | ||
httpTimeout: Joi.number() | ||
.integer() | ||
.min(0), | ||
interval: Joi.number() | ||
.integer() | ||
.min(0) | ||
.default(250), | ||
resources: Joi.array().items(Joi.string().required()).required(), | ||
delay: Joi.number().integer().min(0).default(0), | ||
httpTimeout: Joi.number().integer().min(0), | ||
interval: Joi.number().integer().min(0).default(250), | ||
log: Joi.boolean().default(false), | ||
reverse: Joi.boolean().default(false), | ||
simultaneous: Joi.number() | ||
.integer() | ||
.min(1) | ||
.default(Infinity), | ||
timeout: Joi.number() | ||
.integer() | ||
.min(0) | ||
.default(Infinity), | ||
simultaneous: Joi.number().integer().min(1).default(Infinity), | ||
timeout: Joi.number().integer().min(0).default(Infinity), | ||
verbose: Joi.boolean().default(false), | ||
window: Joi.number() | ||
.integer() | ||
.min(0) | ||
.default(750), | ||
tcpTimeout: Joi.number() | ||
.integer() | ||
.min(0) | ||
.default(300), | ||
window: Joi.number().integer().min(0).default(750), | ||
tcpTimeout: Joi.number().integer().min(0).default(300), | ||
// http options3 | ||
// http/https options | ||
ca: [Joi.string(), Joi.binary()], | ||
cert: [Joi.string(), Joi.binary()], | ||
key: [Joi.string(), Joi.binary()], | ||
key: [Joi.string(), Joi.binary(), Joi.object()], | ||
passphrase: Joi.string(), | ||
auth: Joi.object({ | ||
user: Joi.string(), | ||
username: Joi.string(), | ||
password: Joi.string(), | ||
pass: Joi.string() | ||
}), | ||
httpSignature: Joi.object({ | ||
keyId: Joi.string().required(), | ||
key: Joi.string().required() | ||
}), | ||
strictSSL: Joi.boolean(), | ||
followAllRedirects: Joi.boolean(), | ||
followRedirect: Joi.boolean(), | ||
headers: Joi.object() | ||
strictSSL: Joi.boolean().default(false), | ||
followRedirect: Joi.boolean().default(true), // HTTP 3XX responses | ||
headers: Joi.object(), | ||
}); | ||
@@ -91,2 +65,5 @@ | ||
- socket:/path/sock verifies a service is listening on (UDS) socket | ||
For http over socket, use http://unix:SOCK_PATH:URL_PATH | ||
like http://unix:/path/to/sock:/foo/bar or | ||
http-get://unix:/path/to/sock:/foo/bar | ||
@@ -113,4 +90,4 @@ @param opts object configuring waitOn | ||
// promise API | ||
return new Promise(function(resolve, reject) { | ||
waitOnImpl(opts, function(err) { | ||
return new Promise(function (resolve, reject) { | ||
waitOnImpl(opts, function (err) { | ||
if (err) { | ||
@@ -136,3 +113,3 @@ reject(err); | ||
...(validResult.value.window < validResult.value.interval ? { window: validResult.value.interval } : {}), | ||
...(validResult.value.verbose ? { log: true } : {}) // if debug logging then normal log is also enabled | ||
...(validResult.value.verbose ? { log: true } : {}), // if debug logging then normal log is also enabled | ||
}; | ||
@@ -175,5 +152,5 @@ | ||
merge(timeoutError$, resourcesCompleted$) | ||
.pipe(takeWhile(resourceStates => resourceStates.some(x => !x))) | ||
.pipe(takeWhile((resourceStates) => resourceStates.some((x) => !x))) | ||
.subscribe({ | ||
next: resourceStates => { | ||
next: (resourceStates) => { | ||
lastResourcesState = resourceStates; | ||
@@ -183,3 +160,3 @@ logWaitingForWDeps(resourceStates); | ||
error: cleanup, | ||
complete: cleanup | ||
complete: cleanup, | ||
}); | ||
@@ -224,3 +201,3 @@ } | ||
const checkOperator = reverse | ||
? map(size => size === -1) // check that file does not exist | ||
? map((size) => size === -1) // check that file does not exist | ||
: scan( | ||
@@ -255,3 +232,3 @@ // check that file exists and the size is stable | ||
checkOperator, | ||
map(x => (isNotABoolean(x) ? false : x)), | ||
map((x) => (isNotABoolean(x) ? false : x)), | ||
startWith(false), | ||
@@ -289,26 +266,30 @@ distinctUntilChanged(), | ||
function createHTTP$({ validatedOpts, output }, resource) { | ||
const { delay, interval, reverse, simultaneous } = validatedOpts; | ||
const method = HTTP_GET_RE.test(resource) ? 'GET' : 'HEAD'; | ||
const uri = resource.replace('-get:', ':'); | ||
const { | ||
delay, | ||
followRedirect, | ||
httpTimeout: timeout, | ||
interval, | ||
reverse, | ||
simultaneous, | ||
strictSSL: rejectUnauthorized, | ||
} = validatedOpts; | ||
const method = HTTP_GET_RE.test(resource) ? 'get' : 'head'; | ||
const url = resource.replace('-get:', ':'); | ||
const matchHttpUnixSocket = HTTP_UNIX_RE.exec(url); // http://unix:/sock:/url | ||
const urlSocketOptions = matchHttpUnixSocket | ||
? { socketPath: matchHttpUnixSocket[1], url: matchHttpUnixSocket[2] } | ||
: { url }; | ||
const socketPathDesc = urlSocketOptions.socketPath ? `socketPath:${urlSocketOptions.socketPath}` : ''; | ||
const httpOptions = { | ||
...pick( | ||
[ | ||
'auth', | ||
'httpSignature', | ||
'followRedirect', | ||
'followAllRedirects', | ||
'strictSSL', | ||
'headers', | ||
'cert', | ||
'key', | ||
'passphrase', | ||
'ca' | ||
], | ||
validatedOpts | ||
), | ||
...(validatedOpts.httpTimeout ? { timeout: validatedOpts.httpTimeout } : {}), | ||
uri, | ||
...pick(['auth', 'headers'], validatedOpts), | ||
httpsAgent: new https.Agent({ | ||
rejectUnauthorized, | ||
...pick(['ca', 'cert', 'key', 'passphrase'], validatedOpts), | ||
}), | ||
...(followRedirect ? {} : { maxRedirects: 0 }), // defaults to 5 (enabled) | ||
...(timeout && { timeout }), | ||
...urlSocketOptions, | ||
method, | ||
resolveWithFullResponse: true, | ||
simple: true // statusCodes other than 2xx will reject | ||
// by default it provides full response object | ||
// validStatus is 2xx unless followRedirect is true (default) | ||
}; | ||
@@ -318,3 +299,3 @@ const checkFn = reverse ? negateAsync(httpCallSucceeds) : httpCallSucceeds; | ||
mergeMap(() => { | ||
output(`making HTTP ${method} request to ${uri} ...`); | ||
output(`making HTTP(S) ${method} request to ${socketPathDesc} url:${urlSocketOptions.url} ...`); | ||
return from(checkFn(output, httpOptions)); | ||
@@ -330,7 +311,11 @@ }, simultaneous), | ||
try { | ||
const result = await requestProm(httpOptions); | ||
output(` HTTP result for ${httpOptions.uri}: ${JSON.stringify(result)}`); | ||
const result = await axios(httpOptions); | ||
output( | ||
` HTTP(S) result for ${httpOptions.url}: ${util.inspect( | ||
pick(['status', 'statusText', 'headers', 'data'], result) | ||
)}` | ||
); | ||
return true; | ||
} catch (err) { | ||
output(` HTTP error for ${httpOptions.uri} ${err.toString()}`); | ||
output(` HTTP(S) error for ${httpOptions.url} ${err.toString()}`); | ||
return false; | ||
@@ -357,6 +342,6 @@ } | ||
const host = hostMatched || 'localhost'; | ||
return new Promise(resolve => { | ||
return new Promise((resolve) => { | ||
const conn = net | ||
.connect(port, host) | ||
.on('error', err => { | ||
.on('error', (err) => { | ||
output(` error connecting to TCP host:${host} port:${port} ${err.toString()}`); | ||
@@ -394,6 +379,6 @@ resolve(false); | ||
async function socketExists(output, socketPath) { | ||
return new Promise(resolve => { | ||
return new Promise((resolve) => { | ||
const conn = net | ||
.connect(socketPath) | ||
.on('error', err => { | ||
.on('error', (err) => { | ||
output(` error connecting to socket socket:${socketPath} ${err.toString()}`); | ||
@@ -411,3 +396,3 @@ resolve(false); | ||
function negateAsync(asyncFn) { | ||
return async function(...args) { | ||
return async function (...args) { | ||
return !(await asyncFn(...args)); | ||
@@ -414,0 +399,0 @@ }; |
{ | ||
"name": "wait-on", | ||
"description": "wait-on is a cross platform command line utility and Node.js API which will wait for files, ports, sockets, and http(s) resources to become available", | ||
"version": "4.0.2", | ||
"version": "5.0.0-rc.0", | ||
"main": "lib/wait-on", | ||
@@ -42,6 +42,5 @@ "bin": { | ||
"@hapi/joi": "^17.1.1", | ||
"axios": "^0.19.2", | ||
"lodash": "^4.17.15", | ||
"minimist": "^1.2.5", | ||
"request": "^2.88.2", | ||
"request-promise-native": "^1.0.8", | ||
"rxjs": "^6.5.5" | ||
@@ -48,0 +47,0 @@ }, |
@@ -158,3 +158,3 @@ # wait-on - wait for files, ports, sockets, http(s) resources | ||
'http://unix:/my/sock:/my/url', | ||
'http-get://unix:/my/sock:/my/url' | ||
'http-get://unix:/my/sock:/my/url', | ||
], | ||
@@ -180,18 +180,13 @@ delay: 1000, // initial delay in ms, default 0 | ||
user: 'theuser', // or username | ||
pass: 'thepassword' // or password | ||
pass: 'thepassword', // or password | ||
}, | ||
httpSignature: { | ||
keyId: 'yourKeyId', | ||
key: 'yourKey' | ||
}, | ||
strictSSL: false, | ||
followAllRedirects: true, | ||
followRedirect: true, | ||
headers: { | ||
'x-custom': 'headers' | ||
} | ||
'x-custom': 'headers', | ||
}, | ||
}; | ||
// Usage with callback function | ||
waitOn(opts, function(err) { | ||
waitOn(opts, function (err) { | ||
if (err) { | ||
@@ -205,6 +200,6 @@ return handleError(err); | ||
waitOn(opts) | ||
.then(function() { | ||
.then(function () { | ||
// once here, all resources are available | ||
}) | ||
.catch(function(err) { | ||
.catch(function (err) { | ||
handleError(err); | ||
@@ -233,3 +228,3 @@ }); | ||
- opts.window - optional stabilization time in ms, default 750ms. Waits this amount of time for file sizes to stabilize or other resource availability to remain unchanged. | ||
- http(s) specific options, see https://github.com/request/request#readme for specific details | ||
- http(s) specific options, see https://nodejs.org/api/tls.html#tls_tls_connect_options_callback for specific details | ||
@@ -241,6 +236,4 @@ - opts.ca: [ /* strings or binaries */ ], | ||
- opts.auth: { user, pass } | ||
- opts.httpSignature: { keyId, key } | ||
- opts.strictSSL: false, | ||
- opts.followAllRedirects: true, | ||
- opts.followRedirect: true, | ||
- opts.followRedirect: false, // defaults to true | ||
- opts.headers: { 'x-custom': 'headers' }, | ||
@@ -247,0 +240,0 @@ |
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
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
32557
5
396
2
266
2
+ Addedaxios@^0.19.2
+ Addedaxios@0.19.2(transitive)
+ Addedfollow-redirects@1.5.10(transitive)
- Removedrequest@^2.88.2
- Removedrequest-promise-native@^1.0.8
- Removedajv@6.12.6(transitive)
- Removedasn1@0.2.6(transitive)
- Removedassert-plus@1.0.0(transitive)
- Removedasynckit@0.4.0(transitive)
- Removedaws-sign2@0.7.0(transitive)
- Removedaws4@1.13.2(transitive)
- Removedbcrypt-pbkdf@1.0.2(transitive)
- Removedcaseless@0.12.0(transitive)
- Removedcombined-stream@1.0.8(transitive)
- Removedcore-util-is@1.0.2(transitive)
- Removeddashdash@1.14.1(transitive)
- Removeddelayed-stream@1.0.0(transitive)
- Removedecc-jsbn@0.1.2(transitive)
- Removedextend@3.0.2(transitive)
- Removedextsprintf@1.3.0(transitive)
- Removedfast-deep-equal@3.1.3(transitive)
- Removedfast-json-stable-stringify@2.1.0(transitive)
- Removedforever-agent@0.6.1(transitive)
- Removedform-data@2.3.3(transitive)
- Removedgetpass@0.1.7(transitive)
- Removedhar-schema@2.0.0(transitive)
- Removedhar-validator@5.1.5(transitive)
- Removedhttp-signature@1.2.0(transitive)
- Removedis-typedarray@1.0.0(transitive)
- Removedisstream@0.1.2(transitive)
- Removedjsbn@0.1.1(transitive)
- Removedjson-schema@0.4.0(transitive)
- Removedjson-schema-traverse@0.4.1(transitive)
- Removedjson-stringify-safe@5.0.1(transitive)
- Removedjsprim@1.4.2(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removedoauth-sign@0.9.0(transitive)
- Removedperformance-now@2.1.0(transitive)
- Removedpsl@1.9.0(transitive)
- Removedpunycode@2.3.1(transitive)
- Removedqs@6.5.3(transitive)
- Removedrequest@2.88.2(transitive)
- Removedrequest-promise-core@1.1.4(transitive)
- Removedrequest-promise-native@1.0.9(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedsshpk@1.18.0(transitive)
- Removedstealthy-require@1.1.1(transitive)
- Removedtough-cookie@2.5.0(transitive)
- Removedtunnel-agent@0.6.0(transitive)
- Removedtweetnacl@0.14.5(transitive)
- Removeduri-js@4.4.1(transitive)
- Removeduuid@3.4.0(transitive)
- Removedverror@1.10.0(transitive)