Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

couchdb-love

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

couchdb-love

couchdb love requests with promises

  • 0.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

couchdb-love

simple couchdb love client

  • request-promise centric

    • build requestOptions as for request-promise.
  • cookie authentication

    • handles session management (creation & persistence)
    • inserts sessionid into headers.
    • increased security
    • must configure couchdb for cookie authentication
  • performance logging

    • query performance info logged at:
      • {logpath}/stderr.log (error logging).
      • {logpath}/stdout.log
    • log records are JSON objects.

configurations

local.ini

[couch_httpd_auth]
allow_persistent_cookies = true

config

{
  host: 'http://localhost',
  port: 5984,
  username: 'username',
  password: 'password',
  logpath: __dirname + '/../log'
};

logpath: where peformance log statements are stored.

1 init couchdb-love

const CLove = require('../lib')(Config);
// or
const CLove2 = new require('../lib')(Config2);

note use "new" when muliple users.

2 Build a request with a promise

const requestOptions = (session) => {

    return new Promise((resolve, reject) => {

        const options = {
            method: 'PUT',
            uri: Config.host + ':' + Config.port + '/test_uuser',
            headers: {
                'X-Couchdb-WWW-Authenticate': 'Cookie',
                'Content-Type': 'application/x-www-form-urlencoded',
                'Cookie': 'AuthSession=' + session.cookie
            },
            resolveWithFullResponse: true,
            json: true, // Automatically parses the JSON string in the response
            requestError: 'Failed to destroy database \"test_uuser\".'  // @note must have for error message.
        };

        resolve(options);
    });

request options must be built using a promise as illustrated above. couchdb-love utilizes promises and generator functions to build a simple request lifecycle. Lifecycle:

  • generate session
  • load requestOptions
  • begin logging
  • execute request
  • tail - print log statements
  • return result to user

If you do not use a promise to load requestOptions, the lifecycle will break.

3 next pass requestOptions to couchdb-love

    const CLove = require('couchdb-love')(Config);

    CLove.request(requestOptions, (err, result) => {

        expect(result.statusCode).to.equal(201);
        done(err);
    });

4 relax and make more request

Tests

100% test coverage node v6.9.4

depends on:

  • couchdb-session
  • itera
  • request
  • request-promise

Keywords

FAQs

Package last updated on 10 Feb 2017

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc