npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

tms-koa-bucket

v0.1.2

Published

tms-koa实现基于bucket的租户分离

Downloads

145

Readme

通过创建 bucket,实现数据逻辑隔离。

环境变量

| 环境变量 | 说明 | 默认值 | | ---------------------------------------- | --------------------------------------------------------------------------------- | --------- | | TMS_KOA_BUCKET_DB | 存放管理数据的数据库。 | tms_admin | | TMS_KOA_META_ADMIN_DB | 存放管理数据的数据库。 | tms_admin | | TMS_KOA_BUCKET_CL | 存放空间管理数据的集合。 | bucket | | TMS_KOA_BUCKET_COWORKER_CL | 存放空间要求管理数据的集合。 | bucket | | TMS_KOA_BUCKET_COWORKER_INVITE_EXPIRE_MS | 邀请有效期。 | 30 分钟 | | TMS_KOA_BUCKET_COWORKER_USERNAME_AS_ID | 用户名称与用户 ID 一致,并且作为接受邀请检查条件。可选值:no/yes. | yes | | TMS_KOA_BUCKET_RANDOM_NAME_SIZE | 自动生成的空间名称的长度。如果不指定,就不自动生成。最少 6 位,建议设置为 21 位。 | 无 |

api

新建 bucket

curl 'http://localhost:3009/api/bucket/admin/bucket/create' -H 'content-type: application/json' -H 'authorization: Bearer accesstoken01' -d '{"name": "test01", "title": "测试01"}'
{
  "msg": "正常",
  "code": 0,
  "result": {
    "name": "test01",
    "title": "测试01",
    "creator": "app01",
    "createAt": "2025-04-04T09:09:40.299Z",
    "_id": "67efa1d44b21209ee232dbd8"
  }
}

注意:createAt是 ISO 格式,差 8 小时。

查看用户的 bucket

curl 'http://localhost:3009/api/bucket/admin/bucket/list' -H 'content-type: application/json'  -H 'authorization: Bearer accesstoken01' -d '{"name": "test01", "title": "测试01"}'
{
  "msg": "正常",
  "code": 0,
  "result": [
    {
      "_id": "67ecf83aa9aae9785a138db9",
      "name": "test01",
      "title": "测试01",
      "creator": "app01",
      "createAt": "2025-04-04T09:09:20.199Z"
    },
    {
      "_id": "67efa1d44b21209ee232dbd8",
      "name": "test02",
      "title": "测试02",
      "creator": "app01",
      "createAt": "2025-04-04T09:09:40.299Z"
    }
  ]
}

包含用户创建的空间和被邀请加入的空间。

更新 bucket

curl 'http://localhost:3009/api/bucket/admin/bucket/update?bucket=test01' -H 'content-type: application/json' -H 'authorization: Bearer  accesstoken01' -d '{"title": "测试01_1"}'
{ "msg": "正常", "code": 0, "result": { "title": "测试05_1" } }

注意:无法修改namecreator字段。

删除 bucket

curl 'http://localhost:3009/api/bucket/admin/bucket/remove?bucket=test01' -H 'authorization: Bearer accesstoken01'
{ "msg": "正常", "code": 0, "result": "ok" }

邀请加入 bucket

curl 'http://localhost:3009/api/bucket/admin/coworker/invite?bucket=test01' -H "authorization: Bearer accesstoken01" -H 'content-type: application/json' -d '{"username": "alice"}'

注意:只允许空间的创建人发起邀请。

{ "msg": "正常", "code": 0, "result": "xxxx" }

查看所有邀请

curl 'http://localhost:3009/api/bucket/admin/coworker/list?bucket=test01' -H 'authorization: Bearer accesstoken01'
{
  "msg": "正常",
  "code": 0,
  "result": [
    {
      "_id": "67ef95c71c3b85fb3140b2da",
      "inviter": "app01",
      "bucket": "test01",
      "code": "l5AF",
      "createAt": "2025-04-04T08:18:15.431Z",
      "coworker": {
        "username": "alice",
        "id": "alice"
      },
      "acceptAt": "2025-04-04T08:18:34.737Z"
    }
  ]
}

接受邀请

curl 'http://localhost:3009/api/bucket/admin/coworker/accept?bucket=test01' -H 'content-type: application/json' -H "authorization: Bearer $access_token" -d '{"code": "98Ef", "username": "alice"}'
{ "msg": "正常", "code": 0, "result": "ok" }

查看空间(含被邀请的)

curl 'http://localhost:3009/api/bucket/admin/bucket/list' -H "authorization: Bearer $access_token"
{
  "msg": "正常",
  "code": 0,
  "result": [
    {
      "name": "test01",
      "title": "测试01",
      "creator": "app01",
      "createAt": "2025-04-04T09:09:30.199Z"
    },
    {
      "name": "test05",
      "title": "测试05",
      "creator": "app01",
      "createAt": "2025-04-04T09:09:40.299Z"
    }
  ]
}

注意:没有提供bucket_id

取消邀请

curl 'http://localhost:3009/api/bucket/admin/coworker/remove?bucket=test01&username=alice' -H 'authorization: Bearer accesstoken01'
{ "msg": "正常", "code": 0, "result": "ok" }

自定义属性

配置文件bucket.js

export default {
  disabled: true,
  schemas: {},
  schemasRootName: '',
}