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

supabase / supabase-js / 15874278845

25 Jun 2025 10:46AM UTC coverage: 72.889%. Remained the same
15874278845

Pull #1468

github

web-flow
Merge e03bdb03f into 008063e4e
Pull Request #1468: fix: bump realtime-js to 2.11.15

55 of 93 branches covered (59.14%)

Branch coverage included in aggregate %.

109 of 132 relevant lines covered (82.58%)

8.81 hits per line

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

39.47
/src/lib/fetch.ts
1
// @ts-ignore
2
import nodeFetch, { Headers as NodeFetchHeaders } from '@supabase/node-fetch'
2✔
3

4
type Fetch = typeof fetch
5

6
export const resolveFetch = (customFetch?: Fetch): Fetch => {
2✔
7
  let _fetch: Fetch
8
  if (customFetch) {
19!
9
    _fetch = customFetch
×
10
  } else if (typeof fetch === 'undefined') {
19!
11
    _fetch = nodeFetch as unknown as Fetch
×
12
  } else {
13
    _fetch = fetch
19✔
14
  }
15
  return (...args: Parameters<Fetch>) => _fetch(...args)
19✔
16
}
17

18
export const resolveHeadersConstructor = () => {
2✔
19
  if (typeof Headers === 'undefined') {
19!
20
    return NodeFetchHeaders
×
21
  }
22

23
  return Headers
19✔
24
}
25

26
export const fetchWithAuth = (
2✔
27
  supabaseKey: string,
28
  getAccessToken: () => Promise<string | null>,
29
  customFetch?: Fetch
30
): Fetch => {
31
  const fetch = resolveFetch(customFetch)
19✔
32
  const HeadersConstructor = resolveHeadersConstructor()
19✔
33

34
  return async (input, init) => {
19✔
35
    const accessToken = (await getAccessToken()) ?? supabaseKey
×
36
    let headers = new HeadersConstructor(init?.headers)
×
37

38
    if (!headers.has('apikey')) {
×
39
      headers.set('apikey', supabaseKey)
×
40
    }
41

42
    if (!headers.has('Authorization')) {
×
43
      headers.set('Authorization', `Bearer ${accessToken}`)
×
44
    }
45

46
    return fetch(input, { ...init, headers })
×
47
  }
48
}
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