Skip to content

Commit ed5a3d4

Browse files
authored
feat: track javascript environment. (#854)
1 parent 8cf2b96 commit ed5a3d4

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/lib/constants.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
11
// constants.ts
22
import { version } from './version'
3-
export const DEFAULT_HEADERS = { 'X-Client-Info': `supabase-js/${version}` }
3+
let JS_ENV = ''
4+
// @ts-ignore
5+
if (typeof Deno !== 'undefined') {
6+
JS_ENV = 'deno'
7+
} else if (typeof document !== 'undefined') {
8+
JS_ENV = 'web'
9+
} else if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {
10+
JS_ENV = 'react-native'
11+
} else {
12+
JS_ENV = 'node'
13+
}
14+
export const DEFAULT_HEADERS = { 'X-Client-Info': `supabase-js-${JS_ENV}/${version}` }

test/constants.test.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,19 @@ import { DEFAULT_HEADERS } from '../src/lib/constants'
22
import { version } from '../src/lib/version'
33

44
test('it has the correct type of returning with the correct value', () => {
5+
let JS_ENV = ''
6+
// @ts-ignore
7+
if (typeof Deno !== 'undefined') {
8+
JS_ENV = 'deno'
9+
} else if (typeof document !== 'undefined') {
10+
JS_ENV = 'web'
11+
} else if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {
12+
JS_ENV = 'react-native'
13+
} else {
14+
JS_ENV = 'node'
15+
}
516
const expected = {
6-
'X-Client-Info': `supabase-js/${version}`,
17+
'X-Client-Info': `supabase-js-${JS_ENV}/${version}`,
718
}
819
expect(DEFAULT_HEADERS).toEqual(expected)
920
expect(typeof DEFAULT_HEADERS).toBe('object')

0 commit comments

Comments
 (0)