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

supabase / supabase-js / 16300970139

15 Jul 2025 06:11PM UTC coverage: 68.536% (-4.4%) from 72.889%
16300970139

Pull #1505

github

web-flow
Merge ad01a02d3 into 184421505
Pull Request #1505: feat: add missing HTTP headers for client platform and runtime detection

78 of 136 branches covered (57.35%)

Branch coverage included in aggregate %.

34 of 54 new or added lines in 1 file covered. (62.96%)

142 of 185 relevant lines covered (76.76%)

21.16 hits per line

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

60.17
/src/lib/constants.ts
1
// constants.ts
2
import { RealtimeClientOptions } from '@supabase/realtime-js'
3
import { SupabaseAuthClientOptions } from './types'
4
import { version } from './version'
12✔
5

6
let JS_ENV = ''
12✔
7
// @ts-ignore
8
if (typeof Deno !== 'undefined') {
12!
9
  JS_ENV = 'deno'
×
10
} else if (typeof document !== 'undefined') {
12!
11
  JS_ENV = 'web'
×
12
} else if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {
12!
13
  JS_ENV = 'react-native'
×
14
} else {
15
  JS_ENV = 'node'
12✔
16
}
17

18
export function getClientPlatform(): string | null {
12✔
19
  // @ts-ignore
20
  if (typeof process !== 'undefined' && process.platform) {
15✔
21
    // @ts-ignore
22
    const platform = process.platform
15✔
23
    if (platform === 'darwin') return 'macOS'
15✔
24
    if (platform === 'win32') return 'Windows'
10✔
25
    if (platform === 'linux') return 'Linux'
5✔
NEW
26
    if (platform === 'android') return 'Android'
×
27
  }
28

29
  // @ts-ignore
NEW
30
  if (typeof navigator !== 'undefined') {
×
31
    // Modern User-Agent Client Hints API
32
    // @ts-ignore
NEW
33
    if (navigator.userAgentData && navigator.userAgentData.platform) {
×
34
      // @ts-ignore
NEW
35
      const platform = navigator.userAgentData.platform
×
NEW
36
      if (platform === 'macOS') return 'macOS'
×
NEW
37
      if (platform === 'Windows') return 'Windows'
×
NEW
38
      if (platform === 'Linux') return 'Linux'
×
NEW
39
      if (platform === 'Android') return 'Android'
×
NEW
40
      if (platform === 'iOS') return 'iOS'
×
41
    }
42
  }
43

NEW
44
  return null
×
45
}
46

47
export function getClientPlatformVersion(): string | null {
12✔
48
  // @ts-ignore
49
  if (typeof process !== 'undefined' && process.version) {
15✔
50
    // @ts-ignore
51
    return process.version.slice(1)
15✔
52
  }
53

54
  // @ts-ignore
NEW
55
  if (typeof navigator !== 'undefined') {
×
56
    // Modern User-Agent Client Hints API
57
    // @ts-ignore
NEW
58
    if (navigator.userAgentData && navigator.userAgentData.platformVersion) {
×
59
      // @ts-ignore
NEW
60
      return navigator.userAgentData.platformVersion
×
61
    }
62
  }
63

NEW
64
  return null
×
65
}
66

67
export function getClientRuntime(): string | null {
12✔
68
  // @ts-ignore
69
  if (typeof Deno !== 'undefined') {
15!
NEW
70
    return 'deno'
×
71
  }
72
  // @ts-ignore
73
  if (typeof Bun !== 'undefined') {
15!
NEW
74
    return 'bun'
×
75
  }
76
  // @ts-ignore
77
  if (typeof process !== 'undefined' && process.versions && process.versions.node) {
15✔
78
    return 'node'
15✔
79
  }
NEW
80
  return null
×
81
}
82

83
export function getClientRuntimeVersion(): string | null {
12✔
84
  // @ts-ignore
85
  if (typeof Deno !== 'undefined' && Deno.version) {
15!
86
    // @ts-ignore
NEW
87
    return Deno.version.deno
×
88
  }
89
  // @ts-ignore
90
  if (typeof Bun !== 'undefined' && Bun.version) {
15!
91
    // @ts-ignore
NEW
92
    return Bun.version
×
93
  }
94
  // @ts-ignore
95
  if (typeof process !== 'undefined' && process.versions && process.versions.node) {
15✔
96
    // @ts-ignore
97
    return process.versions.node
15✔
98
  }
NEW
99
  return null
×
100
}
101

102
function buildHeaders() {
103
  const headers: Record<string, string> = {
12✔
104
    'X-Client-Info': `supabase-js-${JS_ENV}/${version}`,
105
  }
106

107
  const platform = getClientPlatform()
12✔
108
  if (platform) {
12✔
109
    headers['X-Supabase-Client-Platform'] = platform
12✔
110
  }
111

112
  const platformVersion = getClientPlatformVersion()
12✔
113
  if (platformVersion) {
12✔
114
    headers['X-Supabase-Client-Platform-Version'] = platformVersion
12✔
115
  }
116

117
  const runtime = getClientRuntime()
12✔
118
  if (runtime) {
12✔
119
    headers['X-Supabase-Client-Runtime'] = runtime
12✔
120
  }
121

122
  const runtimeVersion = getClientRuntimeVersion()
12✔
123
  if (runtimeVersion) {
12✔
124
    headers['X-Supabase-Client-Runtime-Version'] = runtimeVersion
12✔
125
  }
126

127
  return headers
12✔
128
}
129

130
export const DEFAULT_HEADERS = buildHeaders()
12✔
131

132
export const DEFAULT_GLOBAL_OPTIONS = {
12✔
133
  headers: DEFAULT_HEADERS,
134
}
135

136
export const DEFAULT_DB_OPTIONS = {
12✔
137
  schema: 'public',
138
}
139

140
export const DEFAULT_AUTH_OPTIONS: SupabaseAuthClientOptions = {
12✔
141
  autoRefreshToken: true,
142
  persistSession: true,
143
  detectSessionInUrl: true,
144
  flowType: 'implicit',
145
}
146

147
export const DEFAULT_REALTIME_OPTIONS: RealtimeClientOptions = {}
12✔
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

© 2025 Coveralls, Inc