@zea.cl/auth 0.1.6

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,453 @@
1
+ import { T as ThalamusConfig$1, U as UserInfo$1, a as User$1, O as Organization, R as Role, D as DomainRole$1 } from './index-BnHWPrKX.js';
2
+
3
+ /**
4
+ * ZEA Thalamus SDK Types
5
+ *
6
+ * TypeScript type definitions for the Thalamus OAuth2 SDK
7
+ */
8
+ interface ThalamusConfig {
9
+ /** OAuth2 Client ID */
10
+ clientId: string;
11
+ /** OAuth2 Client Secret (for confidential clients) */
12
+ clientSecret?: string;
13
+ /** Redirect URI for authorization callback */
14
+ redirectUri: string;
15
+ /** Thalamus base URL (e.g., https://auth.example.com) */
16
+ baseUrl: string;
17
+ /** Default scopes to request */
18
+ defaultScopes?: string[];
19
+ }
20
+ interface TokenResponse {
21
+ access_token: string;
22
+ token_type: 'Bearer';
23
+ expires_in: number;
24
+ refresh_token?: string;
25
+ scope?: string;
26
+ }
27
+ interface IntrospectionResponse {
28
+ active: boolean;
29
+ scope?: string;
30
+ client_id?: string;
31
+ user_id?: string;
32
+ username?: string;
33
+ email?: string;
34
+ organization_id?: string;
35
+ tenant_id?: string;
36
+ token_type?: string;
37
+ exp?: number;
38
+ iat?: number;
39
+ nbf?: number;
40
+ sub?: string;
41
+ aud?: string;
42
+ iss?: string;
43
+ jti?: string;
44
+ agent_type?: 'autonomous' | 'supervised' | 'ephemeral';
45
+ delegated_by?: string;
46
+ delegation_chain?: string[];
47
+ delegation_depth?: number;
48
+ task_id?: string;
49
+ max_operations?: number;
50
+ operations_remaining?: number;
51
+ expires_on_completion?: boolean;
52
+ intent_description?: string;
53
+ }
54
+ interface UserInfo {
55
+ sub: string;
56
+ email?: string;
57
+ email_verified?: boolean;
58
+ name?: string;
59
+ given_name?: string;
60
+ family_name?: string;
61
+ picture?: string;
62
+ organization_id?: string;
63
+ }
64
+ interface AuthorizationUrlOptions {
65
+ scope?: string[];
66
+ state?: string;
67
+ responseType?: 'code';
68
+ codeChallenge?: string;
69
+ codeChallengeMethod?: 'S256';
70
+ }
71
+ interface TokenExchangeOptions {
72
+ code: string;
73
+ codeVerifier?: string;
74
+ }
75
+ interface ClientCredentialsOptions {
76
+ scope?: string[];
77
+ }
78
+ interface RefreshTokenOptions {
79
+ refreshToken: string;
80
+ }
81
+ interface ThalamusError extends Error {
82
+ statusCode?: number;
83
+ error?: string;
84
+ error_description?: string;
85
+ }
86
+ interface MCPServerConfig {
87
+ name: string;
88
+ type: 'cli' | 'url' | 'sse';
89
+ /** Executable command (for type: cli) */
90
+ command?: string;
91
+ /** Server URL (for type: url, sse) */
92
+ url?: string;
93
+ /** Glob patterns to filter which tools are exposed. ["*"] = all, ["venture_*"] = filtered */
94
+ tools_filter?: string[];
95
+ enabled: boolean;
96
+ }
97
+ interface AgentConfig {
98
+ system_prompt?: string;
99
+ skills?: string[];
100
+ icon?: string;
101
+ model?: string;
102
+ mcp_servers?: MCPServerConfig[];
103
+ custom_skills?: CustomSkill[];
104
+ }
105
+ interface CustomSkill {
106
+ name: string;
107
+ description: string;
108
+ body: string;
109
+ }
110
+
111
+ /**
112
+ * OAuth2 Authentication Module
113
+ *
114
+ * Handles OAuth2 authorization code flow, client credentials, and token refresh
115
+ */
116
+
117
+ declare class OAuth2 {
118
+ private config;
119
+ constructor(config: ThalamusConfig);
120
+ /**
121
+ * Generate OAuth2 authorization URL for user login
122
+ *
123
+ * @example
124
+ * ```ts
125
+ * const authUrl = thalamus.auth.getAuthorizationUrl({
126
+ * scope: ['openid', 'profile', 'email'],
127
+ * state: 'random-state-string'
128
+ * })
129
+ * // Redirect user to authUrl
130
+ * ```
131
+ */
132
+ getAuthorizationUrl(options?: AuthorizationUrlOptions): string;
133
+ /**
134
+ * Exchange authorization code for access token
135
+ *
136
+ * @example
137
+ * ```ts
138
+ * const tokens = await thalamus.auth.exchangeCode('authorization_code_here')
139
+ * console.log(tokens.access_token)
140
+ * ```
141
+ */
142
+ exchangeCode(codeOrOptions: string | TokenExchangeOptions): Promise<TokenResponse>;
143
+ /**
144
+ * Get access token using client credentials (M2M)
145
+ *
146
+ * @example
147
+ * ```ts
148
+ * const tokens = await thalamus.auth.getClientCredentialsToken({
149
+ * scope: ['api:read', 'api:write']
150
+ * })
151
+ * ```
152
+ */
153
+ getClientCredentialsToken(options?: ClientCredentialsOptions): Promise<TokenResponse>;
154
+ /**
155
+ * Refresh access token using refresh token
156
+ *
157
+ * @example
158
+ * ```ts
159
+ * const newTokens = await thalamus.auth.refreshToken({
160
+ * refreshToken: 'rt_...'
161
+ * })
162
+ * ```
163
+ */
164
+ refreshToken(options: RefreshTokenOptions): Promise<TokenResponse>;
165
+ /**
166
+ * Revoke a token (access or refresh token)
167
+ *
168
+ * @example
169
+ * ```ts
170
+ * await thalamus.auth.revokeToken('at_...')
171
+ * ```
172
+ */
173
+ revokeToken(token: string, tokenTypeHint?: 'access_token' | 'refresh_token'): Promise<void>;
174
+ /**
175
+ * Generate random state for CSRF protection
176
+ */
177
+ generateState(length?: number): string;
178
+ /**
179
+ * Make token request to /oauth/token
180
+ */
181
+ private requestToken;
182
+ /**
183
+ * Handle API errors
184
+ */
185
+ private handleError;
186
+ }
187
+
188
+ /**
189
+ * Token Management Module
190
+ *
191
+ * Handles token introspection and validation
192
+ */
193
+
194
+ declare class TokenManager {
195
+ private config;
196
+ constructor(config: ThalamusConfig);
197
+ /**
198
+ * Introspect a token to check if it's valid and get metadata
199
+ *
200
+ * @example
201
+ * ```ts
202
+ * const tokenInfo = await thalamus.tokens.introspect('at_...')
203
+ * if (tokenInfo.active) {
204
+ * console.log(tokenInfo.user_id)
205
+ * console.log(tokenInfo.scope)
206
+ * }
207
+ * ```
208
+ */
209
+ introspect(token: string): Promise<IntrospectionResponse>;
210
+ /**
211
+ * Get user information from OpenID Connect userinfo endpoint
212
+ *
213
+ * @example
214
+ * ```ts
215
+ * const user = await thalamus.tokens.getUserInfo('at_...')
216
+ * console.log(user.email)
217
+ * console.log(user.name)
218
+ * ```
219
+ */
220
+ getUserInfo(accessToken: string): Promise<UserInfo>;
221
+ /**
222
+ * Validate token and return true if active, false otherwise
223
+ *
224
+ * @example
225
+ * ```ts
226
+ * const isValid = await thalamus.tokens.validate('at_...')
227
+ * if (isValid) {
228
+ * // Token is valid
229
+ * }
230
+ * ```
231
+ */
232
+ validate(token: string): Promise<boolean>;
233
+ /**
234
+ * Handle API errors
235
+ */
236
+ private handleError;
237
+ }
238
+
239
+ /**
240
+ * Admin API Module
241
+ *
242
+ * User, organization, role, and domain management endpoints.
243
+ * Requires JWT Bearer token authentication.
244
+ */
245
+
246
+ interface User {
247
+ id: string;
248
+ name: string;
249
+ email: string;
250
+ status: string;
251
+ organization_id?: string;
252
+ is_agent: boolean;
253
+ agent_config?: AgentConfig;
254
+ }
255
+ interface AdminOrganization {
256
+ id: string;
257
+ name: string;
258
+ domains?: string[];
259
+ }
260
+ interface AdminRole {
261
+ id: string;
262
+ organization_id: string;
263
+ name: string;
264
+ description?: string;
265
+ scopes: string[];
266
+ }
267
+ interface DomainRole {
268
+ id: string;
269
+ user_id: string;
270
+ organization_id: string;
271
+ domain: string;
272
+ role: string;
273
+ scopes: string[];
274
+ }
275
+ interface EffectiveScopes {
276
+ user_id: string;
277
+ scopes: string[];
278
+ }
279
+ declare class AdminAPI {
280
+ private config;
281
+ constructor(config: ThalamusConfig);
282
+ private get baseUrl();
283
+ /** List all users */
284
+ listUsers(): Promise<User[]>;
285
+ /** List all agents (users with is_agent === true) */
286
+ listAgents(): Promise<User[]>;
287
+ /** Get a single user */
288
+ getUser(id: string): Promise<User>;
289
+ /** Add a member to an organization */
290
+ addOrgMember(orgId: string, userId: string): Promise<{
291
+ message: string;
292
+ }>;
293
+ /** Update a user (only name and agent_config are writable) */
294
+ updateUser(id: string, data: Partial<Pick<User, 'name' | 'agent_config'>>): Promise<User>;
295
+ /** Create a user */
296
+ createUser(data: {
297
+ email: string;
298
+ password: string;
299
+ name?: string;
300
+ is_agent?: boolean;
301
+ agent_config?: AgentConfig;
302
+ }): Promise<User>;
303
+ /** Get an organization */
304
+ getOrganization(id: string): Promise<AdminOrganization>;
305
+ /** List all organizations */
306
+ listOrganizations(): Promise<AdminOrganization[]>;
307
+ /** List domain roles (optionally filtered) */
308
+ listDomainRoles(filters?: {
309
+ user_id?: string;
310
+ organization_id?: string;
311
+ domain?: string;
312
+ }): Promise<DomainRole[]>;
313
+ /** Grant a domain role to a user */
314
+ grantDomainRole(params: {
315
+ user_id: string;
316
+ organization_id: string;
317
+ domain: string;
318
+ role: string;
319
+ scopes?: string[];
320
+ entity_id?: string;
321
+ }): Promise<{
322
+ message: string;
323
+ }>;
324
+ /** Revoke a domain role from a user */
325
+ revokeDomainRole(params: {
326
+ user_id: string;
327
+ organization_id: string;
328
+ domain: string;
329
+ role: string;
330
+ }): Promise<{
331
+ message: string;
332
+ }>;
333
+ /** List all roles */
334
+ listRoles(): Promise<AdminRole[]>;
335
+ /** Create a role */
336
+ createRole(params: {
337
+ organization_id: string;
338
+ name: string;
339
+ description?: string;
340
+ scopes: string[];
341
+ }): Promise<AdminRole>;
342
+ /** Delete a role */
343
+ deleteRole(id: string): Promise<void>;
344
+ /** Get user's effective scopes */
345
+ getEffectiveScopes(userId: string): Promise<EffectiveScopes>;
346
+ private getAccessToken;
347
+ private request;
348
+ private toError;
349
+ }
350
+
351
+ /**
352
+ * ZEA Thalamus OAuth2 Client
353
+ *
354
+ * Official JavaScript/TypeScript SDK for Thalamus OAuth2 Server
355
+ *
356
+ * @example
357
+ * ```ts
358
+ * import ThalamusClient from '@zea/thalamus-js'
359
+ *
360
+ * const thalamus = new ThalamusClient({
361
+ * clientId: process.env.THALAMUS_CLIENT_ID,
362
+ * clientSecret: process.env.THALAMUS_CLIENT_SECRET,
363
+ * redirectUri: 'https://yourapp.com/auth/callback',
364
+ * baseUrl: 'https://auth.example.com'
365
+ * })
366
+ *
367
+ * // Get authorization URL
368
+ * const authUrl = thalamus.auth.getAuthorizationUrl()
369
+ *
370
+ * // Exchange code for tokens
371
+ * const tokens = await thalamus.auth.exchangeCode(code)
372
+ *
373
+ * // Introspect token
374
+ * const tokenInfo = await thalamus.tokens.introspect(accessToken)
375
+ * ```
376
+ */
377
+
378
+ declare class ThalamusClient {
379
+ /** OAuth2 authentication methods */
380
+ readonly auth: OAuth2;
381
+ /** Token management and introspection */
382
+ readonly tokens: TokenManager;
383
+ /** Admin API — users, orgs, roles, domain management */
384
+ readonly admin: AdminAPI;
385
+ private readonly config;
386
+ /**
387
+ * Create a new Thalamus client
388
+ *
389
+ * @param config - Client configuration
390
+ */
391
+ constructor(config: ThalamusConfig);
392
+ /**
393
+ * Get the current configuration
394
+ */
395
+ getConfig(): Readonly<ThalamusConfig>;
396
+ }
397
+
398
+ interface UseThalamusOptions extends ThalamusConfig$1 {
399
+ /** Storage key for persisting auth (default: 'thalamus_auth') */
400
+ storageKey?: string;
401
+ }
402
+ interface UseThalamusReturn {
403
+ /** Start OAuth2 PKCE login flow (redirects browser) */
404
+ login: (options?: {
405
+ scope?: string[];
406
+ }) => Promise<void>;
407
+ /** Clear stored token and reset state */
408
+ logout: () => void;
409
+ /** Raw access token */
410
+ token: string | null;
411
+ /** Decoded user info */
412
+ user: UserInfo$1 | null;
413
+ /** Whether authenticated */
414
+ isAuthenticated: boolean;
415
+ /** Whether loading auth state */
416
+ isLoading: boolean;
417
+ /** Refresh the access token */
418
+ refreshToken: () => Promise<void>;
419
+ /** ThalamusClient instance for direct API calls */
420
+ client: ThalamusClient;
421
+ /** Error message if any */
422
+ error: string | null;
423
+ }
424
+ declare function useThalamus(options: UseThalamusOptions): UseThalamusReturn;
425
+
426
+ interface UseAdminOptions {
427
+ baseUrl: string;
428
+ /** If true, auto-fetches on mount */
429
+ autoFetch?: boolean;
430
+ }
431
+ interface UseAdminReturn {
432
+ users: User$1[];
433
+ agents: User$1[];
434
+ organizations: Organization[];
435
+ roles: Role[];
436
+ loading: boolean;
437
+ error: string | null;
438
+ refresh: () => Promise<void>;
439
+ createUser: (data: {
440
+ email: string;
441
+ password: string;
442
+ name?: string;
443
+ is_agent?: boolean;
444
+ }) => Promise<User$1 | null>;
445
+ listDomainRoles: (filters?: {
446
+ user_id?: string;
447
+ organization_id?: string;
448
+ domain?: string;
449
+ }) => Promise<DomainRole$1[]>;
450
+ }
451
+ declare function useAdmin(options: UseAdminOptions): UseAdminReturn;
452
+
453
+ export { AdminAPI as A, type DomainRole as D, type IntrospectionResponse as I, OAuth2 as O, ThalamusClient as T, type UseAdminOptions as U, type AgentConfig as a, type AdminOrganization as b, type AdminRole as c, type ThalamusConfig as d, type ThalamusError as e, TokenManager as f, type TokenResponse as g, type UseAdminReturn as h, type UseThalamusOptions as i, type UseThalamusReturn as j, type User as k, type UserInfo as l, useThalamus as m, useAdmin as u };