@absolutejs/auth 0.26.0-beta.1 → 0.26.0-beta.2

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.
package/dist/index.d.ts CHANGED
@@ -1189,5 +1189,7 @@ export * from './lockout/config';
1189
1189
  export * from './lockout/types';
1190
1190
  export { createInMemoryLockoutStore } from './lockout/inMemoryLockoutStore';
1191
1191
  export { createNeonLockoutStore, createPostgresLockoutStore, lockoutsTable } from './lockout/postgresLockoutStore';
1192
+ export { createRedisLockoutStore } from './lockout/redisLockoutStore';
1193
+ export type { RedisLike } from './stores/redis';
1192
1194
  export { createInMemoryAuditSink } from './audit/inMemoryAuditStore';
1193
1195
  export { auditEventsTable, createNeonAuditSink, createPostgresAuditSink } from './audit/postgresAuditStore';
package/dist/index.js CHANGED
@@ -15167,6 +15167,53 @@ var createPostgresLockoutStore = (db) => {
15167
15167
  }
15168
15168
  };
15169
15169
  };
15170
+ // src/lockout/redisLockoutStore.ts
15171
+ var DEFAULT_PREFIX = "auth:lockout:";
15172
+ var toRecord2 = (raw, key) => {
15173
+ const parsed = JSON.parse(raw);
15174
+ if (typeof parsed !== "object" || parsed === null)
15175
+ return;
15176
+ const failedAttempts = Reflect.get(parsed, "failedAttempts");
15177
+ const windowStartedAt = Reflect.get(parsed, "windowStartedAt");
15178
+ const lockedUntil = Reflect.get(parsed, "lockedUntil");
15179
+ if (typeof failedAttempts !== "number" || typeof windowStartedAt !== "number") {
15180
+ return;
15181
+ }
15182
+ return {
15183
+ failedAttempts,
15184
+ key,
15185
+ lockedUntil: typeof lockedUntil === "number" ? lockedUntil : undefined,
15186
+ windowStartedAt
15187
+ };
15188
+ };
15189
+ var createRedisLockoutStore = (redis, keyPrefix = DEFAULT_PREFIX) => {
15190
+ const read = async (key) => {
15191
+ const raw = await redis.get(keyPrefix + key);
15192
+ return raw ? toRecord2(raw, key) : undefined;
15193
+ };
15194
+ return {
15195
+ get: read,
15196
+ increment: async (key, windowMs) => {
15197
+ const now = Date.now();
15198
+ const existing = await read(key);
15199
+ const next = existing !== undefined && now - existing.windowStartedAt <= windowMs ? { ...existing, failedAttempts: existing.failedAttempts + 1 } : { failedAttempts: 1, key, windowStartedAt: now };
15200
+ await redis.set(keyPrefix + key, JSON.stringify(next), windowMs);
15201
+ return next;
15202
+ },
15203
+ lock: async (key, lockedUntil) => {
15204
+ const existing = await read(key) ?? {
15205
+ failedAttempts: 0,
15206
+ key,
15207
+ windowStartedAt: Date.now()
15208
+ };
15209
+ const ttlMs = Math.max(lockedUntil - Date.now(), 1);
15210
+ await redis.set(keyPrefix + key, JSON.stringify({ ...existing, lockedUntil }), ttlMs);
15211
+ },
15212
+ reset: async (key) => {
15213
+ await redis.del(keyPrefix + key);
15214
+ }
15215
+ };
15216
+ };
15170
15217
  // src/audit/inMemoryAuditStore.ts
15171
15218
  var createInMemoryAuditSink = () => {
15172
15219
  const events = [];
@@ -15394,6 +15441,7 @@ export {
15394
15441
  credentialRoutes,
15395
15442
  credentialResetTokensTable,
15396
15443
  createTotpKeyUri,
15444
+ createRedisLockoutStore,
15397
15445
  createPostgresMfaStore,
15398
15446
  createPostgresLockoutStore,
15399
15447
  createPostgresCredentialStore,
@@ -15437,5 +15485,5 @@ export {
15437
15485
  AuthIdentityConflictError
15438
15486
  };
15439
15487
 
15440
- //# debugId=B747E5842F47E36264756E2164756E21
15488
+ //# debugId=44D2758802359A7064756E2164756E21
15441
15489
  //# sourceMappingURL=index.js.map