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

ask-lowdb-persistence-adapter

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ask-lowdb-persistence-adapter

An Alexa Skills Kit persistence adapter for Lowdb

  • 0.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

ASK Lowdb Persistence Adapter

An Alexa Skills Kit persistence adapter for lowdb.

Why?

For deployed Alexa Skills, you should use a proper persistence layer (for example Amazon S3 using the ask-sdk-s3-persistence-adapter), but for local development S3 can be awkward to use. Using lowdb is great because it saves the data locally making it easy to debug and work with.

Installation

Install adapter:

npm i ask-lowdb-persistence-adapter

Install peer dependencies:

npm i lowdb

Usage

Basic usage:

const LowdbPersistenceAdapter = require("ask-lowdb-persistence-adapter");

// ...

const options = {
  // the name of the lowdb database, default value shown here
  dbName: "persistenceAttributes.db.json",
  // the name of the key to store persistence attributes under in the
  // database, default value shown here
  attributesKey: "persistenceAttributes",
};

Alexa.SkillBuilders.custom()
  .withPersistenceAdapter(new LowdbPersistenceAdapter(options))
  .addRequestHandlers(/* ... */)
  .lambda();

Since the primary purpose of this adapter is for use locally when a proper persistence layer is unavailable, a nice pattern for creating your persistence adapter is to use a factory. For example, if one wanted to use S3 when it was available and lowdb otherwise, one could implement it like so:

const LowdbPersistenceAdapter = require("ask-lowdb-persistence-adapter");
const S3PersistenceAdapter = require("ask-sdk-s3-persistence-adapter")
  .S3PersistenceAdapter;

class PersistenceAdapterFactory {
  constructor(s3BucketName) {
    this.s3BucketName = s3BucketName;
  }

  createPersistenceAdapter() {
    if (this.s3BucketName) {
      return new S3PersistenceAdapter({
        bucketName: this.s3BucketName,
      });
    } else {
      return new LowdbPersistenceAdapter();
    }
  }
}

// ...

const persistenceAdapterFactory = new PersistenceAdapterFactory(
  process.env.S3_PERSISTENCE_BUCKET
);

Alexa.SkillBuilders.custom()
  .withPersistenceAdapter(persistenceAdapterFactory.createPersistenceAdapter())
  .addRequestHandlers(/* ... */)
  .lambda();

Keywords

FAQs

Package last updated on 03 Sep 2020

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