Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
*/
import tv4 from 'tv4';
import debug from 'debug';
import URI from 'urijs';
import ActivityStreams from 'activity-streams';
import * as SockethubSchemas from 'sockethub-schemas';
import init from './bootstrap/init';
import config from './config';
const activity = ActivityStreams(config.get('activity-streams:opts')),
log = debug('sockethub:validate');
// load sockethub-activity-stream schema and register it with tv4
// http://sockethub.org/schemas/v0/activity-stream#
tv4.addSchema(SockethubSchemas.ActivityStream.id, SockethubSchemas.ActivityStream);
// load sockethub-activity-object schema and register it with tv4
// http://sockethub.org/schemas/v0/activity-object#
tv4.addSchema(SockethubSchemas.ActivityObject.id, SockethubSchemas.ActivityObject);
// educated guess on what the displayName is, if it's not defined
// since we know the @id is a URI, we prioritize by username, then fragment (no case yet for path)
function ensureDisplayName(msg) {
if ((msg['@id']) && (! msg.displayName)) {
const uri = new URI(msg['@id']);
return uri.username() || getUriFragment(uri) || uri.path();
}
return msg.displayName;
}
function ensureObject(msg) {
return !((typeof msg !== 'object') || (Array.isArray(msg)));
function validateActivityStream(msg) {
// TODO figure out a way to allow for special objects from platforms, without
// ignoring failed activity stream schema checks
if (! tv4.validate(msg, SockethubSchemas.ActivityStream)) {
return tv4.getSchema(`http://sockethub.org/schemas/v0/context/${msg.context}/messages`);
}
return true;
}
const tv4 = require('tv4'),
debug = require('debug')('sockethub:bootstrap:init'),
nconf = require('nconf');
debug('running init routines');
const packageJSON = require('./../../package.json');
const junk = require(__dirname + '/config.js')();
const platforms = require(__dirname + '/platforms.js')(Object.keys(packageJSON.dependencies));
const SockethubSchemas = require('sockethub-schemas');
// load sockethub-activity-stream schema and register it with tv4
tv4.addSchema(SockethubSchemas.ActivityStream.id, SockethubSchemas.ActivityStream);
// load sockethub-activity-object schema and register it with tv4
tv4.addSchema(SockethubSchemas.ActivityObject.id, SockethubSchemas.ActivityObject);
function defaultEnvParams(host, port, prop) {
nconf.set(prop + ':host', host);
nconf.set(prop + ':port', port);
}
defaultEnvParams(
process.env.HOST || nconf.get('service:host'),
process.env.PORT || nconf.get('service:port'),
'service'
);
defaultEnvParams(
process.env.REDIS_HOST || nconf.get('redis:host'),
process.env.REDIS_PORT || nconf.get('redis:port'),