@hamak/auth 0.5.1

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.
Files changed (116) hide show
  1. package/README.md +366 -0
  2. package/dist/api/api/auth-service.d.ts +111 -0
  3. package/dist/api/api/auth-service.d.ts.map +1 -0
  4. package/dist/api/api/auth-service.js +5 -0
  5. package/dist/api/api/index.d.ts +2 -0
  6. package/dist/api/api/index.d.ts.map +1 -0
  7. package/dist/api/api/index.js +1 -0
  8. package/dist/api/index.d.ts +10 -0
  9. package/dist/api/index.d.ts.map +1 -0
  10. package/dist/api/index.js +12 -0
  11. package/dist/api/tokens/index.d.ts +2 -0
  12. package/dist/api/tokens/index.d.ts.map +1 -0
  13. package/dist/api/tokens/index.js +1 -0
  14. package/dist/api/tokens/service-tokens.d.ts +26 -0
  15. package/dist/api/tokens/service-tokens.d.ts.map +1 -0
  16. package/dist/api/tokens/service-tokens.js +25 -0
  17. package/dist/api/types/auth-result.d.ts +69 -0
  18. package/dist/api/types/auth-result.d.ts.map +1 -0
  19. package/dist/api/types/auth-result.js +5 -0
  20. package/dist/api/types/config.d.ts +130 -0
  21. package/dist/api/types/config.d.ts.map +1 -0
  22. package/dist/api/types/config.js +5 -0
  23. package/dist/api/types/credentials.d.ts +52 -0
  24. package/dist/api/types/credentials.d.ts.map +1 -0
  25. package/dist/api/types/credentials.js +5 -0
  26. package/dist/api/types/index.d.ts +5 -0
  27. package/dist/api/types/index.d.ts.map +1 -0
  28. package/dist/api/types/index.js +4 -0
  29. package/dist/api/types/user.d.ts +39 -0
  30. package/dist/api/types/user.d.ts.map +1 -0
  31. package/dist/api/types/user.js +5 -0
  32. package/dist/impl/index.d.ts +15 -0
  33. package/dist/impl/index.d.ts.map +1 -0
  34. package/dist/impl/index.js +21 -0
  35. package/dist/impl/plugin/auth-plugin-factory.d.ts +20 -0
  36. package/dist/impl/plugin/auth-plugin-factory.d.ts.map +1 -0
  37. package/dist/impl/plugin/auth-plugin-factory.js +226 -0
  38. package/dist/impl/plugin/index.d.ts +2 -0
  39. package/dist/impl/plugin/index.d.ts.map +1 -0
  40. package/dist/impl/plugin/index.js +1 -0
  41. package/dist/impl/services/AuthService.d.ts +44 -0
  42. package/dist/impl/services/AuthService.d.ts.map +1 -0
  43. package/dist/impl/services/AuthService.js +277 -0
  44. package/dist/impl/services/index.d.ts +2 -0
  45. package/dist/impl/services/index.d.ts.map +1 -0
  46. package/dist/impl/services/index.js +1 -0
  47. package/dist/impl/storage/LocalTokenStorage.d.ts +32 -0
  48. package/dist/impl/storage/LocalTokenStorage.d.ts.map +1 -0
  49. package/dist/impl/storage/LocalTokenStorage.js +148 -0
  50. package/dist/impl/storage/MemoryTokenStorage.d.ts +34 -0
  51. package/dist/impl/storage/MemoryTokenStorage.d.ts.map +1 -0
  52. package/dist/impl/storage/MemoryTokenStorage.js +91 -0
  53. package/dist/impl/storage/SessionTokenStorage.d.ts +33 -0
  54. package/dist/impl/storage/SessionTokenStorage.d.ts.map +1 -0
  55. package/dist/impl/storage/SessionTokenStorage.js +147 -0
  56. package/dist/impl/storage/index.d.ts +10 -0
  57. package/dist/impl/storage/index.d.ts.map +1 -0
  58. package/dist/impl/storage/index.js +26 -0
  59. package/dist/impl/store/auth-reducer.d.ts +135 -0
  60. package/dist/impl/store/auth-reducer.d.ts.map +1 -0
  61. package/dist/impl/store/auth-reducer.js +179 -0
  62. package/dist/impl/store/index.d.ts +2 -0
  63. package/dist/impl/store/index.d.ts.map +1 -0
  64. package/dist/impl/store/index.js +1 -0
  65. package/dist/impl/strategies/KeycloakStrategy.d.ts +42 -0
  66. package/dist/impl/strategies/KeycloakStrategy.d.ts.map +1 -0
  67. package/dist/impl/strategies/KeycloakStrategy.js +237 -0
  68. package/dist/impl/strategies/OAuth2Strategy.d.ts +30 -0
  69. package/dist/impl/strategies/OAuth2Strategy.d.ts.map +1 -0
  70. package/dist/impl/strategies/OAuth2Strategy.js +232 -0
  71. package/dist/impl/strategies/PasswordStrategy.d.ts +25 -0
  72. package/dist/impl/strategies/PasswordStrategy.d.ts.map +1 -0
  73. package/dist/impl/strategies/PasswordStrategy.js +159 -0
  74. package/dist/impl/strategies/StrategyRegistry.d.ts +24 -0
  75. package/dist/impl/strategies/StrategyRegistry.d.ts.map +1 -0
  76. package/dist/impl/strategies/StrategyRegistry.js +70 -0
  77. package/dist/impl/strategies/index.d.ts +5 -0
  78. package/dist/impl/strategies/index.d.ts.map +1 -0
  79. package/dist/impl/strategies/index.js +4 -0
  80. package/dist/impl/utils/index.d.ts +3 -0
  81. package/dist/impl/utils/index.d.ts.map +1 -0
  82. package/dist/impl/utils/index.js +2 -0
  83. package/dist/impl/utils/jwt.d.ts +81 -0
  84. package/dist/impl/utils/jwt.d.ts.map +1 -0
  85. package/dist/impl/utils/jwt.js +103 -0
  86. package/dist/impl/utils/pkce.d.ts +44 -0
  87. package/dist/impl/utils/pkce.d.ts.map +1 -0
  88. package/dist/impl/utils/pkce.js +93 -0
  89. package/dist/index.d.ts +12 -0
  90. package/dist/index.d.ts.map +1 -0
  91. package/dist/index.js +11 -0
  92. package/dist/spi/guards/AuthGuard.d.ts +108 -0
  93. package/dist/spi/guards/AuthGuard.d.ts.map +1 -0
  94. package/dist/spi/guards/AuthGuard.js +5 -0
  95. package/dist/spi/guards/index.d.ts +2 -0
  96. package/dist/spi/guards/index.d.ts.map +1 -0
  97. package/dist/spi/guards/index.js +1 -0
  98. package/dist/spi/index.d.ts +12 -0
  99. package/dist/spi/index.d.ts.map +1 -0
  100. package/dist/spi/index.js +15 -0
  101. package/dist/spi/storage/ITokenStorage.d.ts +107 -0
  102. package/dist/spi/storage/ITokenStorage.d.ts.map +1 -0
  103. package/dist/spi/storage/ITokenStorage.js +5 -0
  104. package/dist/spi/storage/index.d.ts +2 -0
  105. package/dist/spi/storage/index.d.ts.map +1 -0
  106. package/dist/spi/storage/index.js +1 -0
  107. package/dist/spi/strategies/IAuthStrategy.d.ts +114 -0
  108. package/dist/spi/strategies/IAuthStrategy.d.ts.map +1 -0
  109. package/dist/spi/strategies/IAuthStrategy.js +16 -0
  110. package/dist/spi/strategies/IStrategyRegistry.d.ts +64 -0
  111. package/dist/spi/strategies/IStrategyRegistry.d.ts.map +1 -0
  112. package/dist/spi/strategies/IStrategyRegistry.js +5 -0
  113. package/dist/spi/strategies/index.d.ts +3 -0
  114. package/dist/spi/strategies/index.d.ts.map +1 -0
  115. package/dist/spi/strategies/index.js +2 -0
  116. package/package.json +78 -0
@@ -0,0 +1,107 @@
1
+ /**
2
+ * Token Storage Interface
3
+ * Abstraction for persisting authentication tokens
4
+ */
5
+ import type { User } from '../../api';
6
+ /**
7
+ * Stored token data structure
8
+ */
9
+ export interface StoredTokens {
10
+ /** The access token */
11
+ accessToken: string;
12
+ /** The refresh token (if available) */
13
+ refreshToken?: string;
14
+ /** Token type (usually 'Bearer') */
15
+ tokenType?: string;
16
+ /** When the access token expires (timestamp in ms) */
17
+ expiresAt?: number;
18
+ /** Token scopes */
19
+ scope?: string[];
20
+ }
21
+ /**
22
+ * Token storage interface
23
+ *
24
+ * Provides an abstraction layer over the actual storage mechanism.
25
+ * Implementations can use localStorage, sessionStorage, cookies, etc.
26
+ */
27
+ export interface ITokenStorage {
28
+ /**
29
+ * Get the stored access token
30
+ * @returns The access token or null if not stored
31
+ */
32
+ getAccessToken(): string | null;
33
+ /**
34
+ * Store the access token
35
+ * @param token The access token
36
+ * @param expiresAt When the token expires (timestamp in ms)
37
+ */
38
+ setAccessToken(token: string, expiresAt?: number): void;
39
+ /**
40
+ * Get the stored refresh token
41
+ * @returns The refresh token or null if not stored
42
+ */
43
+ getRefreshToken(): string | null;
44
+ /**
45
+ * Store the refresh token
46
+ * @param token The refresh token
47
+ */
48
+ setRefreshToken(token: string): void;
49
+ /**
50
+ * Get all stored token data
51
+ * @returns The stored tokens or null if not stored
52
+ */
53
+ getTokens(): StoredTokens | null;
54
+ /**
55
+ * Store all token data at once
56
+ * @param tokens The tokens to store
57
+ */
58
+ setTokens(tokens: StoredTokens): void;
59
+ /**
60
+ * Clear all stored tokens
61
+ */
62
+ clearTokens(): void;
63
+ /**
64
+ * Check if the access token is expired
65
+ * @returns true if the token is expired or not present
66
+ */
67
+ isTokenExpired(): boolean;
68
+ /**
69
+ * Check if the token will expire soon
70
+ * @param thresholdMs Time in ms before expiry to consider "soon"
71
+ * @returns true if the token will expire within the threshold
72
+ */
73
+ isTokenExpiringSoon(thresholdMs: number): boolean;
74
+ /**
75
+ * Get the token expiration time
76
+ * @returns Timestamp in ms when the token expires, or null
77
+ */
78
+ getTokenExpiry(): number | null;
79
+ /**
80
+ * Get the stored user data
81
+ * @returns The user or null if not stored
82
+ */
83
+ getUser(): User | null;
84
+ /**
85
+ * Store user data
86
+ * @param user The user to store
87
+ */
88
+ setUser(user: User): void;
89
+ /**
90
+ * Clear stored user data
91
+ */
92
+ clearUser(): void;
93
+ /**
94
+ * Clear all auth data (tokens and user)
95
+ */
96
+ clearAll(): void;
97
+ }
98
+ /**
99
+ * Configuration for token storage
100
+ */
101
+ export interface TokenStorageConfig {
102
+ /** Key prefix for storage (default: '@hamak/auth') */
103
+ keyPrefix?: string;
104
+ /** Whether to encrypt tokens before storing (implementation-specific) */
105
+ encrypt?: boolean;
106
+ }
107
+ //# sourceMappingURL=ITokenStorage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ITokenStorage.d.ts","sourceRoot":"","sources":["../../../src/spi/storage/ITokenStorage.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEtC;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,uBAAuB;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,uCAAuC;IACvC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,oCAAoC;IACpC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,sDAAsD;IACtD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,mBAAmB;IACnB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;CAClB;AAED;;;;;GAKG;AACH,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,cAAc,IAAI,MAAM,GAAG,IAAI,CAAC;IAEhC;;;;OAIG;IACH,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAExD;;;OAGG;IACH,eAAe,IAAI,MAAM,GAAG,IAAI,CAAC;IAEjC;;;OAGG;IACH,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAErC;;;OAGG;IACH,SAAS,IAAI,YAAY,GAAG,IAAI,CAAC;IAEjC;;;OAGG;IACH,SAAS,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI,CAAC;IAEtC;;OAEG;IACH,WAAW,IAAI,IAAI,CAAC;IAEpB;;;OAGG;IACH,cAAc,IAAI,OAAO,CAAC;IAE1B;;;;OAIG;IACH,mBAAmB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC;IAElD;;;OAGG;IACH,cAAc,IAAI,MAAM,GAAG,IAAI,CAAC;IAEhC;;;OAGG;IACH,OAAO,IAAI,IAAI,GAAG,IAAI,CAAC;IAEvB;;;OAGG;IACH,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;IAE1B;;OAEG;IACH,SAAS,IAAI,IAAI,CAAC;IAElB;;OAEG;IACH,QAAQ,IAAI,IAAI,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,sDAAsD;IACtD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,yEAAyE;IACzE,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Token Storage Interface
3
+ * Abstraction for persisting authentication tokens
4
+ */
5
+ export {};
@@ -0,0 +1,2 @@
1
+ export * from './ITokenStorage';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/spi/storage/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
@@ -0,0 +1 @@
1
+ export * from './ITokenStorage';
@@ -0,0 +1,114 @@
1
+ /**
2
+ * Auth Strategy Interface
3
+ * Base interface for all authentication strategy implementations
4
+ */
5
+ import type { AuthResult, AuthStrategyType, LoginCredentials, OAuthCallbackParams, User } from '../../api';
6
+ /**
7
+ * HTTP client interface for making auth requests
8
+ * This abstraction allows strategies to work with any HTTP client
9
+ */
10
+ export interface IHttpClient {
11
+ get<T = unknown>(url: string, config?: HttpRequestConfig): Promise<HttpResponse<T>>;
12
+ post<T = unknown>(url: string, data?: unknown, config?: HttpRequestConfig): Promise<HttpResponse<T>>;
13
+ put<T = unknown>(url: string, data?: unknown, config?: HttpRequestConfig): Promise<HttpResponse<T>>;
14
+ delete<T = unknown>(url: string, config?: HttpRequestConfig): Promise<HttpResponse<T>>;
15
+ }
16
+ export interface HttpRequestConfig {
17
+ headers?: Record<string, string>;
18
+ params?: Record<string, string>;
19
+ timeout?: number;
20
+ }
21
+ export interface HttpResponse<T = unknown> {
22
+ data: T;
23
+ status: number;
24
+ headers: Record<string, string>;
25
+ }
26
+ /**
27
+ * Base authentication strategy interface
28
+ *
29
+ * All authentication strategies must implement this interface.
30
+ * Strategies handle the specifics of authentication flows while
31
+ * the AuthService provides a unified API.
32
+ */
33
+ export interface IAuthStrategy {
34
+ /**
35
+ * The type identifier for this strategy
36
+ */
37
+ readonly type: AuthStrategyType;
38
+ /**
39
+ * Unique name for this strategy instance
40
+ * Allows multiple strategies of the same type (e.g., multiple OAuth providers)
41
+ */
42
+ readonly name: string;
43
+ /**
44
+ * Authenticate with the given credentials
45
+ * @param credentials The login credentials
46
+ * @returns Authentication result with tokens and user info
47
+ */
48
+ authenticate(credentials: LoginCredentials): Promise<AuthResult>;
49
+ /**
50
+ * Refresh the access token using a refresh token
51
+ * @param refreshToken The refresh token
52
+ * @returns New authentication result with fresh tokens
53
+ */
54
+ refreshToken(refreshToken: string): Promise<AuthResult>;
55
+ /**
56
+ * Revoke tokens and end the session
57
+ * @param accessToken The current access token
58
+ */
59
+ logout(accessToken: string): Promise<void>;
60
+ /**
61
+ * Extract user information from a token (optional)
62
+ * Used for JWT-based strategies that embed user info in tokens
63
+ * @param token The access token
64
+ */
65
+ extractUserFromToken?(token: string): User | null;
66
+ }
67
+ /**
68
+ * OAuth-capable strategy interface
69
+ * Extends base strategy with OAuth-specific methods
70
+ */
71
+ export interface IOAuthStrategy extends IAuthStrategy {
72
+ /**
73
+ * Get the authorization URL for OAuth redirect
74
+ * @returns The full authorization URL with all parameters
75
+ */
76
+ getAuthorizationUrl(): string | Promise<string>;
77
+ /**
78
+ * Handle the OAuth callback after user authorization
79
+ * @param params The callback parameters from the OAuth provider
80
+ * @returns Authentication result
81
+ */
82
+ handleCallback(params: OAuthCallbackParams): Promise<AuthResult>;
83
+ /**
84
+ * Get the stored state parameter for validation
85
+ * Used to validate the state parameter in OAuth callbacks
86
+ */
87
+ getStoredState(): string | null;
88
+ /**
89
+ * Clear stored OAuth state (code verifier, state, etc.)
90
+ */
91
+ clearOAuthState(): void;
92
+ }
93
+ /**
94
+ * Strategy that supports direct password authentication
95
+ * Some OAuth providers (like Keycloak) can also support direct grant
96
+ */
97
+ export interface IDirectAuthStrategy extends IAuthStrategy {
98
+ /**
99
+ * Authenticate directly with username/password
100
+ * @param username The username
101
+ * @param password The password
102
+ * @returns Authentication result
103
+ */
104
+ authenticateDirect(username: string, password: string): Promise<AuthResult>;
105
+ }
106
+ /**
107
+ * Type guard to check if a strategy supports OAuth
108
+ */
109
+ export declare function isOAuthStrategy(strategy: IAuthStrategy): strategy is IOAuthStrategy;
110
+ /**
111
+ * Type guard to check if a strategy supports direct auth
112
+ */
113
+ export declare function isDirectAuthStrategy(strategy: IAuthStrategy): strategy is IDirectAuthStrategy;
114
+ //# sourceMappingURL=IAuthStrategy.d.ts.map
@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,IAAI,mBAAmB,CAE7F"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Auth Strategy Interface
3
+ * Base interface for all authentication strategy implementations
4
+ */
5
+ /**
6
+ * Type guard to check if a strategy supports OAuth
7
+ */
8
+ export function isOAuthStrategy(strategy) {
9
+ return 'getAuthorizationUrl' in strategy && 'handleCallback' in strategy;
10
+ }
11
+ /**
12
+ * Type guard to check if a strategy supports direct auth
13
+ */
14
+ export function isDirectAuthStrategy(strategy) {
15
+ return 'authenticateDirect' in strategy;
16
+ }
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Strategy Registry Interface
3
+ * Registry for managing multiple authentication strategies
4
+ */
5
+ import type { IAuthStrategy, IOAuthStrategy } from './IAuthStrategy';
6
+ /**
7
+ * Registry for authentication strategies
8
+ *
9
+ * Allows registering and retrieving multiple strategies.
10
+ * Useful for applications that support multiple login methods.
11
+ */
12
+ export interface IStrategyRegistry {
13
+ /**
14
+ * Register an authentication strategy
15
+ * @param strategy The strategy to register
16
+ */
17
+ register(strategy: IAuthStrategy): void;
18
+ /**
19
+ * Unregister a strategy by name
20
+ * @param name The strategy name
21
+ */
22
+ unregister(name: string): void;
23
+ /**
24
+ * Get a strategy by name
25
+ * @param name The strategy name
26
+ * @returns The strategy or undefined if not found
27
+ */
28
+ get(name: string): IAuthStrategy | undefined;
29
+ /**
30
+ * Get an OAuth strategy by name
31
+ * @param name The strategy name
32
+ * @returns The OAuth strategy or undefined if not found
33
+ */
34
+ getOAuth(name: string): IOAuthStrategy | undefined;
35
+ /**
36
+ * Get all registered strategies
37
+ * @returns Array of all strategies
38
+ */
39
+ getAll(): IAuthStrategy[];
40
+ /**
41
+ * Get all OAuth strategies
42
+ * @returns Array of OAuth strategies
43
+ */
44
+ getAllOAuth(): IOAuthStrategy[];
45
+ /**
46
+ * Check if a strategy is registered
47
+ * @param name The strategy name
48
+ */
49
+ has(name: string): boolean;
50
+ /**
51
+ * Get the default strategy
52
+ */
53
+ getDefault(): IAuthStrategy | undefined;
54
+ /**
55
+ * Set the default strategy
56
+ * @param name The strategy name to use as default
57
+ */
58
+ setDefault(name: string): void;
59
+ /**
60
+ * Clear all registered strategies
61
+ */
62
+ clear(): void;
63
+ }
64
+ //# sourceMappingURL=IStrategyRegistry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IStrategyRegistry.d.ts","sourceRoot":"","sources":["../../../src/spi/strategies/IStrategyRegistry.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAErE;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,QAAQ,CAAC,QAAQ,EAAE,aAAa,GAAG,IAAI,CAAC;IAExC;;;OAGG;IACH,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAE/B;;;;OAIG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAAC;IAE7C;;;;OAIG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS,CAAC;IAEnD;;;OAGG;IACH,MAAM,IAAI,aAAa,EAAE,CAAC;IAE1B;;;OAGG;IACH,WAAW,IAAI,cAAc,EAAE,CAAC;IAEhC;;;OAGG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IAE3B;;OAEG;IACH,UAAU,IAAI,aAAa,GAAG,SAAS,CAAC;IAExC;;;OAGG;IACH,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAE/B;;OAEG;IACH,KAAK,IAAI,IAAI,CAAC;CACf"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Strategy Registry Interface
3
+ * Registry for managing multiple authentication strategies
4
+ */
5
+ export {};
@@ -0,0 +1,3 @@
1
+ export * from './IAuthStrategy';
2
+ export * from './IStrategyRegistry';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/spi/strategies/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './IAuthStrategy';
2
+ export * from './IStrategyRegistry';
package/package.json ADDED
@@ -0,0 +1,78 @@
1
+ {
2
+ "name": "@hamak/auth",
3
+ "version": "0.5.1",
4
+ "description": "Auth - Complete authentication plugin with password, OAuth2, and Keycloak support",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ },
13
+ "./api": {
14
+ "types": "./dist/api/index.d.ts",
15
+ "import": "./dist/api/index.js"
16
+ },
17
+ "./spi": {
18
+ "types": "./dist/spi/index.d.ts",
19
+ "import": "./dist/spi/index.js"
20
+ }
21
+ },
22
+ "typesVersions": {
23
+ "*": {
24
+ "api": [
25
+ "./dist/api/index.d.ts"
26
+ ],
27
+ "spi": [
28
+ "./dist/spi/index.d.ts"
29
+ ]
30
+ }
31
+ },
32
+ "files": [
33
+ "dist"
34
+ ],
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "https://github.com/amah/app-framework.git",
38
+ "directory": "packages/auth"
39
+ },
40
+ "publishConfig": {
41
+ "access": "public"
42
+ },
43
+ "scripts": {
44
+ "build": "tsc -p tsconfig.lib.json",
45
+ "clean": "rm -rf dist",
46
+ "test": "vitest run",
47
+ "test:watch": "vitest"
48
+ },
49
+ "keywords": [
50
+ "auth",
51
+ "authentication",
52
+ "oauth2",
53
+ "keycloak",
54
+ "microkernel",
55
+ "plugin"
56
+ ],
57
+ "author": "",
58
+ "license": "MIT",
59
+ "dependencies": {
60
+ "@hamak/microkernel-api": "*",
61
+ "@hamak/microkernel-spi": "*",
62
+ "@hamak/logging-api": "*"
63
+ },
64
+ "peerDependencies": {
65
+ "@hamak/ui-store-api": "*",
66
+ "axios": "^1.6.0"
67
+ },
68
+ "peerDependenciesMeta": {
69
+ "@hamak/ui-store-api": {
70
+ "optional": true
71
+ }
72
+ },
73
+ "devDependencies": {
74
+ "axios": "^1.6.0",
75
+ "typescript": "^5.9.3",
76
+ "vitest": "^3.2.4"
77
+ }
78
+ }