@mulingai-npm/redis 3.25.0 → 3.26.0

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.
@@ -11,7 +11,6 @@ export type MulingstreamSpeakerData = {
11
11
  recordingsDuration: number;
12
12
  targetLanguages: string[];
13
13
  timestamp: string;
14
- isEmailVerified: boolean;
15
14
  };
16
15
  export declare class MulingstreamSpeakerManager {
17
16
  private redisClient;
@@ -32,8 +32,7 @@ class MulingstreamSpeakerManager {
32
32
  prompts: hash.prompts,
33
33
  recordingsDuration: parseInt(hash.recordingsDuration, 10) || 0,
34
34
  targetLanguages: JSON.parse(hash.targetLanguages || '[]'),
35
- timestamp: hash.timestamp,
36
- isEmailVerified: hash.isEmailVerified === 'true'
35
+ timestamp: hash.timestamp
37
36
  };
38
37
  }
39
38
  serialize(data) {
@@ -47,8 +46,7 @@ class MulingstreamSpeakerManager {
47
46
  prompts: data.prompts,
48
47
  recordingsDuration: data.recordingsDuration.toString(),
49
48
  targetLanguages: JSON.stringify(data.targetLanguages),
50
- timestamp: data.timestamp,
51
- isEmailVerified: data.isEmailVerified.toString()
49
+ timestamp: data.timestamp
52
50
  };
53
51
  if (data.roomUuid) {
54
52
  result.roomUuid = data.roomUuid;
@@ -1,22 +1,32 @@
1
1
  import { RedisClient } from '../redis-client';
2
2
  /**
3
- * Cached user profile data - minimal data needed for quick lookups
3
+ * Cached user profile data
4
+ * Includes account verification status + billing consumption status
4
5
  */
5
6
  export interface CachedUserProfile {
6
7
  userId: string;
7
8
  email: string;
8
9
  name: string | null;
10
+ preferredLanguage: string;
9
11
  isEmailVerified: boolean;
12
+ isPhoneVerified: boolean;
13
+ isProfileActivated: boolean;
14
+ canConsume: boolean;
10
15
  cachedAt: string;
11
16
  }
12
17
  /**
13
18
  * Redis manager for caching user profile data
14
- * Used to avoid expensive database queries on every request
15
19
  *
16
- * Cache invalidation should happen on:
17
- * - Email verification
18
- * - Profile update
19
- * - Account deletion
20
+ * Cache Strategy:
21
+ * - Cache on: sign in, profile fetch, profile change
22
+ * - Invalidate on: email verification, profile update, account deletion
23
+ * - TTL: 24 hours (but usually invalidated before expiry)
24
+ *
25
+ * Usage:
26
+ * - auth-service: cache on sign in / profile fetch
27
+ * - auth-service: invalidate + re-cache on email verification
28
+ * - speaker-realtime-service: get cached profile on speaker join
29
+ * - pipeline-service: check canConsume during recording
20
30
  */
21
31
  export declare class UserProfileManager {
22
32
  private redisClient;
@@ -32,18 +42,12 @@ export declare class UserProfileManager {
32
42
  */
33
43
  getUserProfile(userId: string): Promise<CachedUserProfile | null>;
34
44
  /**
35
- * Check if user email is verified (quick lookup)
36
- * Returns null if not cached
37
- */
38
- isEmailVerified(userId: string): Promise<boolean | null>;
39
- /**
40
- * Invalidate user profile cache
41
- * Call this when profile data changes (verification, update, etc.)
45
+ * Invalidate (delete) user profile cache
46
+ * Call before re-caching on profile changes
42
47
  */
43
48
  invalidateUserProfile(userId: string): Promise<void>;
44
49
  /**
45
- * Update only the email verification status in cache
46
- * More efficient than full invalidation when only verification changes
50
+ * Check if user profile is cached
47
51
  */
48
- updateEmailVerificationStatus(userId: string, isVerified: boolean): Promise<boolean>;
52
+ hasUserProfile(userId: string): Promise<boolean>;
49
53
  }
@@ -1,16 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.UserProfileManager = void 0;
4
- // Cache for 1 hour
5
- const CACHE_EXPIRATION = 60 * 60;
4
+ // Cache for 24 hours - invalidated on profile changes
5
+ const CACHE_TTL = 24 * 60 * 60;
6
6
  /**
7
7
  * Redis manager for caching user profile data
8
- * Used to avoid expensive database queries on every request
9
8
  *
10
- * Cache invalidation should happen on:
11
- * - Email verification
12
- * - Profile update
13
- * - Account deletion
9
+ * Cache Strategy:
10
+ * - Cache on: sign in, profile fetch, profile change
11
+ * - Invalidate on: email verification, profile update, account deletion
12
+ * - TTL: 24 hours (but usually invalidated before expiry)
13
+ *
14
+ * Usage:
15
+ * - auth-service: cache on sign in / profile fetch
16
+ * - auth-service: invalidate + re-cache on email verification
17
+ * - speaker-realtime-service: get cached profile on speaker join
18
+ * - pipeline-service: check canConsume during recording
14
19
  */
15
20
  class UserProfileManager {
16
21
  constructor(redisClient) {
@@ -29,7 +34,7 @@ class UserProfileManager {
29
34
  cachedAt: new Date().toISOString()
30
35
  };
31
36
  await this.redisClient.set(key, JSON.stringify(data));
32
- await this.redisClient.expire(key, CACHE_EXPIRATION);
37
+ await this.redisClient.expire(key, CACHE_TTL);
33
38
  }
34
39
  /**
35
40
  * Get cached user profile
@@ -45,42 +50,24 @@ class UserProfileManager {
45
50
  return JSON.parse(data);
46
51
  }
47
52
  catch {
48
- // Invalid JSON, delete and return null
49
53
  await this.redisClient.del(key);
50
54
  return null;
51
55
  }
52
56
  }
53
57
  /**
54
- * Check if user email is verified (quick lookup)
55
- * Returns null if not cached
56
- */
57
- async isEmailVerified(userId) {
58
- const profile = await this.getUserProfile(userId);
59
- return profile ? profile.isEmailVerified : null;
60
- }
61
- /**
62
- * Invalidate user profile cache
63
- * Call this when profile data changes (verification, update, etc.)
58
+ * Invalidate (delete) user profile cache
59
+ * Call before re-caching on profile changes
64
60
  */
65
61
  async invalidateUserProfile(userId) {
66
62
  const key = this.buildKey(userId);
67
63
  await this.redisClient.del(key);
68
64
  }
69
65
  /**
70
- * Update only the email verification status in cache
71
- * More efficient than full invalidation when only verification changes
66
+ * Check if user profile is cached
72
67
  */
73
- async updateEmailVerificationStatus(userId, isVerified) {
74
- const profile = await this.getUserProfile(userId);
75
- if (profile === null) {
76
- return false;
77
- }
78
- profile.isEmailVerified = isVerified;
79
- profile.cachedAt = new Date().toISOString();
68
+ async hasUserProfile(userId) {
80
69
  const key = this.buildKey(userId);
81
- await this.redisClient.set(key, JSON.stringify(profile));
82
- await this.redisClient.expire(key, CACHE_EXPIRATION);
83
- return true;
70
+ return (await this.redisClient.exists(key)) === 1;
84
71
  }
85
72
  }
86
73
  exports.UserProfileManager = UserProfileManager;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mulingai-npm/redis",
3
- "version": "3.25.0",
3
+ "version": "3.26.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": {