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

farrow-session

v1.0.1

Published

A session middleware for farrow.

Downloads

1

Readme

farrow-session

NPM Documentation Action Status License: MIT

A session middleware for farrow.

Install

Unpublsihed

Frist Look

import { Http, Response, Router } from 'farrow-http'
import { createSessionContext } from 'farrow-session'

const http = Http()
const user = Router()

const Session = createSessionContext({
  secret: 'farrow.session',
})

http.route('/user').use(Session.provider()).use(user)

user
  .match({
    url: '/',
    method: ['GET', 'POST'],
  })
  .use((req, next) => {
    const sid = Session.id
    return Response.text(`Hello world! ${sid}`)
  })

http.listen(3600)

Options

cookie

Settings object for the session ID cookie. The default value is { path: '/', httpOnly: true, secure: false, maxAge: undefined }.

The following are options that can be set in this object.

cookie.domain

Type: string | undefined

Default: undefined

Specifies the value for the Domain Set-Cookie attribute. By default, no domain is set, and most clients will consider the cookie to apply to only the current domain.

cookie.path

Type: string | undefined

Default: '/'

Specifies the value for the Path Set-Cookie.

cookie.expires

Type: Date | undefined

Default: undefined

Specifies the Date object to be the value for the Expires Set-Cookie attribute. By default, no expiration is set, and most clients will consider this a "non-persistent cookie" and will delete it on a condition like exiting a web browser application.

Note If both expires and maxAge are set in the options, then the last one defined in the object is what is used.

Note The expires option should not be set directly; instead only use the maxAge option.

cookie.httpOnly

Type: boolean

Default: true

Specifies the boolean value for the HttpOnly Set-Cookie attribute. When truthy, the HttpOnly attribute is set, otherwise it is not.

Note be careful when setting this to true, as compliant clients will not allow client-side JavaScript to see the cookie in document.cookie.

cookie.maxAge

Type: number | undefined

Default: undefined

Specifies the number (in milliseconds) to use when calculating the Expires Set-Cookie attribute. This is done by taking the current server time and adding maxAge milliseconds to the value to calculate an Expires datetime. By default, no maximum age is set.

Note If both expires and maxAge are set in the options, then the last one defined in the object is what is used.

cookie.sameSite

Type: 'None' | 'Strict' | 'Lax'

Default: 'None'

Specifies the string to be the value for the SameSite Set-Cookie attribute.

  • 'Lax' will set the SameSite attribute to Lax for lax same site enforcement.
  • 'None' will set the SameSite attribute to None for an explicit cross-site cookie.
  • 'Strict' will set the SameSite attribute to Strict for strict same site enforcement.

Detail at SameSite

cookie.secure

Type: boolean

Default: true

Specifies the boolean value for the Secure Set-Cookie attribute. When truthy, the Secure attribute is set, otherwise it is not. By default, the Secure attribute is not set.

Note be careful when setting this to true, as compliant clients will not send the cookie back to the server in the future if the browser does not have an HTTPS connection.

genid

Type: () => string

Default: uuid.v4

Function to call to generate a new session ID. Provide a function that returns a string that will be used as a session ID.

name

Type: string

Default: 'connect.sid'

The name of the session ID cookie to set in the response (and read from in the request).

proxy

Type: boolean

Default: true

Trust the reverse proxy when setting secure cookies (via the "X-Forwarded-Proto" header).

store

Type: Store

Default: MemoryStore

Every session store must be an EventEmitter and implement specific methods. The following methods are the list of required, recommended, and optional.

store.get

Type: (sid: string) => SessionData | false

Get SessionData by session ID.

store.set

Type: (sid: string, session: Session) => void

Set SessionData for a new session.

store.touch

Type: (sid: string, session: Session) => void

Upate expire time for the session.

store.destroy

Type: (sid: string) => void

Remove the session data for the session.

store.clear

Type: () => void

Remove all the session data in this store.

store.length

Type: () => number

Get the amount of sessions in this store.

API

Should call in farrow middleware otherwise operation is invalid.

Session.id

Type: string | undefined

Each session has a unique ID associated with it and cannot be modified.

Session.cookie

Type: Cookie

Each session has a unique cookie object accompany it. This allows you to alter the session cookie per visitor.

Session.generate

Type: () => Session

Generage a new Session for current request.

Session.destory

Type: () => Session

Remove current session and message for current request.

Session.touch

Type: () => Session

Upate expire time of current session.

Session.store

The storage object of session data. You can access this object by this way.