1.7.1 • Published 2 years ago

@arcblock/did-auth-storage v1.7.1

Weekly downloads
259
License
Apache-2.0
Repository
github
Last release
2 years ago

@arcblock/did-auth-storage

styled with prettier

Interface for define a storage class that can be used by @arcblock/did-auth.

Table of Contents

Motivation & Spec

Since tokens are used everywhere make achieve better QR code experience, we should allow users to customize how to generate/store/update token records.

Basic APIs that a token storage should support:

  • async init(), optional, should be called before creating any instance, open a database connection, creating a embed database on file system
  • async create(token, status = created), create a new token record, persist in data store
  • async exist?(token, did), check for token existense
  • async read(token), read a token from database,
  • async update(token, updates), update token record
  • async delete(token), remove a token record
  • async gc(), optional, run garbage collection on the token storage

Plan to support:

  • token-storage-mongo
  • token-storage-psql
  • token-storage-nedb
  • token-storage-memory

Install

npm install @arcblock/did-auth-storage
// or
yarn add @arcblock/did-auth-storage

Usage

const StorageInterface = require('@arcblock/did-auth-storage');
const keystone = require('keystone');

module.exports = class KeystoneStorage extends StorageInterface {
  constructor() {
    this.model = keystone.list('LoginToken').model;
  }

  create(token, status = 'created') {
    const LoginToken = this.model;
    const item = new LoginToken({ token, status });
    return item.save();
  }

  read(token) {
    return this.model.findOne({ token });
  }

  update(token, updates) {
    return this.model.findOneAndUpdate({ token }, updates);
  }

  delete(token) {
    return this.model.remove({ token });
  }

  exist(token, did) {
    return this.model.findOne({ token, did });
  }
};

Contributors

NameWebsite
wangshijunhttps://ocap.arcblock.io
1.7.1

2 years ago

1.7.0

2 years ago

1.6.3

3 years ago

1.6.2

3 years ago

1.6.1

3 years ago

1.6.0

3 years ago

1.5.8

3 years ago

1.5.7

3 years ago

1.5.6

3 years ago

1.5.5

3 years ago

1.5.4

3 years ago

1.5.3

3 years ago

1.5.2

3 years ago

1.5.1

3 years ago

1.5.0

3 years ago

1.4.8

3 years ago

1.4.7

3 years ago

1.4.6

3 years ago

1.4.5

3 years ago

1.4.4

3 years ago

1.4.3

3 years ago

1.4.2

4 years ago

1.4.1

4 years ago

1.4.0

4 years ago

1.2.7

4 years ago

1.0.13

4 years ago

1.0.0

4 years ago

0.41.0

4 years ago

0.40.10

5 years ago

0.40.9

5 years ago

0.40.6

5 years ago

0.40.5

5 years ago

0.40.0

5 years ago

0.39.7

5 years ago

0.39.3

5 years ago

0.39.1

5 years ago

0.39.0

5 years ago

0.38.10

5 years ago

0.21.1

5 years ago

0.21.0

5 years ago

0.20.1

5 years ago

0.20.0

5 years ago

0.19.0

5 years ago

0.18.0

5 years ago

0.17.1

5 years ago

0.17.0

5 years ago

0.16.0

5 years ago

0.15.2

5 years ago

0.15.1

5 years ago