@supabase/supabase-js 2.111.1-canary.1 → 2.112.0-beta.0
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 +6 -1
- package/dist/cors.cjs +0 -1
- package/dist/cors.cjs.map +1 -1
- package/dist/index.cjs +151 -800
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +26 -8
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +26 -8
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +17 -71
- package/dist/index.mjs.map +1 -1
- package/dist/tracing.cjs +59 -0
- package/dist/tracing.cjs.map +1 -0
- package/dist/tracing.d.cts +1 -0
- package/dist/tracing.d.mts +1 -0
- package/dist/tracing.mjs +60 -0
- package/dist/tracing.mjs.map +1 -0
- package/dist/tracingRegistry.cjs +32 -0
- package/dist/tracingRegistry.cjs.map +1 -0
- package/dist/tracingRegistry.mjs +20 -0
- package/dist/tracingRegistry.mjs.map +1 -0
- package/dist/umd/supabase.js +4 -4
- package/package.json +39 -12
- package/src/SupabaseClient.ts +3 -1
- package/src/lib/fetch.ts +37 -5
- package/src/lib/tracingRegistry.ts +42 -0
- package/src/lib/types.ts +23 -7
- package/src/lib/version.ts +1 -1
- package/src/tracing.ts +26 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@supabase/supabase-js",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.112.0-beta.0",
|
|
4
4
|
"description": "Isomorphic Javascript SDK for Supabase",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"javascript",
|
|
@@ -49,26 +49,53 @@
|
|
|
49
49
|
"default": "./dist/cors.cjs"
|
|
50
50
|
}
|
|
51
51
|
},
|
|
52
|
+
"./tracing": {
|
|
53
|
+
"react-native": {
|
|
54
|
+
"types": "./dist/tracing.d.cts",
|
|
55
|
+
"default": "./dist/tracing.cjs"
|
|
56
|
+
},
|
|
57
|
+
"import": {
|
|
58
|
+
"types": "./dist/tracing.d.mts",
|
|
59
|
+
"default": "./dist/tracing.mjs"
|
|
60
|
+
},
|
|
61
|
+
"require": {
|
|
62
|
+
"types": "./dist/tracing.d.cts",
|
|
63
|
+
"default": "./dist/tracing.cjs"
|
|
64
|
+
}
|
|
65
|
+
},
|
|
52
66
|
"./dist/*": "./dist/*",
|
|
53
67
|
"./package.json": "./package.json"
|
|
54
68
|
},
|
|
55
|
-
"sideEffects":
|
|
69
|
+
"sideEffects": [
|
|
70
|
+
"./dist/tracing.cjs",
|
|
71
|
+
"./dist/tracing.mjs",
|
|
72
|
+
"./src/tracing.ts"
|
|
73
|
+
],
|
|
56
74
|
"repository": {
|
|
57
75
|
"type": "git",
|
|
58
76
|
"url": "https://github.com/supabase/supabase-js.git",
|
|
59
77
|
"directory": "packages/core/supabase-js"
|
|
60
78
|
},
|
|
61
79
|
"dependencies": {
|
|
62
|
-
"@supabase/auth-js": "2.
|
|
63
|
-
"@supabase/
|
|
64
|
-
"@supabase/realtime-js": "2.
|
|
65
|
-
"@supabase/
|
|
66
|
-
"@supabase/storage-js": "2.
|
|
80
|
+
"@supabase/auth-js": "2.112.0-beta.0",
|
|
81
|
+
"@supabase/postgrest-js": "2.112.0-beta.0",
|
|
82
|
+
"@supabase/realtime-js": "2.112.0-beta.0",
|
|
83
|
+
"@supabase/functions-js": "2.112.0-beta.0",
|
|
84
|
+
"@supabase/storage-js": "2.112.0-beta.0"
|
|
85
|
+
},
|
|
86
|
+
"peerDependencies": {
|
|
87
|
+
"@opentelemetry/api": ">=1.0.0"
|
|
88
|
+
},
|
|
89
|
+
"peerDependenciesMeta": {
|
|
90
|
+
"@opentelemetry/api": {
|
|
91
|
+
"optional": true
|
|
92
|
+
}
|
|
67
93
|
},
|
|
68
94
|
"devDependencies": {
|
|
69
95
|
"@arethetypeswrong/cli": "^0.18.2",
|
|
70
96
|
"@jest/globals": "^30.0.0",
|
|
71
97
|
"@jest/types": "^30.0.0",
|
|
98
|
+
"@opentelemetry/api": "^1.9.0",
|
|
72
99
|
"@types/jest": "30.0.0",
|
|
73
100
|
"@types/jsonwebtoken": "^8.5.8",
|
|
74
101
|
"@types/node": "20.19.9",
|
|
@@ -129,14 +156,14 @@
|
|
|
129
156
|
"test:bun": "cd test/integration/bun && bun install && bun test",
|
|
130
157
|
"test:expo": "cd test/integration/expo && npm test",
|
|
131
158
|
"test:next": "cd test/integration/next && npm test",
|
|
132
|
-
"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",
|
|
159
|
+
"test:types": "tsd --files test/types/index.test-d.ts && tsd --typings dist/cors.d.cts --files test/types/cors.test-d.ts && tsd --typings dist/tracing.d.cts --files test/types/tracing.test-d.ts && jsr publish --dry-run --allow-dirty",
|
|
133
160
|
"test:exports": "attw --pack . --ignore-rules no-resolution",
|
|
134
|
-
"test:esm": "node test/module-resolution.test.mjs && node test/module-resolution-cors.test.mjs",
|
|
135
|
-
"test:cjs": "node test/module-resolution.test.cjs && node test/module-resolution-cors.test.cjs",
|
|
161
|
+
"test:esm": "node test/module-resolution.test.mjs && node test/module-resolution-cors.test.mjs && node test/module-resolution-tracing.test.mjs",
|
|
162
|
+
"test:cjs": "node test/module-resolution.test.cjs && node test/module-resolution-cors.test.cjs && node test/module-resolution-tracing.test.cjs",
|
|
136
163
|
"test:hermes-compat": "node test/bundle-hermes-compat.test.cjs",
|
|
137
164
|
"test:module-resolution": "npm run test:exports && npm run test:esm && npm run test:cjs && npm run test:hermes-compat",
|
|
138
|
-
"docs": "typedoc --options ../../../typedoc.base.mjs --entryPoints src/index.ts --entryPoints src/cors.ts --out docs/v2",
|
|
139
|
-
"docs:json": "typedoc --options ../../../typedoc.base.mjs --entryPoints src/index.ts --entryPoints src/cors.ts --json docs/v2/spec.json --excludeExternals",
|
|
165
|
+
"docs": "typedoc --options ../../../typedoc.base.mjs --entryPoints src/index.ts --entryPoints src/cors.ts --entryPoints src/tracing.ts --out docs/v2",
|
|
166
|
+
"docs:json": "typedoc --options ../../../typedoc.base.mjs --entryPoints src/index.ts --entryPoints src/cors.ts --entryPoints src/tracing.ts --json docs/v2/spec.json --excludeExternals",
|
|
140
167
|
"serve:coverage": "pnpm nx test:coverage supabase-js && pnpm dlx serve test/coverage",
|
|
141
168
|
"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",
|
|
142
169
|
"update:test-deps:expo": "cd test/integration/expo && pnpm install --ignore-workspace",
|
package/src/SupabaseClient.ts
CHANGED
|
@@ -288,10 +288,12 @@ export default class SupabaseClient<
|
|
|
288
288
|
* Opt in to W3C trace context propagation so the `trace_id` from your
|
|
289
289
|
* client-side spans is attached to Supabase requests and appears in API
|
|
290
290
|
* Gateway and Edge Function logs. Requires `@opentelemetry/api` to be
|
|
291
|
-
* installed in your application
|
|
291
|
+
* installed in your application and the tracing runtime to be loaded via
|
|
292
|
+
* `import '@supabase/supabase-js/tracing'`. See [Tracing with the JS SDK](https://supabase.com/docs/guides/telemetry/client-side-tracing).
|
|
292
293
|
*
|
|
293
294
|
* @example With OpenTelemetry tracing
|
|
294
295
|
* ```ts
|
|
296
|
+
* import '@supabase/supabase-js/tracing'
|
|
295
297
|
* import { createClient } from '@supabase/supabase-js'
|
|
296
298
|
* import { trace } from '@opentelemetry/api'
|
|
297
299
|
*
|
package/src/lib/fetch.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
|
-
extractTraceContext,
|
|
3
2
|
parseTraceParent,
|
|
4
3
|
shouldPropagateToTarget,
|
|
5
4
|
getDefaultPropagationTargets,
|
|
6
5
|
type TraceContext,
|
|
7
6
|
type TracePropagationTarget,
|
|
8
7
|
} from '@supabase/tracing'
|
|
8
|
+
import { getTraceContextExtractor } from './tracingRegistry'
|
|
9
9
|
import type { TracePropagationOptions } from './types'
|
|
10
10
|
|
|
11
11
|
type Fetch = typeof fetch
|
|
@@ -95,7 +95,7 @@ export const fetchWithAuth = (
|
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
if (traceTargets) {
|
|
98
|
-
const traceHeaders =
|
|
98
|
+
const traceHeaders = getTraceHeaders(input, traceTargets, respectSampling)
|
|
99
99
|
|
|
100
100
|
if (traceHeaders) {
|
|
101
101
|
if (traceHeaders.traceparent && !headers.has('traceparent')) {
|
|
@@ -114,11 +114,43 @@ export const fetchWithAuth = (
|
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
-
|
|
117
|
+
let warnedMissingTracingRuntime = false
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* For tests only. Resets the one-time missing-tracing-runtime warning.
|
|
121
|
+
*
|
|
122
|
+
* @internal
|
|
123
|
+
*/
|
|
124
|
+
export function _resetTracingRuntimeWarning(): void {
|
|
125
|
+
warnedMissingTracingRuntime = false
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function getTraceHeaders(
|
|
118
129
|
input: RequestInfo | URL,
|
|
119
130
|
targets: TracePropagationTarget[],
|
|
120
131
|
respectSampling: boolean
|
|
121
|
-
):
|
|
132
|
+
): TraceContext | null {
|
|
133
|
+
// Read the registry before the target check so the warning fires on the
|
|
134
|
+
// first request with tracing enabled, not only on Supabase-target ones.
|
|
135
|
+
// Reading per request (one globalThis property access) deliberately
|
|
136
|
+
// supports late registration: with ESM evaluation order, `createClient`
|
|
137
|
+
// can run in a module evaluated before the application entry point's
|
|
138
|
+
// `import '@supabase/supabase-js/tracing'`.
|
|
139
|
+
const extractTraceContext = getTraceContextExtractor()
|
|
140
|
+
|
|
141
|
+
if (!extractTraceContext) {
|
|
142
|
+
if (!warnedMissingTracingRuntime) {
|
|
143
|
+
warnedMissingTracingRuntime = true
|
|
144
|
+
console.warn(
|
|
145
|
+
'@supabase/supabase-js: tracePropagation is enabled but the tracing runtime is not loaded, ' +
|
|
146
|
+
"so trace headers will not be attached. Add `import '@supabase/supabase-js/tracing'` at " +
|
|
147
|
+
'your application entry point (requires the OpenTelemetry API package to be installed). ' +
|
|
148
|
+
'The CDN/UMD build does not support trace propagation.'
|
|
149
|
+
)
|
|
150
|
+
}
|
|
151
|
+
return null
|
|
152
|
+
}
|
|
153
|
+
|
|
122
154
|
const targetUrl: string | URL =
|
|
123
155
|
typeof input === 'string' ? input : input instanceof URL ? input : input.url
|
|
124
156
|
|
|
@@ -126,7 +158,7 @@ async function getTraceHeaders(
|
|
|
126
158
|
return null
|
|
127
159
|
}
|
|
128
160
|
|
|
129
|
-
const traceContext =
|
|
161
|
+
const traceContext = extractTraceContext()
|
|
130
162
|
|
|
131
163
|
if (!traceContext || !traceContext.traceparent) {
|
|
132
164
|
return null
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { TraceContextExtractor } from '@supabase/tracing'
|
|
2
|
+
|
|
3
|
+
export type { TraceContextExtractor }
|
|
4
|
+
|
|
5
|
+
// The extractor lives in a `Symbol.for()`-keyed slot on `globalThis` rather
|
|
6
|
+
// than a module-level variable. Bundlers and the ESM/CJS dual build can load
|
|
7
|
+
// this module more than once in a single application (e.g. the tracing
|
|
8
|
+
// subpath resolved to `dist/tracing.mjs` while the main entry resolves to
|
|
9
|
+
// `dist/index.cjs`) — separate module instances would each get their own
|
|
10
|
+
// variable, but they all share the global symbol registry.
|
|
11
|
+
//
|
|
12
|
+
// The symbol string is a de-facto stable contract: module-resolution tests
|
|
13
|
+
// read the slot directly, and changing it orphans registrations from other
|
|
14
|
+
// copies of this package in the same process.
|
|
15
|
+
const EXTRACTOR_KEY = Symbol.for('@supabase/supabase-js.traceContextExtractor')
|
|
16
|
+
|
|
17
|
+
type ExtractorSlot = { [EXTRACTOR_KEY]?: TraceContextExtractor }
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Register the trace context extractor used by all Supabase clients in this
|
|
21
|
+
* process. Called by the `@supabase/supabase-js/tracing` subpath as an import
|
|
22
|
+
* side effect; the last registration wins.
|
|
23
|
+
*/
|
|
24
|
+
export function registerTraceContextExtractor(extractor: TraceContextExtractor): void {
|
|
25
|
+
;(globalThis as ExtractorSlot)[EXTRACTOR_KEY] = extractor
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The currently registered trace context extractor, if any.
|
|
30
|
+
*/
|
|
31
|
+
export function getTraceContextExtractor(): TraceContextExtractor | undefined {
|
|
32
|
+
return (globalThis as ExtractorSlot)[EXTRACTOR_KEY]
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* For tests only. Removes the registered extractor.
|
|
37
|
+
*
|
|
38
|
+
* @internal
|
|
39
|
+
*/
|
|
40
|
+
export function _unregisterTraceContextExtractor(): void {
|
|
41
|
+
delete (globalThis as ExtractorSlot)[EXTRACTOR_KEY]
|
|
42
|
+
}
|
package/src/lib/types.ts
CHANGED
|
@@ -35,12 +35,17 @@ export type Fetch = typeof fetch
|
|
|
35
35
|
* Gateway and Edge Function logs, so logs forwarded through Log Drains can
|
|
36
36
|
* be correlated back to the originating client-side span.
|
|
37
37
|
*
|
|
38
|
-
* Requires `@opentelemetry/api`
|
|
39
|
-
*
|
|
40
|
-
*
|
|
38
|
+
* Requires two opt-in steps: install `@opentelemetry/api` in the consuming
|
|
39
|
+
* application, and load the tracing runtime with
|
|
40
|
+
* `import '@supabase/supabase-js/tracing'` at the application entry point.
|
|
41
|
+
* If the runtime is not loaded, the SDK logs a one-time warning and sends
|
|
42
|
+
* requests without trace headers; if there is no active context at request
|
|
43
|
+
* time, propagation silently no-ops. Not available via the CDN/UMD build.
|
|
41
44
|
*
|
|
42
45
|
* @example Enable with defaults
|
|
43
46
|
* ```ts
|
|
47
|
+
* import '@supabase/supabase-js/tracing'
|
|
48
|
+
*
|
|
44
49
|
* const supabase = createClient(url, key, {
|
|
45
50
|
* tracePropagation: { enabled: true },
|
|
46
51
|
* })
|
|
@@ -63,6 +68,8 @@ export interface TracePropagationOptions {
|
|
|
63
68
|
*
|
|
64
69
|
* @example
|
|
65
70
|
* ```ts
|
|
71
|
+
* import '@supabase/supabase-js/tracing'
|
|
72
|
+
*
|
|
66
73
|
* const supabase = createClient(url, key, {
|
|
67
74
|
* tracePropagation: { enabled: true },
|
|
68
75
|
* })
|
|
@@ -85,6 +92,8 @@ export interface TracePropagationOptions {
|
|
|
85
92
|
*
|
|
86
93
|
* @example Always propagate, ignore sampling
|
|
87
94
|
* ```ts
|
|
95
|
+
* import '@supabase/supabase-js/tracing'
|
|
96
|
+
*
|
|
88
97
|
* const supabase = createClient(url, key, {
|
|
89
98
|
* tracePropagation: { enabled: true, respectSamplingDecision: false },
|
|
90
99
|
* })
|
|
@@ -262,10 +271,13 @@ export type SupabaseClientOptions<SchemaName> = {
|
|
|
262
271
|
* active OpenTelemetry context and inject `traceparent` / `tracestate` /
|
|
263
272
|
* `baggage` headers) or an object for fine-grained control.
|
|
264
273
|
*
|
|
265
|
-
* Requires `@opentelemetry/api` to be installed in your application
|
|
266
|
-
*
|
|
267
|
-
*
|
|
268
|
-
*
|
|
274
|
+
* Requires `@opentelemetry/api` to be installed in your application AND
|
|
275
|
+
* the tracing runtime to be loaded with
|
|
276
|
+
* `import '@supabase/supabase-js/tracing'` at your application entry
|
|
277
|
+
* point. Without that import, the SDK logs a one-time warning and sends
|
|
278
|
+
* requests without trace headers. Not available via the CDN/UMD build.
|
|
279
|
+
* Trace headers are only attached to requests targeting Supabase domains,
|
|
280
|
+
* so third-party hosts called through a custom `fetch` are never tagged.
|
|
269
281
|
*
|
|
270
282
|
* The resulting `trace_id` appears in Supabase logs (API Gateway, Edge
|
|
271
283
|
* Functions), letting you correlate client-side spans with server-side
|
|
@@ -273,6 +285,7 @@ export type SupabaseClientOptions<SchemaName> = {
|
|
|
273
285
|
*
|
|
274
286
|
* @example Shorthand — opt in with defaults
|
|
275
287
|
* ```ts
|
|
288
|
+
* import '@supabase/supabase-js/tracing'
|
|
276
289
|
* import { createClient } from '@supabase/supabase-js'
|
|
277
290
|
*
|
|
278
291
|
* const supabase = createClient(url, key, { tracePropagation: true })
|
|
@@ -280,6 +293,7 @@ export type SupabaseClientOptions<SchemaName> = {
|
|
|
280
293
|
*
|
|
281
294
|
* @example With an active OpenTelemetry span
|
|
282
295
|
* ```ts
|
|
296
|
+
* import '@supabase/supabase-js/tracing'
|
|
283
297
|
* import { createClient } from '@supabase/supabase-js'
|
|
284
298
|
* import { trace } from '@opentelemetry/api'
|
|
285
299
|
*
|
|
@@ -295,6 +309,8 @@ export type SupabaseClientOptions<SchemaName> = {
|
|
|
295
309
|
*
|
|
296
310
|
* @example Advanced — always propagate, even for non-sampled traces
|
|
297
311
|
* ```ts
|
|
312
|
+
* import '@supabase/supabase-js/tracing'
|
|
313
|
+
*
|
|
298
314
|
* const supabase = createClient(url, key, {
|
|
299
315
|
* tracePropagation: { enabled: true, respectSamplingDecision: false },
|
|
300
316
|
* })
|
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.112.0-beta.0'
|
package/src/tracing.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Opt-in OpenTelemetry runtime for `tracePropagation`.
|
|
3
|
+
*
|
|
4
|
+
* Importing this module registers the OpenTelemetry trace context extractor
|
|
5
|
+
* used by every Supabase client in the process. It has no exports — the
|
|
6
|
+
* import itself is the opt-in:
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* import '@supabase/supabase-js/tracing'
|
|
10
|
+
* import { createClient } from '@supabase/supabase-js'
|
|
11
|
+
*
|
|
12
|
+
* const supabase = createClient(url, key, { tracePropagation: true })
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* Requires `@opentelemetry/api` to be installed — this module imports it
|
|
16
|
+
* directly, so bundlers include it and resolution fails loudly when it is
|
|
17
|
+
* missing. Without this import, enabling `tracePropagation` logs a one-time
|
|
18
|
+
* warning and requests are sent without trace headers.
|
|
19
|
+
*
|
|
20
|
+
* @module tracing
|
|
21
|
+
*/
|
|
22
|
+
import { propagation, context } from '@opentelemetry/api'
|
|
23
|
+
import { createTraceContextExtractor } from '@supabase/tracing'
|
|
24
|
+
import { registerTraceContextExtractor } from './lib/tracingRegistry'
|
|
25
|
+
|
|
26
|
+
registerTraceContextExtractor(createTraceContextExtractor({ propagation, context }))
|