qa360 1.4.5 → 2.0.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 (209) hide show
  1. package/README.md +1 -1
  2. package/dist/commands/ai.d.ts +41 -0
  3. package/dist/commands/ai.js +499 -0
  4. package/dist/commands/ask.js +12 -12
  5. package/dist/commands/coverage.d.ts +8 -0
  6. package/dist/commands/coverage.js +252 -0
  7. package/dist/commands/explain.d.ts +27 -0
  8. package/dist/commands/explain.js +630 -0
  9. package/dist/commands/flakiness.d.ts +73 -0
  10. package/dist/commands/flakiness.js +435 -0
  11. package/dist/commands/generate.d.ts +66 -0
  12. package/dist/commands/generate.js +438 -0
  13. package/dist/commands/init.d.ts +56 -9
  14. package/dist/commands/init.js +217 -10
  15. package/dist/commands/monitor.d.ts +27 -0
  16. package/dist/commands/monitor.js +225 -0
  17. package/dist/commands/ollama.d.ts +40 -0
  18. package/dist/commands/ollama.js +301 -0
  19. package/dist/commands/pack.d.ts +37 -9
  20. package/dist/commands/pack.js +240 -141
  21. package/dist/commands/regression.d.ts +8 -0
  22. package/dist/commands/regression.js +340 -0
  23. package/dist/commands/repair.d.ts +26 -0
  24. package/dist/commands/repair.js +307 -0
  25. package/dist/commands/retry.d.ts +43 -0
  26. package/dist/commands/retry.js +275 -0
  27. package/dist/commands/run.d.ts +8 -3
  28. package/dist/commands/run.js +45 -31
  29. package/dist/commands/slo.d.ts +8 -0
  30. package/dist/commands/slo.js +327 -0
  31. package/dist/core/adapters/playwright-native-api.d.ts +183 -0
  32. package/dist/core/adapters/playwright-native-api.js +461 -0
  33. package/dist/core/adapters/playwright-ui.d.ts +7 -0
  34. package/dist/core/adapters/playwright-ui.js +29 -1
  35. package/dist/core/ai/anthropic-provider.d.ts +50 -0
  36. package/dist/core/ai/anthropic-provider.js +211 -0
  37. package/dist/core/ai/deepseek-provider.d.ts +81 -0
  38. package/dist/core/ai/deepseek-provider.js +254 -0
  39. package/dist/core/ai/index.d.ts +60 -0
  40. package/dist/core/ai/index.js +18 -0
  41. package/dist/core/ai/llm-client.d.ts +45 -0
  42. package/dist/core/ai/llm-client.js +7 -0
  43. package/dist/core/ai/mock-provider.d.ts +49 -0
  44. package/dist/core/ai/mock-provider.js +121 -0
  45. package/dist/core/ai/ollama-provider.d.ts +78 -0
  46. package/dist/core/ai/ollama-provider.js +192 -0
  47. package/dist/core/ai/openai-provider.d.ts +48 -0
  48. package/dist/core/ai/openai-provider.js +188 -0
  49. package/dist/core/ai/provider-factory.d.ts +160 -0
  50. package/dist/core/ai/provider-factory.js +269 -0
  51. package/dist/core/auth/api-key-provider.d.ts +16 -0
  52. package/dist/core/auth/api-key-provider.js +63 -0
  53. package/dist/core/auth/aws-iam-provider.d.ts +35 -0
  54. package/dist/core/auth/aws-iam-provider.js +177 -0
  55. package/dist/core/auth/azure-ad-provider.d.ts +15 -0
  56. package/dist/core/auth/azure-ad-provider.js +99 -0
  57. package/dist/core/auth/basic-auth-provider.d.ts +26 -0
  58. package/dist/core/auth/basic-auth-provider.js +111 -0
  59. package/dist/core/auth/gcp-adc-provider.d.ts +27 -0
  60. package/dist/core/auth/gcp-adc-provider.js +126 -0
  61. package/dist/core/auth/index.d.ts +238 -0
  62. package/dist/core/auth/index.js +82 -0
  63. package/dist/core/auth/jwt-provider.d.ts +19 -0
  64. package/dist/core/auth/jwt-provider.js +160 -0
  65. package/dist/core/auth/manager.d.ts +84 -0
  66. package/dist/core/auth/manager.js +230 -0
  67. package/dist/core/auth/oauth2-provider.d.ts +17 -0
  68. package/dist/core/auth/oauth2-provider.js +114 -0
  69. package/dist/core/auth/totp-provider.d.ts +31 -0
  70. package/dist/core/auth/totp-provider.js +134 -0
  71. package/dist/core/auth/ui-login-provider.d.ts +26 -0
  72. package/dist/core/auth/ui-login-provider.js +198 -0
  73. package/dist/core/cache/index.d.ts +7 -0
  74. package/dist/core/cache/index.js +6 -0
  75. package/dist/core/cache/lru-cache.d.ts +203 -0
  76. package/dist/core/cache/lru-cache.js +397 -0
  77. package/dist/core/coverage/analyzer.d.ts +101 -0
  78. package/dist/core/coverage/analyzer.js +415 -0
  79. package/dist/core/coverage/collector.d.ts +74 -0
  80. package/dist/core/coverage/collector.js +459 -0
  81. package/dist/core/coverage/config.d.ts +37 -0
  82. package/dist/core/coverage/config.js +156 -0
  83. package/dist/core/coverage/index.d.ts +11 -0
  84. package/dist/core/coverage/index.js +15 -0
  85. package/dist/core/coverage/types.d.ts +267 -0
  86. package/dist/core/coverage/types.js +6 -0
  87. package/dist/core/coverage/vault.d.ts +95 -0
  88. package/dist/core/coverage/vault.js +405 -0
  89. package/dist/core/dashboard/assets.d.ts +6 -0
  90. package/dist/core/dashboard/assets.js +690 -0
  91. package/dist/core/dashboard/index.d.ts +6 -0
  92. package/dist/core/dashboard/index.js +5 -0
  93. package/dist/core/dashboard/server.d.ts +72 -0
  94. package/dist/core/dashboard/server.js +354 -0
  95. package/dist/core/dashboard/types.d.ts +70 -0
  96. package/dist/core/dashboard/types.js +5 -0
  97. package/dist/core/discoverer/index.d.ts +115 -0
  98. package/dist/core/discoverer/index.js +250 -0
  99. package/dist/core/flakiness/index.d.ts +228 -0
  100. package/dist/core/flakiness/index.js +384 -0
  101. package/dist/core/generation/code-formatter.d.ts +111 -0
  102. package/dist/core/generation/code-formatter.js +307 -0
  103. package/dist/core/generation/code-generator.d.ts +144 -0
  104. package/dist/core/generation/code-generator.js +293 -0
  105. package/dist/core/generation/generator.d.ts +40 -0
  106. package/dist/core/generation/generator.js +76 -0
  107. package/dist/core/generation/index.d.ts +30 -0
  108. package/dist/core/generation/index.js +28 -0
  109. package/dist/core/generation/pack-generator.d.ts +107 -0
  110. package/dist/core/generation/pack-generator.js +416 -0
  111. package/dist/core/generation/prompt-builder.d.ts +132 -0
  112. package/dist/core/generation/prompt-builder.js +672 -0
  113. package/dist/core/generation/source-analyzer.d.ts +213 -0
  114. package/dist/core/generation/source-analyzer.js +657 -0
  115. package/dist/core/generation/test-optimizer.d.ts +117 -0
  116. package/dist/core/generation/test-optimizer.js +328 -0
  117. package/dist/core/generation/types.d.ts +214 -0
  118. package/dist/core/generation/types.js +4 -0
  119. package/dist/core/index.d.ts +23 -1
  120. package/dist/core/index.js +39 -0
  121. package/dist/core/pack/validator.js +31 -1
  122. package/dist/core/pack-v2/index.d.ts +9 -0
  123. package/dist/core/pack-v2/index.js +8 -0
  124. package/dist/core/pack-v2/loader.d.ts +62 -0
  125. package/dist/core/pack-v2/loader.js +231 -0
  126. package/dist/core/pack-v2/migrator.d.ts +56 -0
  127. package/dist/core/pack-v2/migrator.js +455 -0
  128. package/dist/core/pack-v2/validator.d.ts +61 -0
  129. package/dist/core/pack-v2/validator.js +577 -0
  130. package/dist/core/regression/detector.d.ts +107 -0
  131. package/dist/core/regression/detector.js +497 -0
  132. package/dist/core/regression/index.d.ts +9 -0
  133. package/dist/core/regression/index.js +11 -0
  134. package/dist/core/regression/trend-analyzer.d.ts +102 -0
  135. package/dist/core/regression/trend-analyzer.js +345 -0
  136. package/dist/core/regression/types.d.ts +222 -0
  137. package/dist/core/regression/types.js +7 -0
  138. package/dist/core/regression/vault.d.ts +87 -0
  139. package/dist/core/regression/vault.js +289 -0
  140. package/dist/core/repair/engine/fixer.d.ts +24 -0
  141. package/dist/core/repair/engine/fixer.js +226 -0
  142. package/dist/core/repair/engine/suggestion-engine.d.ts +18 -0
  143. package/dist/core/repair/engine/suggestion-engine.js +187 -0
  144. package/dist/core/repair/index.d.ts +10 -0
  145. package/dist/core/repair/index.js +13 -0
  146. package/dist/core/repair/repairer.d.ts +90 -0
  147. package/dist/core/repair/repairer.js +284 -0
  148. package/dist/core/repair/types.d.ts +91 -0
  149. package/dist/core/repair/types.js +6 -0
  150. package/dist/core/repair/utils/error-analyzer.d.ts +28 -0
  151. package/dist/core/repair/utils/error-analyzer.js +264 -0
  152. package/dist/core/retry/flakiness-integration.d.ts +60 -0
  153. package/dist/core/retry/flakiness-integration.js +228 -0
  154. package/dist/core/retry/index.d.ts +14 -0
  155. package/dist/core/retry/index.js +16 -0
  156. package/dist/core/retry/retry-engine.d.ts +80 -0
  157. package/dist/core/retry/retry-engine.js +296 -0
  158. package/dist/core/retry/types.d.ts +178 -0
  159. package/dist/core/retry/types.js +52 -0
  160. package/dist/core/retry/vault.d.ts +77 -0
  161. package/dist/core/retry/vault.js +304 -0
  162. package/dist/core/runner/e2e-helpers.d.ts +102 -0
  163. package/dist/core/runner/e2e-helpers.js +153 -0
  164. package/dist/core/runner/phase3-runner.d.ts +101 -2
  165. package/dist/core/runner/phase3-runner.js +559 -24
  166. package/dist/core/self-healing/assertion-healer.d.ts +97 -0
  167. package/dist/core/self-healing/assertion-healer.js +371 -0
  168. package/dist/core/self-healing/engine.d.ts +122 -0
  169. package/dist/core/self-healing/engine.js +538 -0
  170. package/dist/core/self-healing/index.d.ts +10 -0
  171. package/dist/core/self-healing/index.js +11 -0
  172. package/dist/core/self-healing/selector-healer.d.ts +103 -0
  173. package/dist/core/self-healing/selector-healer.js +372 -0
  174. package/dist/core/self-healing/types.d.ts +152 -0
  175. package/dist/core/self-healing/types.js +6 -0
  176. package/dist/core/slo/config.d.ts +107 -0
  177. package/dist/core/slo/config.js +360 -0
  178. package/dist/core/slo/index.d.ts +11 -0
  179. package/dist/core/slo/index.js +15 -0
  180. package/dist/core/slo/sli-calculator.d.ts +92 -0
  181. package/dist/core/slo/sli-calculator.js +364 -0
  182. package/dist/core/slo/slo-tracker.d.ts +148 -0
  183. package/dist/core/slo/slo-tracker.js +379 -0
  184. package/dist/core/slo/types.d.ts +281 -0
  185. package/dist/core/slo/types.js +7 -0
  186. package/dist/core/slo/vault.d.ts +102 -0
  187. package/dist/core/slo/vault.js +427 -0
  188. package/dist/core/tui/index.d.ts +7 -0
  189. package/dist/core/tui/index.js +6 -0
  190. package/dist/core/tui/monitor.d.ts +92 -0
  191. package/dist/core/tui/monitor.js +271 -0
  192. package/dist/core/tui/renderer.d.ts +33 -0
  193. package/dist/core/tui/renderer.js +218 -0
  194. package/dist/core/tui/types.d.ts +63 -0
  195. package/dist/core/tui/types.js +5 -0
  196. package/dist/core/types/pack-v2.d.ts +425 -0
  197. package/dist/core/types/pack-v2.js +8 -0
  198. package/dist/core/vault/index.d.ts +116 -0
  199. package/dist/core/vault/index.js +400 -5
  200. package/dist/core/watch/index.d.ts +7 -0
  201. package/dist/core/watch/index.js +6 -0
  202. package/dist/core/watch/watch-mode.d.ts +213 -0
  203. package/dist/core/watch/watch-mode.js +389 -0
  204. package/dist/index.js +68 -68
  205. package/dist/utils/config.d.ts +5 -0
  206. package/dist/utils/config.js +136 -0
  207. package/package.json +5 -1
  208. package/dist/core/adapters/playwright-api.d.ts +0 -82
  209. package/dist/core/adapters/playwright-api.js +0 -264
@@ -0,0 +1,230 @@
1
+ /**
2
+ * Authentication Manager and Factory
3
+ *
4
+ * Central manager for handling multiple authentication profiles
5
+ * and creating auth providers based on configuration.
6
+ */
7
+ import { authCache } from './index.js';
8
+ import { JWTProvider } from './jwt-provider.js';
9
+ import { OAuth2Provider } from './oauth2-provider.js';
10
+ import { APIKeyProvider } from './api-key-provider.js';
11
+ import { BearerProvider, BasicAuthProvider } from './basic-auth-provider.js';
12
+ import { TOTPProvider } from './totp-provider.js';
13
+ import { UILoginProvider } from './ui-login-provider.js';
14
+ import { GCPADCProvider } from './gcp-adc-provider.js';
15
+ import { AWSIamProvider } from './aws-iam-provider.js';
16
+ import { AzureADProvider } from './azure-ad-provider.js';
17
+ /**
18
+ * Authentication error
19
+ */
20
+ export class AuthError extends Error {
21
+ code = 'AUTH_ERROR';
22
+ provider;
23
+ constructor(message, provider) {
24
+ super(message);
25
+ this.name = 'AuthError';
26
+ this.provider = provider;
27
+ }
28
+ }
29
+ /**
30
+ * Authentication Manager
31
+ *
32
+ * Manages multiple authentication profiles and provides
33
+ * a unified interface for authentication operations.
34
+ */
35
+ export class AuthManager {
36
+ profiles = new Map();
37
+ /**
38
+ * Register an authentication profile
39
+ */
40
+ registerProfile(name, config) {
41
+ this.profiles.set(name, config);
42
+ }
43
+ /**
44
+ * Unregister an authentication profile
45
+ */
46
+ unregisterProfile(name) {
47
+ this.profiles.delete(name);
48
+ }
49
+ /**
50
+ * Get a registered profile
51
+ */
52
+ getProfile(name) {
53
+ return this.profiles.get(name);
54
+ }
55
+ /**
56
+ * List all registered profiles
57
+ */
58
+ listProfiles() {
59
+ return Array.from(this.profiles.keys());
60
+ }
61
+ /**
62
+ * Authenticate using a named profile
63
+ */
64
+ async authenticate(name) {
65
+ const config = this.profiles.get(name);
66
+ if (!config) {
67
+ return {
68
+ success: false,
69
+ error: `Profile '${name}' not found`
70
+ };
71
+ }
72
+ return this.authenticateWithConfig(config);
73
+ }
74
+ /**
75
+ * Authenticate using a configuration directly
76
+ */
77
+ async authenticateWithConfig(config) {
78
+ const provider = this.createProvider(config);
79
+ try {
80
+ return await provider.authenticate(config);
81
+ }
82
+ catch (error) {
83
+ return {
84
+ success: false,
85
+ error: `Authentication failed: ${error.message}`
86
+ };
87
+ }
88
+ }
89
+ /**
90
+ * Create an auth provider based on configuration type
91
+ */
92
+ createProvider(config) {
93
+ switch (config.type) {
94
+ case 'jwt':
95
+ return new JWTProvider();
96
+ case 'oauth2':
97
+ return new OAuth2Provider();
98
+ case 'api_key':
99
+ return new APIKeyProvider();
100
+ case 'bearer':
101
+ return new BearerProvider();
102
+ case 'basic':
103
+ return new BasicAuthProvider();
104
+ case 'totp':
105
+ return new TOTPProvider();
106
+ case 'ui_login':
107
+ return new UILoginProvider();
108
+ case 'gcp_adc':
109
+ return new GCPADCProvider();
110
+ case 'aws_iam':
111
+ return new AWSIamProvider();
112
+ case 'azure_ad':
113
+ return new AzureADProvider();
114
+ case 'none':
115
+ return new NoneAuthProvider();
116
+ default:
117
+ throw new AuthError(`Unknown auth type: ${config.type}`);
118
+ }
119
+ }
120
+ /**
121
+ * Refresh authentication for a named profile
122
+ */
123
+ async refresh(name) {
124
+ const config = this.profiles.get(name);
125
+ if (!config) {
126
+ return {
127
+ success: false,
128
+ error: `Profile '${name}' not found`
129
+ };
130
+ }
131
+ const provider = this.createProvider(config);
132
+ if (provider.refresh) {
133
+ try {
134
+ return await provider.refresh(config);
135
+ }
136
+ catch (error) {
137
+ return {
138
+ success: false,
139
+ error: `Refresh failed: ${error.message}`
140
+ };
141
+ }
142
+ }
143
+ return {
144
+ success: false,
145
+ error: `Auth type '${config.type}' does not support refresh`
146
+ };
147
+ }
148
+ /**
149
+ * Clear authentication for a named profile
150
+ */
151
+ async clear(name) {
152
+ const config = this.profiles.get(name);
153
+ if (!config)
154
+ return;
155
+ const provider = this.createProvider(config);
156
+ if (provider.clear) {
157
+ await provider.clear(config);
158
+ }
159
+ }
160
+ /**
161
+ * Validate authentication for a named profile
162
+ */
163
+ async validate(name) {
164
+ const config = this.profiles.get(name);
165
+ if (!config)
166
+ return false;
167
+ const provider = this.createProvider(config);
168
+ if (provider.validate) {
169
+ return provider.validate(config);
170
+ }
171
+ return true;
172
+ }
173
+ /**
174
+ * Clear all cached credentials
175
+ */
176
+ clearAll() {
177
+ authCache.clear();
178
+ }
179
+ }
180
+ /**
181
+ * No-op authentication provider (for unauthenticated requests)
182
+ */
183
+ class NoneAuthProvider {
184
+ type = 'none';
185
+ async authenticate() {
186
+ return {
187
+ success: true,
188
+ credentials: { type: 'none' }
189
+ };
190
+ }
191
+ async validate() {
192
+ return true;
193
+ }
194
+ }
195
+ /**
196
+ * Global auth manager instance
197
+ */
198
+ export const authManager = new AuthManager();
199
+ /**
200
+ * Helper function to authenticate with a single config
201
+ */
202
+ export async function authenticate(config) {
203
+ const manager = new AuthManager();
204
+ return manager.authenticateWithConfig(config);
205
+ }
206
+ /**
207
+ * Helper function to create auth credentials for use in requests
208
+ */
209
+ export function createAuthHeaders(credentials) {
210
+ const headers = {};
211
+ if (credentials.headers) {
212
+ Object.assign(headers, credentials.headers);
213
+ }
214
+ return headers;
215
+ }
216
+ /**
217
+ * Apply auth credentials to a fetch request init
218
+ */
219
+ export function applyAuthToRequest(credentials, init = {}) {
220
+ const headers = new Headers(init.headers);
221
+ if (credentials.headers) {
222
+ Object.entries(credentials.headers).forEach(([key, value]) => {
223
+ headers.set(key, value);
224
+ });
225
+ }
226
+ return {
227
+ ...init,
228
+ headers
229
+ };
230
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * OAuth2 Authentication Provider
3
+ *
4
+ * Handles OAuth2 authentication with support for:
5
+ * - Client credentials grant
6
+ * - Password grant (resource owner)
7
+ * - Authorization code grant (requires pre-issued code)
8
+ */
9
+ import { AuthProvider, AuthResult, OAuth2AuthConfig } from './index.js';
10
+ export declare class OAuth2Provider implements AuthProvider<OAuth2AuthConfig> {
11
+ readonly type: "oauth2";
12
+ authenticate(config: OAuth2AuthConfig): Promise<AuthResult>;
13
+ refresh(config: OAuth2AuthConfig): Promise<AuthResult>;
14
+ clear(config: OAuth2AuthConfig): Promise<void>;
15
+ validate(config: OAuth2AuthConfig): Promise<boolean>;
16
+ private getCacheKey;
17
+ }
@@ -0,0 +1,114 @@
1
+ /**
2
+ * OAuth2 Authentication Provider
3
+ *
4
+ * Handles OAuth2 authentication with support for:
5
+ * - Client credentials grant
6
+ * - Password grant (resource owner)
7
+ * - Authorization code grant (requires pre-issued code)
8
+ */
9
+ import { authCache, createCacheKey } from './index.js';
10
+ export class OAuth2Provider {
11
+ type = 'oauth2';
12
+ async authenticate(config) {
13
+ const cacheKey = this.getCacheKey(config);
14
+ // Check cache first
15
+ if (config.cache?.enabled !== false) {
16
+ const cached = authCache.get(cacheKey);
17
+ if (cached) {
18
+ return { success: true, credentials: cached };
19
+ }
20
+ }
21
+ // Prepare token request based on grant type
22
+ const grantType = config.grant_type || 'client_credentials';
23
+ const body = {
24
+ grant_type: grantType,
25
+ client_id: config.client_id,
26
+ };
27
+ // Add client secret for most grants (except some implicit flows)
28
+ if (config.client_secret) {
29
+ body.client_secret = config.client_secret;
30
+ }
31
+ // Grant-specific parameters
32
+ if (grantType === 'password') {
33
+ if (!config.username || !config.password) {
34
+ return {
35
+ success: false,
36
+ error: 'Username and password required for password grant'
37
+ };
38
+ }
39
+ body.username = config.username;
40
+ body.password = config.password;
41
+ }
42
+ if (config.scopes && config.scopes.length > 0) {
43
+ body.scope = config.scopes.join(' ');
44
+ }
45
+ try {
46
+ const response = await fetch(config.token_url, {
47
+ method: 'POST',
48
+ headers: {
49
+ 'Content-Type': 'application/x-www-form-urlencoded',
50
+ },
51
+ body: new URLSearchParams(body).toString(),
52
+ });
53
+ if (!response.ok) {
54
+ const error = await response.text().catch(() => 'Unknown error');
55
+ return {
56
+ success: false,
57
+ error: `OAuth2 token request failed: ${response.status} ${error}`
58
+ };
59
+ }
60
+ const data = await response.json();
61
+ const token = data.access_token;
62
+ if (!token) {
63
+ return {
64
+ success: false,
65
+ error: 'No access_token in OAuth2 response'
66
+ };
67
+ }
68
+ const credentials = {
69
+ type: 'oauth2',
70
+ headers: {
71
+ 'Authorization': `Bearer ${token}`
72
+ }
73
+ };
74
+ // Calculate expiration
75
+ let expiresAt;
76
+ if (data.expires_in) {
77
+ expiresAt = Date.now() + data.expires_in * 1000;
78
+ }
79
+ // Cache if enabled
80
+ if (config.cache?.enabled !== false) {
81
+ const ttl = config.cache?.ttl || data.expires_in || 3600;
82
+ authCache.set(cacheKey, credentials, ttl);
83
+ }
84
+ return {
85
+ success: true,
86
+ credentials,
87
+ expiresAt
88
+ };
89
+ }
90
+ catch (error) {
91
+ return {
92
+ success: false,
93
+ error: `OAuth2 request failed: ${error.message}`
94
+ };
95
+ }
96
+ }
97
+ async refresh(config) {
98
+ // For OAuth2, refresh is typically the same as authenticate
99
+ // unless we have a refresh token (which we don't store currently)
100
+ return this.authenticate(config);
101
+ }
102
+ clear(config) {
103
+ const key = this.getCacheKey(config);
104
+ authCache.clear(key);
105
+ return Promise.resolve();
106
+ }
107
+ async validate(config) {
108
+ const key = this.getCacheKey(config);
109
+ return authCache.has(key);
110
+ }
111
+ getCacheKey(config) {
112
+ return createCacheKey('oauth2', config.client_id);
113
+ }
114
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * TOTP Authentication Provider
3
+ *
4
+ * Handles Time-based One-Time Password authentication.
5
+ * Generates TOTP codes using HMAC-based algorithm.
6
+ */
7
+ import { AuthProvider, AuthResult, TOTPAuthConfig } from './index.js';
8
+ export declare class TOTPProvider implements AuthProvider<TOTPAuthConfig> {
9
+ readonly type: "totp";
10
+ authenticate(config: TOTPAuthConfig): Promise<AuthResult>;
11
+ clear(config: TOTPAuthConfig): Promise<void>;
12
+ validate(config: TOTPAuthConfig): Promise<boolean>;
13
+ private getCacheKey;
14
+ /**
15
+ * Generate TOTP code
16
+ * Based on RFC 6238
17
+ */
18
+ private generateTOTP;
19
+ /**
20
+ * Convert counter to 8-byte array
21
+ */
22
+ private counterToBytes;
23
+ /**
24
+ * Decode Base32 string to Buffer
25
+ */
26
+ private base32Decode;
27
+ /**
28
+ * Get Node.js crypto module
29
+ */
30
+ private getCrypto;
31
+ }
@@ -0,0 +1,134 @@
1
+ /**
2
+ * TOTP Authentication Provider
3
+ *
4
+ * Handles Time-based One-Time Password authentication.
5
+ * Generates TOTP codes using HMAC-based algorithm.
6
+ */
7
+ import { authCache, createCacheKey } from './index.js';
8
+ export class TOTPProvider {
9
+ type = 'totp';
10
+ async authenticate(config) {
11
+ const { secret, digits = 6, period = 30, algorithm = 'sha1', cache } = config;
12
+ if (!secret) {
13
+ return {
14
+ success: false,
15
+ error: 'TOTP secret is required'
16
+ };
17
+ }
18
+ const cacheKey = this.getCacheKey(config);
19
+ // Check cache first (short TTL for TOTP - codes change every 30 seconds)
20
+ if (cache?.enabled !== false) {
21
+ const cached = authCache.get(cacheKey);
22
+ if (cached) {
23
+ return { success: true, credentials: cached };
24
+ }
25
+ }
26
+ // Generate current TOTP code
27
+ const code = this.generateTOTP(secret, digits, period, algorithm);
28
+ const credentials = {
29
+ type: 'totp',
30
+ headers: {
31
+ 'X-TOTP': code
32
+ },
33
+ body: {
34
+ totp_code: code,
35
+ totp_algorithm: algorithm,
36
+ totp_digits: digits,
37
+ totp_period: period
38
+ }
39
+ };
40
+ // Cache with short TTL (default 30 seconds - one TOTP period)
41
+ if (cache?.enabled !== false) {
42
+ const ttl = cache?.ttl || period;
43
+ authCache.set(cacheKey, credentials, ttl);
44
+ }
45
+ // Calculate expiration time
46
+ const now = Math.floor(Date.now() / 1000);
47
+ const currentPeriod = Math.floor(now / period);
48
+ const nextPeriodTime = (currentPeriod + 1) * period * 1000;
49
+ return {
50
+ success: true,
51
+ credentials,
52
+ expiresAt: nextPeriodTime
53
+ };
54
+ }
55
+ async clear(config) {
56
+ const key = this.getCacheKey(config);
57
+ authCache.clear(key);
58
+ }
59
+ async validate(config) {
60
+ const key = this.getCacheKey(config);
61
+ // Check cache first, then validate secret
62
+ if (authCache.has(key)) {
63
+ return true;
64
+ }
65
+ return !!config.secret && config.secret.length > 0;
66
+ }
67
+ getCacheKey(config) {
68
+ // Use secret hash as identifier since secret is the main config
69
+ const crypto = this.getCrypto();
70
+ const hash = crypto.createHash('sha256').update(config.secret || '').digest('hex').substring(0, 16);
71
+ return createCacheKey('totp', hash);
72
+ }
73
+ /**
74
+ * Generate TOTP code
75
+ * Based on RFC 6238
76
+ */
77
+ generateTOTP(secret, digits, period, algorithm) {
78
+ const counter = Math.floor(Date.now() / 1000 / period);
79
+ const counterBytes = this.counterToBytes(counter);
80
+ const key = this.base32Decode(secret);
81
+ // Import crypto conditionally for Node.js
82
+ const crypto = this.getCrypto();
83
+ const hmac = crypto.createHmac(algorithm, key);
84
+ hmac.update(counterBytes);
85
+ const hmacResult = hmac.digest();
86
+ // Dynamic truncation
87
+ const offset = hmacResult[hmacResult.length - 1] & 0xf;
88
+ const binary = ((hmacResult[offset] & 0x7f) << 24) |
89
+ ((hmacResult[offset + 1] & 0xff) << 16) |
90
+ ((hmacResult[offset + 2] & 0xff) << 8) |
91
+ (hmacResult[offset + 3] & 0xff);
92
+ const otp = binary % Math.pow(10, digits);
93
+ return otp.toString().padStart(digits, '0');
94
+ }
95
+ /**
96
+ * Convert counter to 8-byte array
97
+ */
98
+ counterToBytes(counter) {
99
+ const buffer = Buffer.alloc(8);
100
+ for (let i = 7; i >= 0; i--) {
101
+ buffer[i] = counter & 0xff;
102
+ counter = counter >> 8;
103
+ }
104
+ return buffer;
105
+ }
106
+ /**
107
+ * Decode Base32 string to Buffer
108
+ */
109
+ base32Decode(secret) {
110
+ const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
111
+ const bits = secret.toUpperCase().replace(/[^A-Z2-7]/g, '');
112
+ const hex = [];
113
+ for (let i = 0; i < bits.length; i += 8) {
114
+ const chunk = bits.substring(i, i + 8);
115
+ let byte = 0;
116
+ for (let j = 0; j < 8; j++) {
117
+ const val = alphabet.indexOf(chunk[j]);
118
+ if (val === -1)
119
+ continue;
120
+ byte = (byte << 5) | val;
121
+ }
122
+ hex.push((byte >> 16) & 0xff);
123
+ hex.push((byte >> 8) & 0xff);
124
+ hex.push(byte & 0xff);
125
+ }
126
+ return Buffer.from(hex);
127
+ }
128
+ /**
129
+ * Get Node.js crypto module
130
+ */
131
+ getCrypto() {
132
+ return require('node:crypto');
133
+ }
134
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * UI Login Authentication Provider
3
+ *
4
+ * Handles form-based UI login authentication using Playwright.
5
+ * Supports TOTP for 2FA and session persistence.
6
+ */
7
+ import { AuthProvider, AuthResult, UILoginAuthConfig, Cookie } from './index.js';
8
+ export declare class UILoginProvider implements AuthProvider<UILoginAuthConfig> {
9
+ readonly type: "ui_login";
10
+ authenticate(config: UILoginAuthConfig): Promise<AuthResult>;
11
+ clear(config: UILoginAuthConfig): Promise<void>;
12
+ validate(config: UILoginAuthConfig): Promise<boolean>;
13
+ private getCacheKey;
14
+ /**
15
+ * Generate TOTP code (simplified version)
16
+ */
17
+ private generateTOTP;
18
+ /**
19
+ * Save session cookies to file
20
+ */
21
+ private saveSession;
22
+ /**
23
+ * Load session cookies from file
24
+ */
25
+ loadSession(filepath: string): Promise<Cookie[]>;
26
+ }