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

alexa-ability-stash

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

alexa-ability-stash

An alexa-ability middleware for persistent user storage.

  • 0.2.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

alexa-ability-stash Build Status

An alexa-ability middleware for persistent user storage.

Warning: Still in development. Not suitable for use in production yet.

Example

import { Ability } from 'alexa-ability';
import { handleAbility } from 'alexa-ability-lambda-handler';
import createStash from 'alexa-ability-stash';
import createRedisStore from 'connect-redis'; // or any compatible express-session store

const RedisStore = createRedisStore(createStash);
const store = new RedisStore(options);
const app = new Ability();

app.use(createStash({ store }));

app.on('LuckyNumberIntent', function(req, next) {
    if (!req.stash.luckyNumber) {
        // persisted "forever"
        req.stash.luckyNumber = Math.floor(Math.random() * 100 + 1);
    }

    req.say(`Your lucky number is ${req.stash.luckyNumber}!`).end();
});

export const handler = handleAbility(app);

API

createStash(options) -> middleware

Creates a middleware function to handle the stash.

Takes the following options:

  • store - one of the stores defined below
  • genid - a function that takes a request object and returns a string. Returns <appId>:<userId> by default.
  • unset - Behavior when req.stash is deleted. destroy or keep. Defaults to keep.
    • keep The stash will be kept, but modifications made during the request are ignored and not saved.
    • destroy: The stash will be destroyed (deleted) when the response ends.
  • resave Forces the stash to be saved, even if the stash was never modified. Defaults to true.

Attaches two properties to the request object:

  • stash an object you can read and modify. Changes will be saved across requests.
  • stashId the id generated by genid.

Stores

Theoretically all the store supported by express-session should work. In practice, only connect-redis has been tested.

If a store doesn't work for you raise an issue!

Keywords

FAQs

Package last updated on 26 Feb 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

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