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 = function(evaluator, options) {
// default options
options = evaluator(
_.defaults(options, {
t: chance.integer({ min: 0, max: MAX_TS }),
i: chance.integer({ min: 0, max: MAX_TS })
})
);
return new bson.Timestamp(options.t, options.i);
};
var users = runtime.db.get('users')
var intents = runtime.db.get('intents')
user = await users.findOne({ userId: userId })
if (!user) { return reply(boom.notFound('user entry does not exist: ' + userId)) }
result = await helper.verify(debug, user, request.payload)
if (result) return reply(result)
result = await helper.sessionId2stats(runtime, userId, sessionId)
// NB: alternatives is temporary
reply(user.version ? helper.add_nonce_data(result) : result)
intent = { userId: userId,
sessionID: sessionId,
timestamp: bson.Timestamp(),
type: type,
payload: underscore.extend(payload, { timestamp: timestamp })
}
try {
await intents.insert(intent)
} catch (ex) {
debug('insert failed for intents', ex)
}
}
},
function genClusterTime(time) {
return {
clusterTime: new Timestamp(time),
signature: {
hash: new Binary(Buffer.from('testing')),
keyId: 42
}
};
}
return async function (request, reply) {
var result
var debug = braveHapi.debug(module, request)
var payload = request.payload
var hostname = payload.hostname
var siteInfo = runtime.db.get('site_info')
try {
await siteInfo.insert(underscore.extend(payload, { timestamp: bson.Timestamp() }))
} catch (ex) {
debug('insert failed for siteInfo', ex)
return reply(boom.badData('ad-manifest entry already exists: ' + hostname))
}
result = await siteInfo.findOne({ hostname: hostname })
if (!result) { return reply(boom.badImplementation('database creation failed: ' + hostname)) }
result = underscore.extend(underscore.omit(result, '_id', 'timestamp'), { timestamp: result.timestamp.toString() })
reply(result)
}
},
return async (request, reply) => {
var result
var debug = braveHapi.debug(module, request)
var payload = request.payload
var publisher = payload.publisher
var publishers = runtime.db.get('publishersV2', debug)
result = await publishers.findOne({ publisher: publisher })
if (result) return reply(boom.badData('publisher identity entry already exists: ' + publisher))
try {
await publishers.insert(underscore.extend(payload, { timestamp: bson.Timestamp() }))
} catch (ex) {
runtime.notify(debug, { text: 'publishers error: ' + ex.toString() })
debug('publishers error', ex)
return reply(boom.badData(ex.toString()))
}
result = await publishers.findOne({ publisher: publisher })
if (!result) return reply(boom.badImplementation('database creation failed: ' + publisher))
result = underscore.extend(underscore.omit(result, [ '_id', 'timestamp' ]), { timestamp: result.timestamp.toString() })
reply(result)
}
},
return async function (request, reply) {
var result
var debug = braveHapi.debug(module, request)
var payload = request.payload
var hostname = payload.hostname
var siteInfo = runtime.db.get('site_info')
try {
await siteInfo.insert(underscore.extend(payload, { timestamp: bson.Timestamp() }))
} catch (ex) {
debug('insert failed for siteInfo', ex)
return reply(boom.badData('ad-manifest entry already exists: ' + hostname))
}
result = await siteInfo.findOne({ hostname: hostname })
if (!result) { return reply(boom.badImplementation('database creation failed: ' + hostname)) }
result = underscore.extend(underscore.omit(result, '_id', 'timestamp'), { timestamp: result.timestamp.toString() })
reply(result)
}
},
Timestamp: function(low, high) {
return new bson.Timestamp(low, high);
},
ISODate: function(s) {
$timestamp: function(val) {
return bson.Timestamp(val.$timestamp.t, val.$timestamp.i);
},
$numberLong: function(val) {