Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
for (let moduleName of moduleList) {
if (rx.test(moduleName)) {
// found a sockethub platform
const platformName = moduleName.replace(rx, '');
log('registering ' + platformName + ' platform');
if (platformIsAccepted(platformName)) {
// try to load platform
const P = require(moduleName);
const p = new P();
const packageJson = require(`./../../node_modules/${moduleName}/package.json`);
let types = [];
// validate schema property
if (! tv4.validate(p.schema, schemas.platform)) {
throw new Error(
`${platformName} platform schema failed to validate: ${tv4.error.message}`);
} else if (typeof p.config !== 'object') {
throw new Error(
`${platformName} platform must have a config property that is an object.`);
} else if (p.schema.credentials) {
// register the platforms credentials schema
types.push('credentials');
tv4.addSchema(`http://sockethub.org/schemas/v0/context/${platformName}/credentials`,
p.schema.credentials);
}
tv4.addSchema(`http://sockethub.org/schemas/v0/context/${platformName}/messages`,
p.schema.messages);
if (platformListsSupportedTypes(p)) {
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'),
'redis'
);
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 errorHandler(type, msg, next) {
*/
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'),
function validateActivityObject(msg) {
return tv4.validate({ object: msg }, SockethubSchemas.ActivityObject);
}