npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

db-cookie-store

v0.1.1

Published

Store cookies in database

Downloads

3

Readme

Build Status

Introduction

db-cookie-store - this is database based store for cookie management library tough cookie. The library uses ORM Sequelize and allow store cookies in databases which are supported by sequelize: MySQL, MariaDB, SQLite, PostgreSQL.

Synopsis

var DBCookieStore = require('db-cookie-store');
var CookieJar = require("tough-cookie").CookieJar;
var jar = new CookieJar(new DBCookieStore(db_name, db_user, db_password, db_options));

Installation

If you have npm installed, you can simply type:

      npm install db-cookie-store

Or you can clone this repository using the git command:

      git clone git://github.com/JSBizon/db-cookie-store.git

Usage

Class DbCookieStore has options:

  • cookies_model - pre-defined sequalize model for store cookies ( Default : null)
  • cookies_model_create - create table for store cookies if table doesn't exist ( Default : true)
  • cookies_table - name of table for store cookies ( Default : cookies )
  • cookies_store_schema - name of pre-defined schema or object with fields for custom schema. There are several pre-defined schemes: default, mozilla, chrome-win. ( Default : default).
  • cookies_fields_map - map fields from cookie to the table. ( Default : null, it's dependent from store schema)
  • cookies_model_options - options parameter for creating cookies sequalize model. ( Default : null, it's dependent from store schema)
  • cookies_schema_init - this function will be called before create new cookies sequalize model. It must return promise.( Default : null, it's dependent from store schema)
  • transactions_queue - use transaction queue for insert and update sql queries. If value is true, requests will executed step by step. ( Default : true)

Store schema

Store schema describes how cookies data will be stored to the database. Store schema defines columns name and type. For example there are columns for default schema:

fields_map : {
    'id'        : { type: Sequelize.INTEGER, primaryKey: true, autoIncrement: true, allowNull: false, field: "id" },
    'key'       : { type: Sequelize.TEXT, allowNull: false, field : "key"},
    'value'     : { type: Sequelize.TEXT, allowNull: false, field : "value" },
    'expires'   : {type: Sequelize.INTEGER, field : "expires"},
    'maxAge'    : {type: Sequelize.INTEGER, field : "max_age"},
    'domain'    : {type: Sequelize.TEXT, allowNull: false, field : "domain"},
    'path'      : {type: Sequelize.TEXT, allowNull: false, field : "path"},
    'secure'    : {type: Sequelize.BOOLEAN, allowNull: false, defaultValue: true, field : "secure"},
    'httpOnly'  : {type: Sequelize.BOOLEAN, allowNull: false, defaultValue: true, field : "http_only"},
    'creation'  : {type: Sequelize.INTEGER, field : "creation_time"},
    'lastAccessed' : {type: Sequelize.INTEGER, field : "last_accessed"}
}

this means cookies attribute key will be writed(or readed) to the column key with type TEXT, cookies attribute expires will be writed to the column expires with type INTEGER, etc. Supported all options which supported by sequalize define method.

There are exists next pre-defined schemas: default, mozilla, chrome-win.

You can define your own schema. Usually schema is a hash with fields: fields_map, options, init:

var my_schema = {
  //sequalize fields description
  fields_map : {
  .....
  },
  //sequalize options
  options : {
    timestamps: false,
    indexes : [
      {fields : [{attribute : "domain", length : 25}]},
      {fields : [{attribute: "key", length : 25}, {attribute : "domain", length: 25},
      {attribute : "path", length: 25}] }
    ]
  },

  //should return Promise, will be called before model created
  init: function () {
    return new Sequelize.Promise(function (resolve, reject) {
        ......
      });
    }
  }
}

Export cookies

For receive all cookies from the store might be used method export:

cookie_store.export(function(cookies) {
  //cookies - array of cookies
});

cookie_store.export(new MemoryCookieStore(),function(memory_cookie_store) {
  //memory_cookie_store - instance of MemoryCookieStore
});

Examples

Using this module with 'cookies_store_schema' parameter allow to read/write cookies from/to different cookies storages

Read/Write cookies from firefox cookies storage

Firefox uses Sqlite database for store cookies. So cookies could be readed and writed via CookieJar:

var DBCookieStore = require('db-cookie-store');
var CookieJar = require("tough-cookie").CookieJar;

var cookie_jar = new CookieJar(new DBCookieStore(null,null,null,{
    cookies_store_schema : 'mozilla', //use pre-defined fields set
    dialect : 'sqlite',
    storage: './cookies.sqlite',
}));

Read/Write cookies from chrome cookies storage(Linux)

Chrome uses uses Sqlite database for store cookies. Chrome for linux decode values of cookies. Encoding/decoding is implemented in chrome store schema:

var DBCookieStore = require('db-cookie-store');
var CookieJar = require("tough-cookie").CookieJar;
var chrome_schema = require('db-cookie-store/lib/chrome-linux-schema'); //load chrome schema

var cookie_jar = new CookieJar(new DBCookieStore(null,null,null,{
    cookies_store_schema : chrome_schema, //use loaded fieldset
    dialect : 'sqlite',
    storage: './Cookies',
}));