@supabase/supabase-js 2.105.5-beta.8 → 2.106.0-canary.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -0
- package/dist/index.cjs +256 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +62 -0
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +62 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +256 -5
- package/dist/index.mjs.map +1 -1
- package/dist/umd/supabase.js +8 -8
- package/package.json +8 -7
- package/src/SupabaseClient.ts +16 -2
- package/src/lib/constants.ts +6 -1
- package/src/lib/fetch.ts +65 -1
- package/src/lib/helpers.ts +28 -3
- package/src/lib/types.ts +58 -0
- package/src/lib/version.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@supabase/supabase-js",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.106.0-canary.1",
|
|
4
4
|
"description": "Isomorphic Javascript SDK for Supabase",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"javascript",
|
|
@@ -49,15 +49,16 @@
|
|
|
49
49
|
"directory": "packages/core/supabase-js"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@supabase/auth-js": "2.
|
|
53
|
-
"@supabase/
|
|
54
|
-
"@supabase/
|
|
55
|
-
"@supabase/
|
|
56
|
-
"@supabase/storage-js": "2.
|
|
52
|
+
"@supabase/auth-js": "2.106.0-canary.1",
|
|
53
|
+
"@supabase/functions-js": "2.106.0-canary.1",
|
|
54
|
+
"@supabase/realtime-js": "2.106.0-canary.1",
|
|
55
|
+
"@supabase/postgrest-js": "2.106.0-canary.1",
|
|
56
|
+
"@supabase/storage-js": "2.106.0-canary.1"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"jsr": "^0.13.5",
|
|
60
|
-
"puppeteer": "^24.9.0"
|
|
60
|
+
"puppeteer": "^24.9.0",
|
|
61
|
+
"@supabase/tracing": "0.0.0-automated"
|
|
61
62
|
},
|
|
62
63
|
"jsdelivr": "dist/umd/supabase.js",
|
|
63
64
|
"unpkg": "dist/umd/supabase.js",
|
package/src/SupabaseClient.ts
CHANGED
|
@@ -18,9 +18,14 @@ import {
|
|
|
18
18
|
DEFAULT_DB_OPTIONS,
|
|
19
19
|
DEFAULT_GLOBAL_OPTIONS,
|
|
20
20
|
DEFAULT_REALTIME_OPTIONS,
|
|
21
|
+
DEFAULT_TRACE_PROPAGATION_OPTIONS,
|
|
21
22
|
} from './lib/constants'
|
|
22
23
|
import { fetchWithAuth } from './lib/fetch'
|
|
23
|
-
import {
|
|
24
|
+
import {
|
|
25
|
+
applySettingDefaults,
|
|
26
|
+
validateSupabaseUrl,
|
|
27
|
+
type ResolvedSupabaseClientOptions,
|
|
28
|
+
} from './lib/helpers'
|
|
24
29
|
import { SupabaseAuthClient } from './lib/SupabaseAuthClient'
|
|
25
30
|
import type {
|
|
26
31
|
Fetch,
|
|
@@ -89,6 +94,7 @@ export default class SupabaseClient<
|
|
|
89
94
|
protected accessToken?: () => Promise<string | null>
|
|
90
95
|
|
|
91
96
|
protected headers: Record<string, string>
|
|
97
|
+
protected settings?: ResolvedSupabaseClientOptions<SchemaName>
|
|
92
98
|
|
|
93
99
|
/**
|
|
94
100
|
* Create a new client for use in the browser.
|
|
@@ -298,9 +304,11 @@ export default class SupabaseClient<
|
|
|
298
304
|
realtime: DEFAULT_REALTIME_OPTIONS,
|
|
299
305
|
auth: { ...DEFAULT_AUTH_OPTIONS, storageKey: defaultStorageKey },
|
|
300
306
|
global: DEFAULT_GLOBAL_OPTIONS,
|
|
307
|
+
tracePropagation: DEFAULT_TRACE_PROPAGATION_OPTIONS,
|
|
301
308
|
}
|
|
302
309
|
|
|
303
310
|
const settings = applySettingDefaults(options ?? {}, DEFAULTS)
|
|
311
|
+
this.settings = settings
|
|
304
312
|
|
|
305
313
|
this.storageKey = settings.auth.storageKey ?? ''
|
|
306
314
|
this.headers = settings.global.headers ?? {}
|
|
@@ -325,7 +333,13 @@ export default class SupabaseClient<
|
|
|
325
333
|
})
|
|
326
334
|
}
|
|
327
335
|
|
|
328
|
-
this.fetch = fetchWithAuth(
|
|
336
|
+
this.fetch = fetchWithAuth(
|
|
337
|
+
supabaseKey,
|
|
338
|
+
supabaseUrl,
|
|
339
|
+
this._getAccessToken.bind(this),
|
|
340
|
+
settings.global.fetch,
|
|
341
|
+
settings.tracePropagation
|
|
342
|
+
)
|
|
329
343
|
this.realtime = this._initRealtimeClient({
|
|
330
344
|
headers: this.headers,
|
|
331
345
|
accessToken: this._getAccessToken.bind(this),
|
package/src/lib/constants.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// constants.ts
|
|
2
2
|
import { RealtimeClientOptions } from '@supabase/realtime-js'
|
|
3
|
-
import { SupabaseAuthClientOptions } from './types'
|
|
3
|
+
import { SupabaseAuthClientOptions, TracePropagationOptions } from './types'
|
|
4
4
|
import { version } from './version'
|
|
5
5
|
|
|
6
6
|
let JS_ENV = ''
|
|
@@ -33,3 +33,8 @@ export const DEFAULT_AUTH_OPTIONS: SupabaseAuthClientOptions = {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
export const DEFAULT_REALTIME_OPTIONS: RealtimeClientOptions = {}
|
|
36
|
+
|
|
37
|
+
export const DEFAULT_TRACE_PROPAGATION_OPTIONS: TracePropagationOptions = {
|
|
38
|
+
enabled: false,
|
|
39
|
+
respectSamplingDecision: true,
|
|
40
|
+
}
|
package/src/lib/fetch.ts
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
import {
|
|
2
|
+
extractTraceContext,
|
|
3
|
+
parseTraceParent,
|
|
4
|
+
shouldPropagateToTarget,
|
|
5
|
+
getDefaultPropagationTargets,
|
|
6
|
+
type TraceContext,
|
|
7
|
+
type TracePropagationTarget,
|
|
8
|
+
} from '@supabase/tracing'
|
|
9
|
+
import type { TracePropagationOptions } from './types'
|
|
10
|
+
|
|
1
11
|
type Fetch = typeof fetch
|
|
2
12
|
|
|
3
13
|
export const resolveFetch = (customFetch?: Fetch): Fetch => {
|
|
@@ -13,12 +23,22 @@ export const resolveHeadersConstructor = () => {
|
|
|
13
23
|
|
|
14
24
|
export const fetchWithAuth = (
|
|
15
25
|
supabaseKey: string,
|
|
26
|
+
supabaseUrl: string,
|
|
16
27
|
getAccessToken: () => Promise<string | null>,
|
|
17
|
-
customFetch?: Fetch
|
|
28
|
+
customFetch?: Fetch,
|
|
29
|
+
tracePropagationOptions?: TracePropagationOptions
|
|
18
30
|
): Fetch => {
|
|
19
31
|
const fetch = resolveFetch(customFetch)
|
|
20
32
|
const HeadersConstructor = resolveHeadersConstructor()
|
|
21
33
|
|
|
34
|
+
// Pre-compute trace propagation state once. When disabled, the per-request
|
|
35
|
+
// path skips all tracing work with a single truthy check.
|
|
36
|
+
const traceEnabled = tracePropagationOptions?.enabled === true
|
|
37
|
+
const respectSampling = tracePropagationOptions?.respectSamplingDecision !== false
|
|
38
|
+
const traceTargets: TracePropagationTarget[] | null = traceEnabled
|
|
39
|
+
? getDefaultPropagationTargets(supabaseUrl)
|
|
40
|
+
: null
|
|
41
|
+
|
|
22
42
|
return async (input, init) => {
|
|
23
43
|
const accessToken = (await getAccessToken()) ?? supabaseKey
|
|
24
44
|
let headers = new HeadersConstructor(init?.headers)
|
|
@@ -31,6 +51,50 @@ export const fetchWithAuth = (
|
|
|
31
51
|
headers.set('Authorization', `Bearer ${accessToken}`)
|
|
32
52
|
}
|
|
33
53
|
|
|
54
|
+
if (traceTargets) {
|
|
55
|
+
const traceHeaders = await getTraceHeaders(input, traceTargets, respectSampling)
|
|
56
|
+
|
|
57
|
+
if (traceHeaders) {
|
|
58
|
+
if (traceHeaders.traceparent && !headers.has('traceparent')) {
|
|
59
|
+
headers.set('traceparent', traceHeaders.traceparent)
|
|
60
|
+
}
|
|
61
|
+
if (traceHeaders.tracestate && !headers.has('tracestate')) {
|
|
62
|
+
headers.set('tracestate', traceHeaders.tracestate)
|
|
63
|
+
}
|
|
64
|
+
if (traceHeaders.baggage && !headers.has('baggage')) {
|
|
65
|
+
headers.set('baggage', traceHeaders.baggage)
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
34
70
|
return fetch(input, { ...init, headers })
|
|
35
71
|
}
|
|
36
72
|
}
|
|
73
|
+
|
|
74
|
+
async function getTraceHeaders(
|
|
75
|
+
input: RequestInfo | URL,
|
|
76
|
+
targets: TracePropagationTarget[],
|
|
77
|
+
respectSampling: boolean
|
|
78
|
+
): Promise<TraceContext | null> {
|
|
79
|
+
const targetUrl: string | URL =
|
|
80
|
+
typeof input === 'string' ? input : input instanceof URL ? input : input.url
|
|
81
|
+
|
|
82
|
+
if (!shouldPropagateToTarget(targetUrl, targets)) {
|
|
83
|
+
return null
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const traceContext = await extractTraceContext()
|
|
87
|
+
|
|
88
|
+
if (!traceContext || !traceContext.traceparent) {
|
|
89
|
+
return null
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (respectSampling) {
|
|
93
|
+
const parsed = parseTraceParent(traceContext.traceparent)
|
|
94
|
+
if (parsed && !parsed.isSampled) {
|
|
95
|
+
return null
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return traceContext
|
|
100
|
+
}
|
package/src/lib/helpers.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
// helpers.ts
|
|
2
|
-
import { SupabaseClientOptions } from './types'
|
|
2
|
+
import { SupabaseClientOptions, TracePropagationOptions } from './types'
|
|
3
|
+
|
|
4
|
+
function normalizeTracePropagation(
|
|
5
|
+
value: TracePropagationOptions | boolean | undefined
|
|
6
|
+
): TracePropagationOptions | undefined {
|
|
7
|
+
return typeof value === 'boolean' ? { enabled: value } : value
|
|
8
|
+
}
|
|
3
9
|
|
|
4
10
|
export function uuid() {
|
|
5
11
|
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
@@ -15,6 +21,13 @@ export function ensureTrailingSlash(url: string): string {
|
|
|
15
21
|
|
|
16
22
|
export const isBrowser = () => typeof window !== 'undefined'
|
|
17
23
|
|
|
24
|
+
export type ResolvedSupabaseClientOptions<SchemaName> = Omit<
|
|
25
|
+
Required<SupabaseClientOptions<SchemaName>>,
|
|
26
|
+
'tracePropagation'
|
|
27
|
+
> & {
|
|
28
|
+
tracePropagation: TracePropagationOptions
|
|
29
|
+
}
|
|
30
|
+
|
|
18
31
|
export function applySettingDefaults<
|
|
19
32
|
Database = any,
|
|
20
33
|
SchemaName extends string & keyof Database = 'public' extends keyof Database
|
|
@@ -23,7 +36,7 @@ export function applySettingDefaults<
|
|
|
23
36
|
>(
|
|
24
37
|
options: SupabaseClientOptions<SchemaName>,
|
|
25
38
|
defaults: SupabaseClientOptions<any>
|
|
26
|
-
):
|
|
39
|
+
): ResolvedSupabaseClientOptions<SchemaName> {
|
|
27
40
|
const {
|
|
28
41
|
db: dbOptions,
|
|
29
42
|
auth: authOptions,
|
|
@@ -37,7 +50,11 @@ export function applySettingDefaults<
|
|
|
37
50
|
global: DEFAULT_GLOBAL_OPTIONS,
|
|
38
51
|
} = defaults
|
|
39
52
|
|
|
40
|
-
|
|
53
|
+
// Accept either a boolean shorthand or an options object on both sides.
|
|
54
|
+
const tracePropagationOptions = normalizeTracePropagation(options.tracePropagation)
|
|
55
|
+
const DEFAULT_TRACE_PROPAGATION_OPTIONS = normalizeTracePropagation(defaults.tracePropagation)
|
|
56
|
+
|
|
57
|
+
const result: ResolvedSupabaseClientOptions<SchemaName> = {
|
|
41
58
|
db: {
|
|
42
59
|
...DEFAULT_DB_OPTIONS,
|
|
43
60
|
...dbOptions,
|
|
@@ -59,6 +76,14 @@ export function applySettingDefaults<
|
|
|
59
76
|
...(globalOptions?.headers ?? {}),
|
|
60
77
|
},
|
|
61
78
|
},
|
|
79
|
+
tracePropagation: {
|
|
80
|
+
enabled:
|
|
81
|
+
tracePropagationOptions?.enabled ?? DEFAULT_TRACE_PROPAGATION_OPTIONS?.enabled ?? false,
|
|
82
|
+
respectSamplingDecision:
|
|
83
|
+
tracePropagationOptions?.respectSamplingDecision ??
|
|
84
|
+
DEFAULT_TRACE_PROPAGATION_OPTIONS?.respectSamplingDecision ??
|
|
85
|
+
true,
|
|
86
|
+
},
|
|
62
87
|
accessToken: async () => '',
|
|
63
88
|
}
|
|
64
89
|
|
package/src/lib/types.ts
CHANGED
|
@@ -25,6 +25,42 @@ export interface SupabaseAuthClientOptions extends GoTrueClientOptions {}
|
|
|
25
25
|
|
|
26
26
|
export type Fetch = typeof fetch
|
|
27
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Configuration options for trace context propagation.
|
|
30
|
+
*
|
|
31
|
+
* Enables distributed tracing across Supabase services using W3C Trace Context
|
|
32
|
+
* and OpenTelemetry standards. When enabled, the SDK automatically attaches
|
|
33
|
+
* trace context headers (traceparent, tracestate, baggage) to outgoing requests
|
|
34
|
+
* to Supabase domains.
|
|
35
|
+
*
|
|
36
|
+
* @see https://www.w3.org/TR/trace-context/
|
|
37
|
+
* @see https://opentelemetry.io/docs/concepts/context-propagation/
|
|
38
|
+
*/
|
|
39
|
+
export interface TracePropagationOptions {
|
|
40
|
+
/**
|
|
41
|
+
* Enable trace propagation. Disabled by default.
|
|
42
|
+
*
|
|
43
|
+
* When enabled, automatically detects and propagates active trace context
|
|
44
|
+
* from the OpenTelemetry API to outgoing Supabase requests. Trace context
|
|
45
|
+
* is only propagated to Supabase domains (*.supabase.co, *.supabase.in,
|
|
46
|
+
* localhost) for security.
|
|
47
|
+
*
|
|
48
|
+
* @default false
|
|
49
|
+
*/
|
|
50
|
+
enabled?: boolean
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Respect upstream sampling decisions.
|
|
54
|
+
*
|
|
55
|
+
* When true, trace context will not be propagated if the upstream trace
|
|
56
|
+
* indicates non-sampling (sampled flag = 0 in traceparent header).
|
|
57
|
+
* This helps reduce overhead when traces are not being collected.
|
|
58
|
+
*
|
|
59
|
+
* @default true
|
|
60
|
+
*/
|
|
61
|
+
respectSamplingDecision?: boolean
|
|
62
|
+
}
|
|
63
|
+
|
|
28
64
|
export type SupabaseClientOptions<SchemaName> = {
|
|
29
65
|
/**
|
|
30
66
|
* The Postgres schema which your tables belong to. Must be on the list of exposed schemas in Supabase. Defaults to `public`.
|
|
@@ -175,6 +211,28 @@ export type SupabaseClientOptions<SchemaName> = {
|
|
|
175
211
|
* authentications concurrently in the same application.
|
|
176
212
|
*/
|
|
177
213
|
accessToken?: () => Promise<string | null>
|
|
214
|
+
/**
|
|
215
|
+
* Enable OpenTelemetry / W3C trace context propagation to Supabase services.
|
|
216
|
+
*
|
|
217
|
+
* Disabled by default. Pass `true` for the common case (auto-detect an
|
|
218
|
+
* active OTel context and inject `traceparent` / `tracestate` / `baggage`
|
|
219
|
+
* headers) or an object for fine-grained control.
|
|
220
|
+
*
|
|
221
|
+
* Requires `@opentelemetry/api` to be installed in your application; if
|
|
222
|
+
* not present, the SDK silently no-ops.
|
|
223
|
+
*
|
|
224
|
+
* @example
|
|
225
|
+
* ```ts
|
|
226
|
+
* // Shorthand — opt in with defaults.
|
|
227
|
+
* createClient(url, key, { tracePropagation: true })
|
|
228
|
+
*
|
|
229
|
+
* // Advanced — always propagate, even for non-sampled traces.
|
|
230
|
+
* createClient(url, key, {
|
|
231
|
+
* tracePropagation: { enabled: true, respectSamplingDecision: false },
|
|
232
|
+
* })
|
|
233
|
+
* ```
|
|
234
|
+
*/
|
|
235
|
+
tracePropagation?: TracePropagationOptions | boolean
|
|
178
236
|
}
|
|
179
237
|
|
|
180
238
|
/**
|
package/src/lib/version.ts
CHANGED
|
@@ -4,4 +4,4 @@
|
|
|
4
4
|
// - Debugging and support (identifying which version is running)
|
|
5
5
|
// - Telemetry and logging (version reporting in errors/analytics)
|
|
6
6
|
// - Ensuring build artifacts match the published package version
|
|
7
|
-
export const version = '2.
|
|
7
|
+
export const version = '2.106.0-canary.1'
|