Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

wait-on

Package Overview
Dependencies
Maintainers
1
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wait-on - npm Package Compare versions

Comparing version 4.0.2 to 5.0.0-rc.0

25

exampleConfig.js
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 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc