wip:milestone 0 fixes
Some checks failed
CI/CD Pipeline / unit-tests (push) Failing after 1m16s
CI/CD Pipeline / integration-tests (push) Failing after 2m32s
CI/CD Pipeline / lint (push) Successful in 5m22s
CI/CD Pipeline / e2e-tests (push) Has been skipped
CI/CD Pipeline / build (push) Has been skipped

This commit is contained in:
2026-03-15 12:35:42 +02:00
parent 6708cf28a7
commit cffdf8af86
61266 changed files with 4511646 additions and 1938 deletions

View File

@@ -0,0 +1,8 @@
import { AuthClient } from '@supabase/auth-js'
import { SupabaseAuthClientOptions } from './types'
export class SupabaseAuthClient extends AuthClient {
constructor(options: SupabaseAuthClientOptions) {
super(options)
}
}

View File

@@ -0,0 +1,35 @@
// constants.ts
import { RealtimeClientOptions } from '@supabase/realtime-js'
import { SupabaseAuthClientOptions } from './types'
import { version } from './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}` }
export const DEFAULT_GLOBAL_OPTIONS = {
headers: DEFAULT_HEADERS,
}
export const DEFAULT_DB_OPTIONS = {
schema: 'public',
}
export const DEFAULT_AUTH_OPTIONS: SupabaseAuthClientOptions = {
autoRefreshToken: true,
persistSession: true,
detectSessionInUrl: true,
flowType: 'implicit',
}
export const DEFAULT_REALTIME_OPTIONS: RealtimeClientOptions = {}

View File

@@ -0,0 +1,36 @@
type Fetch = typeof fetch
export const resolveFetch = (customFetch?: Fetch): Fetch => {
if (customFetch) {
return (...args: Parameters<Fetch>) => customFetch(...args)
}
return (...args: Parameters<Fetch>) => fetch(...args)
}
export const resolveHeadersConstructor = () => {
return Headers
}
export const fetchWithAuth = (
supabaseKey: string,
getAccessToken: () => Promise<string | null>,
customFetch?: Fetch
): Fetch => {
const fetch = resolveFetch(customFetch)
const HeadersConstructor = resolveHeadersConstructor()
return async (input, init) => {
const accessToken = (await getAccessToken()) ?? supabaseKey
let headers = new HeadersConstructor(init?.headers)
if (!headers.has('apikey')) {
headers.set('apikey', supabaseKey)
}
if (!headers.has('Authorization')) {
headers.set('Authorization', `Bearer ${accessToken}`)
}
return fetch(input, { ...init, headers })
}
}

View File

@@ -0,0 +1,98 @@
// helpers.ts
import { SupabaseClientOptions } from './types'
export function uuid() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
var r = (Math.random() * 16) | 0,
v = c == 'x' ? r : (r & 0x3) | 0x8
return v.toString(16)
})
}
export function ensureTrailingSlash(url: string): string {
return url.endsWith('/') ? url : url + '/'
}
export const isBrowser = () => typeof window !== 'undefined'
export function applySettingDefaults<
Database = any,
SchemaName extends string & keyof Database = 'public' extends keyof Database
? 'public'
: string & keyof Database,
>(
options: SupabaseClientOptions<SchemaName>,
defaults: SupabaseClientOptions<any>
): Required<SupabaseClientOptions<SchemaName>> {
const {
db: dbOptions,
auth: authOptions,
realtime: realtimeOptions,
global: globalOptions,
} = options
const {
db: DEFAULT_DB_OPTIONS,
auth: DEFAULT_AUTH_OPTIONS,
realtime: DEFAULT_REALTIME_OPTIONS,
global: DEFAULT_GLOBAL_OPTIONS,
} = defaults
const result: Required<SupabaseClientOptions<SchemaName>> = {
db: {
...DEFAULT_DB_OPTIONS,
...dbOptions,
},
auth: {
...DEFAULT_AUTH_OPTIONS,
...authOptions,
},
realtime: {
...DEFAULT_REALTIME_OPTIONS,
...realtimeOptions,
},
storage: {},
global: {
...DEFAULT_GLOBAL_OPTIONS,
...globalOptions,
headers: {
...(DEFAULT_GLOBAL_OPTIONS?.headers ?? {}),
...(globalOptions?.headers ?? {}),
},
},
accessToken: async () => '',
}
if (options.accessToken) {
result.accessToken = options.accessToken
} else {
// hack around Required<>
delete (result as any).accessToken
}
return result
}
/**
* Validates a Supabase client URL
*
* @param {string} supabaseUrl - The Supabase client URL string.
* @returns {URL} - The validated base URL.
* @throws {Error}
*/
export function validateSupabaseUrl(supabaseUrl: string): URL {
const trimmedUrl = supabaseUrl?.trim()
if (!trimmedUrl) {
throw new Error('supabaseUrl is required.')
}
if (!trimmedUrl.match(/^https?:\/\//i)) {
throw new Error('Invalid supabaseUrl: Must be a valid HTTP or HTTPS URL.')
}
try {
return new URL(ensureTrailingSlash(trimmedUrl))
} catch {
throw Error('Invalid supabaseUrl: Provided URL is malformed.')
}
}

View File

@@ -0,0 +1,66 @@
/**
* AUTO-GENERATED FILE - DO NOT EDIT
*
* This file is automatically synchronized from @supabase/postgrest-js
* Source: packages/core/postgrest-js/src/types/common/
*
* To update this file, modify the source in postgrest-js and run:
* npm run codegen
*/
// Types that are shared between supabase-js and postgrest-js
export type Fetch = typeof fetch
export type GenericRelationship = {
foreignKeyName: string
columns: string[]
isOneToOne?: boolean
referencedRelation: string
referencedColumns: string[]
}
export type GenericTable = {
Row: Record<string, unknown>
Insert: Record<string, unknown>
Update: Record<string, unknown>
Relationships: GenericRelationship[]
}
export type GenericUpdatableView = {
Row: Record<string, unknown>
Insert: Record<string, unknown>
Update: Record<string, unknown>
Relationships: GenericRelationship[]
}
export type GenericNonUpdatableView = {
Row: Record<string, unknown>
Relationships: GenericRelationship[]
}
export type GenericView = GenericUpdatableView | GenericNonUpdatableView
export type GenericSetofOption = {
isSetofReturn?: boolean | undefined
isOneToOne?: boolean | undefined
isNotNullable?: boolean | undefined
to: string
from: string
}
export type GenericFunction = {
Args: Record<string, unknown> | never
Returns: unknown
SetofOptions?: GenericSetofOption
}
export type GenericSchema = {
Tables: Record<string, GenericTable>
Views: Record<string, GenericView>
Functions: Record<string, GenericFunction>
}
export type ClientServerOptions = {
PostgrestVersion?: string
}

View File

@@ -0,0 +1,158 @@
/**
* AUTO-GENERATED FILE - DO NOT EDIT
*
* This file is automatically synchronized from @supabase/postgrest-js
* Source: packages/core/postgrest-js/src/types/common/
*
* To update this file, modify the source in postgrest-js and run:
* npm run codegen
*/
import type { GenericFunction, GenericSchema, GenericSetofOption } from './common'
// Functions matching utils
type IsMatchingArgs<
FnArgs extends GenericFunction['Args'],
PassedArgs extends GenericFunction['Args'],
> = [FnArgs] extends [Record<PropertyKey, never>]
? PassedArgs extends Record<PropertyKey, never>
? true
: false
: keyof PassedArgs extends keyof FnArgs
? PassedArgs extends FnArgs
? true
: false
: false
type MatchingFunctionArgs<
Fn extends GenericFunction,
Args extends GenericFunction['Args'],
> = Fn extends { Args: infer A extends GenericFunction['Args'] }
? IsMatchingArgs<A, Args> extends true
? Fn
: never
: false
type FindMatchingFunctionByArgs<
FnUnion,
Args extends GenericFunction['Args'],
> = FnUnion extends infer Fn extends GenericFunction ? MatchingFunctionArgs<Fn, Args> : false
// Types for working with database schemas
type TablesAndViews<Schema extends GenericSchema> = Schema['Tables'] & Exclude<Schema['Views'], ''>
// Utility types for working with unions
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void
? I
: never
type LastOf<T> =
UnionToIntersection<T extends any ? () => T : never> extends () => infer R ? R : never
type IsAny<T> = 0 extends 1 & T ? true : false
type ExactMatch<T, S> = [T] extends [S] ? ([S] extends [T] ? true : false) : false
type ExtractExactFunction<Fns, Args> = Fns extends infer F
? F extends GenericFunction
? ExactMatch<F['Args'], Args> extends true
? F
: never
: never
: never
type IsNever<T> = [T] extends [never] ? true : false
type RpcFunctionNotFound<FnName> = {
Row: any
Result: {
error: true
} & "Couldn't infer function definition matching provided arguments"
RelationName: FnName
Relationships: null
}
type CrossSchemaError<TableRef extends string> = {
error: true
} & `Function returns SETOF from a different schema ('${TableRef}'). Use .overrideTypes<YourReturnType>() to specify the return type explicitly.`
export type GetRpcFunctionFilterBuilderByArgs<
Schema extends GenericSchema,
FnName extends string & keyof Schema['Functions'],
Args,
> = {
0: Schema['Functions'][FnName]
// If the Args is exactly never (function call without any params)
1: IsAny<Schema> extends true
? any
: IsNever<Args> extends true
? // This is for retro compatibility, if the funcition is defined with an single return and an union of Args
// we fallback to the last function definition matched by name
IsNever<ExtractExactFunction<Schema['Functions'][FnName], Args>> extends true
? LastOf<Schema['Functions'][FnName]>
: ExtractExactFunction<Schema['Functions'][FnName], Args>
: Args extends Record<PropertyKey, never>
? LastOf<Schema['Functions'][FnName]>
: // Otherwise, we attempt to match with one of the function definition in the union based
// on the function arguments provided
Args extends GenericFunction['Args']
? // This is for retro compatibility, if the funcition is defined with an single return and an union of Args
// we fallback to the last function definition matched by name
IsNever<
LastOf<FindMatchingFunctionByArgs<Schema['Functions'][FnName], Args>>
> extends true
? LastOf<Schema['Functions'][FnName]>
: // Otherwise, we use the arguments based function definition narrowing to get the right value
LastOf<FindMatchingFunctionByArgs<Schema['Functions'][FnName], Args>>
: // If we can't find a matching function by args, we try to find one by function name
ExtractExactFunction<Schema['Functions'][FnName], Args> extends GenericFunction
? ExtractExactFunction<Schema['Functions'][FnName], Args>
: any
}[1] extends infer Fn
? // If we are dealing with an non-typed client everything is any
IsAny<Fn> extends true
? { Row: any; Result: any; RelationName: FnName; Relationships: null }
: // Otherwise, we use the arguments based function definition narrowing to get the right value
Fn extends GenericFunction
? {
Row: Fn['SetofOptions'] extends GenericSetofOption
? Fn['SetofOptions']['to'] extends keyof TablesAndViews<Schema>
? TablesAndViews<Schema>[Fn['SetofOptions']['to']]['Row']
: // Cross-schema fallback: use Returns type when table is not in current schema
Fn['Returns'] extends any[]
? Fn['Returns'][number] extends Record<string, unknown>
? Fn['Returns'][number]
: CrossSchemaError<Fn['SetofOptions']['to'] & string>
: Fn['Returns'] extends Record<string, unknown>
? Fn['Returns']
: CrossSchemaError<Fn['SetofOptions']['to'] & string>
: Fn['Returns'] extends any[]
? Fn['Returns'][number] extends Record<string, unknown>
? Fn['Returns'][number]
: never
: Fn['Returns'] extends Record<string, unknown>
? Fn['Returns']
: never
Result: Fn['SetofOptions'] extends GenericSetofOption
? Fn['SetofOptions']['isSetofReturn'] extends true
? Fn['SetofOptions']['isOneToOne'] extends true
? Fn['Returns'][]
: Fn['Returns']
: Fn['Returns']
: Fn['Returns']
RelationName: Fn['SetofOptions'] extends GenericSetofOption
? Fn['SetofOptions']['to']
: FnName
Relationships: Fn['SetofOptions'] extends GenericSetofOption
? Fn['SetofOptions']['to'] extends keyof Schema['Tables']
? Schema['Tables'][Fn['SetofOptions']['to']]['Relationships']
: Fn['SetofOptions']['to'] extends keyof Schema['Views']
? Schema['Views'][Fn['SetofOptions']['to']]['Relationships']
: null
: null
}
: // If we failed to find the function by argument, we still pass with any but also add an overridable
Fn extends false
? RpcFunctionNotFound<FnName>
: RpcFunctionNotFound<FnName>
: RpcFunctionNotFound<FnName>

View File

@@ -0,0 +1,173 @@
import { GoTrueClientOptions } from '@supabase/auth-js'
import { RealtimeClientOptions } from '@supabase/realtime-js'
import { PostgrestError } from '@supabase/postgrest-js'
import type { StorageClientOptions } from '@supabase/storage-js'
import type {
GenericSchema,
GenericRelationship,
GenericTable,
GenericUpdatableView,
GenericNonUpdatableView,
GenericView,
GenericFunction,
} from './rest/types/common/common'
export type {
GenericSchema,
GenericRelationship,
GenericTable,
GenericUpdatableView,
GenericNonUpdatableView,
GenericView,
GenericFunction,
}
export interface SupabaseAuthClientOptions extends GoTrueClientOptions {}
export type Fetch = typeof fetch
export type SupabaseClientOptions<SchemaName> = {
/**
* The Postgres schema which your tables belong to. Must be on the list of exposed schemas in Supabase. Defaults to `public`.
*/
db?: {
schema?: SchemaName
/**
* Optional timeout in milliseconds for PostgREST requests.
* When set, requests will automatically abort after this duration to prevent indefinite hangs.
*
* @example
* ```ts
* const supabase = createClient(url, key, {
* db: { timeout: 30000 } // 30 second timeout
* })
* ```
*/
timeout?: number
/**
* Maximum URL length in characters before warnings/errors are triggered.
* Defaults to 8000 characters. Used to provide helpful hints when URLs
* exceed server limits.
*
* @example
* ```ts
* const supabase = createClient(url, key, {
* db: { urlLengthLimit: 10000 } // Custom limit
* })
* ```
*/
urlLengthLimit?: number
}
auth?: {
/**
* Automatically refreshes the token for logged-in users. Defaults to true.
*/
autoRefreshToken?: boolean
/**
* Optional key name used for storing tokens in local storage.
*/
storageKey?: string
/**
* Whether to persist a logged-in session to storage. Defaults to true.
*/
persistSession?: boolean
/**
* Detect a session from the URL. Used for OAuth login callbacks. Defaults to true.
*
* Can be set to a function to provide custom logic for determining if a URL contains
* a Supabase auth callback. The function receives the current URL and parsed parameters,
* and should return true if the URL should be processed as a Supabase auth callback.
*
* This is useful when your app uses other OAuth providers (e.g., Facebook Login) that
* also return access_token in the URL fragment, which would otherwise be incorrectly
* intercepted by Supabase Auth.
*
* @example
* ```ts
* detectSessionInUrl: (url, params) => {
* // Ignore Facebook OAuth redirects
* if (url.pathname === '/facebook/redirect') return false
* // Use default detection for other URLs
* return Boolean(params.access_token || params.error_description)
* }
* ```
*/
detectSessionInUrl?: boolean | ((url: URL, params: { [parameter: string]: string }) => boolean)
/**
* A storage provider. Used to store the logged-in session.
*/
storage?: SupabaseAuthClientOptions['storage']
/**
* A storage provider to store the user profile separately from the session.
* Useful when you need to store the session information in cookies,
* without bloating the data with the redundant user object.
*
* @experimental
*/
userStorage?: SupabaseAuthClientOptions['userStorage']
/**
* OAuth flow to use - defaults to implicit flow. PKCE is recommended for mobile and server-side applications.
*/
flowType?: SupabaseAuthClientOptions['flowType']
/**
* If debug messages for authentication client are emitted. Can be used to inspect the behavior of the library.
*/
debug?: SupabaseAuthClientOptions['debug']
/**
* Provide your own locking mechanism based on the environment. By default no locking is done at this time.
*
* @experimental
*/
lock?: SupabaseAuthClientOptions['lock']
/**
* If there is an error with the query, throwOnError will reject the promise by
* throwing the error instead of returning it as part of a successful response.
*/
throwOnError?: SupabaseAuthClientOptions['throwOnError']
}
/**
* Options passed to the realtime-js instance
*/
realtime?: RealtimeClientOptions
storage?: StorageClientOptions
global?: {
/**
* A custom `fetch` implementation.
*/
fetch?: Fetch
/**
* Optional headers for initializing the client.
*/
headers?: Record<string, string>
}
/**
* Optional function for using a third-party authentication system with
* Supabase. The function should return an access token or ID token (JWT) by
* obtaining it from the third-party auth SDK. Note that this
* function may be called concurrently and many times. Use memoization and
* locking techniques if this is not supported by the SDKs.
*
* When set, the `auth` namespace of the Supabase client cannot be used.
* Create another client if you wish to use Supabase Auth and third-party
* authentications concurrently in the same application.
*/
accessToken?: () => Promise<string | null>
}
/**
* Helper types for query results.
*/
export type QueryResult<T> = T extends PromiseLike<infer U> ? U : never
export type QueryData<T> = T extends PromiseLike<{ data: infer U }> ? Exclude<U, null> : never
export type QueryError = PostgrestError
/**
* Strips internal Supabase metadata from Database types.
* Useful for libraries defining generic constraints on Database types.
*
* @example
* ```typescript
* type CleanDB = DatabaseWithoutInternals<Database>
* ```
*/
export type DatabaseWithoutInternals<DB> = Omit<DB, '__InternalSupabase'>

View File

@@ -0,0 +1,7 @@
// Generated automatically during releases by scripts/update-version-files.ts
// This file provides runtime access to the package version for:
// - HTTP request headers (e.g., X-Client-Info header for API requests)
// - Debugging and support (identifying which version is running)
// - Telemetry and logging (version reporting in errors/analytics)
// - Ensuring build artifacts match the published package version
export const version = '2.99.1'