New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

botmaster-session-ware

Package Overview
Dependencies
Maintainers
2
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

botmaster-session-ware - npm Package Compare versions

Comparing version 0.1.3 to 1.1.0

yarn.lock

6

dist/adapters/MemoryStore.js

@@ -8,3 +8,7 @@ "use strict";

/**
* The most basic adapter ever for SessionWare
* The most basic adapter ever for SessionWare. This is the default store that is
* used when instantiating a SessionWare object without any params.
* It provides the standard required API for stores. I.e. a getter and a setter method.
* Called `get` and `set` that both return promises where get resolves with the session
* value and set sets the session value
* @class

@@ -11,0 +15,0 @@ */

52

dist/index.js

@@ -13,7 +13,11 @@ 'use strict';

/**
* Create an object providing incoming and outgoing middleware
* Create an object providing incoming and outgoing middleware that manages a
* session object for you. By using this middleware, your other middleware will
* have access to a persisted `update.session` object.
*
* @param {Object} [options] options object for generated sessionWare
* @param {Object} [options.adapter] an object implementing the adapter api. defaults to in memory.
* @param {Object} [options.adapter] an object implementing the adapter api. defaults to in MemoryStore.
* @param {String} [options.sessionPath] dot denoted path to where to store the context in the update. defaults to 'session'
* @return {Object} an object that contains two functions 'incoming' and 'outgoing'. The incoming should be placed before any middleware that requires it and the outgoing should be placed after all middleware have used it.
* @return {Object} an object that contains two functions 'incoming' and 'outgoing'.
* They should be used with the useWrapped method of botmaster
*/

@@ -36,22 +40,28 @@ var SessionWare = function SessionWare(options) {

var incoming = function incoming(bot, update, next) {
store.get(idFromUpdate(update)).then(function (session) {
Debug('botmaster:session:incoming')('got session for ' + idFromUpdate(update));
var sessionPathLens = R.lensPath(sessionPath.splice(1));
update[sessionPath[0]] = R.set(sessionPathLens, session, update);
next();
}).catch(function (err) {
Debug('botmaster:session:incoming')('error ' + err.message);
next(err);
});
var incoming = {
type: 'incoming',
controller: function controller(bot, update, next) {
store.get(idFromUpdate(update)).then(function (session) {
Debug('botmaster:session:incoming')('got session for ' + idFromUpdate(update));
var sessionPathLens = R.lensPath(sessionPath.splice(1));
update[sessionPath[0]] = R.set(sessionPathLens, session, update);
next();
}).catch(function (err) {
Debug('botmaster:session:incoming')('error ' + err.message);
next(err);
});
}
};
var outgoing = function outgoing(bot, update, messsage, next) {
assert(typeof next == 'function', 'please ensure you have the correct version of botmaster');
var sessionPathLens = R.lensPath(sessionPath);
var session = R.view(sessionPathLens, update);
store.set(idFromUpdate(update), session).then(function () {
Debug('botmaster:session:outgoing')('updated session for ' + idFromUpdate(update));
next();
});
var outgoing = {
type: 'outgoing',
controller: function controller(bot, update, message, next) {
assert(typeof next == 'function', 'please ensure you have the correct version of botmaster');
var sessionPathLens = R.lensPath(sessionPath);
var session = R.view(sessionPathLens, update);
store.set(idFromUpdate(update), session).then(function () {
Debug('botmaster:session:outgoing')('updated session for ' + idFromUpdate(update));
next();
});
}
};

@@ -58,0 +68,0 @@

{
"name": "botmaster-session-ware",
"version": "0.1.3",
"version": "1.1.0",
"description": "botmaster session ware for storing context",

@@ -12,8 +12,9 @@ "main": "dist/index.js",

"build": "mkdir -p dist && babel --presets=es2015 src --out-dir dist",
"docs": "documentation readme src/index.js --section=\"API Usage\"",
"prepublish": "npm run build"
"docs": "documentation readme src/index.js --section=\"API\"",
"prepublish": "npm run build",
"postversion": "git push && git push --tags"
},
"repository": {
"type": "git",
"url": "git+https://github.com/botmasterai/botmaster-mem-session-ware.git"
"url": "git+https://github.com/botmasterai/botmaster-session-ware.git"
},

@@ -30,8 +31,8 @@ "keywords": [

"bugs": {
"url": "https://github.com/botmasterai/botmaster-mem-session-ware/issues"
"url": "https://github.com/botmasterai/botmaster-session-ware/issues"
},
"peerDependencies": {
"botmaster": ">=2.3.0"
"botmaster": "^3.0.7"
},
"homepage": "https://github.com/botmasterai/botmaster-mem-session-ware#readme",
"homepage": "https://github.com/botmasterai/botmaster-session-ware#readme",
"devDependencies": {

@@ -38,0 +39,0 @@ "babel-cli": "^6.22.2",

@@ -5,3 +5,3 @@ [![Build Status](https://travis-ci.org/botmasterai/botmaster-session-ware.svg?branch=master)](https://travis-ci.org/botmasterai/botmaster-session-ware)

A configurable botmaster ware to provide session data to downstream middleware.
A configurable botmaster ware to provide session data to downstream middleware. Works with Botmaster ^3.0.7.

@@ -18,5 +18,19 @@ # Quick Start

const {incoming, outgoing} = SessionWare();
botmaster.use('incoming', incoming);
botmaster.use('outgoing', outgoing);
botmaster.use({
type: 'incoming',
name: 'some controller',
controller: (bot, update) => {
// this will be {} on the first call from a certain user
// and will contain the last message upon all the next iterations
console.log(update.session);
update.session.lastMessage = update.message;
}
})
.
.
.
// place after declaring all your other middleware
const sessionWare = SessionWare();
botmaster.useWrapped(sessionWare.incoming, sessionWare.outgoing);
```

@@ -28,7 +42,26 @@

## API Usage
## API
### SessionWare
Create an object providing incoming and outgoing middleware that manages a
session object for you. By using this middleware, your other middleware will
have access to a persisted `update.session` object.
**Parameters**
- `options` **\[[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)]** options object for generated sessionWare
- `options.adapter` **\[[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)]** an object implementing the adapter api. defaults to in MemoryStore.
- `options.sessionPath` **\[[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)]** dot denoted path to where to store the context in the update. defaults to 'session'
Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** an object that contains two functions 'incoming' and 'outgoing'.
They should be used with the useWrapped method of botmaster
### MemoryStore
The most basic adapter ever for SessionWare
The most basic adapter ever for SessionWare. This is the default store that is
used when instantiating a SessionWare object without any params.
It provides the standard required API for stores. I.e. a getter and a setter method.
Called `get` and `set` that both return promises where get resolves with the session
value and set sets the session value

@@ -41,5 +74,5 @@ #### get

- `id` **String** a unique id for the session
- `id` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** a unique id for the session
Returns **Promise** evaluates to an object that is the session
Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** evaluates to an object that is the session

@@ -52,17 +85,5 @@ #### set

- `id` **String** a unique id for the session
- `value` **Object** the new value for the session
- `id` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** a unique id for the session
- `value` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** the new value for the session
Returns **Promise** resolves when the session has been saved
### SessionWare
Create an object providing incoming and outgoing middleware
**Parameters**
- `options` **[Object]** options object for generated sessionWare
- `options.adapter` **[Object]** an object implementing the adapter api. defaults to in memory.
- `options.sessionPath` **[String]** dot denoted path to where to store the context in the update. defaults to 'session'
Returns **Object** an object that contains two functions 'incoming' and 'outgoing'. The incoming should be placed before any middleware that requires it and the outgoing should be placed after all middleware have used it.
Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** resolves when the session has been saved
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