@neon/neon-js 0.0.0 → 0.10.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.
@@ -0,0 +1,2 @@
1
+ export * from "@neon/auth/vanilla/adapters";
2
+ export {};
@@ -0,0 +1,2 @@
1
+ export * from "@neon/auth/vanilla/adapters";
2
+ export {};
@@ -0,0 +1,2 @@
1
+ export * from "@neon/auth/vanilla";
2
+ export {};
@@ -0,0 +1,2 @@
1
+ export * from "@neon/auth/vanilla";
2
+ export {};
@@ -0,0 +1,219 @@
1
+ import { BetterAuthVanillaAdapterInstance } from "@neon/auth/vanilla/adapters";
2
+ import { DefaultSchemaName, DefaultSchemaName as DefaultSchemaName$1, NeonPostgrestClient, NeonPostgrestClientConstructorOptions } from "@neon/postgrest-js";
3
+ import { NeonAuth, NeonAuthAdapter, NeonAuthConfig, NeonAuthPublicApi } from "@neon/auth";
4
+ import { BetterAuthReactAdapterInstance } from "@neon/auth/react/adapters";
5
+
6
+ //#region src/client/derive-urls.d.ts
7
+
8
+ /**
9
+ * Pure function: given a Neon base URL, returns the corresponding
10
+ * auth and Data API URLs.
11
+ *
12
+ * Wrappers (e.g. @databricks/lakebase-js) can supply a different implementation
13
+ * via the `deriveUrls` option on createClient.
14
+ */
15
+ type DeriveNeonUrls = (baseUrl: string) => {
16
+ auth: string;
17
+ dataApi: string;
18
+ };
19
+ /**
20
+ * Default URL derivation for Neon endpoints.
21
+ *
22
+ * Insert `neonauth` / `apirest` after the first hostname label and append
23
+ * `/auth` / `/rest/v1` to the path.
24
+ *
25
+ * Only the protocol, host, port, and path are used. A query string, hash
26
+ * fragment, or embedded credentials (`user:pass@host`) are rejected.
27
+ *
28
+ * Constraints (use the object form or a custom `deriveUrls` to bypass them):
29
+ * - The hostname must have at least 3 dot-separated labels, so `localhost`
30
+ * and single-host proxies are intentionally rejected.
31
+ * - A single port is applied to both derived hosts, so split-port local
32
+ * setups (e.g. `neonauth:30443` vs `apirest:9443`) cannot be expressed
33
+ * via the string form. In production both services share port 443.
34
+ *
35
+ * Example:
36
+ * https://ep-xxx.c-2.us-east-2.aws.neon.build/dbname
37
+ * → auth: https://ep-xxx.neonauth.c-2.us-east-2.aws.neon.build/dbname/auth
38
+ * → dataApi: https://ep-xxx.apirest.c-2.us-east-2.aws.neon.build/dbname/rest/v1
39
+ */
40
+ declare const defaultDeriveNeonUrls: DeriveNeonUrls;
41
+ //#endregion
42
+ //#region src/client/neon-client.d.ts
43
+ type NeonClientConstructorOptions<SchemaName, TAuth extends NeonAuthAdapter = NeonAuthAdapter> = NeonPostgrestClientConstructorOptions<SchemaName> & {
44
+ authClient: NeonAuth<TAuth>;
45
+ };
46
+ /**
47
+ * Neon client with integrated authentication
48
+ *
49
+ * Extends NeonPostgrestClient with Neon Auth integration.
50
+ * For auth-free clients, use @neon/postgrest-js instead.
51
+ */
52
+ declare class NeonClient<Database = any, SchemaName extends string & keyof Database = DefaultSchemaName<Database>, TAuth extends NeonAuthAdapter = NeonAuthAdapter> extends NeonPostgrestClient<Database, SchemaName> {
53
+ auth: NeonAuthPublicApi<TAuth>;
54
+ constructor({
55
+ dataApiUrl,
56
+ options,
57
+ authClient
58
+ }: NeonClientConstructorOptions<SchemaName, TAuth>);
59
+ }
60
+ //#endregion
61
+ //#region src/client/client-factory.d.ts
62
+ /**
63
+ * Auth configuration for createClient
64
+ */
65
+ type CreateClientAuthConfig<T extends NeonAuthAdapter> = {
66
+ /** The auth service URL */
67
+ url: string;
68
+ } & NeonAuthConfig<T>;
69
+ /**
70
+ * Data API configuration for createClient
71
+ */
72
+ type CreateClientDataApiConfig<SchemaName, TAuth extends NeonAuthAdapter> = {
73
+ /** The Data API URL */
74
+ url: string;
75
+ /** Additional client options */
76
+ options?: Omit<NeonClientConstructorOptions<SchemaName, TAuth>, "dataApiUrl" | "authClient">["options"];
77
+ };
78
+ /**
79
+ * Configuration for createClient
80
+ */
81
+ type CreateClientConfig<SchemaName, T extends NeonAuthAdapter> = {
82
+ /** Auth service configuration */
83
+ auth: CreateClientAuthConfig<T>;
84
+ /** Data API configuration */
85
+ dataApi: CreateClientDataApiConfig<SchemaName, T>;
86
+ };
87
+ /**
88
+ * Returns a valid JWT for the current user, or `null` if there is no session.
89
+ *
90
+ * Called lazily on every Data API request. Wire this to your own identity
91
+ * provider — e.g. Clerk's `getToken()` or Auth0's `getAccessTokenSilently()`.
92
+ * Neon validates the returned token against the JWKS URL configured for the
93
+ * provider.
94
+ */
95
+ type NeonDataApiTokenProvider = () => Promise<string | null>;
96
+ /**
97
+ * Data API configuration for the external-auth-provider form of createClient.
98
+ *
99
+ * Same as {@link CreateClientDataApiConfig} but carries a `getToken` function
100
+ * instead of relying on a Neon Auth service.
101
+ */
102
+ type CreateClientExternalDataApiConfig<SchemaName> = CreateClientDataApiConfig<SchemaName, NeonAuthAdapter> & {
103
+ /** Token provider consulted on every Data API request. */
104
+ getToken: NeonDataApiTokenProvider;
105
+ };
106
+ /**
107
+ * Configuration for the external-auth-provider form of createClient.
108
+ *
109
+ * Use this when authentication is handled by your own identity provider
110
+ * (Clerk, Auth0, …) rather than Neon Auth: omit the `auth` block entirely and
111
+ * supply `dataApi.getToken`. No Neon Auth client is created, and the returned
112
+ * client is a plain {@link NeonPostgrestClient} (no `.auth` property).
113
+ */
114
+ type CreateClientExternalConfig<SchemaName> = {
115
+ /** External providers do not use a Neon Auth service. */
116
+ auth?: never;
117
+ /** Data API configuration, including your token provider. */
118
+ dataApi: CreateClientExternalDataApiConfig<SchemaName>;
119
+ };
120
+ /**
121
+ * Factory function to create NeonClient with seamless auth integration.
122
+ *
123
+ * @param config - Configuration with auth and dataApi sections
124
+ * @returns NeonClient instance with auth-aware fetch wrapper
125
+ * @throws AuthRequiredError when making requests without authentication
126
+ *
127
+ * @example
128
+ * ```typescript
129
+ * // Simple usage with default BetterAuthVanillaAdapter
130
+ * import { createClient } from '@neon/neon-js';
131
+ *
132
+ * const client = createClient({
133
+ * auth: { url: 'https://auth.example.com' },
134
+ * dataApi: { url: 'https://data-api.example.com/rest/v1' },
135
+ * });
136
+ *
137
+ * // Better Auth API
138
+ * await client.auth.signIn.email({ email, password });
139
+ *
140
+ * // Database queries (automatic token injection)
141
+ * const { data: items } = await client.from('items').select();
142
+ * ```
143
+ *
144
+ * @example
145
+ * ```typescript
146
+ * // Single base URL — auth and Data API URLs are derived automatically.
147
+ * const client = createClient(
148
+ * 'https://ep-xxx.c-2.us-east-2.aws.neon.build/dbname'
149
+ * );
150
+ * ```
151
+ *
152
+ * @example
153
+ * ```typescript
154
+ * // External auth provider (Clerk, Auth0, …): omit `auth` and supply a
155
+ * // `getToken` function. The returned client has no `.auth` property.
156
+ * const client = createClient({
157
+ * dataApi: {
158
+ * url: 'https://data-api.example.com/rest/v1',
159
+ * getToken: async () => await yourAuthProvider.getToken(),
160
+ * },
161
+ * });
162
+ *
163
+ * const { data: items } = await client.from('items').select();
164
+ * ```
165
+ */
166
+ /**
167
+ * The value `BetterAuthVanillaAdapter()` and friends return: a builder that `createClient`
168
+ * invokes with the auth URL. Distinct from the adapter instance it produces.
169
+ */
170
+ type AdapterBuilder<T extends NeonAuthAdapter> = NonNullable<NeonAuthConfig<T>["adapter"]>;
171
+ /**
172
+ * Helper type to create NeonClient with proper schema resolution.
173
+ * Uses 'public' as the default schema since it's the most common case.
174
+ */
175
+ type CreateClientResult<Database, TAdapter extends NeonAuthAdapter> = NeonClient<Database, DefaultSchemaName$1<Database>, TAdapter>;
176
+ declare function createClient<Database = any>(config: CreateClientExternalConfig<DefaultSchemaName$1<Database>>): NeonPostgrestClient<Database, DefaultSchemaName$1<Database>>;
177
+ declare function createClient<Database = any>(config: {
178
+ auth: {
179
+ url: string;
180
+ allowAnonymous?: boolean;
181
+ };
182
+ dataApi: CreateClientDataApiConfig<DefaultSchemaName$1<Database>, BetterAuthVanillaAdapterInstance>;
183
+ }): CreateClientResult<Database, BetterAuthVanillaAdapterInstance>;
184
+ declare function createClient<Database = any>(config: CreateClientConfig<DefaultSchemaName$1<Database>, BetterAuthVanillaAdapterInstance>): CreateClientResult<Database, BetterAuthVanillaAdapterInstance>;
185
+ declare function createClient<Database = any>(config: CreateClientConfig<DefaultSchemaName$1<Database>, BetterAuthReactAdapterInstance>): CreateClientResult<Database, BetterAuthReactAdapterInstance>;
186
+ declare function createClient<Database = any>(baseUrl: string, options?: CreateClientStringOptions<DefaultSchemaName$1<Database>, BetterAuthVanillaAdapterInstance>): CreateClientResult<Database, BetterAuthVanillaAdapterInstance>;
187
+ declare function createClient<Database = any>(baseUrl: string, options: CreateClientStringOptions<DefaultSchemaName$1<Database>, BetterAuthVanillaAdapterInstance> & {
188
+ auth: {
189
+ adapter: AdapterBuilder<BetterAuthVanillaAdapterInstance>;
190
+ };
191
+ }): CreateClientResult<Database, BetterAuthVanillaAdapterInstance>;
192
+ declare function createClient<Database = any>(baseUrl: string, options: CreateClientStringOptions<DefaultSchemaName$1<Database>, BetterAuthReactAdapterInstance> & {
193
+ auth: {
194
+ adapter: AdapterBuilder<BetterAuthReactAdapterInstance>;
195
+ };
196
+ }): CreateClientResult<Database, BetterAuthReactAdapterInstance>;
197
+ /**
198
+ * Adapter-agnostic implementation behind every public `createClient`, so entry points that
199
+ * pin an adapter (`@neon/neon-js/supabase`) share one code path with the main entry.
200
+ */
201
+
202
+ /**
203
+ * Per-call overrides accepted alongside a single base URL.
204
+ *
205
+ * Every field is optional; defaults come from `deriveUrls(baseUrl)`.
206
+ */
207
+ type CreateClientStringOptions<SchemaName, T extends NeonAuthAdapter> = {
208
+ auth?: Partial<CreateClientAuthConfig<T>>;
209
+ dataApi?: Partial<CreateClientDataApiConfig<SchemaName, T>>;
210
+ /**
211
+ * Override the auth/Data API URL derivation. End users do not need this;
212
+ * it is intended for wrapper packages (e.g. `@databricks/lakebase-js`)
213
+ * that have their own endpoint pattern.
214
+ */
215
+ deriveUrls?: DeriveNeonUrls;
216
+ };
217
+ //#endregion
218
+ export { CreateClientStringOptions as a, DefaultSchemaName$1 as c, CreateClientResult as i, DeriveNeonUrls as l, CreateClientExternalConfig as n, NeonDataApiTokenProvider as o, CreateClientExternalDataApiConfig as r, createClient as s, CreateClientDataApiConfig as t, defaultDeriveNeonUrls as u };
219
+ //# sourceMappingURL=client-factory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client-factory.d.ts","names":["DeriveNeonUrls","defaultDeriveNeonUrls","NeonAuth","NeonAuthAdapter","NeonAuthPublicApi","DefaultSchemaName","NeonPostgrestClient","NeonPostgrestClientConstructorOptions","NeonClientConstructorOptions","SchemaName","TAuth","NeonClient","Database","dataApiUrl","options","authClient","NeonAuthAdapter","NeonAuthConfig","BetterAuthReactAdapterInstance","BetterAuthVanillaAdapterInstance","NeonPostgrestClient","DeriveNeonUrls","DefaultSchemaName","NeonClient","NeonClientConstructorOptions","CreateClientAuthConfig","T","CreateClientDataApiConfig","SchemaName","TAuth","Omit","CreateClientConfig","NeonDataApiTokenProvider","Promise","CreateClientExternalDataApiConfig","CreateClientExternalConfig","AdapterBuilder","NonNullable","CreateClientResult","Database","TAdapter","createClient","CreateClientStringOptions","createClientImpl","TAuthAdapter","Partial","DefaultSchemaName","BetterAuthVanillaAdapterInstance","DefaultSchemaName","DefaultSchemaName$1","NeonPostgrestClient","NeonPostgrestClientConstructorOptions","NeonAuth","NeonAuthAdapter","NeonAuthConfig","NeonAuthPublicApi","BetterAuthReactAdapterInstance","DeriveNeonUrls","baseUrl","auth","dataApi","defaultDeriveNeonUrls","NeonClientConstructorOptions","SchemaName","authClient","TAuth","NeonClient","Database","constructor","dataApiUrl","options","CreateClientAuthConfig","url","T","CreateClientDataApiConfig","Omit","CreateClientConfig","NeonDataApiTokenProvider","Promise","CreateClientExternalDataApiConfig","getToken","CreateClientExternalConfig","AdapterBuilder","NonNullable","CreateClientResult","TAdapter","createClient","config","allowAnonymous","CreateClientStringOptions","adapter","Partial","deriveUrls","a","c","i","l","n","o","r","s","t","u"],"sources":["../src/client/derive-urls.ts","../src/client/neon-client.ts","../src/client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AAlBjB;AACAH;AAFQuB;AAG6BvB;AAAfiB,KA8JZM,yBA9JYN,CAAAA,UAAAA,EAAAA,UA8JoCpB,eA9JpCoB,CAAAA,GAAAA;EACFG,IAAAA,CAAAA,EA8JdM,OA9JcN,CA8JNd,sBA9JMc,CA8JiBb,CA9JjBa,CAAAA,CAAAA;EAAUpB,OAAAA,CAAAA,EA+JrB0B,OA/JqB1B,CA+JbQ,yBA/JaR,CA+JaS,UA/JbT,EA+JyBO,CA/JzBP,CAAAA,CAAAA;EAA7BmB;AAAkB;AAIrB;AAA4B;AAGRC;EAAlBjB,UAAAA,CAAAA,EA8JYD,cA9JZC;AACAJ,CAAAA"}
@@ -0,0 +1,235 @@
1
+ import { BetterAuthVanillaAdapter } from "@neon/auth/vanilla/adapters";
2
+ import { NeonPostgrestClient, X_NEON_CLIENT_INFO_HEADER, fetchWithToken } from "@neon/postgrest-js";
3
+ import { BETTER_AUTH_VERSION, createInternalNeonAuth, getAdapterName } from "@neon/auth";
4
+ //#region ../../internals/internal/dist/client-info.js
5
+ /**
6
+ * Type guard for checking if a property exists on globalThis
7
+ */
8
+ function hasGlobalProperty(key) {
9
+ return key in globalThis;
10
+ }
11
+ /**
12
+ * Detects the JavaScript framework being used at runtime.
13
+ * Detection order matters to avoid false positives (e.g., Next.js includes React).
14
+ */
15
+ function detectFramework() {
16
+ if (typeof process !== "undefined" && process.env && (process.env.NEXT_RUNTIME || process.env.__NEXT_PRIVATE_ORIGIN)) return "next";
17
+ if (typeof globalThis.window !== "undefined") {
18
+ if (hasGlobalProperty("__NEXT_DATA__")) return "next";
19
+ if (hasGlobalProperty("__remixContext")) return "remix";
20
+ if (hasGlobalProperty("__REACT_DEVTOOLS_GLOBAL_HOOK__")) return "react";
21
+ if (hasGlobalProperty("__VUE__")) return "vue";
22
+ if (hasGlobalProperty("Zone")) return "angular";
23
+ }
24
+ }
25
+ function getClientInfo$1(sdkName, sdkVersion, extras) {
26
+ const base = {
27
+ sdk: sdkName,
28
+ version: sdkVersion,
29
+ runtime: "unknown",
30
+ runtimeVersion: "unknown",
31
+ platform: "unknown",
32
+ arch: "unknown"
33
+ };
34
+ let result;
35
+ if (typeof process !== "undefined" && process.versions?.node) result = {
36
+ ...base,
37
+ runtime: "node",
38
+ runtimeVersion: process.versions.node,
39
+ platform: process.platform,
40
+ arch: process.arch
41
+ };
42
+ else if (typeof Deno !== "undefined") result = {
43
+ ...base,
44
+ runtime: "deno",
45
+ runtimeVersion: Deno.version?.deno ?? "unknown",
46
+ platform: Deno.build?.os ?? "unknown",
47
+ arch: Deno.build?.arch ?? "unknown"
48
+ };
49
+ else if (typeof Bun !== "undefined") result = {
50
+ ...base,
51
+ runtime: "bun",
52
+ runtimeVersion: Bun.version ?? "unknown",
53
+ platform: process?.platform ?? "unknown",
54
+ arch: process?.arch ?? "unknown"
55
+ };
56
+ else if (typeof EdgeRuntime !== "undefined" || typeof process !== "undefined" && !process.versions?.node && typeof globalThis.window === "undefined" && typeof document === "undefined") result = {
57
+ ...base,
58
+ runtime: "edge"
59
+ };
60
+ else if (globalThis.window !== void 0 && typeof document !== "undefined") result = {
61
+ ...base,
62
+ runtime: "browser",
63
+ runtimeVersion: "unknown",
64
+ platform: "web",
65
+ arch: "unknown"
66
+ };
67
+ else result = base;
68
+ const framework = detectFramework();
69
+ if (framework) result.framework = framework;
70
+ if (extras?.betterAuthVersion) result.betterAuthVersion = extras.betterAuthVersion;
71
+ if (extras?.adapter) result.adapter = extras.adapter;
72
+ return result;
73
+ }
74
+ //#endregion
75
+ //#region package.json
76
+ var name = "@neon/neon-js";
77
+ var version = "0.10.0";
78
+ //#endregion
79
+ //#region src/utils/client-info.ts
80
+ function buildNeonJsClientInfo(adapter) {
81
+ const info = getClientInfo$1(name, version, {
82
+ betterAuthVersion: BETTER_AUTH_VERSION,
83
+ adapter
84
+ });
85
+ return JSON.stringify(info);
86
+ }
87
+ //#endregion
88
+ //#region src/client/derive-urls.ts
89
+ /**
90
+ * Default URL derivation for Neon endpoints.
91
+ *
92
+ * Insert `neonauth` / `apirest` after the first hostname label and append
93
+ * `/auth` / `/rest/v1` to the path.
94
+ *
95
+ * Only the protocol, host, port, and path are used. A query string, hash
96
+ * fragment, or embedded credentials (`user:pass@host`) are rejected.
97
+ *
98
+ * Constraints (use the object form or a custom `deriveUrls` to bypass them):
99
+ * - The hostname must have at least 3 dot-separated labels, so `localhost`
100
+ * and single-host proxies are intentionally rejected.
101
+ * - A single port is applied to both derived hosts, so split-port local
102
+ * setups (e.g. `neonauth:30443` vs `apirest:9443`) cannot be expressed
103
+ * via the string form. In production both services share port 443.
104
+ *
105
+ * Example:
106
+ * https://ep-xxx.c-2.us-east-2.aws.neon.build/dbname
107
+ * → auth: https://ep-xxx.neonauth.c-2.us-east-2.aws.neon.build/dbname/auth
108
+ * → dataApi: https://ep-xxx.apirest.c-2.us-east-2.aws.neon.build/dbname/rest/v1
109
+ */
110
+ const defaultDeriveNeonUrls = (baseUrl) => {
111
+ const url = new URL(baseUrl);
112
+ if (url.search !== "" || url.hash !== "") throw new Error(`Invalid Neon base URL: must not include a query string or hash fragment (got "${baseUrl}").`);
113
+ if (url.username !== "" || url.password !== "") throw new Error(`Invalid Neon base URL: must not include credentials (got "${baseUrl}").`);
114
+ const labels = url.hostname.split(".");
115
+ if (labels.length < 3) throw new Error(`Invalid Neon base URL: hostname "${url.hostname}" must have at least 3 dot-separated labels (e.g. ep-xxx.region.tld).`);
116
+ const [first, ...rest] = labels;
117
+ const authHost = [
118
+ first,
119
+ "neonauth",
120
+ ...rest
121
+ ].join(".");
122
+ const dataApiHost = [
123
+ first,
124
+ "apirest",
125
+ ...rest
126
+ ].join(".");
127
+ const basePath = url.pathname.replace(/\/+$/, "");
128
+ const port = url.port ? `:${url.port}` : "";
129
+ return {
130
+ auth: `${url.protocol}//${authHost}${port}${basePath}/auth`,
131
+ dataApi: `${url.protocol}//${dataApiHost}${port}${basePath}/rest/v1`
132
+ };
133
+ };
134
+ //#endregion
135
+ //#region src/client/neon-client.ts
136
+ /**
137
+ * Neon client with integrated authentication
138
+ *
139
+ * Extends NeonPostgrestClient with Neon Auth integration.
140
+ * For auth-free clients, use @neon/postgrest-js instead.
141
+ */
142
+ var NeonClient = class extends NeonPostgrestClient {
143
+ auth;
144
+ constructor({ dataApiUrl, options, authClient }) {
145
+ super({
146
+ dataApiUrl,
147
+ options
148
+ });
149
+ this.auth = authClient.adapter;
150
+ }
151
+ };
152
+ //#endregion
153
+ //#region src/client/client-factory.ts
154
+ function createClient(arg1, arg2) {
155
+ return createClientImpl(arg1, arg2);
156
+ }
157
+ /**
158
+ * Adapter-agnostic implementation behind every public `createClient`, so entry points that
159
+ * pin an adapter (`@neon/neon-js/supabase`) share one code path with the main entry.
160
+ */
161
+ function createClientImpl(arg1, arg2) {
162
+ if (typeof arg1 !== "string" && !arg1.auth) return buildExternalClient(arg1.dataApi);
163
+ const { auth: authConfig, dataApi: dataApiConfig } = typeof arg1 === "string" ? buildConfigFromBaseUrl(arg1, arg2) : arg1;
164
+ const adapter = authConfig.adapter ?? BetterAuthVanillaAdapter();
165
+ const clientInfoHeader = buildNeonJsClientInfo(getAdapterName(adapter));
166
+ const auth = createInternalNeonAuth(authConfig.url, {
167
+ adapter,
168
+ allowAnonymous: authConfig.allowAnonymous ?? false,
169
+ fetchOptions: { headers: { [X_NEON_CLIENT_INFO_HEADER]: clientInfoHeader } }
170
+ });
171
+ const getAccessToken = async () => {
172
+ return auth.getJWTToken();
173
+ };
174
+ const authFetch = fetchWithToken(getAccessToken, dataApiConfig.options?.global?.fetch);
175
+ return new NeonClient({
176
+ dataApiUrl: dataApiConfig.url,
177
+ authClient: auth,
178
+ options: {
179
+ ...dataApiConfig.options,
180
+ global: {
181
+ ...dataApiConfig.options?.global,
182
+ fetch: authFetch,
183
+ headers: {
184
+ ...dataApiConfig.options?.global?.headers,
185
+ [X_NEON_CLIENT_INFO_HEADER]: clientInfoHeader
186
+ }
187
+ }
188
+ }
189
+ });
190
+ }
191
+ /**
192
+ * Builds the external-auth-provider client: a plain NeonPostgrestClient whose
193
+ * every request carries the caller's token via `fetchWithToken(getToken)`.
194
+ *
195
+ * Mirrors the fetch/header wiring of the auth path, but the token comes from
196
+ * the caller's `getToken` rather than a Neon Auth session.
197
+ */
198
+ function buildExternalClient(dataApiConfig) {
199
+ const clientInfoHeader = buildNeonJsClientInfo();
200
+ const tokenFetch = fetchWithToken(dataApiConfig.getToken, dataApiConfig.options?.global?.fetch);
201
+ const options = {
202
+ ...dataApiConfig.options,
203
+ global: {
204
+ ...dataApiConfig.options?.global,
205
+ fetch: tokenFetch,
206
+ headers: {
207
+ ...dataApiConfig.options?.global?.headers,
208
+ [X_NEON_CLIENT_INFO_HEADER]: clientInfoHeader
209
+ }
210
+ }
211
+ };
212
+ return new NeonPostgrestClient({
213
+ dataApiUrl: dataApiConfig.url,
214
+ options
215
+ });
216
+ }
217
+ function buildConfigFromBaseUrl(baseUrl, options) {
218
+ const derived = (options?.deriveUrls ?? defaultDeriveNeonUrls)(baseUrl);
219
+ const authOverrides = options?.auth ?? {};
220
+ const dataApiOverrides = options?.dataApi ?? {};
221
+ return {
222
+ auth: {
223
+ ...authOverrides,
224
+ url: authOverrides.url ?? derived.auth
225
+ },
226
+ dataApi: {
227
+ ...dataApiOverrides,
228
+ url: dataApiOverrides.url ?? derived.dataApi
229
+ }
230
+ };
231
+ }
232
+ //#endregion
233
+ export { createClientImpl as n, defaultDeriveNeonUrls as r, createClient as t };
234
+
235
+ //# sourceMappingURL=client-factory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client-factory.js","names":["getClientInfo","getInternalClientInfo","pkg.name","pkg.version"],"sources":["../../../internals/internal/dist/client-info.js","../package.json","../src/utils/client-info.ts","../src/client/derive-urls.ts","../src/client/neon-client.ts","../src/client/client-factory.ts"],"sourcesContent":["//#region src/client-info.ts\nconst X_NEON_CLIENT_INFO_HEADER = \"X-Neon-Client-Info\";\n/**\n* Type guard for checking if a property exists on globalThis\n*/\nfunction hasGlobalProperty(key) {\n\treturn key in globalThis;\n}\n/**\n* Detects the JavaScript framework being used at runtime.\n* Detection order matters to avoid false positives (e.g., Next.js includes React).\n*/\nfunction detectFramework() {\n\tif (typeof process !== \"undefined\" && process.env && (process.env.NEXT_RUNTIME || process.env.__NEXT_PRIVATE_ORIGIN)) return \"next\";\n\tif (typeof globalThis.window !== \"undefined\") {\n\t\tif (hasGlobalProperty(\"__NEXT_DATA__\")) return \"next\";\n\t\tif (hasGlobalProperty(\"__remixContext\")) return \"remix\";\n\t\tif (hasGlobalProperty(\"__REACT_DEVTOOLS_GLOBAL_HOOK__\")) return \"react\";\n\t\tif (hasGlobalProperty(\"__VUE__\")) return \"vue\";\n\t\tif (hasGlobalProperty(\"Zone\")) return \"angular\";\n\t}\n}\nfunction getClientInfo(sdkName, sdkVersion, extras) {\n\tconst base = {\n\t\tsdk: sdkName,\n\t\tversion: sdkVersion,\n\t\truntime: \"unknown\",\n\t\truntimeVersion: \"unknown\",\n\t\tplatform: \"unknown\",\n\t\tarch: \"unknown\"\n\t};\n\tlet result;\n\tif (typeof process !== \"undefined\" && process.versions?.node) result = {\n\t\t...base,\n\t\truntime: \"node\",\n\t\truntimeVersion: process.versions.node,\n\t\tplatform: process.platform,\n\t\tarch: process.arch\n\t};\n\telse if (typeof Deno !== \"undefined\") result = {\n\t\t...base,\n\t\truntime: \"deno\",\n\t\truntimeVersion: Deno.version?.deno ?? \"unknown\",\n\t\tplatform: Deno.build?.os ?? \"unknown\",\n\t\tarch: Deno.build?.arch ?? \"unknown\"\n\t};\n\telse if (typeof Bun !== \"undefined\") result = {\n\t\t...base,\n\t\truntime: \"bun\",\n\t\truntimeVersion: Bun.version ?? \"unknown\",\n\t\tplatform: process?.platform ?? \"unknown\",\n\t\tarch: process?.arch ?? \"unknown\"\n\t};\n\telse if (typeof EdgeRuntime !== \"undefined\" || typeof process !== \"undefined\" && !process.versions?.node && typeof globalThis.window === \"undefined\" && typeof document === \"undefined\") result = {\n\t\t...base,\n\t\truntime: \"edge\"\n\t};\n\telse if (globalThis.window !== void 0 && typeof document !== \"undefined\") result = {\n\t\t...base,\n\t\truntime: \"browser\",\n\t\truntimeVersion: \"unknown\",\n\t\tplatform: \"web\",\n\t\tarch: \"unknown\"\n\t};\n\telse result = base;\n\tconst framework = detectFramework();\n\tif (framework) result.framework = framework;\n\tif (extras?.betterAuthVersion) result.betterAuthVersion = extras.betterAuthVersion;\n\tif (extras?.adapter) result.adapter = extras.adapter;\n\treturn result;\n}\nfunction createClientInfoInjector(defaultSdkName, defaultSdkVersion, extras) {\n\tconst cachedClientInfo = JSON.stringify(getClientInfo(defaultSdkName, defaultSdkVersion, extras));\n\treturn function injectClientInfo(headers, sdkOverride) {\n\t\tconst result = new Headers(headers);\n\t\tif (result.has(\"X-Neon-Client-Info\")) return result;\n\t\tconst clientInfoString = sdkOverride ? JSON.stringify(getClientInfo(sdkOverride.name, sdkOverride.version, extras)) : cachedClientInfo;\n\t\tresult.set(X_NEON_CLIENT_INFO_HEADER, clientInfoString);\n\t\treturn result;\n\t};\n}\n//#endregion\nexport { X_NEON_CLIENT_INFO_HEADER, createClientInfoInjector, getClientInfo };\n\n//# sourceMappingURL=client-info.js.map","","import { BETTER_AUTH_VERSION, type getAdapterName } from \"@neon/auth\";\nimport { getClientInfo as getInternalClientInfo } from \"@neon-internals/internal\";\nimport pkg from \"../../package.json\" with { type: \"json\" };\n\nexport function buildNeonJsClientInfo(\n\tadapter?: ReturnType<typeof getAdapterName>,\n): string {\n\tconst info = getInternalClientInfo(pkg.name, pkg.version, {\n\t\tbetterAuthVersion: BETTER_AUTH_VERSION,\n\t\tadapter,\n\t});\n\treturn JSON.stringify(info);\n}\n\nexport {\n\ttype ClientInfo,\n\tgetClientInfo,\n\tinjectClientInfo,\n\tX_NEON_CLIENT_INFO_HEADER,\n} from \"@neon/postgrest-js\";\n","/**\n * Pure function: given a Neon base URL, returns the corresponding\n * auth and Data API URLs.\n *\n * Wrappers (e.g. @databricks/lakebase-js) can supply a different implementation\n * via the `deriveUrls` option on createClient.\n */\nexport type DeriveNeonUrls = (baseUrl: string) => {\n\tauth: string;\n\tdataApi: string;\n};\n\n/**\n * Default URL derivation for Neon endpoints.\n *\n * Insert `neonauth` / `apirest` after the first hostname label and append\n * `/auth` / `/rest/v1` to the path.\n *\n * Only the protocol, host, port, and path are used. A query string, hash\n * fragment, or embedded credentials (`user:pass@host`) are rejected.\n *\n * Constraints (use the object form or a custom `deriveUrls` to bypass them):\n * - The hostname must have at least 3 dot-separated labels, so `localhost`\n * and single-host proxies are intentionally rejected.\n * - A single port is applied to both derived hosts, so split-port local\n * setups (e.g. `neonauth:30443` vs `apirest:9443`) cannot be expressed\n * via the string form. In production both services share port 443.\n *\n * Example:\n * https://ep-xxx.c-2.us-east-2.aws.neon.build/dbname\n * → auth: https://ep-xxx.neonauth.c-2.us-east-2.aws.neon.build/dbname/auth\n * → dataApi: https://ep-xxx.apirest.c-2.us-east-2.aws.neon.build/dbname/rest/v1\n */\nexport const defaultDeriveNeonUrls: DeriveNeonUrls = (baseUrl) => {\n\tconst url = new URL(baseUrl);\n\n\tif (url.search !== \"\" || url.hash !== \"\") {\n\t\tthrow new Error(\n\t\t\t`Invalid Neon base URL: must not include a query string or hash fragment (got \"${baseUrl}\").`,\n\t\t);\n\t}\n\n\tif (url.username !== \"\" || url.password !== \"\") {\n\t\tthrow new Error(\n\t\t\t`Invalid Neon base URL: must not include credentials (got \"${baseUrl}\").`,\n\t\t);\n\t}\n\n\tconst labels = url.hostname.split(\".\");\n\tif (labels.length < 3) {\n\t\tthrow new Error(\n\t\t\t`Invalid Neon base URL: hostname \"${url.hostname}\" must have at least 3 dot-separated labels (e.g. ep-xxx.region.tld).`,\n\t\t);\n\t}\n\n\tconst [first, ...rest] = labels;\n\tconst authHost = [first, \"neonauth\", ...rest].join(\".\");\n\tconst dataApiHost = [first, \"apirest\", ...rest].join(\".\");\n\n\tconst basePath = url.pathname.replace(/\\/+$/, \"\");\n\tconst port = url.port ? `:${url.port}` : \"\";\n\n\treturn {\n\t\tauth: `${url.protocol}//${authHost}${port}${basePath}/auth`,\n\t\tdataApi: `${url.protocol}//${dataApiHost}${port}${basePath}/rest/v1`,\n\t};\n};\n","import type { NeonAuth, NeonAuthAdapter, NeonAuthPublicApi } from \"@neon/auth\";\nimport {\n\ttype DefaultSchemaName,\n\tNeonPostgrestClient,\n\ttype NeonPostgrestClientConstructorOptions,\n} from \"@neon/postgrest-js\";\n\n// Constructor options for NeonClient with required auth\nexport type NeonClientConstructorOptions<\n\tSchemaName,\n\tTAuth extends NeonAuthAdapter = NeonAuthAdapter,\n> = NeonPostgrestClientConstructorOptions<SchemaName> & {\n\tauthClient: NeonAuth<TAuth>;\n};\n\n/**\n * Neon client with integrated authentication\n *\n * Extends NeonPostgrestClient with Neon Auth integration.\n * For auth-free clients, use @neon/postgrest-js instead.\n */\nexport class NeonClient<\n\t// biome-ignore lint/suspicious/noExplicitAny: `any` is the default so an unspecified Database generic stays compatible with the upstream PostgrestClient's untyped schema.\n\tDatabase = any,\n\tSchemaName extends string & keyof Database = DefaultSchemaName<Database>,\n\tTAuth extends NeonAuthAdapter = NeonAuthAdapter,\n> extends NeonPostgrestClient<Database, SchemaName> {\n\tauth: NeonAuthPublicApi<TAuth>;\n\n\tconstructor({\n\t\tdataApiUrl,\n\t\toptions,\n\t\tauthClient,\n\t}: NeonClientConstructorOptions<SchemaName, TAuth>) {\n\t\tsuper({ dataApiUrl, options });\n\n\t\tthis.auth = authClient.adapter;\n\t}\n}\n\nexport type { DefaultSchemaName } from \"@neon/postgrest-js\";\n","import {\n\tcreateInternalNeonAuth,\n\tgetAdapterName,\n\ttype NeonAuthAdapter,\n\ttype NeonAuthConfig,\n} from \"@neon/auth\";\nimport type { BetterAuthReactAdapterInstance } from \"@neon/auth/react/adapters\";\nimport {\n\tBetterAuthVanillaAdapter,\n\ttype BetterAuthVanillaAdapterInstance,\n} from \"@neon/auth/vanilla/adapters\";\nimport {\n\tfetchWithToken,\n\tNeonPostgrestClient,\n\ttype NeonPostgrestClientConstructorOptions,\n} from \"@neon/postgrest-js\";\nimport {\n\tbuildNeonJsClientInfo,\n\tX_NEON_CLIENT_INFO_HEADER,\n} from \"../utils/client-info\";\nimport { type DeriveNeonUrls, defaultDeriveNeonUrls } from \"./derive-urls\";\nimport {\n\ttype DefaultSchemaName,\n\tNeonClient,\n\ttype NeonClientConstructorOptions,\n} from \"./neon-client\";\n\n/**\n * Auth configuration for createClient\n */\nexport type CreateClientAuthConfig<T extends NeonAuthAdapter> = {\n\t/** The auth service URL */\n\turl: string;\n} & NeonAuthConfig<T>;\n\n/**\n * Data API configuration for createClient\n */\nexport type CreateClientDataApiConfig<\n\tSchemaName,\n\tTAuth extends NeonAuthAdapter,\n> = {\n\t/** The Data API URL */\n\turl: string;\n\t/** Additional client options */\n\toptions?: Omit<\n\t\tNeonClientConstructorOptions<SchemaName, TAuth>,\n\t\t\"dataApiUrl\" | \"authClient\"\n\t>[\"options\"];\n};\n\n/**\n * Configuration for createClient\n */\nexport type CreateClientConfig<SchemaName, T extends NeonAuthAdapter> = {\n\t/** Auth service configuration */\n\tauth: CreateClientAuthConfig<T>;\n\t/** Data API configuration */\n\tdataApi: CreateClientDataApiConfig<SchemaName, T>;\n};\n\n/**\n * Returns a valid JWT for the current user, or `null` if there is no session.\n *\n * Called lazily on every Data API request. Wire this to your own identity\n * provider — e.g. Clerk's `getToken()` or Auth0's `getAccessTokenSilently()`.\n * Neon validates the returned token against the JWKS URL configured for the\n * provider.\n */\nexport type NeonDataApiTokenProvider = () => Promise<string | null>;\n\n/**\n * Data API configuration for the external-auth-provider form of createClient.\n *\n * Same as {@link CreateClientDataApiConfig} but carries a `getToken` function\n * instead of relying on a Neon Auth service.\n */\nexport type CreateClientExternalDataApiConfig<SchemaName> =\n\tCreateClientDataApiConfig<SchemaName, NeonAuthAdapter> & {\n\t\t/** Token provider consulted on every Data API request. */\n\t\tgetToken: NeonDataApiTokenProvider;\n\t};\n\n/**\n * Configuration for the external-auth-provider form of createClient.\n *\n * Use this when authentication is handled by your own identity provider\n * (Clerk, Auth0, …) rather than Neon Auth: omit the `auth` block entirely and\n * supply `dataApi.getToken`. No Neon Auth client is created, and the returned\n * client is a plain {@link NeonPostgrestClient} (no `.auth` property).\n */\nexport type CreateClientExternalConfig<SchemaName> = {\n\t/** External providers do not use a Neon Auth service. */\n\tauth?: never;\n\t/** Data API configuration, including your token provider. */\n\tdataApi: CreateClientExternalDataApiConfig<SchemaName>;\n};\n\n/**\n * Factory function to create NeonClient with seamless auth integration.\n *\n * @param config - Configuration with auth and dataApi sections\n * @returns NeonClient instance with auth-aware fetch wrapper\n * @throws AuthRequiredError when making requests without authentication\n *\n * @example\n * ```typescript\n * // Simple usage with default BetterAuthVanillaAdapter\n * import { createClient } from '@neon/neon-js';\n *\n * const client = createClient({\n * auth: { url: 'https://auth.example.com' },\n * dataApi: { url: 'https://data-api.example.com/rest/v1' },\n * });\n *\n * // Better Auth API\n * await client.auth.signIn.email({ email, password });\n *\n * // Database queries (automatic token injection)\n * const { data: items } = await client.from('items').select();\n * ```\n *\n * @example\n * ```typescript\n * // Single base URL — auth and Data API URLs are derived automatically.\n * const client = createClient(\n * 'https://ep-xxx.c-2.us-east-2.aws.neon.build/dbname'\n * );\n * ```\n *\n * @example\n * ```typescript\n * // External auth provider (Clerk, Auth0, …): omit `auth` and supply a\n * // `getToken` function. The returned client has no `.auth` property.\n * const client = createClient({\n * dataApi: {\n * url: 'https://data-api.example.com/rest/v1',\n * getToken: async () => await yourAuthProvider.getToken(),\n * },\n * });\n *\n * const { data: items } = await client.from('items').select();\n * ```\n */\n\n/**\n * The value `BetterAuthVanillaAdapter()` and friends return: a builder that `createClient`\n * invokes with the auth URL. Distinct from the adapter instance it produces.\n */\ntype AdapterBuilder<T extends NeonAuthAdapter> = NonNullable<\n\tNeonAuthConfig<T>[\"adapter\"]\n>;\n\n/**\n * Helper type to create NeonClient with proper schema resolution.\n * Uses 'public' as the default schema since it's the most common case.\n */\nexport type CreateClientResult<\n\tDatabase,\n\tTAdapter extends NeonAuthAdapter,\n> = NeonClient<Database, DefaultSchemaName<Database>, TAdapter>;\n\n// Overload: External auth provider (no Neon Auth) — returns a plain\n// NeonPostgrestClient with no `.auth` property. Listed first so its `auth?:\n// never` shape is matched before the auth-required object overloads.\n// biome-ignore lint/suspicious/noExplicitAny: `any` is the default so an unspecified Database generic stays compatible with the upstream PostgrestClient's untyped schema.\nexport function createClient<Database = any>(\n\tconfig: CreateClientExternalConfig<DefaultSchemaName<Database>>,\n): NeonPostgrestClient<Database, DefaultSchemaName<Database>>;\n\n// Overload: No adapter specified (defaults to BetterAuthVanillaAdapter)\n// biome-ignore lint/suspicious/noExplicitAny: `any` is the default so an unspecified Database generic stays compatible with the upstream PostgrestClient's untyped schema.\nexport function createClient<Database = any>(config: {\n\tauth: { url: string; allowAnonymous?: boolean };\n\tdataApi: CreateClientDataApiConfig<\n\t\tDefaultSchemaName<Database>,\n\t\tBetterAuthVanillaAdapterInstance\n\t>;\n}): CreateClientResult<Database, BetterAuthVanillaAdapterInstance>;\n\n// Overload: BetterAuthVanillaAdapter\n// biome-ignore lint/suspicious/noExplicitAny: `any` is the default so an unspecified Database generic stays compatible with the upstream PostgrestClient's untyped schema.\nexport function createClient<Database = any>(\n\tconfig: CreateClientConfig<\n\t\tDefaultSchemaName<Database>,\n\t\tBetterAuthVanillaAdapterInstance\n\t>,\n): CreateClientResult<Database, BetterAuthVanillaAdapterInstance>;\n\n// Overload: BetterAuthReactAdapter\n// biome-ignore lint/suspicious/noExplicitAny: `any` is the default so an unspecified Database generic stays compatible with the upstream PostgrestClient's untyped schema.\nexport function createClient<Database = any>(\n\tconfig: CreateClientConfig<\n\t\tDefaultSchemaName<Database>,\n\t\tBetterAuthReactAdapterInstance\n\t>,\n): CreateClientResult<Database, BetterAuthReactAdapterInstance>;\n\n// Overload: String form, no adapter specified (defaults to BetterAuthVanillaAdapter)\n// biome-ignore lint/suspicious/noExplicitAny: `any` is the default so an unspecified Database generic stays compatible with the upstream PostgrestClient's untyped schema.\nexport function createClient<Database = any>(\n\tbaseUrl: string,\n\toptions?: CreateClientStringOptions<\n\t\tDefaultSchemaName<Database>,\n\t\tBetterAuthVanillaAdapterInstance\n\t>,\n): CreateClientResult<Database, BetterAuthVanillaAdapterInstance>;\n\n// Overload: String form, BetterAuthVanillaAdapter\n// biome-ignore lint/suspicious/noExplicitAny: `any` is the default so an unspecified Database generic stays compatible with the upstream PostgrestClient's untyped schema.\nexport function createClient<Database = any>(\n\tbaseUrl: string,\n\toptions: CreateClientStringOptions<\n\t\tDefaultSchemaName<Database>,\n\t\tBetterAuthVanillaAdapterInstance\n\t> & { auth: { adapter: AdapterBuilder<BetterAuthVanillaAdapterInstance> } },\n): CreateClientResult<Database, BetterAuthVanillaAdapterInstance>;\n\n// Overload: String form, BetterAuthReactAdapter\n// biome-ignore lint/suspicious/noExplicitAny: `any` is the default so an unspecified Database generic stays compatible with the upstream PostgrestClient's untyped schema.\nexport function createClient<Database = any>(\n\tbaseUrl: string,\n\toptions: CreateClientStringOptions<\n\t\tDefaultSchemaName<Database>,\n\t\tBetterAuthReactAdapterInstance\n\t> & { auth: { adapter: AdapterBuilder<BetterAuthReactAdapterInstance> } },\n): CreateClientResult<Database, BetterAuthReactAdapterInstance>;\n\n// Implementation signature\nexport function createClient<\n\t// biome-ignore lint/suspicious/noExplicitAny: `any` is the default so an unspecified Database generic stays compatible with the upstream PostgrestClient's untyped schema.\n\tDatabase = any,\n\tSchemaName extends string & keyof Database = DefaultSchemaName<Database>,\n\tTAuthAdapter extends NeonAuthAdapter = BetterAuthVanillaAdapterInstance,\n>(\n\targ1:\n\t\t| string\n\t\t| CreateClientConfig<SchemaName, TAuthAdapter>\n\t\t| CreateClientExternalConfig<SchemaName>,\n\targ2?: CreateClientStringOptions<SchemaName, TAuthAdapter>,\n):\n\t| NeonClient<Database, SchemaName, TAuthAdapter>\n\t| NeonPostgrestClient<Database, SchemaName> {\n\treturn createClientImpl<Database, SchemaName, TAuthAdapter>(arg1, arg2);\n}\n\n/**\n * Adapter-agnostic implementation behind every public `createClient`, so entry points that\n * pin an adapter (`@neon/neon-js/supabase`) share one code path with the main entry.\n */\nexport function createClientImpl<\n\tDatabase,\n\tSchemaName extends string & keyof Database,\n\tTAuthAdapter extends NeonAuthAdapter,\n>(\n\targ1:\n\t\t| string\n\t\t| CreateClientConfig<SchemaName, TAuthAdapter>\n\t\t| CreateClientExternalConfig<SchemaName>,\n\targ2?: CreateClientStringOptions<SchemaName, TAuthAdapter>,\n):\n\t| NeonClient<Database, SchemaName, TAuthAdapter>\n\t| NeonPostgrestClient<Database, SchemaName> {\n\t// External-auth-provider form: no `auth` block, a `getToken` on `dataApi`.\n\t// Build a plain NeonPostgrestClient and let the caller's token flow through\n\t// unchanged — no Neon Auth client is created.\n\tif (typeof arg1 !== \"string\" && !arg1.auth) {\n\t\treturn buildExternalClient<Database, SchemaName>(\n\t\t\t(arg1 as CreateClientExternalConfig<SchemaName>).dataApi,\n\t\t);\n\t}\n\n\tconst config: CreateClientConfig<SchemaName, TAuthAdapter> =\n\t\ttypeof arg1 === \"string\"\n\t\t\t? buildConfigFromBaseUrl<SchemaName, TAuthAdapter>(arg1, arg2)\n\t\t\t: (arg1 as CreateClientConfig<SchemaName, TAuthAdapter>);\n\n\tconst { auth: authConfig, dataApi: dataApiConfig } = config;\n\n\t// Build client info once - sub-packages will see it and skip their own injection\n\t// Same default createInternalNeonAuth applies; resolving it here lets one\n\t// builder feed both the header and the auth client.\n\tconst adapter = (authConfig.adapter ??\n\t\tBetterAuthVanillaAdapter()) as NonNullable<typeof authConfig.adapter>;\n\tconst clientInfoHeader = buildNeonJsClientInfo(getAdapterName(adapter));\n\n\t// Step 1: Instantiate auth adapter\n\tconst auth = createInternalNeonAuth<TAuthAdapter>(authConfig.url, {\n\t\tadapter,\n\t\tallowAnonymous: authConfig.allowAnonymous ?? false,\n\t\tfetchOptions: {\n\t\t\theaders: {\n\t\t\t\t[X_NEON_CLIENT_INFO_HEADER]: clientInfoHeader,\n\t\t\t},\n\t\t},\n\t});\n\n\t// Step 2: Create lazy token accessor - called on every request\n\t// Returns null if no session (will throw AuthRequiredError in fetchWithToken)\n\tconst getAccessToken = async (): Promise<string | null> => {\n\t\treturn auth.getJWTToken();\n\t};\n\n\t// Step 3: Create auth-aware fetch wrapper\n\tconst authFetch = fetchWithToken(\n\t\tgetAccessToken,\n\t\tdataApiConfig.options?.global?.fetch,\n\t);\n\n\t// Step 4: Create client with auth integrated\n\tconst client = new NeonClient<Database, SchemaName, TAuthAdapter>({\n\t\tdataApiUrl: dataApiConfig.url,\n\t\tauthClient: auth,\n\t\toptions: {\n\t\t\t...dataApiConfig.options,\n\t\t\tglobal: {\n\t\t\t\t...dataApiConfig.options?.global,\n\t\t\t\tfetch: authFetch,\n\t\t\t\theaders: {\n\t\t\t\t\t...dataApiConfig.options?.global?.headers,\n\t\t\t\t\t[X_NEON_CLIENT_INFO_HEADER]: clientInfoHeader,\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t});\n\n\treturn client;\n}\n\n/**\n * Builds the external-auth-provider client: a plain NeonPostgrestClient whose\n * every request carries the caller's token via `fetchWithToken(getToken)`.\n *\n * Mirrors the fetch/header wiring of the auth path, but the token comes from\n * the caller's `getToken` rather than a Neon Auth session.\n */\nfunction buildExternalClient<\n\tDatabase,\n\tSchemaName extends string & keyof Database,\n>(\n\tdataApiConfig: CreateClientExternalDataApiConfig<SchemaName>,\n): NeonPostgrestClient<Database, SchemaName> {\n\tconst clientInfoHeader = buildNeonJsClientInfo();\n\n\tconst tokenFetch = fetchWithToken(\n\t\tdataApiConfig.getToken,\n\t\tdataApiConfig.options?.global?.fetch,\n\t);\n\n\tconst options: NeonPostgrestClientConstructorOptions<SchemaName>[\"options\"] =\n\t\t{\n\t\t\t...dataApiConfig.options,\n\t\t\tglobal: {\n\t\t\t\t...dataApiConfig.options?.global,\n\t\t\t\tfetch: tokenFetch,\n\t\t\t\theaders: {\n\t\t\t\t\t...dataApiConfig.options?.global?.headers,\n\t\t\t\t\t[X_NEON_CLIENT_INFO_HEADER]: clientInfoHeader,\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\n\treturn new NeonPostgrestClient<Database, SchemaName>({\n\t\tdataApiUrl: dataApiConfig.url,\n\t\toptions,\n\t});\n}\n\n/**\n * Per-call overrides accepted alongside a single base URL.\n *\n * Every field is optional; defaults come from `deriveUrls(baseUrl)`.\n */\nexport type CreateClientStringOptions<SchemaName, T extends NeonAuthAdapter> = {\n\tauth?: Partial<CreateClientAuthConfig<T>>;\n\tdataApi?: Partial<CreateClientDataApiConfig<SchemaName, T>>;\n\t/**\n\t * Override the auth/Data API URL derivation. End users do not need this;\n\t * it is intended for wrapper packages (e.g. `@databricks/lakebase-js`)\n\t * that have their own endpoint pattern.\n\t */\n\tderiveUrls?: DeriveNeonUrls;\n};\n\nfunction buildConfigFromBaseUrl<\n\tSchemaName,\n\tTAuthAdapter extends NeonAuthAdapter,\n>(\n\tbaseUrl: string,\n\toptions: CreateClientStringOptions<SchemaName, TAuthAdapter> | undefined,\n): CreateClientConfig<SchemaName, TAuthAdapter> {\n\tconst derive = options?.deriveUrls ?? defaultDeriveNeonUrls;\n\tconst derived = derive(baseUrl);\n\n\tconst authOverrides = options?.auth ?? {};\n\tconst dataApiOverrides = options?.dataApi ?? {};\n\n\treturn {\n\t\tauth: {\n\t\t\t...authOverrides,\n\t\t\turl: authOverrides.url ?? derived.auth,\n\t\t} as CreateClientAuthConfig<TAuthAdapter>,\n\t\tdataApi: {\n\t\t\t...dataApiOverrides,\n\t\t\turl: dataApiOverrides.url ?? derived.dataApi,\n\t\t} as CreateClientDataApiConfig<SchemaName, TAuthAdapter>,\n\t};\n}\n"],"mappings":";;;;;;;AAKA,SAAS,kBAAkB,KAAK;CAC/B,OAAO,OAAO;AACf;;;;;AAKA,SAAS,kBAAkB;CAC1B,IAAI,OAAO,YAAY,eAAe,QAAQ,QAAQ,QAAQ,IAAI,gBAAgB,QAAQ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AS,QAAQ,CAAC;CACxC,MAAM,mBAAmB,SAAS,WAAW,CAAC;CAE9C,OAAO;EACN,MAAM;GACL,GAAG;GACH,KAAK,cAAc,OAAO,QAAQ;EACnC;EACA,SAAS;GACR,GAAG;GACH,KAAK,iBAAiB,OAAO,QAAQ;EACtC;CACD;AACD"}
@@ -0,0 +1,5 @@
1
+ import { a as CreateClientStringOptions, l as DeriveNeonUrls, n as CreateClientExternalConfig, o as NeonDataApiTokenProvider, r as CreateClientExternalDataApiConfig, s as createClient, u as defaultDeriveNeonUrls } from "./client-factory.js";
2
+ import { BetterAuthVanillaAdapter, BetterAuthVanillaAdapterInstance, BetterAuthVanillaAdapterOptions } from "@neon/auth/vanilla/adapters";
3
+ import { AuthRequiredError, NeonPostgrestClient, fetchWithToken } from "@neon/postgrest-js";
4
+ import { NeonAuth, NeonAuthAdapter, NeonAuthConfig, NeonAuthPublicApi, ReactBetterAuthClient, VanillaBetterAuthClient } from "@neon/auth";
5
+ export { AuthRequiredError, BetterAuthVanillaAdapter, type BetterAuthVanillaAdapterInstance, type BetterAuthVanillaAdapterOptions, type CreateClientExternalConfig, type CreateClientExternalDataApiConfig, type CreateClientStringOptions, type DeriveNeonUrls, type NeonAuth, type NeonAuthAdapter, type NeonAuthConfig, type NeonAuthPublicApi, type NeonDataApiTokenProvider, NeonPostgrestClient, type ReactBetterAuthClient, type VanillaBetterAuthClient, createClient, defaultDeriveNeonUrls, fetchWithToken };
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ import { r as defaultDeriveNeonUrls, t as createClient } from "./client-factory.js";
2
+ import { BetterAuthVanillaAdapter } from "@neon/auth/vanilla/adapters";
3
+ import { AuthRequiredError, NeonPostgrestClient, fetchWithToken } from "@neon/postgrest-js";
4
+ export { AuthRequiredError, BetterAuthVanillaAdapter, NeonPostgrestClient, createClient, defaultDeriveNeonUrls, fetchWithToken };
@@ -0,0 +1,50 @@
1
+ import { c as DefaultSchemaName, i as CreateClientResult, l as DeriveNeonUrls, t as CreateClientDataApiConfig } from "../client-factory.js";
2
+ import { SupabaseAuthAdapterInstance, SupabaseAuthAdapterOptions } from "@neon/auth/vanilla/adapters";
3
+
4
+ //#region src/supabase/index.d.ts
5
+
6
+ /**
7
+ * `url` and `allowAnonymous` configure the client; every other key is forwarded to
8
+ * `SupabaseAuthAdapter(...)`, e.g. `fetchOptions.headers.Cookie` to forward a request
9
+ * cookie from a server.
10
+ */
11
+ type SupabaseAuthConfig = SupabaseAuthAdapterOptions & {
12
+ /** The auth service URL */
13
+ url: string;
14
+ /** Fall back to an anonymous token when there is no user session. */
15
+ allowAnonymous?: boolean;
16
+ };
17
+ type SupabaseDataApiConfig<SchemaName> = CreateClientDataApiConfig<SchemaName, SupabaseAuthAdapterInstance>;
18
+ /** Configuration for the Supabase-compatible `createClient`. */
19
+ type CreateSupabaseClientConfig<SchemaName> = {
20
+ auth: SupabaseAuthConfig;
21
+ dataApi: SupabaseDataApiConfig<SchemaName>;
22
+ };
23
+ /** Per-call overrides accepted alongside a single base URL. */
24
+ type CreateSupabaseClientStringOptions<SchemaName> = {
25
+ auth?: Partial<SupabaseAuthConfig>;
26
+ dataApi?: Partial<SupabaseDataApiConfig<SchemaName>>;
27
+ deriveUrls?: DeriveNeonUrls;
28
+ };
29
+ /**
30
+ * `createClient` with the auth adapter fixed to `SupabaseAuthAdapter`, so `client.auth`
31
+ * has the Supabase-compatible API (`signInWithPassword`, `onAuthStateChange`, ...).
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * import { createClient } from '@neon/neon-js/supabase';
36
+ *
37
+ * const client = createClient({
38
+ * auth: { url: 'https://auth.example.com' },
39
+ * dataApi: { url: 'https://data-api.example.com/rest/v1' },
40
+ * });
41
+ *
42
+ * await client.auth.signInWithPassword({ email, password });
43
+ * const { data: items } = await client.from('items').select();
44
+ * ```
45
+ */
46
+ declare function createClient<Database = any>(config: CreateSupabaseClientConfig<DefaultSchemaName<Database>>): CreateClientResult<Database, SupabaseAuthAdapterInstance>;
47
+ declare function createClient<Database = any>(baseUrl: string, options?: CreateSupabaseClientStringOptions<DefaultSchemaName<Database>>): CreateClientResult<Database, SupabaseAuthAdapterInstance>;
48
+ //#endregion
49
+ export { CreateSupabaseClientConfig, CreateSupabaseClientStringOptions, createClient };
50
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":["SupabaseAuthAdapterInstance","SupabaseAuthAdapterOptions","CreateClientDataApiConfig","CreateClientResult","DeriveNeonUrls","DefaultSchemaName","SupabaseAuthConfig","SupabaseDataApiConfig","SchemaName","CreateSupabaseClientConfig","CreateSupabaseClientStringOptions","Partial","createClient","Database","c","DefaultSchemaName","i","CreateClientResult","l","DeriveNeonUrls","t","CreateClientDataApiConfig","SupabaseAuthAdapterInstance","SupabaseAuthAdapterOptions","SupabaseAuthConfig","url","allowAnonymous","SupabaseDataApiConfig","SchemaName","CreateSupabaseClientConfig","auth","dataApi","CreateSupabaseClientStringOptions","Partial","deriveUrls","createClient","config","Database","baseUrl","options"],"sources":["../../src/supabase/index.ts"],"mappings":";;;;;AAW2E;AAOvB;AAO1B;AACzBQ;AACAR;AAFwCE,KAPpCI,kBAAAA,GAAqBL,0BAOeC,GAAAA;EAAyB;EAMtDO,GAAAA,EAAAA,MAAAA;EAA0B;EAC/BH,cAAAA,CAAAA,EAAAA,OAAAA;AACyBE,CAAAA;AAAtBD,KARLA,qBAQKA,CAAAA,UAAAA,CAAAA,GAR+BL,yBAQ/BK,CAPTC,UAOSD,EANTP,2BAMSO,CAAAA;AAAqB;AAInBG,KANAD,0BAMAC,CAAAA,UAAiC,CAAA,GAAA;EAAAoB,IAAA,EALtCxB,kBAKsC;EAC7BA,OAAAA,EALNC,qBAKMD,CALgBE,UAKhBF,CAAAA;AAARK,CAAAA;AACiCH;AAAtBD,KAFPG,iCAEOH,CAAAA,UAAAA,CAAAA,GAAAA;EAARI,IAAAA,CAAAA,EADHA,OACGA,CADKL,kBACLK,CAAAA;EACGP,OAAAA,CAAAA,EADHO,OACGP,CADKG,qBACLH,CAD2BI,UAC3BJ,CAAAA,CAAAA;EAAc8B,UAAA,CAAA,EAAd9B,cAAc;AAqB5B,CAAA;AAA4B;AAC0BS;AAAlBR;AAA3BI;AACaI;AAAUb;AAA7BG;AAAkB;AAErB;AAA4B;AAEmCU;AAAlBR;AAAlCK;AACWG;AAAUb;AAA7BG;AAAkB;A,iBAPLS,Y,yBACPH,0B,CAA2BJ,iB,CAAkBQ,Q,KACnDV,kB,CAAmBU,Q,EAAUb,2B;A,iBAEhBY,Y,4CAELF,iC,CAAkCL,iB,CAAkBQ,Q,KAC5DV,kB,CAAmBU,Q,EAAUb,2B"}
@@ -0,0 +1,24 @@
1
+ import { n as createClientImpl } from "../client-factory.js";
2
+ import { SupabaseAuthAdapter } from "@neon/auth/vanilla/adapters";
3
+ //#region src/supabase/index.ts
4
+ function createClient(arg1, arg2) {
5
+ return typeof arg1 === "string" ? createClientImpl(arg1, {
6
+ ...arg2,
7
+ auth: withAdapter(arg2?.auth)
8
+ }) : createClientImpl({
9
+ ...arg1,
10
+ auth: withAdapter(arg1.auth)
11
+ });
12
+ }
13
+ function withAdapter(auth) {
14
+ const { url, allowAnonymous, ...adapterOptions } = auth ?? {};
15
+ return {
16
+ url,
17
+ allowAnonymous,
18
+ adapter: SupabaseAuthAdapter(adapterOptions)
19
+ };
20
+ }
21
+ //#endregion
22
+ export { createClient };
23
+
24
+ //# sourceMappingURL=index.js.map