Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports = (config) => {
const configCopy = Object.assign({}, config);
// handle the 'legacy' configuration where each type had its own propery
if (configCopy.contributorListGithubUrl) {
configCopy.contributors = configCopy.contributorListGithubUrl;
} else if (config.contributorListUrl) {
configCopy.contributors = configCopy.contributorListUrl;
} else if (config.contributorWebhook) {
configCopy.contributors = configCopy.contributorWebhook;
}
if (configCopy.contributors) {
if (is.array(configCopy.contributors)) {
console.info('INFO', 'Checking contributors against the list supplied in the .clabot file');
return contributorArrayVerifier(configCopy.contributors);
} else if (is.url(configCopy.contributors) && configCopy.contributors.indexOf('api.github.com') !== -1) {
console.info('INFO', 'Checking contributors against the github URL supplied in the .clabot file');
return configFileFromGithubUrlVerifier(configCopy.contributors);
} else if (is.url(configCopy.contributors) && configCopy.contributors.indexOf('?') !== -1) {
console.info('INFO', 'Checking contributors against the webhook supplied in the .clabot file');
return webhookVerifier(configCopy.contributors);
} else if (is.url(configCopy.contributors)) {
console.info('INFO', 'Checking contributors against the URL supplied in the .clabot file');
return configFileFromUrlVerifier(configCopy.contributors);
}
}
throw new Error('A mechanism for verifying contributors has not been specified');
};
module.exports = config => {
const configCopy = Object.assign({}, config);
// handle the 'legacy' configuration where each type had its own propery
if (configCopy.contributorListGithubUrl) {
configCopy.contributors = configCopy.contributorListGithubUrl;
} else if (config.contributorListUrl) {
configCopy.contributors = configCopy.contributorListUrl;
} else if (config.contributorWebhook) {
configCopy.contributors = configCopy.contributorWebhook;
}
if (configCopy.contributors) {
if (is.array(configCopy.contributors)) {
console.info(
"INFO",
"Checking contributors against the list supplied in the .clabot file"
);
return contributorArrayVerifier(configCopy.contributors);
} else if (
is.url(configCopy.contributors) &&
configCopy.contributors.indexOf("api.github.com") !== -1
) {
console.info(
"INFO",
"Checking contributors against the github URL supplied in the .clabot file"
);
return configFileFromGithubUrlVerifier(configCopy.contributors);
} else if (
is.url(configCopy.contributors) &&
var i = 0;
var doc = undefined;
while (doc = docs[i++]) {
// options.populate is a key-model pair object
var j = 0;
var key = undefined;
while (key = populate[j++]) {
// model to use when populating the field
var childModel = options.populate[key];
var value = doc[key];
// if value is an array of IDs, loop through it
if (is.array(value)) {
// convert each _id
// to findById op
value = value.map(childModel.findById, childModel);
} else {
value = childModel.findById(value);
}
// replace previous ID with actual documents
doc[key] = yield value;
}
// index - 1, because index here is already an index of the next document
docs[i - 1] = new model(doc, {
populate: options.populate
});
}
get (keyObj, defaultVal) {
let keys
let value
if (is.string(keyObj)) {
keys = [keyObj]
} else if (is.array(keyObj)) {
keys = keyObj.map(k => k.trim())
} else {
throw Error(`Invalid key(s) ${keyObj}`)
}
keys.some(key => {
if (ok(process.env[key])) {
value = process.env[key]
return true
}
})
if (!ok(value) && typeof ok(defaultVal)) {
value = defaultVal
}
exclude (key, value) {
if (is.array(key)) {
let fields = key;
fields.forEach(key => {
this.exclude(key);
});
}
if (is.object(key)) {
let fields = key;
let keys = Object.keys(fields);
keys.forEach(key => {
this.exclude(key, fields[key]);
});
}
async forward(service, method, data, options) {
if (is.not.object(options) || is.array(options)) options = this.options.job || {};
if (is.not.string(service) || is.empty(service)) throw new Error('invalid service');
else if (is.not.string(method) || is.empty(method)) throw new Error('invalid method');
else if (is.not.object(data) || is.array(data)) throw new Error('invalid data');
else if (is.not.object(options) || is.array(options))
throw new Error('invalid options');
data._ = method;
const job = this.services[service].createJob(data);
for (let config in options)
if (jobOptions.includes(config) && is.function(job[config]))
if (is.array(options[config])) job[config](...options[config]);
else job[config](options[config]);
await job.save();
this.logger.info(`${ service }|${ method }|C|${ JSON.stringify(data) }`);
return job;
}
acceptService(service, options) {
if (is.not.object(options) || is.array(options)) options = this.options.bee;
if (is.not.string(service) || is.empty(service))
throw new Error('invalid service');
else if (is.not.object(options)) throw new Error('invalid options');
if (is.not.existy(this.services[service])) {
this.services[service] = new Queue(service, options);
this.logger.info(`${ service }|ready(C)`);
} else this.logger.warn(`${ service }|exists`);
}
module.exports.getMultiple = lambda(async (event, success) => {
assert(is.array(event.body), "getMultiple requires an array");
assert(event.body.every(isurl), "getMultiple requires an array of URLs");
const items = await getItems(event.body);
success(items.Responses.Applause);
});
Query.prototype[method] = function () {
let args = is.array(arguments[0]) ? arguments[0] : Array.from(arguments);
this.query['$' + method] = args;
return this;
};
});
if (attrs.price === '') {
addError('price', app.polyglot.t('itemModelErrors.provideAmount'));
} else if (is.not.number(attrs.price)) {
addError('price', app.polyglot.t('itemModelErrors.provideNumericAmount'));
} else if (attrs.price <= 0) {
addError('price', app.polyglot.t('itemModelErrors.provideAmountGreaterThanZero'));
}
if (!attrs.images.length) {
addError('images', app.polyglot.t('itemModelErrors.imageRequired'));
} else if (attrs.images.length > max.images) {
addError('images', `The number of images cannot exceed ${max.images}`);
}
if (attrs.tags) {
if (is.array(attrs.tags)) {
if (attrs.tags.length > max.tags) {
addError('tags',
app.polyglot.t('itemModelErrors.tooManyTags', { maxTags: max.tags }));
}
attrs.tags.forEach((tag, index) => {
if (is.not.string(tag)) {
addError('tags', `Tag at index ${index} is not a string and should be.`);
} else if (tag.length > this.max.tagLength) {
addError('tags', `Tag ${tag} exceeds the maximum tag length of ${this.max.tagLength}.`);
}
});
} else {
addError('tags', 'Tags must be provided as an array.');
}
}