@vunexa/lixa 0.1.4 → 0.1.6-alpha.10

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/dist/index.d.cts CHANGED
@@ -78,6 +78,8 @@ interface ConnectedResource {
78
78
  accessToken: string;
79
79
  /** Optional refresh token for offline resource access */
80
80
  refreshToken?: string | undefined;
81
+ /** Unix timestamp in milliseconds when the resource access token expires */
82
+ expiresAt?: number | undefined;
81
83
  /** Resource scopes granted by the user */
82
84
  scopes: string[];
83
85
  /** Full raw token response from provider */
@@ -103,25 +105,29 @@ interface Session<TRaw = OAuthTokenResponse> {
103
105
  */
104
106
  id?: string;
105
107
  /**
106
- * The primary access token or session token identifier.
108
+ * Linked identity provider accounts (AuthN) keyed by provider name.
109
+ * Single source of truth for all authenticated user SSO identities.
107
110
  */
108
- token: string;
111
+ accounts?: Record<string, LinkedAccount>;
112
+ /**
113
+ * Connected third-party resource provider tokens (AuthZ) keyed by provider name.
114
+ * Single source of truth for all post-login third-party API permissions.
115
+ */
116
+ resources?: Record<string, ConnectedResource>;
109
117
  /** Unique unified user ID across linked accounts */
110
118
  userId?: string;
111
119
  /** Primary user email */
112
120
  email?: string;
113
- /** Current active auth provider for this session turn */
121
+ /**
122
+ * Optional primary access token or custom session token identifier.
123
+ */
124
+ token?: string;
125
+ /** Optional current active auth provider for this session turn */
114
126
  provider?: string;
115
- /** Linked SSO provider accounts keyed by provider name */
116
- accounts?: Record<string, LinkedAccount>;
117
- /** Connected third-party resource provider tokens keyed by provider name */
118
- resources?: Record<string, ConnectedResource>;
119
127
  /**
120
- * Raw session data.
121
- * Contains the complete OAuth token response and any additional data
122
- * your SessionStrategy adds (user info, database IDs, etc.).
128
+ * Optional raw session token response data from provider.
123
129
  */
124
- raw: TRaw;
130
+ raw?: TRaw;
125
131
  }
126
132
  /**
127
133
  * Provider metadata passed to session strategy.
@@ -308,10 +314,20 @@ interface StateHandler {
308
314
  * }
309
315
  * ```
310
316
  */
317
+ /**
318
+ * Generates OAuth state parameter and associated data (camelCase).
319
+ */
311
320
  generateState?(provider: string): Promise<{
312
321
  state: string;
313
322
  data: StateData;
314
323
  }>;
324
+ /**
325
+ * Generates OAuth state parameter and associated data (PascalCase alias for backward compatibility).
326
+ */
327
+ GenerateState?(provider: string): Promise<{
328
+ state: string;
329
+ data: StateData;
330
+ }>;
315
331
  /**
316
332
  * State storage operations.
317
333
  *
@@ -337,7 +353,7 @@ interface SessionStorage {
337
353
  * Saves a session with expiration.
338
354
  *
339
355
  * @param sessionId - Unique session identifier
340
- * @param session - Session data from GenerateSession()
356
+ * @param session - Session data from generateSession()
341
357
  * @param expiresInSeconds - TTL in seconds (typically 86400 for 24 hours)
342
358
  */
343
359
  saveSession<T extends Session>(sessionId: string, session: T, expiresInSeconds: number): Promise<void>;
@@ -364,19 +380,66 @@ interface SessionStorage {
364
380
  session: T;
365
381
  } | null>;
366
382
  }
383
+ /**
384
+ * Resource storage operations interface.
385
+ *
386
+ * @remarks
387
+ * Manages long-lived third-party resource provider tokens (AuthZ) bound to a user account
388
+ * (User ID or Email), independent of short-lived user sessions.
389
+ *
390
+ * @public
391
+ */
392
+ interface ResourceStorage {
393
+ /**
394
+ * Saves a connected resource token for a user.
395
+ *
396
+ * @param userId - Unique user identifier or email
397
+ * @param provider - Resource provider name (e.g. 'github', 'google')
398
+ * @param resource - Connected resource details including access & refresh tokens
399
+ */
400
+ saveResource(userId: string, provider: string, resource: ConnectedResource): Promise<void>;
401
+ /**
402
+ * Retrieves a connected resource token for a user.
403
+ *
404
+ * @param userId - Unique user identifier or email
405
+ * @param provider - Resource provider name
406
+ */
407
+ getResource(userId: string, provider: string): Promise<ConnectedResource | null>;
408
+ /**
409
+ * Retrieves all connected resources for a user.
410
+ *
411
+ * @param userId - Unique user identifier or email
412
+ */
413
+ getUserResources(userId: string): Promise<Record<string, ConnectedResource>>;
414
+ /**
415
+ * Deletes a connected resource token for a user.
416
+ *
417
+ * @param userId - Unique user identifier or email
418
+ * @param provider - Resource provider name
419
+ */
420
+ deleteResource(userId: string, provider: string): Promise<void>;
421
+ }
422
+ /**
423
+ * Resource handler configuration.
424
+ *
425
+ * @public
426
+ */
427
+ interface ResourceHandler {
428
+ resourceStorage?: ResourceStorage;
429
+ }
367
430
  /**
368
431
  * Session handler for OAuth authentication.
369
432
  *
370
433
  * @remarks
371
434
  * The SessionHandler manages session generation and storage after successful OAuth authentication.
372
435
  *
373
- * - GenerateSession: Optional. Customizes how OAuth tokens are converted into session data.
436
+ * - generateSession: Optional. Customizes how OAuth tokens are converted into session data.
374
437
  * If not provided, uses default implementation (access token as session token).
375
438
  *
376
- * - storage: Optional. Provides custom session storage (save/get/delete operations).
439
+ * - sessionStorage: Optional. Provides custom session storage (save/get/delete operations).
377
440
  * If not provided, uses in-memory cache (not suitable for production).
378
441
  *
379
- * For production, implement both GenerateSession (for user creation/lookup) and storage
442
+ * For production, implement both generateSession (for user creation/lookup) and sessionStorage
380
443
  * (for persistent session storage with Redis, database, etc.).
381
444
  *
382
445
  * @example
@@ -385,7 +448,7 @@ interface SessionStorage {
385
448
  * import { SessionHandler, Session, OAuthTokenResponse, ProviderMetadata, extractUserInfo } from '@vunexa/lixa';
386
449
  *
387
450
  * const sessionHandler: SessionHandler = {
388
- * GenerateSession: async (tokenData, providerMetadata) => {
451
+ * generateSession: async (tokenData, providerMetadata) => {
389
452
  * // Extract user info and create/retrieve user
390
453
  * const { userInfo } = await extractUserInfo(tokenData, providerMetadata);
391
454
  * const user = await db.users.upsert({
@@ -404,7 +467,7 @@ interface SessionStorage {
404
467
  * };
405
468
  * },
406
469
  *
407
- * storage: {
470
+ * sessionStorage: {
408
471
  * saveSession: async (sessionId, session, expiresInSeconds) => {
409
472
  * const expiresAt = new Date(Date.now() + expiresInSeconds * 1000);
410
473
  * await db.sessions.create({
@@ -430,78 +493,21 @@ interface SessionStorage {
430
493
  * };
431
494
  * ```
432
495
  *
433
- * @example
434
- * Minimal implementation (uses defaults):
435
- * ```typescript
436
- * const sessionHandler: SessionHandler = {
437
- * storage: {
438
- * saveSession: async (sessionId, session, expiresInSeconds) => {
439
- * await redis.setex(sessionId, expiresInSeconds, JSON.stringify(session));
440
- * },
441
- * getSession: async (sessionId) => {
442
- * const data = await redis.get(sessionId);
443
- * return data ? JSON.parse(data) : null;
444
- * },
445
- * deleteSession: async (sessionId) => {
446
- * await redis.del(sessionId);
447
- * }
448
- * }
449
- * };
450
- * ```
451
- *
452
496
  * @public
453
497
  */
454
498
  interface SessionHandler {
455
499
  /**
456
- * Generates session data from OAuth token data.
500
+ * Generates session data from OAuth token data (camelCase).
457
501
  *
458
502
  * @param tokenData - The token data received from the OAuth provider's token endpoint
459
503
  * @param providerMetadata - Provider metadata including name and endpoints
460
504
  * @returns A Promise that resolves to session data
461
- *
462
- * @remarks
463
- * This method is responsible for creating session data from OAuth tokens.
464
- * It is called after successfully exchanging the authorization code for tokens.
465
- *
466
- * Token Data:
467
- * - access_token: OAuth access token
468
- * - refresh_token: OAuth refresh token (optional)
469
- * - expires_in: Token expiration time in seconds
470
- * - token_type: Token type (usually "Bearer")
471
- * - id_token: OpenID Connect ID token (for OIDC providers)
472
- * - scope: Granted scopes
473
- *
474
- * Provider Metadata:
475
- * - name: The provider name (e.g., 'google', 'github')
476
- * - endpoints: Provider endpoints (authorization, token, userInfo)
477
- *
478
- * Your implementation should:
479
- * 1. Extract user info (using extractUserInfo or decode ID token)
480
- * 2. Create or lookup users in your database
481
- * 3. Build and return session data with any custom fields
482
- *
483
- * Note: This method should NOT store the session. Storage is handled by the storage object.
484
- *
485
- * If not provided, defaults to using the access token as the session token.
486
- *
487
- * @example
488
- * ```typescript
489
- * GenerateSession: async (tokenData, providerMetadata) => {
490
- * const { userInfo } = await extractUserInfo(tokenData, providerMetadata);
491
- * const user = await db.users.upsert({ email: userInfo.email });
492
- *
493
- * return {
494
- * token: tokenData.access_token,
495
- * raw: {
496
- * ...tokenData,
497
- * userId: user.id,
498
- * provider: providerMetadata.name
499
- * }
500
- * };
501
- * }
502
- * ```
503
505
  */
504
506
  generateSession?<T extends Session>(tokenData: OAuthTokenResponse, providerMetadata: ProviderMetadata): Promise<T>;
507
+ /**
508
+ * Generates session data from OAuth token data (PascalCase alias for backward compatibility).
509
+ */
510
+ GenerateSession?<T extends Session>(tokenData: OAuthTokenResponse, providerMetadata: ProviderMetadata): Promise<T>;
505
511
  /**
506
512
  * Session storage operations.
507
513
  *
@@ -512,13 +518,6 @@ interface SessionHandler {
512
518
  * If not provided, uses in-memory cache (not suitable for production).
513
519
  */
514
520
  sessionStorage?: SessionStorage;
515
- /**
516
- * Optional method to generate session data from OAuth tokens.
517
- *
518
- * @remarks
519
- * If not provided, uses default implementation from LocalSessionHandler.
520
- */
521
- generateSession?<T extends Session>(tokenData: OAuthTokenResponse, providerMetadata: ProviderMetadata): Promise<T>;
522
521
  }
523
522
 
524
523
  /**
@@ -706,6 +705,12 @@ type ProviderConfig = {
706
705
  redirectUri: string;
707
706
  /** Array of OAuth scopes to request */
708
707
  scopes: string[];
708
+ /**
709
+ * Set to true to allow non-identity (resource) scopes during primary authentication flow.
710
+ * By default (false), Lixa restricts primary AuthN scopes to identity scopes to maintain
711
+ * clean AuthN vs AuthZ separation.
712
+ */
713
+ allowNonAuthScopes?: boolean;
709
714
  /** Additional provider-specific configuration parameters */
710
715
  extraConfig?: Record<string, string>;
711
716
  } & ({
@@ -857,12 +862,42 @@ interface LixaConfig<TProviders extends Record<string, ProviderConfig> = Record<
857
862
  * @see {@link SessionHandler}
858
863
  */
859
864
  sessionHandler?: SessionHandler;
865
+ /**
866
+ * Optional custom resource handler.
867
+ * Handles storage and management of long-lived third-party resource provider tokens (AuthZ)
868
+ * bound directly to user accounts (User ID or Email), independent of transient session IDs.
869
+ *
870
+ * @see {@link ResourceHandler}
871
+ */
872
+ resourceHandler?: ResourceHandler;
860
873
  /**
861
874
  * Enable debug logging.
862
875
  * When enabled, outputs structured logs for initialization, auth flow, and errors.
863
876
  * Format: [Lixa] [timestamp] [level] [context] message
864
877
  */
865
878
  debug?: boolean;
879
+ /**
880
+ * Optional custom structured logger implementation.
881
+ * If provided, all Lixa logs will be routed through this logger.
882
+ */
883
+ logger?: LixaLogger;
884
+ }
885
+ /**
886
+ * Log level for Lixa structured logging.
887
+ * @public
888
+ */
889
+ type LogLevel = "INFO" | "WARN" | "ERROR" | "DEBUG";
890
+ /**
891
+ * Log context for Lixa structured logging.
892
+ * @public
893
+ */
894
+ type LogContext = "Init" | "Auth" | "Token" | "Session" | "State" | "AccountLinking" | "Resource";
895
+ /**
896
+ * Custom logger interface for Lixa.
897
+ * @public
898
+ */
899
+ interface LixaLogger {
900
+ log(level: LogLevel, context: LogContext, message: string, data?: Record<string, unknown>): void;
866
901
  }
867
902
  /**
868
903
  * Helper type to create a configuration with only registered providers.
@@ -936,11 +971,15 @@ type ConfiguredProviderKey<T extends LixaConfig<Record<string, ProviderConfig>>>
936
971
  declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConfig>> = LixaConfig> {
937
972
  private static DEFAULT_PROVIDERS;
938
973
  private static CONFIGURED_PROVIDERS;
939
- private static LOCAL_STATE_HANDLER;
940
- private static LOCAL_SESSION_HANDLER;
974
+ private localStateHandler;
975
+ private localSessionHandler;
976
+ private localResourceHandler;
977
+ private userResourceStore;
978
+ private refreshMutexes;
941
979
  private config;
942
980
  private stateHandler;
943
981
  private sessionHandler;
982
+ private resourceHandler;
944
983
  private debug;
945
984
  /**
946
985
  * Creates a new Lixa instance with the provided configuration.
@@ -961,7 +1000,7 @@ declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConfig>> =
961
1000
  *
962
1001
  * @param name - The provider name
963
1002
  * @param config - The provider configuration
964
- * @throws Error when required fields are missing or invalid
1003
+ * @throws InvalidProviderConfigError when required fields are missing or invalid
965
1004
  */
966
1005
  private validateProviderConfig;
967
1006
  /**
@@ -969,20 +1008,16 @@ declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConfig>> =
969
1008
  *
970
1009
  * @param name - The provider name
971
1010
  * @param provider - The provider implementation
972
- * @throws Error when required properties are missing
1011
+ * @throws InvalidProviderConfigError when required properties are missing
973
1012
  */
974
1013
  private validateProviderImplementation;
975
1014
  /**
976
- * Structured debug logging with standardized format.
1015
+ * Structured logging with standardized format and custom logger support.
977
1016
  *
978
- * @param level - Log level (INFO, WARN, ERROR)
979
- * @param context - Context of the log (Init, Auth, Token, Session, State)
1017
+ * @param level - Log level (INFO, WARN, ERROR, DEBUG)
1018
+ * @param context - Context of the log (Init, Auth, Token, Session, State, AccountLinking, Resource)
980
1019
  * @param message - Log message
981
1020
  * @param data - Optional data to log
982
- *
983
- * @remarks
984
- * Format: [Lixa] [timestamp] [level] [context] message
985
- * Only logs when debug mode is enabled.
986
1021
  */
987
1022
  private log;
988
1023
  /**
@@ -1181,7 +1216,7 @@ declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConfig>> =
1181
1216
  */
1182
1217
  getAuthUrl(provider: ConfiguredProviderKey<TConfig> | string, state?: string): Promise<string>;
1183
1218
  /**
1184
- * Restricts primary authentication scopes strictly to AuthN identity scopes.
1219
+ * Restricts primary authentication scopes strictly to AuthN identity scopes unless allowNonAuthScopes is true.
1185
1220
  */
1186
1221
  private resolveAuthNScopes;
1187
1222
  /**
@@ -1247,11 +1282,9 @@ declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConfig>> =
1247
1282
  prompt?: string;
1248
1283
  extraConfig?: Record<string, string>;
1249
1284
  }): Promise<string>;
1285
+ private getUserKeyFromSession;
1250
1286
  /**
1251
- * Handles the OAuth callback for a connected resource provider and stores resource tokens on the session.
1252
- *
1253
- * @param params - Object containing sessionId, provider, code, state, and requested scopes
1254
- * @returns Updated Session containing stored resource tokens under session.resources[provider]
1287
+ * Handles the OAuth callback for a connected resource provider and stores resource tokens bound to user account.
1255
1288
  */
1256
1289
  handleResourceCallback(params: {
1257
1290
  sessionId: string;
@@ -1261,20 +1294,58 @@ declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConfig>> =
1261
1294
  scopes?: string[];
1262
1295
  }): Promise<Session>;
1263
1296
  /**
1264
- * Retrieves a connected resource provider token for an active session.
1297
+ * Retrieves a connected resource for a specific User ID / Email directly (independent of session IDs).
1298
+ * Automatically refreshes expired access tokens if a refresh token is present.
1299
+ *
1300
+ * @param userIdOrEmail - User identifier or email
1301
+ * @param provider - Resource provider identifier (e.g. 'github', 'google')
1302
+ */
1303
+ getUserResource(userIdOrEmail: string, provider: string): Promise<ConnectedResource | null>;
1304
+ /**
1305
+ * Retrieves all connected resources for a specific User ID / Email.
1306
+ */
1307
+ getUserResources(userIdOrEmail: string): Promise<Record<string, ConnectedResource>>;
1308
+ /**
1309
+ * Retrieves a connected resource provider token for an active session, auto-refreshing expired tokens if possible.
1265
1310
  *
1266
1311
  * @param sessionId - Active session ID
1267
- * @param provider - Provider identifier (e.g. 'github')
1312
+ * @param provider - Provider identifier (e.g. 'github', 'google')
1268
1313
  */
1269
1314
  getConnectedResource(sessionId: string, provider: string): Promise<ConnectedResource | null>;
1270
1315
  /**
1271
- * Disconnects a resource provider from an active session.
1316
+ * Refreshes a user's resource access token using its refresh token.
1317
+ * Deduplicates concurrent refresh requests via an in-flight promise mutex.
1272
1318
  *
1273
- * @param sessionId - Active session ID
1274
- * @param provider - Provider identifier to disconnect
1319
+ * @param userIdOrEmail - User identifier or email
1320
+ * @param provider - Provider identifier (e.g. 'google', 'github')
1321
+ */
1322
+ refreshUserResourceToken(userIdOrEmail: string, provider: string, existingResource?: ConnectedResource): Promise<ConnectedResource>;
1323
+ /**
1324
+ * Internal execution of refresh token exchange.
1325
+ */
1326
+ private executeRefreshUserResourceToken;
1327
+ /**
1328
+ * Refreshes a connected resource access token for an active session.
1329
+ */
1330
+ refreshResourceToken(sessionId: string, provider: string): Promise<ConnectedResource>;
1331
+ /**
1332
+ * Disconnects a resource provider for a specific User ID / Email.
1333
+ */
1334
+ disconnectUserResource(userIdOrEmail: string, provider: string): Promise<boolean>;
1335
+ /**
1336
+ * Disconnects a resource provider from an active session and user account.
1275
1337
  */
1276
1338
  disconnectResource(sessionId: string, provider: string): Promise<boolean>;
1339
+ /**
1340
+ * Retrieves active session details from session storage.
1341
+ */
1277
1342
  fetchSessionInfo(sessionId: string): Promise<Session | null>;
1343
+ /**
1344
+ * Deletes a session from session storage (e.g. on logout).
1345
+ *
1346
+ * @param sessionId - Active session identifier
1347
+ */
1348
+ deleteSession(sessionId: string): Promise<void>;
1278
1349
  private exchangeCodeForToken;
1279
1350
  private findProviderByType;
1280
1351
  }
@@ -1360,4 +1431,236 @@ declare function extractUserInfo(tokenData: OAuthTokenResponse, providerMetadata
1360
1431
  userInfo: UserInfo;
1361
1432
  }>;
1362
1433
 
1363
- export { type AccountLinkingConfig, type AccountLinkingMode, AccountLinkingStrategy, type ConnectedResource, type IProvider, Lixa, type LixaConfig, type OAuthTokenResponse, type ProviderConfig, type ProviderMetadata, type SafeLixaConfig, type Session, type SessionHandler, type SessionStorage, type StateData, type StateHandler, type StateStorage, type UserInfo, decodeIdToken, determineProviderFromIssuer, extractUserInfo, fetchUserInfo };
1434
+ /**
1435
+ * Base error class for all Lixa authentication and authorization errors.
1436
+ *
1437
+ * @public
1438
+ */
1439
+ declare class LixaError extends Error {
1440
+ /**
1441
+ * Standard error code string.
1442
+ */
1443
+ readonly code: string;
1444
+ /**
1445
+ * Additional error context data.
1446
+ */
1447
+ readonly details: Record<string, unknown> | undefined;
1448
+ constructor(message: string, code?: string, details?: Record<string, unknown>);
1449
+ }
1450
+ /**
1451
+ * Thrown when an OAuth state parameter is invalid, missing, or has expired.
1452
+ *
1453
+ * @public
1454
+ */
1455
+ declare class InvalidStateError extends LixaError {
1456
+ constructor(message?: string, details?: Record<string, unknown>);
1457
+ }
1458
+ /**
1459
+ * Thrown when attempting to use a provider that is not configured in the Lixa instance.
1460
+ *
1461
+ * @public
1462
+ */
1463
+ declare class ProviderNotConfiguredError extends LixaError {
1464
+ constructor(provider: string, details?: Record<string, unknown>);
1465
+ }
1466
+ /**
1467
+ * Thrown when a provider configuration is invalid or missing required credentials.
1468
+ *
1469
+ * @public
1470
+ */
1471
+ declare class InvalidProviderConfigError extends LixaError {
1472
+ constructor(message: string, details?: Record<string, unknown>);
1473
+ }
1474
+ /**
1475
+ * Thrown when OAuth callback parameters (e.g. authorization code or state) are missing or malformed.
1476
+ *
1477
+ * @public
1478
+ */
1479
+ declare class InvalidOAuthCallbackError extends LixaError {
1480
+ constructor(message: string, details?: Record<string, unknown>);
1481
+ }
1482
+ /**
1483
+ * Thrown when exchanging an authorization code for OAuth tokens fails at the provider endpoint.
1484
+ *
1485
+ * @public
1486
+ */
1487
+ declare class TokenExchangeError extends LixaError {
1488
+ readonly status: number | undefined;
1489
+ constructor(message: string, status?: number, details?: Record<string, unknown>);
1490
+ }
1491
+ /**
1492
+ * Thrown when a user session is not found or has expired.
1493
+ *
1494
+ * @public
1495
+ */
1496
+ declare class SessionNotFoundError extends LixaError {
1497
+ constructor(message?: string, details?: Record<string, unknown>);
1498
+ }
1499
+ /**
1500
+ * Thrown when account linking fails, e.g. when unverified email linking is rejected.
1501
+ *
1502
+ * @public
1503
+ */
1504
+ declare class EmailNotVerifiedError extends LixaError {
1505
+ constructor(email?: string, details?: Record<string, unknown>);
1506
+ }
1507
+ /**
1508
+ * Thrown when unlinking an account violates security constraints (e.g. unlinking the only login provider).
1509
+ *
1510
+ * @public
1511
+ */
1512
+ declare class AccountUnlinkError extends LixaError {
1513
+ constructor(message: string, details?: Record<string, unknown>);
1514
+ }
1515
+ /**
1516
+ * Thrown when a refresh token is missing or token refresh fails for a connected resource.
1517
+ *
1518
+ * @public
1519
+ */
1520
+ declare class RefreshTokenError extends LixaError {
1521
+ constructor(message: string, details?: Record<string, unknown>);
1522
+ }
1523
+
1524
+ /**
1525
+ * Sensible default cookie configuration options.
1526
+ * Follows RFC 6265bis and OAuth 2.0 security best practices.
1527
+ *
1528
+ * @public
1529
+ */
1530
+ interface CookieOptions {
1531
+ /**
1532
+ * Cookie name.
1533
+ * @default 'lixa_session'
1534
+ */
1535
+ name?: string | undefined;
1536
+ /**
1537
+ * Cookie path.
1538
+ * @default '/'
1539
+ */
1540
+ path?: string | undefined;
1541
+ /**
1542
+ * Maximum age of the cookie in seconds.
1543
+ */
1544
+ maxAge?: number | undefined;
1545
+ /**
1546
+ * Prevents client-side scripts from accessing the cookie (XSS protection).
1547
+ * @default true
1548
+ */
1549
+ httpOnly?: boolean | undefined;
1550
+ /**
1551
+ * Ensures the cookie is only transmitted over secure HTTPS connections.
1552
+ * @default false in development, true in production
1553
+ */
1554
+ secure?: boolean | undefined;
1555
+ /**
1556
+ * Controls whether the cookie is sent with cross-site requests (CSRF protection).
1557
+ * @default 'lax'
1558
+ */
1559
+ sameSite?: "lax" | "strict" | "none" | undefined;
1560
+ /**
1561
+ * Cookie domain.
1562
+ */
1563
+ domain?: string | undefined;
1564
+ }
1565
+ /**
1566
+ * Cookie payload containing name, value, options, and formatted header.
1567
+ *
1568
+ * @public
1569
+ */
1570
+ interface CookiePayload {
1571
+ name: string;
1572
+ value: string;
1573
+ options: CookieOptions;
1574
+ /**
1575
+ * Formatted `Set-Cookie` header value string.
1576
+ */
1577
+ header: string;
1578
+ }
1579
+ /**
1580
+ * Default session cookie name.
1581
+ * @public
1582
+ */
1583
+ declare const DEFAULT_SESSION_COOKIE_NAME = "lixa_session";
1584
+ /**
1585
+ * Default OAuth state cookie name.
1586
+ * @public
1587
+ */
1588
+ declare const DEFAULT_STATE_COOKIE_NAME = "lixa_oauth_state";
1589
+ /**
1590
+ * Default session max age in seconds (24 hours).
1591
+ * @public
1592
+ */
1593
+ declare const DEFAULT_SESSION_MAX_AGE_SECONDS: number;
1594
+ /**
1595
+ * Default OAuth state max age in seconds (5 minutes / 300 seconds).
1596
+ * @public
1597
+ */
1598
+ declare const DEFAULT_STATE_MAX_AGE_SECONDS: number;
1599
+ /**
1600
+ * Checks if the runtime environment is production.
1601
+ * @public
1602
+ */
1603
+ declare function isProductionEnvironment(): boolean;
1604
+ /**
1605
+ * Serializes a cookie name, value, and options into a standard `Set-Cookie` header string.
1606
+ *
1607
+ * @param name - Cookie name
1608
+ * @param value - Cookie value
1609
+ * @param options - Cookie attributes
1610
+ * @returns Formatted `Set-Cookie` string
1611
+ *
1612
+ * @public
1613
+ */
1614
+ declare function serializeCookie(name: string, value: string, options?: CookieOptions): string;
1615
+ /**
1616
+ * Generates a session cookie payload with secure default options.
1617
+ *
1618
+ * @param sessionId - The session identifier string
1619
+ * @param options - Optional overrides for cookie attributes
1620
+ *
1621
+ * @example
1622
+ * ```typescript
1623
+ * const cookie = createSessionCookie(sessionId);
1624
+ * res.setHeader("Set-Cookie", cookie.header);
1625
+ * // or with Express:
1626
+ * res.cookie(cookie.name, cookie.value, cookie.options);
1627
+ * ```
1628
+ *
1629
+ * @public
1630
+ */
1631
+ declare function createSessionCookie(sessionId: string, options?: CookieOptions): CookiePayload;
1632
+ /**
1633
+ * Generates an expired session cookie payload to clear the session on logout.
1634
+ *
1635
+ * @param options - Optional overrides for cookie name or attributes
1636
+ *
1637
+ * @example
1638
+ * ```typescript
1639
+ * const cookie = clearSessionCookie();
1640
+ * res.setHeader("Set-Cookie", cookie.header);
1641
+ * // or with Express:
1642
+ * res.clearCookie(cookie.name, cookie.options);
1643
+ * ```
1644
+ *
1645
+ * @public
1646
+ */
1647
+ declare function clearSessionCookie(options?: CookieOptions): CookiePayload;
1648
+ /**
1649
+ * Generates an OAuth CSRF state cookie payload for in-flight authorization flows.
1650
+ *
1651
+ * @param state - The random state string
1652
+ * @param options - Optional overrides for cookie attributes
1653
+ *
1654
+ * @public
1655
+ */
1656
+ declare function createStateCookie(state: string, options?: CookieOptions): CookiePayload;
1657
+ /**
1658
+ * Generates an expired OAuth state cookie payload to clean up the state cookie after callback.
1659
+ *
1660
+ * @param options - Optional overrides for cookie attributes
1661
+ *
1662
+ * @public
1663
+ */
1664
+ declare function clearStateCookie(options?: CookieOptions): CookiePayload;
1665
+
1666
+ export { type AccountLinkingConfig, type AccountLinkingMode, AccountLinkingStrategy, AccountUnlinkError, type ConnectedResource, type CookieOptions, type CookiePayload, DEFAULT_SESSION_COOKIE_NAME, DEFAULT_SESSION_MAX_AGE_SECONDS, DEFAULT_STATE_COOKIE_NAME, DEFAULT_STATE_MAX_AGE_SECONDS, EmailNotVerifiedError, type IProvider, InvalidOAuthCallbackError, InvalidProviderConfigError, InvalidStateError, Lixa, type LixaConfig, LixaError, type LixaLogger, type LogContext, type LogLevel, type OAuthTokenResponse, type ProviderConfig, type ProviderMetadata, ProviderNotConfiguredError, RefreshTokenError, type ResourceHandler, type ResourceStorage, type SafeLixaConfig, type Session, type SessionHandler, SessionNotFoundError, type SessionStorage, type StateData, type StateHandler, type StateStorage, TokenExchangeError, type UserInfo, clearSessionCookie, clearStateCookie, createSessionCookie, createStateCookie, decodeIdToken, determineProviderFromIssuer, extractUserInfo, fetchUserInfo, isProductionEnvironment, serializeCookie };