How to use sockethub-schemas - 7 common examples

To help you get started, we’ve selected a few sockethub-schemas examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sockethub / sockethub / src / bootstrap / platforms.js View on Github external
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)) {
github sockethub / sockethub / lib / bootstrap / init.js View on Github external
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'
);
github sockethub / sockethub / src / validate.ts View on Github external
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) {
github sockethub / sockethub / src / validate.ts View on Github external
*/
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)));
github sockethub / sockethub / src / validate.ts View on Github external
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;
}
github sockethub / sockethub / lib / bootstrap / init.js View on Github external
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'),
github sockethub / sockethub / src / validate.ts View on Github external
function validateActivityObject(msg) {
  return tv4.validate({ object: msg }, SockethubSchemas.ActivityObject);
}

sockethub-schemas

JSON schema files for validating Sockethub Activity Streams

LGPL-3.0
Latest version published 3 years ago

Package Health Score

56 / 100
Full package analysis