@vunexa/lixa 0.1.6-alpha.6 → 0.1.6-alpha.8

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
@@ -1023,7 +1023,7 @@ declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConfig>> =
1023
1023
  *
1024
1024
  * @param name - The provider name
1025
1025
  * @param config - The provider configuration
1026
- * @throws Error when required fields are missing or invalid
1026
+ * @throws InvalidProviderConfigError when required fields are missing or invalid
1027
1027
  */
1028
1028
  private validateProviderConfig;
1029
1029
  /**
@@ -1031,7 +1031,7 @@ declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConfig>> =
1031
1031
  *
1032
1032
  * @param name - The provider name
1033
1033
  * @param provider - The provider implementation
1034
- * @throws Error when required properties are missing
1034
+ * @throws InvalidProviderConfigError when required properties are missing
1035
1035
  */
1036
1036
  private validateProviderImplementation;
1037
1037
  /**
@@ -1366,7 +1366,16 @@ declare class Lixa<TConfig extends LixaConfig<Record<string, ProviderConfig>> =
1366
1366
  * Disconnects a resource provider from an active session and user account.
1367
1367
  */
1368
1368
  disconnectResource(sessionId: string, provider: string): Promise<boolean>;
1369
+ /**
1370
+ * Retrieves active session details from session storage.
1371
+ */
1369
1372
  fetchSessionInfo(sessionId: string): Promise<Session | null>;
1373
+ /**
1374
+ * Deletes a session from session storage (e.g. on logout).
1375
+ *
1376
+ * @param sessionId - Active session identifier
1377
+ */
1378
+ deleteSession(sessionId: string): Promise<void>;
1370
1379
  private exchangeCodeForToken;
1371
1380
  private findProviderByType;
1372
1381
  }
@@ -1452,4 +1461,236 @@ declare function extractUserInfo(tokenData: OAuthTokenResponse, providerMetadata
1452
1461
  userInfo: UserInfo;
1453
1462
  }>;
1454
1463
 
1455
- export { type AccountLinkingConfig, type AccountLinkingMode, AccountLinkingStrategy, type ConnectedResource, type IProvider, Lixa, type LixaConfig, type OAuthTokenResponse, type ProviderConfig, type ProviderMetadata, type ResourceHandler, type ResourceStorage, type SafeLixaConfig, type Session, type SessionHandler, type SessionStorage, type StateData, type StateHandler, type StateStorage, type UserInfo, decodeIdToken, determineProviderFromIssuer, extractUserInfo, fetchUserInfo };
1464
+ /**
1465
+ * Base error class for all Lixa authentication and authorization errors.
1466
+ *
1467
+ * @public
1468
+ */
1469
+ declare class LixaError extends Error {
1470
+ /**
1471
+ * Standard error code string.
1472
+ */
1473
+ readonly code: string;
1474
+ /**
1475
+ * Additional error context data.
1476
+ */
1477
+ readonly details: Record<string, unknown> | undefined;
1478
+ constructor(message: string, code?: string, details?: Record<string, unknown>);
1479
+ }
1480
+ /**
1481
+ * Thrown when an OAuth state parameter is invalid, missing, or has expired.
1482
+ *
1483
+ * @public
1484
+ */
1485
+ declare class InvalidStateError extends LixaError {
1486
+ constructor(message?: string, details?: Record<string, unknown>);
1487
+ }
1488
+ /**
1489
+ * Thrown when attempting to use a provider that is not configured in the Lixa instance.
1490
+ *
1491
+ * @public
1492
+ */
1493
+ declare class ProviderNotConfiguredError extends LixaError {
1494
+ constructor(provider: string, details?: Record<string, unknown>);
1495
+ }
1496
+ /**
1497
+ * Thrown when a provider configuration is invalid or missing required credentials.
1498
+ *
1499
+ * @public
1500
+ */
1501
+ declare class InvalidProviderConfigError extends LixaError {
1502
+ constructor(message: string, details?: Record<string, unknown>);
1503
+ }
1504
+ /**
1505
+ * Thrown when OAuth callback parameters (e.g. authorization code or state) are missing or malformed.
1506
+ *
1507
+ * @public
1508
+ */
1509
+ declare class InvalidOAuthCallbackError extends LixaError {
1510
+ constructor(message: string, details?: Record<string, unknown>);
1511
+ }
1512
+ /**
1513
+ * Thrown when exchanging an authorization code for OAuth tokens fails at the provider endpoint.
1514
+ *
1515
+ * @public
1516
+ */
1517
+ declare class TokenExchangeError extends LixaError {
1518
+ readonly status: number | undefined;
1519
+ constructor(message: string, status?: number, details?: Record<string, unknown>);
1520
+ }
1521
+ /**
1522
+ * Thrown when a user session is not found or has expired.
1523
+ *
1524
+ * @public
1525
+ */
1526
+ declare class SessionNotFoundError extends LixaError {
1527
+ constructor(message?: string, details?: Record<string, unknown>);
1528
+ }
1529
+ /**
1530
+ * Thrown when account linking fails, e.g. when unverified email linking is rejected.
1531
+ *
1532
+ * @public
1533
+ */
1534
+ declare class EmailNotVerifiedError extends LixaError {
1535
+ constructor(email?: string, details?: Record<string, unknown>);
1536
+ }
1537
+ /**
1538
+ * Thrown when unlinking an account violates security constraints (e.g. unlinking the only login provider).
1539
+ *
1540
+ * @public
1541
+ */
1542
+ declare class AccountUnlinkError extends LixaError {
1543
+ constructor(message: string, details?: Record<string, unknown>);
1544
+ }
1545
+ /**
1546
+ * Thrown when a refresh token is missing or token refresh fails for a connected resource.
1547
+ *
1548
+ * @public
1549
+ */
1550
+ declare class RefreshTokenError extends LixaError {
1551
+ constructor(message: string, details?: Record<string, unknown>);
1552
+ }
1553
+
1554
+ /**
1555
+ * Sensible default cookie configuration options.
1556
+ * Follows RFC 6265bis and OAuth 2.0 security best practices.
1557
+ *
1558
+ * @public
1559
+ */
1560
+ interface CookieOptions {
1561
+ /**
1562
+ * Cookie name.
1563
+ * @default 'lixa_session'
1564
+ */
1565
+ name?: string | undefined;
1566
+ /**
1567
+ * Cookie path.
1568
+ * @default '/'
1569
+ */
1570
+ path?: string | undefined;
1571
+ /**
1572
+ * Maximum age of the cookie in seconds.
1573
+ */
1574
+ maxAge?: number | undefined;
1575
+ /**
1576
+ * Prevents client-side scripts from accessing the cookie (XSS protection).
1577
+ * @default true
1578
+ */
1579
+ httpOnly?: boolean | undefined;
1580
+ /**
1581
+ * Ensures the cookie is only transmitted over secure HTTPS connections.
1582
+ * @default false in development, true in production
1583
+ */
1584
+ secure?: boolean | undefined;
1585
+ /**
1586
+ * Controls whether the cookie is sent with cross-site requests (CSRF protection).
1587
+ * @default 'lax'
1588
+ */
1589
+ sameSite?: "lax" | "strict" | "none" | undefined;
1590
+ /**
1591
+ * Cookie domain.
1592
+ */
1593
+ domain?: string | undefined;
1594
+ }
1595
+ /**
1596
+ * Cookie payload containing name, value, options, and formatted header.
1597
+ *
1598
+ * @public
1599
+ */
1600
+ interface CookiePayload {
1601
+ name: string;
1602
+ value: string;
1603
+ options: CookieOptions;
1604
+ /**
1605
+ * Formatted `Set-Cookie` header value string.
1606
+ */
1607
+ header: string;
1608
+ }
1609
+ /**
1610
+ * Default session cookie name.
1611
+ * @public
1612
+ */
1613
+ declare const DEFAULT_SESSION_COOKIE_NAME = "lixa_session";
1614
+ /**
1615
+ * Default OAuth state cookie name.
1616
+ * @public
1617
+ */
1618
+ declare const DEFAULT_STATE_COOKIE_NAME = "lixa_oauth_state";
1619
+ /**
1620
+ * Default session max age in seconds (24 hours).
1621
+ * @public
1622
+ */
1623
+ declare const DEFAULT_SESSION_MAX_AGE_SECONDS: number;
1624
+ /**
1625
+ * Default OAuth state max age in seconds (10 minutes).
1626
+ * @public
1627
+ */
1628
+ declare const DEFAULT_STATE_MAX_AGE_SECONDS: number;
1629
+ /**
1630
+ * Checks if the runtime environment is production.
1631
+ * @public
1632
+ */
1633
+ declare function isProductionEnvironment(): boolean;
1634
+ /**
1635
+ * Serializes a cookie name, value, and options into a standard `Set-Cookie` header string.
1636
+ *
1637
+ * @param name - Cookie name
1638
+ * @param value - Cookie value
1639
+ * @param options - Cookie attributes
1640
+ * @returns Formatted `Set-Cookie` string
1641
+ *
1642
+ * @public
1643
+ */
1644
+ declare function serializeCookie(name: string, value: string, options?: CookieOptions): string;
1645
+ /**
1646
+ * Generates a session cookie payload with secure default options.
1647
+ *
1648
+ * @param sessionId - The session identifier string
1649
+ * @param options - Optional overrides for cookie attributes
1650
+ *
1651
+ * @example
1652
+ * ```typescript
1653
+ * const cookie = createSessionCookie(sessionId);
1654
+ * res.setHeader("Set-Cookie", cookie.header);
1655
+ * // or with Express:
1656
+ * res.cookie(cookie.name, cookie.value, cookie.options);
1657
+ * ```
1658
+ *
1659
+ * @public
1660
+ */
1661
+ declare function createSessionCookie(sessionId: string, options?: CookieOptions): CookiePayload;
1662
+ /**
1663
+ * Generates an expired session cookie payload to clear the session on logout.
1664
+ *
1665
+ * @param options - Optional overrides for cookie name or attributes
1666
+ *
1667
+ * @example
1668
+ * ```typescript
1669
+ * const cookie = clearSessionCookie();
1670
+ * res.setHeader("Set-Cookie", cookie.header);
1671
+ * // or with Express:
1672
+ * res.clearCookie(cookie.name, cookie.options);
1673
+ * ```
1674
+ *
1675
+ * @public
1676
+ */
1677
+ declare function clearSessionCookie(options?: CookieOptions): CookiePayload;
1678
+ /**
1679
+ * Generates an OAuth CSRF state cookie payload for in-flight authorization flows.
1680
+ *
1681
+ * @param state - The random state string
1682
+ * @param options - Optional overrides for cookie attributes
1683
+ *
1684
+ * @public
1685
+ */
1686
+ declare function createStateCookie(state: string, options?: CookieOptions): CookiePayload;
1687
+ /**
1688
+ * Generates an expired OAuth state cookie payload to clean up the state cookie after callback.
1689
+ *
1690
+ * @param options - Optional overrides for cookie attributes
1691
+ *
1692
+ * @public
1693
+ */
1694
+ declare function clearStateCookie(options?: CookieOptions): CookiePayload;
1695
+
1696
+ 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 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 };
package/dist/index.d.ts CHANGED
@@ -18,4 +18,6 @@
18
18
  export { Lixa } from "./lixa";
19
19
  export { type ProviderConfig, type LixaConfig, type SafeLixaConfig, type IProvider, type Session, type ConnectedResource, type ProviderMetadata, type OAuthTokenResponse, type StateHandler, type StateStorage, type SessionHandler, type SessionStorage, type ResourceHandler, type ResourceStorage, type StateData, AccountLinkingStrategy, type AccountLinkingMode, type AccountLinkingConfig, } from "./types";
20
20
  export { type UserInfo, extractUserInfo, decodeIdToken, fetchUserInfo, determineProviderFromIssuer, } from "./utils/user-info";
21
+ export { LixaError, InvalidStateError, ProviderNotConfiguredError, InvalidProviderConfigError, InvalidOAuthCallbackError, TokenExchangeError, SessionNotFoundError, EmailNotVerifiedError, AccountUnlinkError, RefreshTokenError, } from "./errors";
22
+ export { type CookieOptions, type CookiePayload, DEFAULT_SESSION_COOKIE_NAME, DEFAULT_STATE_COOKIE_NAME, DEFAULT_SESSION_MAX_AGE_SECONDS, DEFAULT_STATE_MAX_AGE_SECONDS, isProductionEnvironment, serializeCookie, createSessionCookie, clearSessionCookie, createStateCookie, clearStateCookie, } from "./utils/cookies";
21
23
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,UAAU,EACf,KAAK,cAAc,EACnB,KAAK,SAAS,EACd,KAAK,OAAO,EACZ,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,SAAS,EACd,sBAAsB,EACtB,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,GA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