Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default function merge(target: Target, ...sources: Source[]): Merge {
for (const source of sources) {
for (const [key, sourceValue] of Object.entries(source)) {
const targetValue = target[key];
if (is.urlInstance(targetValue) && is.string(sourceValue)) {
// @ts-ignore TS doesn't recognise Target accepts string keys
target[key] = new URL(sourceValue, targetValue);
} else if (is.plainObject(sourceValue)) {
if (is.plainObject(targetValue)) {
// @ts-ignore TS doesn't recognise Target accepts string keys
target[key] = merge({}, targetValue, sourceValue);
} else {
// @ts-ignore TS doesn't recognise Target accepts string keys
target[key] = merge({}, sourceValue);
}
} else if (is.array(sourceValue)) {
// @ts-ignore TS doesn't recognise Target accepts string keys
target[key] = sourceValue.slice();
} else {
// @ts-ignore TS doesn't recognise Target accepts string keys
target[key] = sourceValue;
}
}
async function fetch (url, options) {
const { origin, pathname, search } = new URL(url)
const session = http2.connect(origin)
const reqHeaders = {
...options.headers,
...{ ':path': pathname + search }
}
const request = session.request(reqHeaders)
request.end(options.body)
const headers = await eventToPromise(request, 'response')
const chunks = []
await readAll(request, chunks)
await promisify(session.close).call(session)
const body = Buffer.concat(chunks)
chunks.length = 0
return {
ok: headers[':status'] < 400,
get headers () { return new Map(Object.entries(headers)) },
function generatePackageReference(version, tarballName) {
if (options.referenceViaVersion === true) {
return version;
}
if (options.hostPath.indexOf('file:') === 0) {
return path.join(options.hostPath, tarballName);
}
return new url.URL(tarballName, options.hostPath);
}
private publishSqs(event, sub) {
const subEndpointUrl = new URL(sub.Endpoint);
const sqsEndpoint = `${subEndpointUrl.protocol}//${subEndpointUrl.host}/`;
const sqs = new SQS({ endpoint: sqsEndpoint, region: this.region });
if (sub["Attributes"]["RawMessageDelivery"] === "true") {
return sqs.sendMessage({
QueueUrl: sub.Endpoint,
MessageBody: event,
}).promise();
} else {
const records = JSON.parse(event).Records;
const messagePromises = records.map(record => {
return sqs
.sendMessage({
QueueUrl: sub.Endpoint,
MessageBody: JSON.stringify(record.Sns),
})
async function recordUrlIfHttp (client, url, baseUrl = undefined) {
let parsedUrl;
try {
parsedUrl = baseUrl ? new urlLib.URL(url, baseUrl) : new urlLib.URL(url);
} catch (_) {
return false;
}
if (parsedUrl.protocol !== "http") {
return false;
}
const insertQuery = `
INSERT INTO
http_domains(domain, last_seen)
VALUES
($1, now())
ON CONFLICT
(domain)
DO UPDATE SET
_urlWithUpdatedParams(params) {
let p = merge({}, this.query, params);
let origin = this.ctxt.request.origin;
if (this.prefix) {
origin = origin + '/' + this.prefix;
}
let u = new URL(origin + (this.ctxt.req.originalUrl || this.ctxt.req.url));
u.search = '?' + qs.stringify(p, { encode: false });
return u.href;
}
}
function normalizeUrl(url) {
return new URL(url).toString();
}
function getUsernameAndPassword (node) {
if (typeof node === 'string') {
const { username, password } = new URL(node)
return {
username: decodeURIComponent(username),
password: decodeURIComponent(password)
}
} else if (node.url instanceof URL) {
return {
username: decodeURIComponent(node.url.username),
password: decodeURIComponent(node.url.password)
}
}
}
}
function getRegistryUrl (resolved) {
if (!resolved) {
return ''
}
let resolvedUrl = ''
try {
const urlObj = new url.URL(resolved)
resolvedUrl = `${urlObj.protocol}//${urlObj.host}`
} catch (error) {
debug('url parse error: %o', error)
}
return resolvedUrl
}
return new Promise(function(resolve,reject){
//setup options
var options = new URL(url);
options.method = 'HEAD'
//make the request
var beforeTime = time;
var req = http.request(options, function(r) {
//return the response code on no errors
if (r.statusCode == 200){
var totalTime = time - beforeTime
resolve({success: true, code: r.statusCode, time: totalTime });
}else{
resolve({ error: true, message: 'request succeeded but response code was non-200, response code:'+r.statusCode });
}
});
req.on('error', function(err) {
//on error return error flag