@llmops/sdk 0.1.1 → 0.1.2-beta.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.
@@ -1,3 +1,3 @@
1
- import "./index-fafxrrPF.cjs";
2
- import { t as createLLMOpsMiddleware } from "./index-UQjBf1t7.cjs";
1
+ import "./index-B4kndBdY.cjs";
2
+ import { t as createLLMOpsMiddleware } from "./index-DuwhMev_.cjs";
3
3
  export { createLLMOpsMiddleware };
@@ -1,3 +1,3 @@
1
- import "./index-BFiKnXi1.mjs";
2
- import { t as createLLMOpsMiddleware } from "./index-BL6HTepw.mjs";
1
+ import "./index-DHPNzRoF.mjs";
2
+ import { t as createLLMOpsMiddleware } from "./index-C80aPeNg.mjs";
3
3
  export { createLLMOpsMiddleware };
package/dist/hono.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { t as LLMOpsClient } from "./index-fafxrrPF.cjs";
1
+ import { t as LLMOpsClient } from "./index-B4kndBdY.cjs";
2
2
  import { MiddlewareHandler } from "hono";
3
3
 
4
4
  //#region src/lib/hono/index.d.ts
package/dist/hono.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { t as LLMOpsClient } from "./index-BFiKnXi1.mjs";
1
+ import { t as LLMOpsClient } from "./index-DHPNzRoF.mjs";
2
2
  import { MiddlewareHandler } from "hono";
3
3
 
4
4
  //#region src/lib/hono/index.d.ts
@@ -0,0 +1,277 @@
1
+ import { AuthConfig, BasicAuthConfig, LLMOpsConfig } from "@llmops/core";
2
+
3
+ //#region src/lib/auth/client.d.ts
4
+
5
+ /**
6
+ * Auth Client - Extensible authentication client for LLMOps
7
+ *
8
+ * Open source: BasicAuthClient with limited functionality
9
+ * Enterprise: Can extend with full user management, RBAC, SSO, etc.
10
+ */
11
+ /**
12
+ * User representation
13
+ */
14
+ interface User {
15
+ id: string;
16
+ email: string;
17
+ name: string;
18
+ role: string | null;
19
+ emailVerified: boolean;
20
+ image: string | null;
21
+ banned: boolean | null;
22
+ banReason: string | null;
23
+ createdAt: Date;
24
+ updatedAt: Date;
25
+ }
26
+ /**
27
+ * Session representation
28
+ */
29
+ interface Session {
30
+ id: string;
31
+ userId: string;
32
+ expiresAt: Date;
33
+ createdAt: Date;
34
+ }
35
+ /**
36
+ * Permission check result
37
+ */
38
+ interface Permission {
39
+ resource: string;
40
+ action: string;
41
+ allowed: boolean;
42
+ }
43
+ /**
44
+ * Pagination options
45
+ */
46
+ interface PaginationOptions {
47
+ limit?: number;
48
+ offset?: number;
49
+ }
50
+ /**
51
+ * Paginated response
52
+ */
53
+ interface PaginatedResponse<T> {
54
+ data: T[];
55
+ total: number;
56
+ limit: number;
57
+ offset: number;
58
+ }
59
+ /**
60
+ * Base auth client interface
61
+ * All auth implementations must implement this interface
62
+ */
63
+ interface AuthClient {
64
+ /**
65
+ * The type of auth client
66
+ */
67
+ readonly type: string;
68
+ /**
69
+ * Get the current session
70
+ * @returns Current session or null if not authenticated
71
+ */
72
+ getSession(): Promise<Session | null>;
73
+ /**
74
+ * Get the current authenticated user
75
+ * @returns Current user or null if not authenticated
76
+ */
77
+ getCurrentUser(): Promise<User | null>;
78
+ /**
79
+ * Check if currently authenticated
80
+ */
81
+ isAuthenticated(): Promise<boolean>;
82
+ /**
83
+ * Get a user by ID
84
+ * @param userId - The user ID
85
+ */
86
+ getUser(userId: string): Promise<User | null>;
87
+ /**
88
+ * List all users (paginated)
89
+ * @param options - Pagination options
90
+ */
91
+ listUsers(options?: PaginationOptions): Promise<PaginatedResponse<User>>;
92
+ /**
93
+ * Create a new user
94
+ * @param data - User data
95
+ */
96
+ createUser(data: {
97
+ email: string;
98
+ name: string;
99
+ password: string;
100
+ role?: string;
101
+ }): Promise<User>;
102
+ /**
103
+ * Update a user
104
+ * @param userId - The user ID
105
+ * @param data - Fields to update
106
+ */
107
+ updateUser(userId: string, data: Partial<Pick<User, 'name' | 'email' | 'role' | 'image'>>): Promise<User>;
108
+ /**
109
+ * Delete a user
110
+ * @param userId - The user ID
111
+ */
112
+ deleteUser(userId: string): Promise<void>;
113
+ /**
114
+ * Get user's role
115
+ * @param userId - The user ID (optional, defaults to current user)
116
+ */
117
+ getRole(userId?: string): Promise<string | null>;
118
+ /**
119
+ * Set user's role
120
+ * @param userId - The user ID
121
+ * @param role - The role to set
122
+ */
123
+ setRole(userId: string, role: string): Promise<void>;
124
+ /**
125
+ * Check if user has permission
126
+ * @param permission - Permission to check (e.g., { resource: 'configs', action: 'create' })
127
+ * @param userId - The user ID (optional, defaults to current user)
128
+ */
129
+ hasPermission(permission: {
130
+ resource: string;
131
+ action: string;
132
+ }, userId?: string): Promise<boolean>;
133
+ /**
134
+ * Get all permissions for a user
135
+ * @param userId - The user ID (optional, defaults to current user)
136
+ */
137
+ getPermissions(userId?: string): Promise<Permission[]>;
138
+ /**
139
+ * Ban a user
140
+ * @param userId - The user ID
141
+ * @param reason - Optional ban reason
142
+ * @param expiresAt - Optional expiration date
143
+ */
144
+ banUser(userId: string, reason?: string, expiresAt?: Date): Promise<void>;
145
+ /**
146
+ * Unban a user
147
+ * @param userId - The user ID
148
+ */
149
+ unbanUser(userId: string): Promise<void>;
150
+ /**
151
+ * List all sessions for a user
152
+ * @param userId - The user ID
153
+ */
154
+ listUserSessions(userId: string): Promise<Session[]>;
155
+ /**
156
+ * Revoke a specific session
157
+ * @param sessionId - The session ID
158
+ */
159
+ revokeSession(sessionId: string): Promise<void>;
160
+ /**
161
+ * Revoke all sessions for a user
162
+ * @param userId - The user ID
163
+ */
164
+ revokeAllSessions(userId: string): Promise<void>;
165
+ }
166
+ /**
167
+ * Error thrown when a feature is not available in the current auth implementation
168
+ */
169
+ declare class AuthFeatureNotAvailableError extends Error {
170
+ constructor(feature: string, authType: string);
171
+ }
172
+ //#endregion
173
+ //#region src/lib/auth/basic-client.d.ts
174
+ /**
175
+ * Basic auth client - minimal implementation
176
+ *
177
+ * Basic auth is stateless HTTP authentication, so most user management
178
+ * features are not available. This client provides stub implementations
179
+ * that throw helpful errors pointing users to the enterprise version.
180
+ */
181
+ declare class BasicAuthClient implements AuthClient {
182
+ readonly type = "basic";
183
+ private config;
184
+ private authenticated;
185
+ constructor(config: BasicAuthConfig$1);
186
+ /**
187
+ * Set authentication status (called after successful basic auth)
188
+ */
189
+ setAuthenticated(status: boolean): void;
190
+ getSession(): Promise<Session | null>;
191
+ getCurrentUser(): Promise<User | null>;
192
+ isAuthenticated(): Promise<boolean>;
193
+ getUser(_userId: string): Promise<User | null>;
194
+ listUsers(_options?: PaginationOptions): Promise<PaginatedResponse<User>>;
195
+ createUser(_data: {
196
+ email: string;
197
+ name: string;
198
+ password: string;
199
+ role?: string;
200
+ }): Promise<User>;
201
+ updateUser(_userId: string, _data: Partial<Pick<User, 'name' | 'email' | 'role' | 'image'>>): Promise<User>;
202
+ deleteUser(_userId: string): Promise<void>;
203
+ getRole(_userId?: string): Promise<string | null>;
204
+ setRole(_userId: string, _role: string): Promise<void>;
205
+ hasPermission(_permission: {
206
+ resource: string;
207
+ action: string;
208
+ }, _userId?: string): Promise<boolean>;
209
+ getPermissions(_userId?: string): Promise<Permission[]>;
210
+ banUser(_userId: string, _reason?: string, _expiresAt?: Date): Promise<void>;
211
+ unbanUser(_userId: string): Promise<void>;
212
+ listUserSessions(_userId: string): Promise<Session[]>;
213
+ revokeSession(_sessionId: string): Promise<void>;
214
+ revokeAllSessions(_userId: string): Promise<void>;
215
+ }
216
+ /**
217
+ * Create a basic auth client
218
+ */
219
+ declare function createBasicAuthClient(config: BasicAuthConfig$1): BasicAuthClient;
220
+ //#endregion
221
+ //#region src/lib/auth/index.d.ts
222
+ type AuthConfig$1 = AuthConfig;
223
+ type BasicAuthConfig$1 = BasicAuthConfig;
224
+ /**
225
+ * Options for basic authentication
226
+ */
227
+ interface BasicAuthOptions {
228
+ /**
229
+ * Default username for basic auth
230
+ * @example "admin@example.com"
231
+ */
232
+ username: string;
233
+ /**
234
+ * Default password for basic auth
235
+ * Should be changed in production!
236
+ */
237
+ password: string;
238
+ }
239
+ /**
240
+ * Create a basic auth configuration
241
+ *
242
+ * @example
243
+ * ```typescript
244
+ * import { llmops, basicAuth } from '@llmops/sdk';
245
+ *
246
+ * const client = llmops({
247
+ * database: pool,
248
+ * basePath: '/llmops',
249
+ * providers: { openai: { apiKey: '...' } },
250
+ * auth: basicAuth({
251
+ * username: 'admin@example.com',
252
+ * password: 'secure-password',
253
+ * }),
254
+ * });
255
+ * ```
256
+ */
257
+ declare function basicAuth(options: BasicAuthOptions): BasicAuthConfig$1;
258
+ //#endregion
259
+ //#region src/client/index.d.ts
260
+ type LLMOpsClient = {
261
+ handler: (request: Request) => Promise<Response>;
262
+ config: LLMOpsConfig;
263
+ /**
264
+ * Auth client for managing authentication
265
+ *
266
+ * For basic auth (open source):
267
+ * - isAuthenticated(), hasPermission() work
268
+ * - User management methods throw AuthFeatureNotAvailableError
269
+ *
270
+ * For enterprise auth:
271
+ * - All methods available (user CRUD, RBAC, sessions, banning)
272
+ */
273
+ authClient: AuthClient;
274
+ };
275
+ declare const createLLMOps: (config: LLMOpsConfig) => LLMOpsClient;
276
+ //#endregion
277
+ export { BasicAuthOptions as a, createBasicAuthClient as c, PaginatedResponse as d, PaginationOptions as f, User as h, BasicAuthConfig$1 as i, AuthClient as l, Session as m, createLLMOps as n, basicAuth as o, Permission as p, AuthConfig$1 as r, BasicAuthClient as s, LLMOpsClient as t, AuthFeatureNotAvailableError as u };
@@ -1,4 +1,4 @@
1
- import { t as LLMOpsClient } from "./index-BFiKnXi1.mjs";
1
+ import { t as LLMOpsClient } from "./index-DHPNzRoF.mjs";
2
2
  import { NextFunction, Request, Response } from "express";
3
3
 
4
4
  //#region src/lib/express/index.d.ts
@@ -0,0 +1,277 @@
1
+ import { AuthConfig, BasicAuthConfig, LLMOpsConfig } from "@llmops/core";
2
+
3
+ //#region src/lib/auth/client.d.ts
4
+
5
+ /**
6
+ * Auth Client - Extensible authentication client for LLMOps
7
+ *
8
+ * Open source: BasicAuthClient with limited functionality
9
+ * Enterprise: Can extend with full user management, RBAC, SSO, etc.
10
+ */
11
+ /**
12
+ * User representation
13
+ */
14
+ interface User {
15
+ id: string;
16
+ email: string;
17
+ name: string;
18
+ role: string | null;
19
+ emailVerified: boolean;
20
+ image: string | null;
21
+ banned: boolean | null;
22
+ banReason: string | null;
23
+ createdAt: Date;
24
+ updatedAt: Date;
25
+ }
26
+ /**
27
+ * Session representation
28
+ */
29
+ interface Session {
30
+ id: string;
31
+ userId: string;
32
+ expiresAt: Date;
33
+ createdAt: Date;
34
+ }
35
+ /**
36
+ * Permission check result
37
+ */
38
+ interface Permission {
39
+ resource: string;
40
+ action: string;
41
+ allowed: boolean;
42
+ }
43
+ /**
44
+ * Pagination options
45
+ */
46
+ interface PaginationOptions {
47
+ limit?: number;
48
+ offset?: number;
49
+ }
50
+ /**
51
+ * Paginated response
52
+ */
53
+ interface PaginatedResponse<T> {
54
+ data: T[];
55
+ total: number;
56
+ limit: number;
57
+ offset: number;
58
+ }
59
+ /**
60
+ * Base auth client interface
61
+ * All auth implementations must implement this interface
62
+ */
63
+ interface AuthClient {
64
+ /**
65
+ * The type of auth client
66
+ */
67
+ readonly type: string;
68
+ /**
69
+ * Get the current session
70
+ * @returns Current session or null if not authenticated
71
+ */
72
+ getSession(): Promise<Session | null>;
73
+ /**
74
+ * Get the current authenticated user
75
+ * @returns Current user or null if not authenticated
76
+ */
77
+ getCurrentUser(): Promise<User | null>;
78
+ /**
79
+ * Check if currently authenticated
80
+ */
81
+ isAuthenticated(): Promise<boolean>;
82
+ /**
83
+ * Get a user by ID
84
+ * @param userId - The user ID
85
+ */
86
+ getUser(userId: string): Promise<User | null>;
87
+ /**
88
+ * List all users (paginated)
89
+ * @param options - Pagination options
90
+ */
91
+ listUsers(options?: PaginationOptions): Promise<PaginatedResponse<User>>;
92
+ /**
93
+ * Create a new user
94
+ * @param data - User data
95
+ */
96
+ createUser(data: {
97
+ email: string;
98
+ name: string;
99
+ password: string;
100
+ role?: string;
101
+ }): Promise<User>;
102
+ /**
103
+ * Update a user
104
+ * @param userId - The user ID
105
+ * @param data - Fields to update
106
+ */
107
+ updateUser(userId: string, data: Partial<Pick<User, 'name' | 'email' | 'role' | 'image'>>): Promise<User>;
108
+ /**
109
+ * Delete a user
110
+ * @param userId - The user ID
111
+ */
112
+ deleteUser(userId: string): Promise<void>;
113
+ /**
114
+ * Get user's role
115
+ * @param userId - The user ID (optional, defaults to current user)
116
+ */
117
+ getRole(userId?: string): Promise<string | null>;
118
+ /**
119
+ * Set user's role
120
+ * @param userId - The user ID
121
+ * @param role - The role to set
122
+ */
123
+ setRole(userId: string, role: string): Promise<void>;
124
+ /**
125
+ * Check if user has permission
126
+ * @param permission - Permission to check (e.g., { resource: 'configs', action: 'create' })
127
+ * @param userId - The user ID (optional, defaults to current user)
128
+ */
129
+ hasPermission(permission: {
130
+ resource: string;
131
+ action: string;
132
+ }, userId?: string): Promise<boolean>;
133
+ /**
134
+ * Get all permissions for a user
135
+ * @param userId - The user ID (optional, defaults to current user)
136
+ */
137
+ getPermissions(userId?: string): Promise<Permission[]>;
138
+ /**
139
+ * Ban a user
140
+ * @param userId - The user ID
141
+ * @param reason - Optional ban reason
142
+ * @param expiresAt - Optional expiration date
143
+ */
144
+ banUser(userId: string, reason?: string, expiresAt?: Date): Promise<void>;
145
+ /**
146
+ * Unban a user
147
+ * @param userId - The user ID
148
+ */
149
+ unbanUser(userId: string): Promise<void>;
150
+ /**
151
+ * List all sessions for a user
152
+ * @param userId - The user ID
153
+ */
154
+ listUserSessions(userId: string): Promise<Session[]>;
155
+ /**
156
+ * Revoke a specific session
157
+ * @param sessionId - The session ID
158
+ */
159
+ revokeSession(sessionId: string): Promise<void>;
160
+ /**
161
+ * Revoke all sessions for a user
162
+ * @param userId - The user ID
163
+ */
164
+ revokeAllSessions(userId: string): Promise<void>;
165
+ }
166
+ /**
167
+ * Error thrown when a feature is not available in the current auth implementation
168
+ */
169
+ declare class AuthFeatureNotAvailableError extends Error {
170
+ constructor(feature: string, authType: string);
171
+ }
172
+ //#endregion
173
+ //#region src/lib/auth/basic-client.d.ts
174
+ /**
175
+ * Basic auth client - minimal implementation
176
+ *
177
+ * Basic auth is stateless HTTP authentication, so most user management
178
+ * features are not available. This client provides stub implementations
179
+ * that throw helpful errors pointing users to the enterprise version.
180
+ */
181
+ declare class BasicAuthClient implements AuthClient {
182
+ readonly type = "basic";
183
+ private config;
184
+ private authenticated;
185
+ constructor(config: BasicAuthConfig$1);
186
+ /**
187
+ * Set authentication status (called after successful basic auth)
188
+ */
189
+ setAuthenticated(status: boolean): void;
190
+ getSession(): Promise<Session | null>;
191
+ getCurrentUser(): Promise<User | null>;
192
+ isAuthenticated(): Promise<boolean>;
193
+ getUser(_userId: string): Promise<User | null>;
194
+ listUsers(_options?: PaginationOptions): Promise<PaginatedResponse<User>>;
195
+ createUser(_data: {
196
+ email: string;
197
+ name: string;
198
+ password: string;
199
+ role?: string;
200
+ }): Promise<User>;
201
+ updateUser(_userId: string, _data: Partial<Pick<User, 'name' | 'email' | 'role' | 'image'>>): Promise<User>;
202
+ deleteUser(_userId: string): Promise<void>;
203
+ getRole(_userId?: string): Promise<string | null>;
204
+ setRole(_userId: string, _role: string): Promise<void>;
205
+ hasPermission(_permission: {
206
+ resource: string;
207
+ action: string;
208
+ }, _userId?: string): Promise<boolean>;
209
+ getPermissions(_userId?: string): Promise<Permission[]>;
210
+ banUser(_userId: string, _reason?: string, _expiresAt?: Date): Promise<void>;
211
+ unbanUser(_userId: string): Promise<void>;
212
+ listUserSessions(_userId: string): Promise<Session[]>;
213
+ revokeSession(_sessionId: string): Promise<void>;
214
+ revokeAllSessions(_userId: string): Promise<void>;
215
+ }
216
+ /**
217
+ * Create a basic auth client
218
+ */
219
+ declare function createBasicAuthClient(config: BasicAuthConfig$1): BasicAuthClient;
220
+ //#endregion
221
+ //#region src/lib/auth/index.d.ts
222
+ type AuthConfig$1 = AuthConfig;
223
+ type BasicAuthConfig$1 = BasicAuthConfig;
224
+ /**
225
+ * Options for basic authentication
226
+ */
227
+ interface BasicAuthOptions {
228
+ /**
229
+ * Default username for basic auth
230
+ * @example "admin@example.com"
231
+ */
232
+ username: string;
233
+ /**
234
+ * Default password for basic auth
235
+ * Should be changed in production!
236
+ */
237
+ password: string;
238
+ }
239
+ /**
240
+ * Create a basic auth configuration
241
+ *
242
+ * @example
243
+ * ```typescript
244
+ * import { llmops, basicAuth } from '@llmops/sdk';
245
+ *
246
+ * const client = llmops({
247
+ * database: pool,
248
+ * basePath: '/llmops',
249
+ * providers: { openai: { apiKey: '...' } },
250
+ * auth: basicAuth({
251
+ * username: 'admin@example.com',
252
+ * password: 'secure-password',
253
+ * }),
254
+ * });
255
+ * ```
256
+ */
257
+ declare function basicAuth(options: BasicAuthOptions): BasicAuthConfig$1;
258
+ //#endregion
259
+ //#region src/client/index.d.ts
260
+ type LLMOpsClient = {
261
+ handler: (request: Request) => Promise<Response>;
262
+ config: LLMOpsConfig;
263
+ /**
264
+ * Auth client for managing authentication
265
+ *
266
+ * For basic auth (open source):
267
+ * - isAuthenticated(), hasPermission() work
268
+ * - User management methods throw AuthFeatureNotAvailableError
269
+ *
270
+ * For enterprise auth:
271
+ * - All methods available (user CRUD, RBAC, sessions, banning)
272
+ */
273
+ authClient: AuthClient;
274
+ };
275
+ declare const createLLMOps: (config: LLMOpsConfig) => LLMOpsClient;
276
+ //#endregion
277
+ export { BasicAuthOptions as a, createBasicAuthClient as c, PaginatedResponse as d, PaginationOptions as f, User as h, BasicAuthConfig$1 as i, AuthClient as l, Session as m, createLLMOps as n, basicAuth as o, Permission as p, AuthConfig$1 as r, BasicAuthClient as s, LLMOpsClient as t, AuthFeatureNotAvailableError as u };
@@ -1,4 +1,4 @@
1
- import { t as LLMOpsClient } from "./index-fafxrrPF.cjs";
1
+ import { t as LLMOpsClient } from "./index-B4kndBdY.cjs";
2
2
  import { NextFunction, Request, Response } from "express";
3
3
 
4
4
  //#region src/lib/express/index.d.ts
package/dist/index.cjs CHANGED
@@ -2,15 +2,179 @@ const require_express = require('./express-B-wbCza5.cjs');
2
2
  require("@llmops/core");
3
3
  let __llmops_app = require("@llmops/app");
4
4
 
5
+ //#region src/lib/auth/client.ts
6
+ /**
7
+ * Error thrown when a feature is not available in the current auth implementation
8
+ */
9
+ var AuthFeatureNotAvailableError = class extends Error {
10
+ constructor(feature, authType) {
11
+ super(`The "${feature}" feature is not available with "${authType}" auth. Upgrade to @llmops/enterprise for full auth functionality.`);
12
+ this.name = "AuthFeatureNotAvailableError";
13
+ }
14
+ };
15
+
16
+ //#endregion
17
+ //#region src/lib/auth/basic-client.ts
18
+ /**
19
+ * Basic auth client - minimal implementation
20
+ *
21
+ * Basic auth is stateless HTTP authentication, so most user management
22
+ * features are not available. This client provides stub implementations
23
+ * that throw helpful errors pointing users to the enterprise version.
24
+ */
25
+ var BasicAuthClient = class {
26
+ type = "basic";
27
+ config;
28
+ authenticated = false;
29
+ constructor(config) {
30
+ this.config = config;
31
+ }
32
+ /**
33
+ * Set authentication status (called after successful basic auth)
34
+ */
35
+ setAuthenticated(status) {
36
+ this.authenticated = status;
37
+ }
38
+ async getSession() {
39
+ if (!this.authenticated) return null;
40
+ return {
41
+ id: "basic-auth-session",
42
+ userId: "basic-auth-user",
43
+ expiresAt: new Date(Date.now() + 1440 * 60 * 1e3),
44
+ createdAt: /* @__PURE__ */ new Date()
45
+ };
46
+ }
47
+ async getCurrentUser() {
48
+ if (!this.authenticated) return null;
49
+ return {
50
+ id: "basic-auth-user",
51
+ email: this.config.defaultUser,
52
+ name: "Admin",
53
+ role: "admin",
54
+ emailVerified: true,
55
+ image: null,
56
+ banned: false,
57
+ banReason: null,
58
+ createdAt: /* @__PURE__ */ new Date(),
59
+ updatedAt: /* @__PURE__ */ new Date()
60
+ };
61
+ }
62
+ async isAuthenticated() {
63
+ return this.authenticated;
64
+ }
65
+ async getUser(_userId) {
66
+ throw new AuthFeatureNotAvailableError("getUser", this.type);
67
+ }
68
+ async listUsers(_options) {
69
+ throw new AuthFeatureNotAvailableError("listUsers", this.type);
70
+ }
71
+ async createUser(_data) {
72
+ throw new AuthFeatureNotAvailableError("createUser", this.type);
73
+ }
74
+ async updateUser(_userId, _data) {
75
+ throw new AuthFeatureNotAvailableError("updateUser", this.type);
76
+ }
77
+ async deleteUser(_userId) {
78
+ throw new AuthFeatureNotAvailableError("deleteUser", this.type);
79
+ }
80
+ async getRole(_userId) {
81
+ if (this.authenticated) return "admin";
82
+ return null;
83
+ }
84
+ async setRole(_userId, _role) {
85
+ throw new AuthFeatureNotAvailableError("setRole", this.type);
86
+ }
87
+ async hasPermission(_permission, _userId) {
88
+ return this.authenticated;
89
+ }
90
+ async getPermissions(_userId) {
91
+ if (!this.authenticated) return [];
92
+ return [{
93
+ resource: "*",
94
+ action: "*",
95
+ allowed: true
96
+ }];
97
+ }
98
+ async banUser(_userId, _reason, _expiresAt) {
99
+ throw new AuthFeatureNotAvailableError("banUser", this.type);
100
+ }
101
+ async unbanUser(_userId) {
102
+ throw new AuthFeatureNotAvailableError("unbanUser", this.type);
103
+ }
104
+ async listUserSessions(_userId) {
105
+ throw new AuthFeatureNotAvailableError("listUserSessions", this.type);
106
+ }
107
+ async revokeSession(_sessionId) {
108
+ throw new AuthFeatureNotAvailableError("revokeSession", this.type);
109
+ }
110
+ async revokeAllSessions(_userId) {
111
+ throw new AuthFeatureNotAvailableError("revokeAllSessions", this.type);
112
+ }
113
+ };
114
+ /**
115
+ * Create a basic auth client
116
+ */
117
+ function createBasicAuthClient(config) {
118
+ return new BasicAuthClient(config);
119
+ }
120
+
121
+ //#endregion
122
+ //#region src/lib/auth/index.ts
123
+ /**
124
+ * Create a basic auth configuration
125
+ *
126
+ * @example
127
+ * ```typescript
128
+ * import { llmops, basicAuth } from '@llmops/sdk';
129
+ *
130
+ * const client = llmops({
131
+ * database: pool,
132
+ * basePath: '/llmops',
133
+ * providers: { openai: { apiKey: '...' } },
134
+ * auth: basicAuth({
135
+ * username: 'admin@example.com',
136
+ * password: 'secure-password',
137
+ * }),
138
+ * });
139
+ * ```
140
+ */
141
+ function basicAuth(options) {
142
+ if (!options.username || options.username.length === 0) throw new Error("basicAuth: username is required");
143
+ if (!options.password || options.password.length === 0) throw new Error("basicAuth: password is required");
144
+ return Object.freeze({
145
+ type: "basic",
146
+ defaultUser: options.username,
147
+ defaultPassword: options.password
148
+ });
149
+ }
150
+
151
+ //#endregion
5
152
  //#region src/client/index.ts
153
+ /**
154
+ * Create an auth client based on the auth config type
155
+ */
156
+ function createAuthClient(auth) {
157
+ if (auth.type === "basic" && typeof auth.defaultUser === "string" && typeof auth.defaultPassword === "string") return new BasicAuthClient({
158
+ type: "basic",
159
+ defaultUser: auth.defaultUser,
160
+ defaultPassword: auth.defaultPassword
161
+ });
162
+ throw new Error(`Unknown auth type "${auth.type}". Use basicAuth() from @llmops/sdk or upgrade to @llmops/enterprise for advanced auth.`);
163
+ }
6
164
  const createLLMOps = (config) => {
7
165
  const { app } = (0, __llmops_app.createApp)(config);
166
+ const authClient = createAuthClient(config.auth);
8
167
  return {
9
168
  handler: async (req) => app.fetch(req, void 0, void 0),
10
- config: Object.freeze(config)
169
+ config: Object.freeze(config),
170
+ authClient
11
171
  };
12
172
  };
13
173
 
14
174
  //#endregion
175
+ exports.AuthFeatureNotAvailableError = AuthFeatureNotAvailableError;
176
+ exports.BasicAuthClient = BasicAuthClient;
177
+ exports.basicAuth = basicAuth;
178
+ exports.createBasicAuthClient = createBasicAuthClient;
15
179
  exports.createLLMOpsMiddleware = require_express.createLLMOpsMiddleware;
16
180
  exports.llmops = createLLMOps;
package/dist/index.d.cts CHANGED
@@ -1,3 +1,3 @@
1
- import { n as createLLMOps } from "./index-fafxrrPF.cjs";
2
- import { t as createLLMOpsMiddleware } from "./index-UQjBf1t7.cjs";
3
- export { createLLMOpsMiddleware, createLLMOps as llmops };
1
+ import { a as BasicAuthOptions, c as createBasicAuthClient, d as PaginatedResponse, f as PaginationOptions, h as User, i as BasicAuthConfig, l as AuthClient, m as Session, n as createLLMOps, o as basicAuth, p as Permission, r as AuthConfig, s as BasicAuthClient, u as AuthFeatureNotAvailableError } from "./index-B4kndBdY.cjs";
2
+ import { t as createLLMOpsMiddleware } from "./index-DuwhMev_.cjs";
3
+ export { AuthClient, AuthConfig, AuthFeatureNotAvailableError, BasicAuthClient, BasicAuthConfig, BasicAuthOptions, PaginatedResponse, PaginationOptions, Permission, Session, User, basicAuth, createBasicAuthClient, createLLMOpsMiddleware, createLLMOps as llmops };
package/dist/index.d.mts CHANGED
@@ -1,3 +1,3 @@
1
- import { n as createLLMOps } from "./index-BFiKnXi1.mjs";
2
- import { t as createLLMOpsMiddleware } from "./index-BL6HTepw.mjs";
3
- export { createLLMOpsMiddleware, createLLMOps as llmops };
1
+ import { a as BasicAuthOptions, c as createBasicAuthClient, d as PaginatedResponse, f as PaginationOptions, h as User, i as BasicAuthConfig, l as AuthClient, m as Session, n as createLLMOps, o as basicAuth, p as Permission, r as AuthConfig, s as BasicAuthClient, u as AuthFeatureNotAvailableError } from "./index-DHPNzRoF.mjs";
2
+ import { t as createLLMOpsMiddleware } from "./index-C80aPeNg.mjs";
3
+ export { AuthClient, AuthConfig, AuthFeatureNotAvailableError, BasicAuthClient, BasicAuthConfig, BasicAuthOptions, PaginatedResponse, PaginationOptions, Permission, Session, User, basicAuth, createBasicAuthClient, createLLMOpsMiddleware, createLLMOps as llmops };
package/dist/index.mjs CHANGED
@@ -2,14 +2,174 @@ import { t as createLLMOpsMiddleware } from "./express-BXdOPP-q.mjs";
2
2
  import "@llmops/core";
3
3
  import { createApp } from "@llmops/app";
4
4
 
5
+ //#region src/lib/auth/client.ts
6
+ /**
7
+ * Error thrown when a feature is not available in the current auth implementation
8
+ */
9
+ var AuthFeatureNotAvailableError = class extends Error {
10
+ constructor(feature, authType) {
11
+ super(`The "${feature}" feature is not available with "${authType}" auth. Upgrade to @llmops/enterprise for full auth functionality.`);
12
+ this.name = "AuthFeatureNotAvailableError";
13
+ }
14
+ };
15
+
16
+ //#endregion
17
+ //#region src/lib/auth/basic-client.ts
18
+ /**
19
+ * Basic auth client - minimal implementation
20
+ *
21
+ * Basic auth is stateless HTTP authentication, so most user management
22
+ * features are not available. This client provides stub implementations
23
+ * that throw helpful errors pointing users to the enterprise version.
24
+ */
25
+ var BasicAuthClient = class {
26
+ type = "basic";
27
+ config;
28
+ authenticated = false;
29
+ constructor(config) {
30
+ this.config = config;
31
+ }
32
+ /**
33
+ * Set authentication status (called after successful basic auth)
34
+ */
35
+ setAuthenticated(status) {
36
+ this.authenticated = status;
37
+ }
38
+ async getSession() {
39
+ if (!this.authenticated) return null;
40
+ return {
41
+ id: "basic-auth-session",
42
+ userId: "basic-auth-user",
43
+ expiresAt: new Date(Date.now() + 1440 * 60 * 1e3),
44
+ createdAt: /* @__PURE__ */ new Date()
45
+ };
46
+ }
47
+ async getCurrentUser() {
48
+ if (!this.authenticated) return null;
49
+ return {
50
+ id: "basic-auth-user",
51
+ email: this.config.defaultUser,
52
+ name: "Admin",
53
+ role: "admin",
54
+ emailVerified: true,
55
+ image: null,
56
+ banned: false,
57
+ banReason: null,
58
+ createdAt: /* @__PURE__ */ new Date(),
59
+ updatedAt: /* @__PURE__ */ new Date()
60
+ };
61
+ }
62
+ async isAuthenticated() {
63
+ return this.authenticated;
64
+ }
65
+ async getUser(_userId) {
66
+ throw new AuthFeatureNotAvailableError("getUser", this.type);
67
+ }
68
+ async listUsers(_options) {
69
+ throw new AuthFeatureNotAvailableError("listUsers", this.type);
70
+ }
71
+ async createUser(_data) {
72
+ throw new AuthFeatureNotAvailableError("createUser", this.type);
73
+ }
74
+ async updateUser(_userId, _data) {
75
+ throw new AuthFeatureNotAvailableError("updateUser", this.type);
76
+ }
77
+ async deleteUser(_userId) {
78
+ throw new AuthFeatureNotAvailableError("deleteUser", this.type);
79
+ }
80
+ async getRole(_userId) {
81
+ if (this.authenticated) return "admin";
82
+ return null;
83
+ }
84
+ async setRole(_userId, _role) {
85
+ throw new AuthFeatureNotAvailableError("setRole", this.type);
86
+ }
87
+ async hasPermission(_permission, _userId) {
88
+ return this.authenticated;
89
+ }
90
+ async getPermissions(_userId) {
91
+ if (!this.authenticated) return [];
92
+ return [{
93
+ resource: "*",
94
+ action: "*",
95
+ allowed: true
96
+ }];
97
+ }
98
+ async banUser(_userId, _reason, _expiresAt) {
99
+ throw new AuthFeatureNotAvailableError("banUser", this.type);
100
+ }
101
+ async unbanUser(_userId) {
102
+ throw new AuthFeatureNotAvailableError("unbanUser", this.type);
103
+ }
104
+ async listUserSessions(_userId) {
105
+ throw new AuthFeatureNotAvailableError("listUserSessions", this.type);
106
+ }
107
+ async revokeSession(_sessionId) {
108
+ throw new AuthFeatureNotAvailableError("revokeSession", this.type);
109
+ }
110
+ async revokeAllSessions(_userId) {
111
+ throw new AuthFeatureNotAvailableError("revokeAllSessions", this.type);
112
+ }
113
+ };
114
+ /**
115
+ * Create a basic auth client
116
+ */
117
+ function createBasicAuthClient(config) {
118
+ return new BasicAuthClient(config);
119
+ }
120
+
121
+ //#endregion
122
+ //#region src/lib/auth/index.ts
123
+ /**
124
+ * Create a basic auth configuration
125
+ *
126
+ * @example
127
+ * ```typescript
128
+ * import { llmops, basicAuth } from '@llmops/sdk';
129
+ *
130
+ * const client = llmops({
131
+ * database: pool,
132
+ * basePath: '/llmops',
133
+ * providers: { openai: { apiKey: '...' } },
134
+ * auth: basicAuth({
135
+ * username: 'admin@example.com',
136
+ * password: 'secure-password',
137
+ * }),
138
+ * });
139
+ * ```
140
+ */
141
+ function basicAuth(options) {
142
+ if (!options.username || options.username.length === 0) throw new Error("basicAuth: username is required");
143
+ if (!options.password || options.password.length === 0) throw new Error("basicAuth: password is required");
144
+ return Object.freeze({
145
+ type: "basic",
146
+ defaultUser: options.username,
147
+ defaultPassword: options.password
148
+ });
149
+ }
150
+
151
+ //#endregion
5
152
  //#region src/client/index.ts
153
+ /**
154
+ * Create an auth client based on the auth config type
155
+ */
156
+ function createAuthClient(auth) {
157
+ if (auth.type === "basic" && typeof auth.defaultUser === "string" && typeof auth.defaultPassword === "string") return new BasicAuthClient({
158
+ type: "basic",
159
+ defaultUser: auth.defaultUser,
160
+ defaultPassword: auth.defaultPassword
161
+ });
162
+ throw new Error(`Unknown auth type "${auth.type}". Use basicAuth() from @llmops/sdk or upgrade to @llmops/enterprise for advanced auth.`);
163
+ }
6
164
  const createLLMOps = (config) => {
7
165
  const { app } = createApp(config);
166
+ const authClient = createAuthClient(config.auth);
8
167
  return {
9
168
  handler: async (req) => app.fetch(req, void 0, void 0),
10
- config: Object.freeze(config)
169
+ config: Object.freeze(config),
170
+ authClient
11
171
  };
12
172
  };
13
173
 
14
174
  //#endregion
15
- export { createLLMOpsMiddleware, createLLMOps as llmops };
175
+ export { AuthFeatureNotAvailableError, BasicAuthClient, basicAuth, createBasicAuthClient, createLLMOpsMiddleware, createLLMOps as llmops };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@llmops/sdk",
3
- "version": "0.1.1",
3
+ "version": "0.1.2-beta.2",
4
4
  "description": "An LLMOps toolkit for TypeScript applications",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -57,8 +57,8 @@
57
57
  "access": "public"
58
58
  },
59
59
  "dependencies": {
60
- "@llmops/app": "^0.1.1",
61
- "@llmops/core": "^0.1.1"
60
+ "@llmops/app": "^0.1.2-beta.2",
61
+ "@llmops/core": "^0.1.2-beta.2"
62
62
  },
63
63
  "devDependencies": {
64
64
  "@types/express": "^5.0.6",
@@ -1,10 +0,0 @@
1
- import { LLMOpsConfig } from "@llmops/core";
2
-
3
- //#region src/client/index.d.ts
4
- type LLMOpsClient = {
5
- handler: (request: Request) => Promise<Response>;
6
- config: LLMOpsConfig;
7
- };
8
- declare const createLLMOps: (config: LLMOpsConfig) => LLMOpsClient;
9
- //#endregion
10
- export { createLLMOps as n, LLMOpsClient as t };
@@ -1,10 +0,0 @@
1
- import { LLMOpsConfig } from "@llmops/core";
2
-
3
- //#region src/client/index.d.ts
4
- type LLMOpsClient = {
5
- handler: (request: Request) => Promise<Response>;
6
- config: LLMOpsConfig;
7
- };
8
- declare const createLLMOps: (config: LLMOpsConfig) => LLMOpsClient;
9
- //#endregion
10
- export { createLLMOps as n, LLMOpsClient as t };