@kne/fastify-oidc 0.1.5 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,6 +12,10 @@ module.exports = fp(async (fastify, options) => {
12
12
  const { Op } = fastify.sequelize.Sequelize;
13
13
  const secret = options.keyEncryptionSecret;
14
14
 
15
+ // 文件型 sqlite 下 sequelize 会为每个事务单独打开一个连接,与默认连接上其他插件的写入争抢文件锁而 SQLITE_BUSY;
16
+ // sqlite 只用于单进程本地开发,直接在共享的默认连接上执行,同一连接内的写入天然串行
17
+ const withTransaction = fn => (fastify.sequelize.instance.getDialect() === 'sqlite' ? fn() : fastify.sequelize.instance.transaction(fn));
18
+
15
19
  const generate = async ({ status, transaction }) => {
16
20
  const { privateKey, publicKey } = crypto.generateKeyPairSync('rsa', { modulusLength: 2048 });
17
21
  const kid = crypto.randomUUID();
@@ -42,7 +46,7 @@ module.exports = fp(async (fastify, options) => {
42
46
  };
43
47
 
44
48
  const ensureKeys = async () => {
45
- await fastify.sequelize.instance.transaction(async transaction => {
49
+ await withTransaction(async transaction => {
46
50
  if (!(await models.key.count({ where: { status: 'active' }, transaction }))) {
47
51
  await generate({ status: 'active', transaction });
48
52
  }
@@ -83,7 +87,7 @@ module.exports = fp(async (fastify, options) => {
83
87
  };
84
88
 
85
89
  const rotate = async () => {
86
- await fastify.sequelize.instance.transaction(async transaction => {
90
+ await withTransaction(async transaction => {
87
91
  const now = new Date();
88
92
  await models.key.update({ status: 'retired', retiredAt: now }, { where: { status: 'active' }, transaction });
89
93
  const next = await models.key.findOne({ where: { status: 'next' }, order: [['createdAt', 'ASC']], transaction });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kne/fastify-oidc",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "基于 oidc-provider 的 Fastify OIDC 认证插件,支持 standalone / central 多项目单点登录、租户与跨项目令牌",
5
5
  "main": "index.js",
6
6
  "scripts": {