How to use moesifapi - 9 common examples

To help you get started, we’ve selected a few moesifapi 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 Moesif / moesif-express / test / outgoingWithMoesif.js View on Github external
before(function() {
      var config = moesifapi.configuration;
      config.ApplicationId = '';
      // config.BaseUri = options.baseUri || options.BaseUri || config.BaseUri;
      var moesifController = moesifapi.ApiController;
      var logger = function(text) {
        console.log('[test logger]:' + text);
      };

      var options = {};

      options.identifyUser =
        options.identifyUser ||
        function() {
          return undefined;
        };

      options.identifyCompany =
      options.identifyCompany ||
      function() {
        return undefined;
github Moesif / moesif-express / test / outgoingWithMoesif.js View on Github external
before(function() {
      var config = moesifapi.configuration;
      config.ApplicationId = '';
      // config.BaseUri = options.baseUri || options.BaseUri || config.BaseUri;
      var moesifController = moesifapi.ApiController;
      var logger = function(text) {
        console.log('[test logger]:' + text);
      };

      var options = {};

      options.identifyUser =
        options.identifyUser ||
        function() {
          return undefined;
        };

      options.identifyCompany =
github Moesif / moesif-express / lib / moesifConfigManager.js View on Github external
MoesifConfigManager.prototype.tryGetConfig = function () {
  if (!this._loadingConfig && this.shouldFetchConfig()) {
    // only send one config request at a time
    this._loadingConfig = true;

    var that = this;

    moesifController.getAppConfig(function (_, __, event) {
      that._loadingConfig = false;

      if (event && event.response.statusCode === 200) {
        that._configHash = event.response.headers[HASH_HEADER];
        try {
          that._config = JSON.parse(event.response.body);
          that._lastConfigUpdate = now();
        } catch (e) {
          console.warn('moesif-express: error parsing config');
        }
      }
    });
  }
};
github Moesif / moesif-express / lib / index.js View on Github external
module.exports = function(options) {
  logMessage(options.debug, 'moesifInitiator', 'start');

  ensureValidOptions(options);

  // config moesifapi
  var config = moesifapi.configuration;
  config.ApplicationId = options.applicationId || options.ApplicationId;
  config.BaseUri = options.baseUri || options.BaseUri || config.BaseUri;
  var moesifController = moesifapi.ApiController;

  options.identifyUser = options.identifyUser || noop;
  options.identifyCompany = options.identifyCompany || noop;

  // function to add custom metadata (must be an object that can be converted to JSON)
  options.getMetadata = options.getMetadata || noop;

  // function to add custom session token (must be a string)
  options.getSessionToken = options.getSessionToken || noop;

  // function to allow adding of custom tags (this is decprecated - getMetadata should be used instead)
  options.getTags = options.getTags || noop;

  // function to declare the api versionused for the request
  options.getApiVersion = options.getApiVersion || noop;
github Moesif / moesif-express / lib / moesifConfigManager.js View on Github external
/*
 * MoesifConfigManager is responsible for fetching and ensuring
 * the config for our api appId is up to date.
 *
 * This is done by ensuring the x-moesif-config-etag doesn't change.
 */

var moesifController = require('moesifapi').ApiController;

const CONFIG_UPDATE_DELAY = 300000; // 5 minutes
const HASH_HEADER = 'x-moesif-config-etag';

function now() {
  return new Date().getTime();
}

function MoesifConfigManager() {
  this._lastConfigUpdate = 0;
}

MoesifConfigManager.prototype.hasConfig = function () {
  return Boolean(this._config);
};
github Moesif / moesif-express / lib / index.js View on Github external
module.exports = function(options) {
  logMessage(options.debug, 'moesifInitiator', 'start');

  ensureValidOptions(options);

  // config moesifapi
  var config = moesifapi.configuration;
  config.ApplicationId = options.applicationId || options.ApplicationId;
  config.BaseUri = options.baseUri || options.BaseUri || config.BaseUri;
  var moesifController = moesifapi.ApiController;

  options.identifyUser = options.identifyUser || noop;
  options.identifyCompany = options.identifyCompany || noop;

  // function to add custom metadata (must be an object that can be converted to JSON)
  options.getMetadata = options.getMetadata || noop;

  // function to add custom session token (must be a string)
  options.getSessionToken = options.getSessionToken || noop;

  // function to allow adding of custom tags (this is decprecated - getMetadata should be used instead)
  options.getTags = options.getTags || noop;
github Moesif / moesif-express / lib / index.js View on Github external
/**
 * Created by Xingheng on 10/16/16.
 */

// express converts headers to lowercase
const TRANSACTION_ID_HEADER = 'x-moesif-transaction-id';

var _ = require('lodash');
var moesifapi = require('moesifapi');
var getRawBody = require('./getRawBody');
var contentType = require('content-type');
var EventModel = moesifapi.EventModel;
var UserModel = moesifapi.UserModel;
var CompanyModel = moesifapi.CompanyModel;
var requestIp = require('request-ip');
var dataUtils = require('./dataUtils');
var patch = require('./outgoing');
var createRecorder = require('./outgoingRecorder');
var createBatcher = require('./batcher');
var PassThrough = require('stream').PassThrough;
var moesifConfigManager = require('./moesifConfigManager');
var uuid4 = require('uuid4');

exports.defaultSkip = function(req, res) {
  return false;
};

//
// ### function moesifExpress(options)
// #### @options {Object} options to initialize the middleware.
github Moesif / moesif-express / lib / index.js View on Github external
/**
 * Created by Xingheng on 10/16/16.
 */

// express converts headers to lowercase
const TRANSACTION_ID_HEADER = 'x-moesif-transaction-id';

var _ = require('lodash');
var moesifapi = require('moesifapi');
var getRawBody = require('./getRawBody');
var contentType = require('content-type');
var EventModel = moesifapi.EventModel;
var UserModel = moesifapi.UserModel;
var CompanyModel = moesifapi.CompanyModel;
var requestIp = require('request-ip');
var dataUtils = require('./dataUtils');
var patch = require('./outgoing');
var createRecorder = require('./outgoingRecorder');
var createBatcher = require('./batcher');
var PassThrough = require('stream').PassThrough;
var moesifConfigManager = require('./moesifConfigManager');
var uuid4 = require('uuid4');

exports.defaultSkip = function(req, res) {
  return false;
};

//
// ### function moesifExpress(options)
github Moesif / moesif-express / test / outgoingWithMoesif.js View on Github external
var trySaveEventLocal = function(eventData) {
        moesifController.createEvent(new moesifapi.EventModel(eventData), function(err) {
          console.log('moesif API callback err=' + err);
          if (err) {
            console.log('moesif API failed with error.');
            if (options.callback) {
              options.callback(err, eventData);
            }
          } else {
              console.log('moesif API succeeded');
            if (options.callback) {
              options.callback(null, eventData);
            }
          }
        });
      };

moesifapi

Collection/Data Ingestion API for Moesif

Apache-2.0
Latest version published 1 month ago

Package Health Score

73 / 100
Full package analysis