Skip to content

Commit

Permalink
feat: track javascript environment. (#854)
Browse files Browse the repository at this point in the history
  • Loading branch information
thorwebdev committed Sep 19, 2023
1 parent 8cf2b96 commit ed5a3d4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
13 changes: 12 additions & 1 deletion src/lib/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
// constants.ts
import { version } from './version'
export const DEFAULT_HEADERS = { 'X-Client-Info': `supabase-js/${version}` }
let JS_ENV = ''
// @ts-ignore
if (typeof Deno !== 'undefined') {
JS_ENV = 'deno'
} else if (typeof document !== 'undefined') {
JS_ENV = 'web'
} else if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {
JS_ENV = 'react-native'
} else {
JS_ENV = 'node'
}
export const DEFAULT_HEADERS = { 'X-Client-Info': `supabase-js-${JS_ENV}/${version}` }
13 changes: 12 additions & 1 deletion test/constants.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,19 @@ import { DEFAULT_HEADERS } from '../src/lib/constants'
import { version } from '../src/lib/version'

test('it has the correct type of returning with the correct value', () => {
let JS_ENV = ''
// @ts-ignore
if (typeof Deno !== 'undefined') {
JS_ENV = 'deno'
} else if (typeof document !== 'undefined') {
JS_ENV = 'web'
} else if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {
JS_ENV = 'react-native'
} else {
JS_ENV = 'node'
}
const expected = {
'X-Client-Info': `supabase-js/${version}`,
'X-Client-Info': `supabase-js-${JS_ENV}/${version}`,
}
expect(DEFAULT_HEADERS).toEqual(expected)
expect(typeof DEFAULT_HEADERS).toBe('object')
Expand Down

0 comments on commit ed5a3d4

Please sign in to comment.