@krutai/auth 0.2.3 → 0.4.2

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 CHANGED
@@ -1,16 +1,17 @@
1
1
  # @krutai/auth
2
2
 
3
- Authentication package for KrutAI powered by [Better Auth](https://www.better-auth.com/).
3
+ Authentication package for KrutAI — a fetch-based HTTP client that calls your server's `/lib-auth` routes (powered by [Better Auth](https://www.better-auth.com/) on the server side).
4
+
5
+ > **Architecture Note:** This package is a **pure HTTP client** — it has no local database or Better Auth dependency. All auth logic (including database connections) lives on your server. This package simply makes authenticated HTTP calls to your server's auth routes.
4
6
 
5
7
  ## Features
6
8
 
7
9
  - 🔐 **API Key Protection** — Requires a valid KrutAI API key (validated via `krutai`)
8
- - 🚀 **Better Auth Integration** — Built on top of Better Auth
9
- - 📦 **Auto-installs everything** — `krutai`, `better-auth`, `better-sqlite3` install automatically
10
- - 🗄️ **Auto-migrates SQLite** — Database tables are created automatically on install
11
- - 🎯 **Next.js Ready** — First-class support via `@krutai/auth/next-js`
10
+ - 🚀 **Better Auth Integration** — Calls your server's Better Auth routes
11
+ - 🐘 **PostgreSQL Ready** — Your server can use any Better Auth-supported database (PostgreSQL, MySQL, etc.)
12
12
  - ⚡ **Dual Format** — Supports both ESM and CommonJS
13
13
  - 🔷 **TypeScript First** — Full type safety and IntelliSense
14
+ - 🌐 **Zero DB Dependencies** — No local database driver needed
14
15
 
15
16
  ## Installation
16
17
 
@@ -18,135 +19,214 @@ Authentication package for KrutAI powered by [Better Auth](https://www.better-au
18
19
  npm install @krutai/auth
19
20
  ```
20
21
 
21
- > **Note:** `krutai`, `better-auth`, `better-sqlite3`, and `@types/better-sqlite3` are all installed automatically. SQLite tables are migrated automatically after install.
22
+ ## How It Works
23
+
24
+ ```
25
+ Your App
26
+ └── @krutai/auth (HTTP client)
27
+ └── POST /lib-auth/api/auth/sign-up/email ──► Your Server
28
+ └── better-auth
29
+ └── PostgreSQL
30
+ ```
31
+
32
+ All database operations (user storage, session management, etc.) happen on your server. This package is just a thin, type-safe HTTP wrapper.
22
33
 
23
34
  ## Quick Start
24
35
 
25
- ### Server-side setup (Next.js)
36
+ ### 1. Server-side setup (PostgreSQL + Better Auth)
26
37
 
27
- ```typescript
28
- // lib/auth.ts
29
- import { krutAuth } from "@krutai/auth";
30
- import Database from "better-sqlite3";
38
+ Set up Better Auth on your server with a PostgreSQL database:
31
39
 
32
- export const auth = krutAuth({
33
- database: new Database("./sqlite.db"),
40
+ ```typescript
41
+ // server: lib/auth.ts
42
+ import { betterAuth } from "better-auth";
43
+ import { Pool } from "pg";
44
+
45
+ export const auth = betterAuth({
46
+ database: new Pool({
47
+ connectionString: process.env.DATABASE_URL,
48
+ // e.g. postgresql://user:password@localhost:5432/mydb
49
+ }),
34
50
  emailAndPassword: {
35
51
  enabled: true,
36
52
  },
37
- baseURL: process.env.BETTER_AUTH_BASE_URL ?? "http://localhost:3000",
53
+ basePath: "/lib-auth",
54
+ baseURL: process.env.BETTER_AUTH_BASE_URL ?? "http://localhost:8000",
55
+ secret: process.env.BETTER_AUTH_SECRET,
38
56
  });
39
57
  ```
40
58
 
41
- > **Required:** Set `BETTER_AUTH_BASE_URL` in your `.env` file (e.g. `http://localhost:3000` for dev, `https://yourdomain.com` for production). Without this, redirects and callbacks will not work.
59
+ > **Required env vars on your server:**
60
+ > - `DATABASE_URL` — PostgreSQL connection string
61
+ > - `BETTER_AUTH_BASE_URL` — Your server's base URL (e.g. `http://localhost:8000`)
62
+ > - `BETTER_AUTH_SECRET` — Secret for signing sessions
42
63
 
43
- ### API Route handler
64
+ ### 2. Mount the auth handler on your server
44
65
 
45
66
  ```typescript
46
- // app/api/auth/[...all]/route.ts
47
- import { auth } from "@/lib/auth";
48
- import { toNextJsHandler } from "@krutai/auth/next-js";
67
+ // server: routes/auth.ts (Express example)
68
+ import { toNodeHandler } from "better-auth/node";
69
+ import { auth } from "./lib/auth";
49
70
 
50
- export const { GET, POST } = toNextJsHandler(auth);
71
+ app.use("/lib-auth", toNodeHandler(auth));
51
72
  ```
52
73
 
53
- ### Client-side (React / Next.js)
74
+ ### 3. Use `@krutai/auth` in your client/consumer app
54
75
 
55
76
  ```typescript
56
- // lib/auth-client.ts
57
- import { createAuthClient } from "@krutai/auth/react";
77
+ import { krutAuth } from "@krutai/auth";
58
78
 
59
- export const authClient = createAuthClient({
60
- baseURL: process.env.NEXT_PUBLIC_APP_URL ?? "http://localhost:3000",
79
+ const auth = krutAuth({
80
+ apiKey: process.env.KRUTAI_API_KEY!,
81
+ serverUrl: "https://your-server.com", // points to the server above
61
82
  });
62
83
 
63
- export const { signIn, signUp, signOut, useSession } = authClient;
64
- ```
65
-
66
- ### With API Key Validation (KrutAuth class)
84
+ await auth.initialize(); // validates API key against server
67
85
 
68
- ```typescript
69
- import { KrutAuth } from "@krutai/auth";
86
+ // Sign up
87
+ const { token, user } = await auth.signUpEmail({
88
+ email: "user@example.com",
89
+ password: "secret123",
90
+ name: "Alice",
91
+ });
70
92
 
71
- const auth = new KrutAuth({
72
- apiKey: "your-krutai-api-key",
73
- betterAuthOptions: {
74
- database: { /* your database config */ },
75
- },
93
+ // Sign in
94
+ const result = await auth.signInEmail({
95
+ email: "user@example.com",
96
+ password: "secret123",
76
97
  });
77
98
 
78
- await auth.initialize();
79
- ```
99
+ // Get session
100
+ const session = await auth.getSession(result.token);
80
101
 
81
- ## Environment Variables
102
+ // Sign out
103
+ await auth.signOut(result.token);
104
+ ```
82
105
 
83
- | Variable | Required | Description |
84
- |---|---|---|
85
- | `BETTER_AUTH_BASE_URL` | ✅ | Your app's base URL (e.g. `http://localhost:3000`) |
86
- | `BETTER_AUTH_SECRET` | recommended | Secret for signing sessions |
106
+ ## Configuration
87
107
 
88
- ## Exports
108
+ ```typescript
109
+ const auth = krutAuth({
110
+ apiKey: "krut_...", // Required (or set KRUTAI_API_KEY env var)
111
+ serverUrl: "https://...", // Default: "http://localhost:8000"
112
+ authPrefix: "/lib-auth", // Default: "/lib-auth"
113
+ validateOnInit: true, // Default: true — set false to skip in tests
114
+ });
115
+ ```
89
116
 
90
- | Import path | What it provides |
91
- |---|---|
92
- | `@krutai/auth` | `krutAuth`, `KrutAuth`, validators |
93
- | `@krutai/auth/react` | `createAuthClient`, `useSession`, etc. |
94
- | `@krutai/auth/next-js` | `toNextJsHandler` |
117
+ | Option | Type | Default | Description |
118
+ |---|---|---|---|
119
+ | `apiKey` | `string` | `process.env.KRUTAI_API_KEY` | Your KrutAI API key |
120
+ | `serverUrl` | `string` | `http://localhost:8000` | Base URL of your server |
121
+ | `authPrefix` | `string` | `/lib-auth` | Path prefix for auth routes |
122
+ | `validateOnInit` | `boolean` | `true` | Validate API key on `initialize()` |
95
123
 
96
124
  ## API Reference
97
125
 
98
- ### `krutAuth(options)`
126
+ ### `krutAuth(config)` — Factory (recommended)
99
127
 
100
- Drop-in replacement for `betterAuth`. Accepts the same options.
128
+ Creates a `KrutAuth` instance.
101
129
 
102
130
  ```typescript
103
131
  import { krutAuth } from "@krutai/auth";
132
+ const auth = krutAuth({ apiKey: "...", serverUrl: "https://..." });
133
+ await auth.initialize();
134
+ ```
135
+
136
+ ### `KrutAuth` class — Methods
104
137
 
105
- export const auth = krutAuth({ /* Better Auth options */ });
138
+ | Method | HTTP Call | Description |
139
+ |---|---|---|
140
+ | `initialize()` | validates API key | **Must be called before other methods** |
141
+ | `signUpEmail(params)` | `POST /lib-auth/api/auth/sign-up/email` | Register a new user |
142
+ | `signInEmail(params)` | `POST /lib-auth/api/auth/sign-in/email` | Authenticate a user |
143
+ | `getSession(token)` | `GET /lib-auth/api/auth/get-session` | Retrieve session info |
144
+ | `signOut(token)` | `POST /lib-auth/api/auth/sign-out` | Invalidate a session |
145
+ | `request(method, path, body?)` | Any | Generic helper for custom endpoints |
146
+ | `isInitialized()` | — | Returns `boolean` |
147
+
148
+ ### Types
149
+
150
+ ```typescript
151
+ interface SignUpEmailParams { email: string; password: string; name: string; }
152
+ interface SignInEmailParams { email: string; password: string; }
153
+
154
+ interface AuthResponse { token: string; user: AuthUser; }
155
+ interface AuthSession { user: AuthUser; session: AuthSessionRecord; }
156
+
157
+ interface AuthUser {
158
+ id: string; email: string; name?: string;
159
+ emailVerified: boolean; createdAt: string; updatedAt: string;
160
+ }
106
161
  ```
107
162
 
108
- ### `KrutAuth` class
163
+ ## Environment Variables
109
164
 
110
- For API-key-protected authentication.
165
+ ### Client app (where `@krutai/auth` is used)
111
166
 
112
- | Option | Type | Required | Description |
113
- |---|---|---|---|
114
- | `apiKey` | `string` | ✅ | Your KrutAI API key |
115
- | `betterAuthOptions` | `object` | — | Better Auth configuration |
116
- | `validateOnInit` | `boolean` | — | Validate API key on init (default: `true`) |
167
+ | Variable | Required | Description |
168
+ |---|---|---|
169
+ | `KRUTAI_API_KEY` | ✅ | Your KrutAI API key |
117
170
 
118
- #### Methods
171
+ ### Server (where Better Auth + PostgreSQL runs)
119
172
 
120
- - `initialize()` Validates API key and sets up Better Auth
121
- - `getBetterAuth()` — Returns the underlying Better Auth instance
122
- - `isInitialized()` Returns `boolean`
123
- - `getApiKey()` Returns the API key string
173
+ | Variable | Required | Description |
174
+ |---|---|---|
175
+ | `DATABASE_URL` | | PostgreSQL connection string |
176
+ | `BETTER_AUTH_BASE_URL` | | Your server's base URL |
177
+ | `BETTER_AUTH_SECRET` | recommended | Secret for signing sessions |
124
178
 
125
179
  ## Error Handling
126
180
 
127
181
  ```typescript
128
- import { KrutAuth, ApiKeyValidationError } from "@krutai/auth";
182
+ import { krutAuth, KrutAuthKeyValidationError } from "@krutai/auth";
129
183
 
130
184
  try {
131
- const auth = new KrutAuth({ apiKey: "invalid" });
185
+ const auth = krutAuth({ apiKey: "invalid-key" });
132
186
  await auth.initialize();
133
- } catch (error) {
134
- if (error instanceof ApiKeyValidationError) {
135
- console.error("API key validation failed:", error.message);
187
+ } catch (e) {
188
+ if (e instanceof KrutAuthKeyValidationError) {
189
+ console.error("Invalid API key:", e.message);
190
+ } else {
191
+ console.error("Auth error:", e);
136
192
  }
137
193
  }
138
194
  ```
139
195
 
196
+ ## Custom Endpoints
197
+
198
+ Use the `request()` method to call any Better Auth endpoint not covered by the convenience methods:
199
+
200
+ ```typescript
201
+ const data = await auth.request("POST", "/api/auth/some-custom-endpoint", {
202
+ someParam: "value",
203
+ });
204
+ ```
205
+
206
+ ## Skipping Validation in Tests
207
+
208
+ ```typescript
209
+ const auth = krutAuth({
210
+ apiKey: "test-api-key",
211
+ serverUrl: "http://localhost:8000",
212
+ validateOnInit: false, // Skip server round-trip in tests
213
+ });
214
+ // No need to call initialize()
215
+ ```
216
+
140
217
  ## Architecture
141
218
 
142
219
  ```
143
- @krutai/auth@0.1.9
144
- ├── dependency: krutai ← API key validation
145
- ├── dependency: better-auth ← auth engine
146
- ├── dependency: better-sqlite3 ← default database adapter
147
- └── dependency: @types/better-sqlite3
220
+ @krutai/auth@0.4.0
221
+ └── dependency: krutai ← API key format validation (also peerDep)
222
+
223
+ Your Server
224
+ ├── better-auth ← Auth engine
225
+ └── pg / postgres ← PostgreSQL adapter
148
226
  ```
149
227
 
228
+ For Better Auth PostgreSQL setup, see: https://www.better-auth.com/docs/adapters/postgresql
229
+
150
230
  For Better Auth documentation, visit: https://www.better-auth.com/docs
151
231
 
152
232
  ## License
package/dist/index.d.mts CHANGED
@@ -1,150 +1,280 @@
1
- import * as better_auth from 'better-auth';
2
- import { BetterAuthOptions, Auth } from 'better-auth';
3
- export { BetterAuthOptions } from 'better-auth';
4
- export { ApiKeyValidationError, validateApiKeyFormat, validateApiKeyWithService } from 'krutai';
1
+ export { KrutAIKeyValidationError, validateApiKey, validateApiKeyFormat } from 'krutai';
5
2
 
3
+ /**
4
+ * Types for @krutai/auth
5
+ *
6
+ * Pure fetch-based auth client — no local better-auth dependency.
7
+ */
8
+ /**
9
+ * Default base URL for the KrutAI server.
10
+ * Used when no serverUrl is provided in the config.
11
+ */
12
+ declare const DEFAULT_SERVER_URL: "http://localhost:8000";
13
+ /**
14
+ * Default path prefix for the auth routes on the server.
15
+ * The server mounts better-auth under this prefix.
16
+ */
17
+ declare const DEFAULT_AUTH_PREFIX: "/lib-auth";
6
18
  /**
7
19
  * Configuration options for KrutAuth
8
20
  */
9
21
  interface KrutAuthConfig {
10
22
  /**
11
- * API key for authentication with KrutAI services
23
+ * KrutAI API key.
24
+ * Validated against the server before use.
12
25
  * Optional: defaults to process.env.KRUTAI_API_KEY
13
26
  */
14
27
  apiKey?: string;
15
28
  /**
16
- * Better Auth configuration options
17
- * @see https://www.better-auth.com/docs
18
- */
19
- betterAuthOptions?: Partial<BetterAuthOptions>;
20
- /**
21
- * Whether to validate the API key on initialization
22
- * @default true
23
- */
24
- validateOnInit?: boolean;
25
- /**
26
- * Base URL of your deployed LangChain backend/validation server
29
+ * Base URL of your deployed KrutAI server.
27
30
  * @default "http://localhost:8000"
31
+ * @example "https://krut.ai"
28
32
  */
29
33
  serverUrl?: string;
30
34
  /**
31
- * Custom API validation endpoint
35
+ * Path prefix for the auth routes on the server.
36
+ * @default "/lib-auth"
32
37
  */
33
- validationEndpoint?: string;
38
+ authPrefix?: string;
39
+ /**
40
+ * Whether to validate the API key against the server on initialization.
41
+ * Set to false to skip the validation round-trip (e.g. in tests).
42
+ * @default true
43
+ */
44
+ validateOnInit?: boolean;
34
45
  }
35
46
  /**
36
- * Authentication session interface
47
+ * Parameters for email/password sign-up
48
+ */
49
+ interface SignUpEmailParams {
50
+ /** User email */
51
+ email: string;
52
+ /** User password */
53
+ password: string;
54
+ /** Display name */
55
+ name: string;
56
+ }
57
+ /**
58
+ * Parameters for email/password sign-in
59
+ */
60
+ interface SignInEmailParams {
61
+ /** User email */
62
+ email: string;
63
+ /** User password */
64
+ password: string;
65
+ }
66
+ /**
67
+ * A user record returned by the auth server
68
+ */
69
+ interface AuthUser {
70
+ id: string;
71
+ email: string;
72
+ name?: string;
73
+ emailVerified: boolean;
74
+ createdAt: string;
75
+ updatedAt: string;
76
+ [key: string]: unknown;
77
+ }
78
+ /**
79
+ * A session record returned by the auth server
80
+ */
81
+ interface AuthSessionRecord {
82
+ id: string;
83
+ userId: string;
84
+ token: string;
85
+ expiresAt: string;
86
+ [key: string]: unknown;
87
+ }
88
+ /**
89
+ * Combined session + user response
37
90
  */
38
91
  interface AuthSession {
39
- user: {
40
- id: string;
41
- email: string;
42
- name?: string;
43
- [key: string]: unknown;
44
- };
45
- session: {
46
- id: string;
47
- expiresAt: Date;
48
- [key: string]: unknown;
49
- };
92
+ user: AuthUser;
93
+ session: AuthSessionRecord;
94
+ }
95
+ /**
96
+ * Sign-up / sign-in response (contains token + user)
97
+ */
98
+ interface AuthResponse {
99
+ token: string;
100
+ user: AuthUser;
101
+ [key: string]: unknown;
50
102
  }
51
103
 
52
104
  /**
53
- * KrutAuth - Authentication client for KrutAI
105
+ * KrutAuth — fetch-based authentication client for KrutAI
54
106
  *
55
- * This class wraps Better Auth and adds API key validation
56
- * to ensure only authorized users can access authentication features.
107
+ * Calls your deployed server's `/lib-auth` routes for all auth operations.
108
+ * The API key is validated against the server before use.
57
109
  *
58
110
  * @example
59
111
  * ```typescript
60
112
  * import { KrutAuth } from '@krutai/auth';
61
113
  *
62
114
  * const auth = new KrutAuth({
63
- * apiKey: 'your-api-key-here',
64
- * betterAuthOptions: {
65
- * // Better Auth configuration
66
- * }
115
+ * apiKey: process.env.KRUTAI_API_KEY!,
116
+ * serverUrl: 'https://krut.ai',
67
117
  * });
68
118
  *
69
- * // Initialize the client (validates API key)
70
- * await auth.initialize();
119
+ * await auth.initialize(); // validates key against server
71
120
  *
72
- * // Use authentication features
73
- * const betterAuth = auth.getBetterAuth();
121
+ * // Sign up
122
+ * const { token, user } = await auth.signUpEmail({
123
+ * email: 'user@example.com',
124
+ * password: 'secret123',
125
+ * name: 'Alice',
126
+ * });
127
+ *
128
+ * // Sign in
129
+ * const result = await auth.signInEmail({
130
+ * email: 'user@example.com',
131
+ * password: 'secret123',
132
+ * });
133
+ *
134
+ * // Get session
135
+ * const session = await auth.getSession(result.token);
74
136
  * ```
75
137
  */
76
138
  declare class KrutAuth {
77
- private config;
78
- private apiKey;
79
- private betterAuthInstance;
139
+ private readonly apiKey;
140
+ private readonly serverUrl;
141
+ private readonly authPrefix;
142
+ private readonly config;
80
143
  private initialized;
81
- /**
82
- * Creates a new KrutAuth instance
83
- * @param config - Configuration options
84
- * @throws {ApiKeyValidationError} If API key is invalid
85
- */
86
144
  constructor(config: KrutAuthConfig);
87
145
  /**
88
- * Initialize the authentication client
89
- * Validates the API key and sets up Better Auth
90
- * @throws {ApiKeyValidationError} If API key validation fails
146
+ * Initialize the auth client.
147
+ * Validates the API key against the server, then marks client as ready.
148
+ *
149
+ * @throws {KrutAuthKeyValidationError} if the key is rejected or the server is unreachable
91
150
  */
92
151
  initialize(): Promise<void>;
93
152
  /**
94
- * Initialize Better Auth instance
95
- * @private
153
+ * Returns whether the client has been initialized.
96
154
  */
97
- private initializeBetterAuth;
155
+ isInitialized(): boolean;
156
+ private assertInitialized;
157
+ /** Common request headers sent to the server on every auth call. */
158
+ private authHeaders;
98
159
  /**
99
- * Get the Better Auth instance
100
- * @throws {Error} If not initialized
160
+ * Build the full URL for an auth endpoint.
161
+ * @param path - The better-auth sub-path, e.g. `/api/auth/sign-up/email`
101
162
  */
102
- getBetterAuth(): Auth;
163
+ private url;
103
164
  /**
104
- * Check if the client is initialized
165
+ * Generic request helper for any better-auth endpoint.
166
+ *
167
+ * Use this to call endpoints not covered by the convenience methods.
168
+ *
169
+ * @param method - HTTP method (GET, POST, etc.)
170
+ * @param path - The better-auth endpoint path (e.g. `/api/auth/sign-up/email`)
171
+ * @param body - Optional JSON body
172
+ * @returns The parsed JSON response
105
173
  */
106
- isInitialized(): boolean;
174
+ request<T = unknown>(method: string, path: string, body?: Record<string, unknown> | object): Promise<T>;
107
175
  /**
108
- * Get the API key (useful for making authenticated requests)
109
- * @returns The API key
176
+ * Sign up a new user with email and password.
177
+ *
178
+ * Calls: POST {serverUrl}/lib-auth/api/auth/sign-up/email
179
+ *
180
+ * @param params - Sign-up parameters (email, password, name)
181
+ * @returns The auth response containing token and user
110
182
  */
111
- getApiKey(): string;
183
+ signUpEmail(params: SignUpEmailParams): Promise<AuthResponse>;
112
184
  /**
113
- * Sign in a user
114
- * This is a convenience method that wraps Better Auth
115
- * You can access the full Better Auth API via getBetterAuth()
185
+ * Sign in with email and password.
186
+ *
187
+ * Calls: POST {serverUrl}/lib-auth/api/auth/sign-in/email
188
+ *
189
+ * @param params - Sign-in parameters (email, password)
190
+ * @returns The auth response containing token and user
116
191
  */
117
- signIn(): Promise<Auth>;
192
+ signInEmail(params: SignInEmailParams): Promise<AuthResponse>;
118
193
  /**
119
- * Sign out the current user
120
- * You can access the full Better Auth API via getBetterAuth()
194
+ * Get the current session for a user.
195
+ *
196
+ * Calls: GET {serverUrl}/lib-auth/api/auth/get-session
197
+ *
198
+ * @param sessionToken - The session token (Bearer token from sign-in)
199
+ * @returns The session containing user and session data
121
200
  */
122
- signOut(): Promise<Auth>;
201
+ getSession(sessionToken: string): Promise<AuthSession>;
123
202
  /**
124
- * Get the current session
125
- * You can access the full Better Auth API via getBetterAuth()
203
+ * Sign out the current user.
204
+ *
205
+ * Calls: POST {serverUrl}/lib-auth/api/auth/sign-out
206
+ *
207
+ * @param sessionToken - The session token to invalidate
126
208
  */
127
- getSession(): Promise<Auth>;
209
+ signOut(sessionToken: string): Promise<void>;
128
210
  }
129
211
 
130
212
  /**
131
- * krutAuthdrop-in replacement for betterAuth.
213
+ * @krutai/authAuthentication package for KrutAI
132
214
  *
133
- * Use this instead of importing betterAuth directly.
215
+ * A fetch-based wrapper that calls your deployed server's `/lib-auth` routes.
216
+ * The user's API key is validated against the server before any auth call is made.
134
217
  *
135
- * @example
218
+ * @example Basic usage
136
219
  * ```typescript
137
- * import { krutAuth } from "@krutai/auth";
138
- * import Database from "better-sqlite3";
220
+ * import { krutAuth } from '@krutai/auth';
139
221
  *
140
- * export const auth = krutAuth({
141
- * database: new Database("./sqlite.db"),
142
- * emailAndPassword: { enabled: true },
222
+ * const auth = krutAuth({
223
+ * apiKey: process.env.KRUTAI_API_KEY!,
224
+ * serverUrl: 'https://krut.ai',
225
+ * });
226
+ *
227
+ * await auth.initialize(); // validates key with server
228
+ *
229
+ * const { token, user } = await auth.signUpEmail({
230
+ * email: 'user@example.com',
231
+ * password: 'secret123',
232
+ * name: 'Alice',
143
233
  * });
144
234
  * ```
235
+ *
236
+ * @example Sign in
237
+ * ```typescript
238
+ * const auth = krutAuth({
239
+ * apiKey: process.env.KRUTAI_API_KEY!,
240
+ * serverUrl: 'https://krut.ai',
241
+ * });
242
+ * await auth.initialize();
243
+ *
244
+ * const { token, user } = await auth.signInEmail({
245
+ * email: 'user@example.com',
246
+ * password: 'secret123',
247
+ * });
248
+ * ```
249
+ *
250
+ * @packageDocumentation
145
251
  */
146
- declare function krutAuth(options: BetterAuthOptions): better_auth.Auth<BetterAuthOptions>;
147
252
 
148
- declare const VERSION = "0.1.9";
253
+ /**
254
+ * krutAuth — convenience factory.
255
+ *
256
+ * Creates a `KrutAuth` instance configured to call your server's `/lib-auth` routes.
257
+ *
258
+ * @param config - Auth configuration (`apiKey` and `serverUrl` are required)
259
+ * @returns A `KrutAuth` instance — call `.initialize()` before use
260
+ *
261
+ * @example
262
+ * ```typescript
263
+ * import { krutAuth } from '@krutai/auth';
264
+ *
265
+ * const auth = krutAuth({
266
+ * apiKey: process.env.KRUTAI_API_KEY!,
267
+ * serverUrl: 'https://krut.ai',
268
+ * });
269
+ *
270
+ * await auth.initialize();
271
+ * const { token, user } = await auth.signInEmail({
272
+ * email: 'user@example.com',
273
+ * password: 'secret123',
274
+ * });
275
+ * ```
276
+ */
277
+ declare function krutAuth(config: KrutAuthConfig): KrutAuth;
278
+ declare const VERSION = "0.4.0";
149
279
 
150
- export { type AuthSession, KrutAuth, type KrutAuthConfig, VERSION, krutAuth };
280
+ export { type AuthResponse, type AuthSession, type AuthSessionRecord, type AuthUser, DEFAULT_AUTH_PREFIX, DEFAULT_SERVER_URL, KrutAuth, type KrutAuthConfig, type SignInEmailParams, type SignUpEmailParams, VERSION, krutAuth };