Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let newArray1 = Hoek.unique(array1, "id"); // results in [{id: 1}, {id: 2}]
// mapToObject(array, key)
array = [1, 2, 3];
let newObject = Hoek.mapToObject(array); // results in {"1": true, "2": true, "3": true}
array1 = [{ id: 1 }, { id: 2 }];
newObject = Hoek.mapToObject(array1, "id"); // results in {"1": true, "2": true}
// intersect(array1, array2)
array = [1, 2, 3];
let array2 = [1, 4, 5];
let newArray2 = Hoek.intersect(array, array2); // results in [1]
// contain(ref, values, [options])
Hoek.contain('aaa', 'a', { only: true }); // true
Hoek.contain([{ a: 1 }], [{ a: 1 }], { deep: true }); // true
Hoek.contain([1, 2, 2], [1, 2], { once: true }); // false
Hoek.contain({ a: 1, b: 2, c: 3 }, { a: 1, d: 4 }, { part: true }); // true
// flatten(array, [target])
let array3 = [1, [2, 3]];
let flattenedArray = Hoek.flatten(array); // results in [1, 2, 3]
array3 = [1, [2, 3]];
let target1 = [4, [5]];
timestamp: now,
tags: tags,
data: data,
internal: !!_internal
};
var tagsMap = Hoek.mapToObject(event.tags);
// Add to request array
this._logger.push(event);
this.connection.emit(_internal ? 'request-internal' : 'request', this, event, tagsMap);
if (this.server._settings.debug &&
this.server._settings.debug.request &&
Hoek.intersect(tagsMap, this.server._settings.debug.request, true)) {
console.error('Debug:', event.tags.join(', '), (data ? '\n ' + (data.stack || (typeof data === 'object' ? Hoek.stringify(data) : data)) : ''));
}
};
internals.Plugin.prototype._select = function (labels, plugin) {
var connections = this.connections;
if (labels &&
labels.length) { // Captures both empty arrays and empty strings
Hoek.assert(this.connections, 'Cannot select inside a connectionless plugin');
connections = [];
for (var i = 0, il = this.connections.length; i < il; ++i) {
var connection = this.connections[i];
if (Hoek.intersect(connection.settings.labels, labels).length) {
connections.push(connection);
}
}
if (!plugin &&
connections.length === this.connections.length) {
return this;
}
}
var env = (plugin !== undefined ? plugin : this.realm); // Allow empty string
return new internals.Plugin(this.root, connections, env, this);
};
request.auth.artifacts = result.artifacts;
// Check scope
if (config.scope) {
var scopes = config.scope;
if (config.hasScopeParameters) {
scopes = [];
var context = { params: request.params, query: request.query };
for (var i = 0, il = config.scope.length; i < il; ++i) {
scopes[i] = Hoek.reachTemplate(context, config.scope[i]);
}
}
if (!credentials.scope ||
(typeof credentials.scope === 'string' ? scopes.indexOf(credentials.scope) === -1 : !Hoek.intersect(scopes, credentials.scope).length)) {
request._log(['auth', 'scope', 'error', name], { got: credentials.scope, need: scopes });
return next(Boom.forbidden('Insufficient scope, expected any of: ' + scopes));
}
}
// Check entity
var entity = config.entity || 'any';
// Entity: 'any'
if (entity === 'any') {
request._log(['auth', name]);
request.auth.isAuthenticated = true;
return next();
routes = routes.filter(function(route) {
var exit;
for (var i = 0; i < tags.length; i++) {
switch(tags[i].substring(0,1)) {
case '-': // exclude tags that match this case
var tag = tags[i].substring(1,tags[i].length);
if (Hoek.intersect(route.settings.tags, [tag]).length > 0) {
exit = true;
}
break;
case ' ': // (+) filter out tagged paths that do not have this tag!
var tag = tags[i].substring(1,tags[i].length);
if (Hoek.intersect(route.settings.tags, [tag]).length == 0) {
exit = true;
}
break;
}
}
// if we have reason to exit, then do so!
if (exit == true) {
return false;
}
case ' ': // (+) filter out tagged paths that do not have this tag!
var tag = tags[i].substring(1,tags[i].length);
if (Hoek.intersect(route.settings.tags, [tag]).length == 0) {
exit = true;
}
break;
}
}
// if we have reason to exit, then do so!
if (exit == true) {
return false;
}
// default behavior for tags is additive
if (Hoek.intersect(route.settings.tags, tags).length > 0) {
return true;
}
// fallback or no tag defined
return false;
});
}
internals.Plugin.prototype._select = function (labels, plugin) {
var connections = this.connections;
if (labels &&
labels.length) { // Captures both empty arrays and empty strings
Hoek.assert(this.connections, 'Cannot select inside a connectionless plugin');
connections = [];
for (var i = 0, il = this.connections.length; i < il; ++i) {
var connection = this.connections[i];
if (Hoek.intersect(connection.settings.labels, labels).length) {
connections.push(connection);
}
}
if (!plugin &&
connections.length === this.connections.length) {
return this;
}
}
var env = (plugin !== undefined ? plugin : this.realm); // Allow empty string
return new internals.Plugin(this.root, connections, env, this);
};
function isSubset(scope, subset) {
if (!scope) {
return false
}
if (scope.length < subset.length) {
return false
}
const common = Hoek.intersect(scope, subset)
return common.length === subset.length
}
internals.validateScope = function (credentials, scope, type) {
if (!scope[type]) {
return true;
}
const count = typeof credentials.scope === 'string' ?
(scope[type].indexOf(credentials.scope) !== -1 ? 1 : 0) :
Hoek.intersect(scope[type], credentials.scope).length;
if (type === 'forbidden') {
return count === 0;
}
if (type === 'required') {
return count === scope.required.length;
}
return !!count;
};
internals.validateScope = function (credentials, scope, type) {
if (!scope[type]) {
return true;
}
const count = typeof credentials.scope === 'string' ?
(scope[type].indexOf(credentials.scope) !== -1 ? 1 : 0) :
Hoek.intersect(scope[type], credentials.scope).length;
if (type === 'forbidden') {
return count === 0;
}
if (type === 'required') {
return count === scope.required.length;
}
return !!count;
};