alexa-ability-stash
An alexa-ability middleware for persistent user storage.
Last updated 4 years ago by nickclaw .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install alexa-ability-stash 
SYNC missed versions from official npm registry.

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!

Current Tags

  • 0.2.1                                ...           latest (4 years ago)

2 Versions

  • 0.2.1                                ...           4 years ago
  • 0.2.0                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 4
Dependencies (4)
Dev Dependencies (14)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |