• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

cameri / nostream / 26300017967

22 May 2026 04:37PM UTC coverage: 36.478% (-28.6%) from 65.107%
26300017967

Pull #622

github

web-flow
Merge cbfcf131b into 36e5af87e
Pull Request #622: feat: add NIP-42 client authentication

791 of 3191 branches covered (24.79%)

Branch coverage included in aggregate %.

21 of 63 new or added lines in 6 files covered. (33.33%)

1585 existing lines in 77 files now uncovered.

2608 of 6127 relevant lines covered (42.57%)

17.63 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

67.86
/src/cache/client.ts
1
import { createClient, RedisClientOptions } from 'redis'
2✔
2
import { CacheClient } from '../@types/cache'
3
import { createLogger } from '../factories/logger-factory'
2✔
4

5
const logger = createLogger('cache-client')
2✔
6

7
const redactRedisUrlCredentials = (url: string): string => {
2✔
8
  try {
1✔
9
    const parsedUrl = new URL(url)
1✔
10

11
    if (!parsedUrl.username && !parsedUrl.password) {
1!
12
      return url
1✔
13
    }
14

15
    parsedUrl.username = parsedUrl.username ? '***' : ''
×
16
    parsedUrl.password = parsedUrl.password ? '***' : ''
×
17

18
    return parsedUrl.toString()
×
19
  } catch {
20
    return url
×
21
  }
22
}
23

24
export const getCacheConfig = (): RedisClientOptions => {
2✔
25
  const password = process.env.REDIS_PASSWORD
2✔
26

27
  if (process.env.REDIS_URI) {
2!
UNCOV
28
    return {
×
29
      url: process.env.REDIS_URI,
30
      ...(password ? { password } : {}),
×
31
    }
32
  }
33

34
  const host = process.env.REDIS_HOST
2✔
35
  const port = process.env.REDIS_PORT
2✔
36

37
  if (password) {
2!
38
    const username = process.env.REDIS_USER ?? 'default'
2!
39

40
    return {
2✔
41
      url: `redis://${host}:${port}`,
42
      username,
43
      password,
44
    }
45
  }
46

UNCOV
47
  return {
×
48
    url: `redis://${host}:${port}`,
49
  }
50
}
51

52
let instance: CacheClient | undefined = undefined
2✔
53

54
export const getCacheClient = (): CacheClient => {
2✔
55
  if (!instance) {
2✔
56
    const config = getCacheConfig()
1✔
57
    // eslint-disable-next-line @typescript-eslint/no-unused-vars
58
    const { password: _, ...loggableConfig } = config
1✔
59
    logger('config: %o', {
1✔
60
      ...loggableConfig,
61
      ...(loggableConfig.url ? { url: redactRedisUrlCredentials(loggableConfig.url) } : {}),
1!
62
    })
63
    instance = createClient(config)
1✔
64
  }
65

66
  return instance
2✔
67
}
68

69
export const closeCacheClient = async (): Promise<void> => {
2✔
70
  if (instance?.isOpen) {
1!
71
    await instance.disconnect()
1✔
72
    instance = undefined
1✔
73
  }
74
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc