@arcblock/app-agent-storage

0.40.9 • Public • Published

@arcblock/app-agent-storage

styled with prettier

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

Table of Contents

Motivation & Spec

Fields

Possible fields to exist in a did-agent storage record

  • authorizeId: Primary key
  • ownerDid: Owner DID
  • agentDid: Agent DID
  • appDid: Application DID
  • appPk: Application public key
  • appName: Application name
  • appDescription: Application description
  • appLogo: Application logo
  • certificate: Application authorize certificate

APIs

Basic APIs that a did-agent storage should support:

  • create(authorizeId, payload): 创建记录
  • update(authorizeId, updates): 更新记录
  • read(authorizeId):按 authorizeId 查询
  • delete(authorizeId):删除记录
  • listByApp(appDid): 按应用查询
  • listByOwner(ownerDid): 按所有者查询

Install

npm install @arcblock/app-agent-storage
// or
yarn add @arcblock/app-agent-storage

Usage

const StorageInterface = require('@arcblock/app-agent-storage');

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

Name Website
wangshijun https://ocap.arcblock.io

Package Sidebar

Install

npm i @arcblock/app-agent-storage

Weekly Downloads

1

Version

0.40.9

License

Apache-2.0

Unpacked Size

6.3 kB

Total Files

5

Last publish

Collaborators

  • gxw
  • mave99a
  • polunzh
  • wangshijun