Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Contextualize definition
if (definition.contextualize) {
if (definition === base) {
definition = Hoek.clone(definition);
}
await definition.contextualize(definition, context);
}
// Validate name
const nameRx = definition.strictHeader ? internals.validateRx.nameRx.strict : internals.validateRx.nameRx.loose;
if (!nameRx.test(cookie.name)) {
throw Boom.badImplementation('Invalid cookie name: ' + cookie.name);
}
// Prepare value (encode, sign)
const value = await exports.prepareValue(cookie.name, cookie.value, definition);
// Validate prepared value
const valueRx = definition.strictHeader ? internals.validateRx.valueRx.strict : internals.validateRx.valueRx.loose;
if (value &&
(typeof value !== 'string' || !value.match(valueRx))) {
throw Boom.badImplementation('Invalid cookie value: ' + cookie.value);
}
// Construct cookie
public async show(request: Hapi.Request, h: Hapi.ResponseToolkit) {
try {
// @ts-ignore
const data = await request.server.methods.v2.locks.show(request);
return super.respondWithCache(data, h);
} catch (error) {
return Boom.badImplementation(error);
}
}
function wrapErrors(err, req, res, next) {
// Es posible que el error que nos llegue no sea de tipo Boom,
// nosotros queremos que apartir de ahi todos los errores tengan la estructura boom
if (!err.isBoom) {
next(boom.badImplementation(err));
}
// Si el error que estamos pasando por acá es de tipo boom,
// llamamos al siguiente middleware con el error
next(err);
}
const keys = Object.keys(context);
for (let i = 0; i < keys.length; ++i) {
const key = keys[i];
base[key] = context[key];
}
}
context = base;
}
context = context || {};
if (compiled.layout &&
context.hasOwnProperty(compiled.settings.layoutKeyword)) {
throw Boom.badImplementation('settings.layoutKeyword conflict', { context, keyword: compiled.settings.layoutKeyword });
}
return new Promise((resolve, reject) => {
compiled.template(context, compiled.settings.runtimeOptions, (err, renderedContent) => {
if (err) {
reject(Boom.badImplementation(err.message, err));
return;
}
// No layout
if (!compiled.layout) {
resolve(renderedContent);
return;
function buildResources (options, udaru, authParams, request, organizationId) {
let resource = authParams.resource
if (resource) return [resource]
const resourceType = request.route.path.split('/')[2]
const resourceBuilder = request.server.udaruConfig.get('AuthConfig.resources')[resourceType]
if (!resourceBuilder) throw Boom.badImplementation('Resource builder not found')
const requestParams = authParams.getParams ? authParams.getParams(request) : {}
const buildParams = Object.assign({}, {organizationId}, requestParams)
if (resourceType === 'users' && buildParams.userId) return buildResourcesForUser(udaru, resourceBuilder, buildParams, organizationId)
return [resourceBuilder(buildParams)]
}
async _prepare(template, options) {
options = options || {};
const fileExtension = Path.extname(template).slice(1);
const extension = fileExtension || this._defaultExtension;
if (!extension) {
throw Boom.badImplementation('Unknown extension and no defaultExtension configured for view template: ' + template);
}
const engine = this._engines[extension];
if (!engine) {
throw Boom.badImplementation('No view engine found for file: ' + template);
}
template = template + (fileExtension ? '' : engine.suffix);
if (!engine.ready) {
await this._prepareEngine(engine);
}
return this._prepareTemplates(template, engine, options);
}
try {
let user: IUser = await User.create(
Object.assign({}, { email, username, id, password: hash, admin: false })
);
let token = createToken(user);
return h
.response({
userID: user.id,
id_token: token,
username: user.username
})
.code(201);
} catch (error) {
return Boom.badImplementation(error);
}
};
public async top(request: Hapi.Request, h: Hapi.ResponseToolkit) {
try {
const wallets = this.databaseService.wallets.top(super.paginate(request));
const accounts = wallets.rows.map(account => ({
address: account.address,
balance: `${account.balance}`,
publicKey: account.publicKey,
}));
return super.respondWith({ accounts });
} catch (error) {
return Boom.badImplementation(error);
}
}
return { error: 'Insufficient document scope.' }
}
}
)
return h.continue
}
}
return h.continue
} catch (err) {
if (err.isBoom) {
throw err
} else {
Log.error(err)
throw Boom.badImplementation(err)
}
}
}
function handleError(err, logger) {
if (!err.isBoom) {
logger.error(err)
throw Boom.badImplementation('There was an error processing the request.')
} else {
throw err
}
}