@supabase/supabase-js 2.105.5-beta.8 → 2.105.5-beta.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@supabase/supabase-js",
3
- "version": "2.105.5-beta.8",
3
+ "version": "2.105.5-beta.9",
4
4
  "description": "Isomorphic Javascript SDK for Supabase",
5
5
  "keywords": [
6
6
  "javascript",
@@ -48,14 +48,46 @@
48
48
  "url": "https://github.com/supabase/supabase-js.git",
49
49
  "directory": "packages/core/supabase-js"
50
50
  },
51
+ "scripts": {
52
+ "build": "tsdown",
53
+ "build:watch": "tsdown --watch",
54
+ "test": "npm run test:types && npm run test:run",
55
+ "test:all": "npm run test:types && npm run test:run && npm run test:integration && npm run test:integration:browser",
56
+ "test:run": "jest --runInBand --detectOpenHandles",
57
+ "test:unit": "jest --runInBand --detectOpenHandles test/unit",
58
+ "test:coverage": "jest --runInBand --coverage --testPathIgnorePatterns=\"test/integration|test/deno|\\.[mc]js$\"",
59
+ "test:integration": "jest --runInBand --detectOpenHandles test/integration.test.ts",
60
+ "test:integration:browser": "deno test --allow-all test/integration.browser.test.ts",
61
+ "test:edge-functions": "cd test/deno && npm run test:edge-functions",
62
+ "test:deno": "cd test/deno && npm run test",
63
+ "test:watch": "jest --watch --verbose false --silent false",
64
+ "test:node:playwright": "cd test/integration/node-browser && npm install && cp ../../../dist/umd/supabase.js . && npm run test",
65
+ "test:bun": "cd test/integration/bun && bun install && bun test",
66
+ "test:expo": "cd test/integration/expo && npm test",
67
+ "test:next": "cd test/integration/next && npm test",
68
+ "test:types": "tsd --files test/types/index.test-d.ts && tsd --typings dist/cors.d.cts --files test/types/cors.test-d.ts && jsr publish --dry-run --allow-dirty",
69
+ "test:exports": "attw --pack . --ignore-rules no-resolution",
70
+ "test:esm": "node test/module-resolution.test.mjs && node test/module-resolution-cors.test.mjs",
71
+ "test:cjs": "node test/module-resolution.test.cjs && node test/module-resolution-cors.test.cjs",
72
+ "test:module-resolution": "npm run test:exports && npm run test:esm && npm run test:cjs",
73
+ "docs": "typedoc --entryPoints src/index.ts --entryPoints src/cors.ts --out docs/v2",
74
+ "docs:json": "typedoc --entryPoints src/index.ts --entryPoints src/cors.ts --json docs/v2/spec.json --excludeExternals",
75
+ "serve:coverage": "npx nx test:coverage supabase-js && npx --yes serve test/coverage",
76
+ "update:test-deps": "npm run update:test-deps:expo && npm run update:test-deps:next && npm run update:test-deps:deno && npm run update:test-deps:bun",
77
+ "update:test-deps:expo": "cd test/integration/expo && npm install",
78
+ "update:test-deps:next": "cd test/integration/next && npm install",
79
+ "update:test-deps:deno": "cd test/deno && npm install",
80
+ "update:test-deps:bun": "cd test/integration/bun && bun install"
81
+ },
51
82
  "dependencies": {
52
- "@supabase/auth-js": "2.105.5-beta.8",
53
- "@supabase/postgrest-js": "2.105.5-beta.8",
54
- "@supabase/functions-js": "2.105.5-beta.8",
55
- "@supabase/realtime-js": "2.105.5-beta.8",
56
- "@supabase/storage-js": "2.105.5-beta.8"
83
+ "@supabase/auth-js": "2.105.5-beta.9",
84
+ "@supabase/functions-js": "2.105.5-beta.9",
85
+ "@supabase/postgrest-js": "2.105.5-beta.9",
86
+ "@supabase/realtime-js": "2.105.5-beta.9",
87
+ "@supabase/storage-js": "2.105.5-beta.9"
57
88
  },
58
89
  "devDependencies": {
90
+ "@supabase/tracing": "*",
59
91
  "jsr": "^0.13.5",
60
92
  "puppeteer": "^24.9.0"
61
93
  },
@@ -87,36 +119,5 @@
87
119
  },
88
120
  "engines": {
89
121
  "node": ">=20.0.0"
90
- },
91
- "scripts": {
92
- "build": "tsdown",
93
- "build:watch": "tsdown --watch",
94
- "test": "npm run test:types && npm run test:run",
95
- "test:all": "npm run test:types && npm run test:run && npm run test:integration && npm run test:integration:browser",
96
- "test:run": "jest --runInBand --detectOpenHandles",
97
- "test:unit": "jest --runInBand --detectOpenHandles test/unit",
98
- "test:coverage": "jest --runInBand --coverage --testPathIgnorePatterns=\"test/integration|test/deno|\\.[mc]js$\"",
99
- "test:integration": "jest --runInBand --detectOpenHandles test/integration.test.ts",
100
- "test:integration:browser": "deno test --allow-all --node-modules-dir=auto test/integration.browser.test.ts",
101
- "test:edge-functions": "cd test/deno && npm run test:edge-functions",
102
- "test:deno": "cd test/deno && npm run test",
103
- "test:watch": "jest --watch --verbose false --silent false",
104
- "test:node:playwright": "cd test/integration/node-browser && npm install && cp ../../../dist/umd/supabase.js . && npm run test",
105
- "test:bun": "cd test/integration/bun && bun install && bun test",
106
- "test:expo": "cd test/integration/expo && npm test",
107
- "test:next": "cd test/integration/next && npm test",
108
- "test:types": "tsd --files test/types/index.test-d.ts && tsd --typings dist/cors.d.cts --files test/types/cors.test-d.ts && jsr publish --dry-run --allow-dirty",
109
- "test:exports": "attw --pack . --ignore-rules no-resolution",
110
- "test:esm": "node test/module-resolution.test.mjs && node test/module-resolution-cors.test.mjs",
111
- "test:cjs": "node test/module-resolution.test.cjs && node test/module-resolution-cors.test.cjs",
112
- "test:module-resolution": "npm run test:exports && npm run test:esm && npm run test:cjs",
113
- "docs": "typedoc --entryPoints src/index.ts --entryPoints src/cors.ts --out docs/v2",
114
- "docs:json": "typedoc --entryPoints src/index.ts --entryPoints src/cors.ts --json docs/v2/spec.json --excludeExternals",
115
- "serve:coverage": "pnpm nx test:coverage supabase-js && pnpm dlx serve test/coverage",
116
- "update:test-deps": "pnpm run update:test-deps:expo && pnpm run update:test-deps:next && pnpm run update:test-deps:deno && pnpm run update:test-deps:bun",
117
- "update:test-deps:expo": "cd test/integration/expo && pnpm install --ignore-workspace",
118
- "update:test-deps:next": "cd test/integration/next && pnpm install --ignore-workspace",
119
- "update:test-deps:deno": "cd test/deno && pnpm install --ignore-workspace",
120
- "update:test-deps:bun": "cd test/integration/bun && bun install"
121
122
  }
122
- }
123
+ }
@@ -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 { applySettingDefaults, validateSupabaseUrl } from './lib/helpers'
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(supabaseKey, this._getAccessToken.bind(this), settings.global.fetch)
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),
@@ -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
+ }
@@ -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
- ): Required<SupabaseClientOptions<SchemaName>> {
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
- const result: Required<SupabaseClientOptions<SchemaName>> = {
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
 
@@ -5,7 +5,7 @@
5
5
  * Source: packages/core/postgrest-js/src/types/common/
6
6
  *
7
7
  * To update this file, modify the source in postgrest-js and run:
8
- * pnpm run codegen
8
+ * npm run codegen
9
9
  */
10
10
 
11
11
  // Types that are shared between supabase-js and postgrest-js
@@ -5,7 +5,7 @@
5
5
  * Source: packages/core/postgrest-js/src/types/common/
6
6
  *
7
7
  * To update this file, modify the source in postgrest-js and run:
8
- * pnpm run codegen
8
+ * npm run codegen
9
9
  */
10
10
 
11
11
  import type { GenericFunction, GenericSchema, GenericSetofOption } from './common'
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
  /**
@@ -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.105.5-beta.8'
7
+ export const version = '2.105.5-beta.9'
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2020 Supabase
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.