@mulingai-npm/redis 3.38.8 → 3.38.10

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.
@@ -9,7 +9,7 @@ import { RedisClient } from '../redis-client';
9
9
  * - demo:pool:all (Set) All demo room IDs
10
10
  * - demo:pool:available (Set) Currently available room IDs
11
11
  * - demo:pool:room:{id}:session (Hash) Active session info per room
12
- * - demo:ratelimit:email:{hash} (Counter) Demos per email per 24h
12
+ * - demo:ratelimit:ip:{hash} (Counter) Demos per IP per 24h
13
13
  */
14
14
  export declare class DemoRoomPoolManager {
15
15
  private redisClient;
@@ -31,7 +31,7 @@ export declare class DemoRoomPoolManager {
31
31
  * Atomic: SPOP removes from available set in one operation.
32
32
  * If no rooms available, attempts to reclaim rooms with expired sessions first.
33
33
  */
34
- assignRoom(emailHash: string, demoSessionId: string, durationMs: number, email?: string): Promise<{
34
+ assignRoom(identifierHash: string, demoSessionId: string, durationMs: number): Promise<{
35
35
  roomId: number;
36
36
  expiresAt: number;
37
37
  } | null>;
@@ -56,17 +56,21 @@ export declare class DemoRoomPoolManager {
56
56
  * Get session info for a room.
57
57
  */
58
58
  getSession(roomId: number): Promise<{
59
- emailHash: string;
59
+ identifierHash: string;
60
60
  demoSessionId: string;
61
61
  startedAt: number;
62
62
  expiresAt: number;
63
63
  } | null>;
64
64
  /**
65
- * Check email rate limit. Returns true if under limit, false if exceeded.
65
+ * Check IP rate limit. Returns true if under limit, false if exceeded.
66
66
  */
67
- checkEmailRateLimit(emailHash: string, max?: number): Promise<boolean>;
67
+ checkIpRateLimit(ipHash: string, max?: number): Promise<boolean>;
68
68
  /**
69
- * Increment email rate limit counter with 24h TTL.
69
+ * Increment IP rate limit counter with 24h TTL.
70
70
  */
71
- incrementEmailRateLimit(emailHash: string): Promise<void>;
71
+ incrementIpRateLimit(ipHash: string): Promise<void>;
72
+ /**
73
+ * Get demo chunks for export.
74
+ */
75
+ getDemoChunks(demoSessionId: string): Promise<string[]>;
72
76
  }
@@ -11,7 +11,7 @@ exports.DemoRoomPoolManager = void 0;
11
11
  * - demo:pool:all (Set) All demo room IDs
12
12
  * - demo:pool:available (Set) Currently available room IDs
13
13
  * - demo:pool:room:{id}:session (Hash) Active session info per room
14
- * - demo:ratelimit:email:{hash} (Counter) Demos per email per 24h
14
+ * - demo:ratelimit:ip:{hash} (Counter) Demos per IP per 24h
15
15
  */
16
16
  class DemoRoomPoolManager {
17
17
  constructor(redisClient) {
@@ -70,7 +70,7 @@ class DemoRoomPoolManager {
70
70
  * Atomic: SPOP removes from available set in one operation.
71
71
  * If no rooms available, attempts to reclaim rooms with expired sessions first.
72
72
  */
73
- async assignRoom(emailHash, demoSessionId, durationMs, email) {
73
+ async assignRoom(identifierHash, demoSessionId, durationMs) {
74
74
  // Atomic pop from available set
75
75
  let roomIdStr = await this.redisClient.spop('demo:pool:available');
76
76
  // If no rooms available, try reclaiming expired sessions
@@ -87,8 +87,7 @@ class DemoRoomPoolManager {
87
87
  const expiresAt = now + durationMs;
88
88
  // Store session info
89
89
  await this.redisClient.hset(`demo:pool:room:${roomId}:session`, {
90
- emailHash,
91
- email: email || '',
90
+ identifierHash,
92
91
  demoSessionId,
93
92
  startedAt: now.toString(),
94
93
  expiresAt: expiresAt.toString(),
@@ -149,26 +148,33 @@ class DemoRoomPoolManager {
149
148
  if (!(data === null || data === void 0 ? void 0 : data.demoSessionId))
150
149
  return null;
151
150
  return {
152
- emailHash: data.emailHash,
151
+ identifierHash: data.identifierHash,
153
152
  demoSessionId: data.demoSessionId,
154
153
  startedAt: parseInt(data.startedAt),
155
154
  expiresAt: parseInt(data.expiresAt)
156
155
  };
157
156
  }
158
157
  /**
159
- * Check email rate limit. Returns true if under limit, false if exceeded.
158
+ * Check IP rate limit. Returns true if under limit, false if exceeded.
160
159
  */
161
- async checkEmailRateLimit(emailHash, max = 3) {
162
- const count = await this.redisClient.get(`demo:ratelimit:email:${emailHash}`);
160
+ async checkIpRateLimit(ipHash, max = 2) {
161
+ const count = await this.redisClient.get(`demo:ratelimit:ip:${ipHash}`);
163
162
  return !count || parseInt(count) < max;
164
163
  }
165
164
  /**
166
- * Increment email rate limit counter with 24h TTL.
165
+ * Increment IP rate limit counter with 24h TTL.
167
166
  */
168
- async incrementEmailRateLimit(emailHash) {
169
- const key = `demo:ratelimit:email:${emailHash}`;
167
+ async incrementIpRateLimit(ipHash) {
168
+ const key = `demo:ratelimit:ip:${ipHash}`;
170
169
  await this.redisClient.incr(key);
171
- await this.redisClient.expire(key, 86400); // 24h
170
+ await this.redisClient.expire(key, 86400);
171
+ }
172
+ /**
173
+ * Get demo chunks for export.
174
+ */
175
+ async getDemoChunks(demoSessionId) {
176
+ const key = `demo:session:${demoSessionId}:chunks`;
177
+ return await this.redisClient.lrange(key, 0, -1);
172
178
  }
173
179
  }
174
180
  exports.DemoRoomPoolManager = DemoRoomPoolManager;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mulingai-npm/redis",
3
- "version": "3.38.8",
3
+ "version": "3.38.10",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": {