šŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more →
Socket
Sign inDemoInstall
Socket

tenant

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tenant

Unopinionated tenanted connection and configuration management

2.1.2
latest
Source
npm
Version published
Weekly downloads
448
-25.95%
Maintainers
1
Weekly downloads
Ā 
Created
Source

Tenant

npm npm CircleCI Coveralls

Getting started

Looking for the express middleware? Try express-tenant!

Installation

$ npm i --save tenant

ES5

var Tenancy = require('tenant');

ES6

import { Tenancy, Tenant, Connection } from 'tenant';

Tenancy configuration options

import Tenancy from 'tenant';
import Bluebird from 'bluebird';

let tenancy = new Tenancy({
  tenants: {
    production: convict({}), // use some library
    staging: config, // a custom module
    development: {}, // a plain object!?
  },
  connections: {

    // I apologize.
    salesforce(config) {
      let { username, hostname, password, token } = config.salesforce;
      let conn = new jsforce.Connection({
        loginUrl: hostname,
        accessToken: token,
      });

      return Bluebird.fromCallback(cb => {
        conn.login(username, password + token, cb);
      })
    },

    // Less gross.
    couch(config) {
      return nano(config.couch.url);
    },

    service(extra, parameters, config) {
      // Return whatever you want, promise, function, object, (spatula?)
    },
    // ...other tenanted connections
  ],
});

Functional initialization

Alternatively you can add connections and tenants functionally. Pass a fully qualified Tenant object or a name and a configuration object. Order doesn't matter, connections will populate to tenants and vice versa

Example:

import { Tenancy, Tenant } from 'tenant';

let tenancy = new Tenancy();

let staging = new Tenant('staging', stagingConfig);

// Chainable. Order doesn't matter.
tenancy
  .tenant(staging)
  .connection('salesforce', (config) => {
    return Promise.reject(new Error('Really? Still Salesforce?'));
  })
  .tenant('production', prodConfig);

export default tenancy;

Getting tenant configuration

let secret = tenancy.tenant('production').config.sessionSecret;

Getting a tenant connection

let CouchDB = tenancy.tenant('staging').connection('couch');

Passing additional arguments to the connection factory method

// Define your factory method with additional arguments
new Connection('couch', (tablename, config) => {
  return nano(config.couchdb).use(tablename);
});

// Call connection with an array of additional arguments
let CouchDB = tenancy.tenant('staging').connection('couch', ['users']);

API Reference

class Tenancy

class Tenant

class Connection

Keywords

multi-tenancy

FAQs

Package last updated on 24 Aug 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts