@happyvertical/auth 0.80.0 → 0.80.2

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 (35) hide show
  1. package/dist/chunks/cognito-thQmKf7L.js +124 -0
  2. package/dist/chunks/cognito-thQmKf7L.js.map +1 -0
  3. package/dist/chunks/decode_jwt-BvtACpi_.js +1183 -0
  4. package/dist/chunks/decode_jwt-BvtACpi_.js.map +1 -0
  5. package/dist/chunks/errors-RgVH84_1.js +343 -0
  6. package/dist/chunks/errors-RgVH84_1.js.map +1 -0
  7. package/dist/chunks/github-uNnnVjFZ.js +311 -0
  8. package/dist/chunks/github-uNnnVjFZ.js.map +1 -0
  9. package/dist/chunks/google-C_p8rExJ.js +374 -0
  10. package/dist/chunks/google-C_p8rExJ.js.map +1 -0
  11. package/dist/chunks/kanidm-DTcc6ufi.js +567 -0
  12. package/dist/chunks/kanidm-DTcc6ufi.js.map +1 -0
  13. package/dist/chunks/keycloak-CzPHgI2z.js +632 -0
  14. package/dist/chunks/keycloak-CzPHgI2z.js.map +1 -0
  15. package/dist/chunks/nostr-zrMaYMU-.js +141 -0
  16. package/dist/chunks/nostr-zrMaYMU-.js.map +1 -0
  17. package/dist/cli/claude-context.js +17 -17
  18. package/dist/cli/claude-context.js.map +1 -1
  19. package/dist/index.js +204 -486
  20. package/dist/index.js.map +1 -1
  21. package/package.json +5 -5
  22. package/dist/chunks/cognito-dmypylFX.js +0 -128
  23. package/dist/chunks/cognito-dmypylFX.js.map +0 -1
  24. package/dist/chunks/decode_jwt-D2OK1b8a.js +0 -1395
  25. package/dist/chunks/decode_jwt-D2OK1b8a.js.map +0 -1
  26. package/dist/chunks/github-NSZp5tVm.js +0 -413
  27. package/dist/chunks/github-NSZp5tVm.js.map +0 -1
  28. package/dist/chunks/google-HXk2ctYR.js +0 -483
  29. package/dist/chunks/google-HXk2ctYR.js.map +0 -1
  30. package/dist/chunks/index-BpsMhFXS.js +0 -151
  31. package/dist/chunks/index-BpsMhFXS.js.map +0 -1
  32. package/dist/chunks/kanidm-hkw-YPVF.js +0 -747
  33. package/dist/chunks/kanidm-hkw-YPVF.js.map +0 -1
  34. package/dist/chunks/keycloak-t6JEUeOz.js +0 -871
  35. package/dist/chunks/keycloak-t6JEUeOz.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,499 +1,217 @@
1
- import { loadEnvConfig, ValidationError } from "@happyvertical/utils";
2
- var AuthErrorCode = /* @__PURE__ */ ((AuthErrorCode2) => {
3
- AuthErrorCode2["INVALID_CREDENTIALS"] = "INVALID_CREDENTIALS";
4
- AuthErrorCode2["INVALID_TOKEN"] = "INVALID_TOKEN";
5
- AuthErrorCode2["TOKEN_EXPIRED"] = "TOKEN_EXPIRED";
6
- AuthErrorCode2["INVALID_REFRESH_TOKEN"] = "INVALID_REFRESH_TOKEN";
7
- AuthErrorCode2["SESSION_EXPIRED"] = "SESSION_EXPIRED";
8
- AuthErrorCode2["MFA_REQUIRED"] = "MFA_REQUIRED";
9
- AuthErrorCode2["INVALID_MFA_CODE"] = "INVALID_MFA_CODE";
10
- AuthErrorCode2["ACCESS_DENIED"] = "ACCESS_DENIED";
11
- AuthErrorCode2["INSUFFICIENT_SCOPE"] = "INSUFFICIENT_SCOPE";
12
- AuthErrorCode2["INVALID_ROLE"] = "INVALID_ROLE";
13
- AuthErrorCode2["USER_NOT_FOUND"] = "USER_NOT_FOUND";
14
- AuthErrorCode2["USER_ALREADY_EXISTS"] = "USER_ALREADY_EXISTS";
15
- AuthErrorCode2["USER_DISABLED"] = "USER_DISABLED";
16
- AuthErrorCode2["PROVIDER_ERROR"] = "PROVIDER_ERROR";
17
- AuthErrorCode2["CONFIGURATION_ERROR"] = "CONFIGURATION_ERROR";
18
- AuthErrorCode2["NETWORK_ERROR"] = "NETWORK_ERROR";
19
- AuthErrorCode2["INVALID_STATE"] = "INVALID_STATE";
20
- AuthErrorCode2["INVALID_NONCE"] = "INVALID_NONCE";
21
- AuthErrorCode2["INVALID_GRANT"] = "INVALID_GRANT";
22
- AuthErrorCode2["INVALID_CLIENT"] = "INVALID_CLIENT";
23
- AuthErrorCode2["INVALID_REDIRECT_URI"] = "INVALID_REDIRECT_URI";
24
- AuthErrorCode2["INVALID_SIGNATURE"] = "INVALID_SIGNATURE";
25
- AuthErrorCode2["RELAY_ERROR"] = "RELAY_ERROR";
26
- AuthErrorCode2["CHALLENGE_EXPIRED"] = "CHALLENGE_EXPIRED";
27
- AuthErrorCode2["EXTENSION_NOT_FOUND"] = "EXTENSION_NOT_FOUND";
28
- AuthErrorCode2["INVALID_KEY"] = "INVALID_KEY";
29
- AuthErrorCode2["NOT_IMPLEMENTED"] = "NOT_IMPLEMENTED";
30
- AuthErrorCode2["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
31
- return AuthErrorCode2;
32
- })(AuthErrorCode || {});
33
- class AuthError extends Error {
34
- code;
35
- provider;
36
- context;
37
- constructor(message, code, provider, context) {
38
- super(message);
39
- this.name = "AuthError";
40
- this.code = code;
41
- this.provider = provider;
42
- this.context = context;
43
- if (Error.captureStackTrace) {
44
- Error.captureStackTrace(this, AuthError);
45
- }
46
- }
47
- /**
48
- * Convert error to JSON for logging/serialization.
49
- */
50
- toJSON() {
51
- return {
52
- name: this.name,
53
- message: this.message,
54
- code: this.code,
55
- provider: this.provider,
56
- context: this.context,
57
- stack: this.stack
58
- };
59
- }
60
- }
61
- class InvalidCredentialsError extends AuthError {
62
- constructor(provider, context) {
63
- super(
64
- "Invalid credentials",
65
- "INVALID_CREDENTIALS",
66
- provider,
67
- context
68
- );
69
- this.name = "InvalidCredentialsError";
70
- }
71
- }
72
- class InvalidTokenError extends AuthError {
73
- constructor(message, provider, context) {
74
- super(
75
- message || "Invalid token",
76
- "INVALID_TOKEN",
77
- provider,
78
- context
79
- );
80
- this.name = "InvalidTokenError";
81
- }
82
- }
83
- class TokenExpiredError extends AuthError {
84
- expiredAt;
85
- constructor(provider, expiredAt, context) {
86
- super("Token has expired", "TOKEN_EXPIRED", provider, context);
87
- this.name = "TokenExpiredError";
88
- this.expiredAt = expiredAt;
89
- }
90
- }
91
- class InvalidRefreshTokenError extends AuthError {
92
- constructor(provider, context) {
93
- super(
94
- "Invalid or expired refresh token",
95
- "INVALID_REFRESH_TOKEN",
96
- provider,
97
- context
98
- );
99
- this.name = "InvalidRefreshTokenError";
100
- }
101
- }
102
- class SessionExpiredError extends AuthError {
103
- constructor(provider, context) {
104
- super(
105
- "Session has expired",
106
- "SESSION_EXPIRED",
107
- provider,
108
- context
109
- );
110
- this.name = "SessionExpiredError";
111
- }
112
- }
113
- class MfaRequiredError extends AuthError {
114
- mfaMethods;
115
- constructor(provider, mfaMethods, context) {
116
- super(
117
- "Multi-factor authentication required",
118
- "MFA_REQUIRED",
119
- provider,
120
- context
121
- );
122
- this.name = "MfaRequiredError";
123
- this.mfaMethods = mfaMethods;
124
- }
125
- }
126
- class InvalidMfaCodeError extends AuthError {
127
- constructor(provider, context) {
128
- super(
129
- "Invalid MFA code",
130
- "INVALID_MFA_CODE",
131
- provider,
132
- context
133
- );
134
- this.name = "InvalidMfaCodeError";
135
- }
136
- }
137
- class AccessDeniedError extends AuthError {
138
- constructor(message, provider, context) {
139
- super(
140
- message || "Access denied",
141
- "ACCESS_DENIED",
142
- provider,
143
- context
144
- );
145
- this.name = "AccessDeniedError";
146
- }
147
- }
148
- class InsufficientScopeError extends AuthError {
149
- requiredScopes;
150
- grantedScopes;
151
- constructor(requiredScopes, grantedScopes, provider, context) {
152
- super(
153
- `Insufficient scope. Required: ${requiredScopes?.join(", ") || "unknown"}`,
154
- "INSUFFICIENT_SCOPE",
155
- provider,
156
- context
157
- );
158
- this.name = "InsufficientScopeError";
159
- this.requiredScopes = requiredScopes;
160
- this.grantedScopes = grantedScopes;
161
- }
162
- }
163
- class UserNotFoundError extends AuthError {
164
- userId;
165
- constructor(userId, provider, context) {
166
- super(
167
- userId ? `User not found: ${userId}` : "User not found",
168
- "USER_NOT_FOUND",
169
- provider,
170
- context
171
- );
172
- this.name = "UserNotFoundError";
173
- this.userId = userId;
174
- }
175
- }
176
- class UserAlreadyExistsError extends AuthError {
177
- constructor(identifier, provider, context) {
178
- super(
179
- identifier ? `User already exists: ${identifier}` : "User already exists",
180
- "USER_ALREADY_EXISTS",
181
- provider,
182
- context
183
- );
184
- this.name = "UserAlreadyExistsError";
185
- }
186
- }
187
- class UserDisabledError extends AuthError {
188
- constructor(userId, provider, context) {
189
- super(
190
- userId ? `User is disabled: ${userId}` : "User is disabled",
191
- "USER_DISABLED",
192
- provider,
193
- context
194
- );
195
- this.name = "UserDisabledError";
196
- }
197
- }
198
- class ProviderError extends AuthError {
199
- originalError;
200
- constructor(message, provider, originalError, context) {
201
- super(message, "PROVIDER_ERROR", provider, context);
202
- this.name = "ProviderError";
203
- this.originalError = originalError;
204
- }
205
- }
206
- class ConfigurationError extends AuthError {
207
- constructor(message, provider, context) {
208
- super(message, "CONFIGURATION_ERROR", provider, context);
209
- this.name = "ConfigurationError";
210
- }
211
- }
212
- class NetworkError extends AuthError {
213
- originalError;
214
- constructor(message, provider, originalError, context) {
215
- super(
216
- message || "Network error",
217
- "NETWORK_ERROR",
218
- provider,
219
- context
220
- );
221
- this.name = "NetworkError";
222
- this.originalError = originalError;
223
- }
224
- }
225
- class InvalidStateError extends AuthError {
226
- constructor(provider, context) {
227
- super(
228
- "Invalid or mismatched state parameter",
229
- "INVALID_STATE",
230
- provider,
231
- context
232
- );
233
- this.name = "InvalidStateError";
234
- }
235
- }
236
- class InvalidNonceError extends AuthError {
237
- constructor(provider, context) {
238
- super(
239
- "Invalid or mismatched nonce",
240
- "INVALID_NONCE",
241
- provider,
242
- context
243
- );
244
- this.name = "InvalidNonceError";
245
- }
246
- }
247
- class InvalidGrantError extends AuthError {
248
- constructor(message, provider, context) {
249
- super(
250
- message || "Invalid grant",
251
- "INVALID_GRANT",
252
- provider,
253
- context
254
- );
255
- this.name = "InvalidGrantError";
256
- }
257
- }
258
- class InvalidClientError extends AuthError {
259
- constructor(provider, context) {
260
- super(
261
- "Invalid client credentials",
262
- "INVALID_CLIENT",
263
- provider,
264
- context
265
- );
266
- this.name = "InvalidClientError";
267
- }
268
- }
269
- class InvalidRedirectUriError extends AuthError {
270
- constructor(provider, context) {
271
- super(
272
- "Invalid or mismatched redirect URI",
273
- "INVALID_REDIRECT_URI",
274
- provider,
275
- context
276
- );
277
- this.name = "InvalidRedirectUriError";
278
- }
279
- }
280
- class InvalidSignatureError extends AuthError {
281
- constructor(message, context) {
282
- super(
283
- message || "Invalid event signature",
284
- "INVALID_SIGNATURE",
285
- "nostr",
286
- context
287
- );
288
- this.name = "InvalidSignatureError";
289
- }
290
- }
291
- class RelayError extends AuthError {
292
- relayUrl;
293
- originalError;
294
- constructor(message, relayUrl, originalError, context) {
295
- super(message, "RELAY_ERROR", "nostr", {
296
- ...context,
297
- relayUrl
298
- });
299
- this.name = "RelayError";
300
- this.relayUrl = relayUrl;
301
- this.originalError = originalError;
302
- }
303
- }
304
- class ChallengeExpiredError extends AuthError {
305
- constructor(context) {
306
- super(
307
- "Authentication challenge has expired",
308
- "CHALLENGE_EXPIRED",
309
- "nostr",
310
- context
311
- );
312
- this.name = "ChallengeExpiredError";
313
- }
314
- }
315
- class ExtensionNotFoundError extends AuthError {
316
- constructor(context) {
317
- super(
318
- "NIP-07 browser extension not found. Install nos2x, Alby, or similar.",
319
- "EXTENSION_NOT_FOUND",
320
- "nostr",
321
- context
322
- );
323
- this.name = "ExtensionNotFoundError";
324
- }
325
- }
326
- class InvalidKeyError extends AuthError {
327
- constructor(message, context) {
328
- super(
329
- message || "Invalid key format",
330
- "INVALID_KEY",
331
- "nostr",
332
- context
333
- );
334
- this.name = "InvalidKeyError";
335
- }
336
- }
337
- class NotImplementedError extends AuthError {
338
- operation;
339
- constructor(operation, provider, context) {
340
- super(
341
- `Operation '${operation}' is not supported by this provider`,
342
- "NOT_IMPLEMENTED",
343
- provider,
344
- context
345
- );
346
- this.name = "NotImplementedError";
347
- this.operation = operation;
348
- }
349
- }
350
- function isAuthError(error) {
351
- return error instanceof AuthError;
352
- }
353
- function hasErrorCode(error, code) {
354
- return isAuthError(error) && error.code === code;
355
- }
1
+ import { A as isAuthError, C as RelayError, D as UserDisabledError, E as UserAlreadyExistsError, O as UserNotFoundError, S as ProviderError, T as TokenExpiredError, _ as InvalidStateError, a as ConfigurationError, b as NetworkError, c as InvalidClientError, d as InvalidKeyError, f as InvalidMfaCodeError, g as InvalidSignatureError, h as InvalidRefreshTokenError, i as ChallengeExpiredError, k as hasErrorCode, l as InvalidCredentialsError, m as InvalidRedirectUriError, n as AuthError, o as ExtensionNotFoundError, p as InvalidNonceError, r as AuthErrorCode, s as InsufficientScopeError, t as AccessDeniedError, u as InvalidGrantError, v as InvalidTokenError, w as SessionExpiredError, x as NotImplementedError, y as MfaRequiredError } from "./chunks/errors-RgVH84_1.js";
2
+ import { ValidationError, loadEnvConfig } from "@happyvertical/utils";
3
+ //#region src/shared/factory.ts
4
+ /**
5
+ * @happyvertical/auth - Factory Functions
6
+ *
7
+ * Creates authentication provider instances based on configuration.
8
+ * Supports Keycloak, AWS Cognito, and Nostr providers.
9
+ */
10
+ /**
11
+ * Checks if the options are for Keycloak provider.
12
+ */
356
13
  function isKeycloakOptions(options) {
357
- return options.type === "keycloak";
14
+ return options.type === "keycloak";
358
15
  }
16
+ /**
17
+ * Checks if the options are for Cognito provider.
18
+ */
359
19
  function isCognitoOptions(options) {
360
- return options.type === "cognito";
20
+ return options.type === "cognito";
361
21
  }
22
+ /**
23
+ * Checks if the options are for Nostr provider.
24
+ */
362
25
  function isNostrOptions(options) {
363
- return options.type === "nostr";
26
+ return options.type === "nostr";
364
27
  }
28
+ /**
29
+ * Checks if the options are for Kanidm provider.
30
+ */
365
31
  function isKanidmOptions(options) {
366
- return options.type === "kanidm";
32
+ return options.type === "kanidm";
367
33
  }
34
+ /**
35
+ * Checks if the options are for Google provider.
36
+ */
368
37
  function isGoogleOptions(options) {
369
- return options.type === "google";
38
+ return options.type === "google";
370
39
  }
40
+ /**
41
+ * Checks if the options are for GitHub provider.
42
+ */
371
43
  function isGitHubOptions(options) {
372
- return options.type === "github";
373
- }
44
+ return options.type === "github";
45
+ }
46
+ /**
47
+ * Creates an authentication provider instance based on the provided options.
48
+ *
49
+ * Supports environment variable configuration using the pattern:
50
+ * - HAVE_AUTH_TYPE → provider type ('keycloak' | 'cognito' | 'nostr')
51
+ * - HAVE_AUTH_SERVER_URL → serverUrl (Keycloak)
52
+ * - HAVE_AUTH_REALM → realm (Keycloak)
53
+ * - HAVE_AUTH_CLIENT_ID → clientId
54
+ * - HAVE_AUTH_CLIENT_SECRET → clientSecret
55
+ * - HAVE_AUTH_REDIRECT_URI → redirectUri
56
+ * - HAVE_AUTH_REGION → region (Cognito)
57
+ * - HAVE_AUTH_USER_POOL_ID → userPoolId (Cognito)
58
+ * - HAVE_AUTH_DOMAIN → domain (Cognito)
59
+ * - HAVE_AUTH_RELAYS → relays (Nostr, comma-separated)
60
+ * - HAVE_AUTH_TIMEOUT → timeout (number)
61
+ * - HAVE_AUTH_MAX_RETRIES → maxRetries (number)
62
+ *
63
+ * User-provided options always take precedence over environment variables.
64
+ *
65
+ * @param options - Configuration options for the auth provider
66
+ * @returns Promise resolving to an AuthInterface implementation
67
+ * @throws {ValidationError} When the provider type is unsupported or invalid
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * // Create Keycloak client
72
+ * const auth = await getAuth({
73
+ * type: 'keycloak',
74
+ * serverUrl: 'https://auth.example.com',
75
+ * realm: 'my-realm',
76
+ * clientId: 'my-app'
77
+ * });
78
+ *
79
+ * // Create Cognito client
80
+ * const auth = await getAuth({
81
+ * type: 'cognito',
82
+ * region: 'us-east-1',
83
+ * userPoolId: 'us-east-1_xxx',
84
+ * clientId: 'xxx'
85
+ * });
86
+ *
87
+ * // Create Nostr client
88
+ * const auth = await getAuth({
89
+ * type: 'nostr',
90
+ * relays: ['wss://relay.damus.io', 'wss://nos.lol']
91
+ * });
92
+ *
93
+ * // Use environment variables
94
+ * // Set: HAVE_AUTH_TYPE=keycloak, HAVE_AUTH_SERVER_URL=..., etc.
95
+ * const auth = await getAuth({} as GetAuthOptions);
96
+ * ```
97
+ */
374
98
  async function getAuth(options) {
375
- const configuredOptions = loadEnvConfig(
376
- options,
377
- {
378
- packageName: "auth",
379
- schema: {
380
- type: "string",
381
- serverUrl: "string",
382
- realm: "string",
383
- clientId: "string",
384
- clientSecret: "string",
385
- redirectUri: "string",
386
- scopes: "string",
387
- // Will be comma-separated
388
- region: "string",
389
- userPoolId: "string",
390
- domain: "string",
391
- relays: "string",
392
- // Will be comma-separated
393
- privateKey: "string",
394
- challengeExpiration: "number",
395
- relayTimeout: "number",
396
- timeout: "number",
397
- maxRetries: "number",
398
- // Kanidm-specific
399
- adminUsername: "string",
400
- adminPassword: "string"
401
- },
402
- transform: {
403
- // Transform comma-separated strings to arrays
404
- relays: (value) => value.split(",").map((r) => r.trim()).filter(Boolean),
405
- scopes: (value) => value.split(",").map((s) => s.trim()).filter(Boolean)
406
- }
407
- }
408
- );
409
- options = configuredOptions;
410
- if (isKeycloakOptions(options)) {
411
- const { KeycloakProvider } = await import("./chunks/keycloak-t6JEUeOz.js");
412
- return new KeycloakProvider(options);
413
- }
414
- if (isCognitoOptions(options)) {
415
- const { CognitoProvider } = await import("./chunks/cognito-dmypylFX.js");
416
- return new CognitoProvider(options);
417
- }
418
- if (isNostrOptions(options)) {
419
- const { NostrProvider } = await import("./chunks/index-BpsMhFXS.js");
420
- return new NostrProvider(options);
421
- }
422
- if (isKanidmOptions(options)) {
423
- const { KanidmProvider } = await import("./chunks/kanidm-hkw-YPVF.js");
424
- return new KanidmProvider(options);
425
- }
426
- if (isGoogleOptions(options)) {
427
- const { GoogleProvider } = await import("./chunks/google-HXk2ctYR.js");
428
- return new GoogleProvider(options);
429
- }
430
- if (isGitHubOptions(options)) {
431
- const { GitHubProvider } = await import("./chunks/github-NSZp5tVm.js");
432
- return new GitHubProvider(options);
433
- }
434
- throw new ValidationError("Unsupported auth provider type", {
435
- supportedTypes: [
436
- "keycloak",
437
- "cognito",
438
- "nostr",
439
- "kanidm",
440
- "google",
441
- "github"
442
- ],
443
- providedType: options.type
444
- });
445
- }
99
+ options = loadEnvConfig(options, {
100
+ packageName: "auth",
101
+ schema: {
102
+ type: "string",
103
+ serverUrl: "string",
104
+ realm: "string",
105
+ clientId: "string",
106
+ clientSecret: "string",
107
+ redirectUri: "string",
108
+ scopes: "string",
109
+ region: "string",
110
+ userPoolId: "string",
111
+ domain: "string",
112
+ relays: "string",
113
+ privateKey: "string",
114
+ challengeExpiration: "number",
115
+ relayTimeout: "number",
116
+ timeout: "number",
117
+ maxRetries: "number",
118
+ adminUsername: "string",
119
+ adminPassword: "string"
120
+ },
121
+ transform: {
122
+ relays: (value) => value.split(",").map((r) => r.trim()).filter(Boolean),
123
+ scopes: (value) => value.split(",").map((s) => s.trim()).filter(Boolean)
124
+ }
125
+ });
126
+ if (isKeycloakOptions(options)) {
127
+ const { KeycloakProvider } = await import("./chunks/keycloak-CzPHgI2z.js");
128
+ return new KeycloakProvider(options);
129
+ }
130
+ if (isCognitoOptions(options)) {
131
+ const { CognitoProvider } = await import("./chunks/cognito-thQmKf7L.js");
132
+ return new CognitoProvider(options);
133
+ }
134
+ if (isNostrOptions(options)) {
135
+ const { NostrProvider } = await import("./chunks/nostr-zrMaYMU-.js");
136
+ return new NostrProvider(options);
137
+ }
138
+ if (isKanidmOptions(options)) {
139
+ const { KanidmProvider } = await import("./chunks/kanidm-DTcc6ufi.js");
140
+ return new KanidmProvider(options);
141
+ }
142
+ if (isGoogleOptions(options)) {
143
+ const { GoogleProvider } = await import("./chunks/google-C_p8rExJ.js");
144
+ return new GoogleProvider(options);
145
+ }
146
+ if (isGitHubOptions(options)) {
147
+ const { GitHubProvider } = await import("./chunks/github-uNnnVjFZ.js");
148
+ return new GitHubProvider(options);
149
+ }
150
+ throw new ValidationError("Unsupported auth provider type", {
151
+ supportedTypes: [
152
+ "keycloak",
153
+ "cognito",
154
+ "nostr",
155
+ "kanidm",
156
+ "google",
157
+ "github"
158
+ ],
159
+ providedType: options.type
160
+ });
161
+ }
162
+ /**
163
+ * Auto-detect provider based on available configuration.
164
+ *
165
+ * @param options - Configuration options that may contain provider-specific settings
166
+ * @returns Promise resolving to an AuthInterface based on detected configuration
167
+ * @throws {ValidationError} When no provider can be detected
168
+ *
169
+ * @example
170
+ * ```typescript
171
+ * // Auto-detect Keycloak from serverUrl and realm
172
+ * const auth = await getAuthAuto({
173
+ * serverUrl: 'https://auth.example.com',
174
+ * realm: 'my-realm',
175
+ * clientId: 'my-app'
176
+ * });
177
+ *
178
+ * // Auto-detect Cognito from region and userPoolId
179
+ * const auth = await getAuthAuto({
180
+ * region: 'us-east-1',
181
+ * userPoolId: 'us-east-1_xxx',
182
+ * clientId: 'xxx'
183
+ * });
184
+ *
185
+ * // Auto-detect Nostr from relays
186
+ * const auth = await getAuthAuto({
187
+ * relays: ['wss://relay.damus.io']
188
+ * });
189
+ * ```
190
+ */
446
191
  async function getAuthAuto(options) {
447
- if (options.serverUrl && options.realm) {
448
- return getAuth({ ...options, type: "keycloak" });
449
- }
450
- if (options.region && options.userPoolId) {
451
- return getAuth({ ...options, type: "cognito" });
452
- }
453
- if (options.relays && Array.isArray(options.relays) && options.relays.length > 0) {
454
- return getAuth({ ...options, type: "nostr" });
455
- }
456
- throw new ValidationError(
457
- "Could not auto-detect auth provider from options",
458
- {
459
- hint: 'Please specify a "type" field or provide provider-specific configuration',
460
- supportedTypes: ["keycloak", "cognito", "nostr"],
461
- providedOptions: Object.keys(options)
462
- }
463
- );
464
- }
465
- export {
466
- AccessDeniedError,
467
- AuthError,
468
- AuthErrorCode,
469
- ChallengeExpiredError,
470
- ConfigurationError,
471
- ExtensionNotFoundError,
472
- InsufficientScopeError,
473
- InvalidClientError,
474
- InvalidCredentialsError,
475
- InvalidGrantError,
476
- InvalidKeyError,
477
- InvalidMfaCodeError,
478
- InvalidNonceError,
479
- InvalidRedirectUriError,
480
- InvalidRefreshTokenError,
481
- InvalidSignatureError,
482
- InvalidStateError,
483
- InvalidTokenError,
484
- MfaRequiredError,
485
- NetworkError,
486
- NotImplementedError,
487
- ProviderError,
488
- RelayError,
489
- SessionExpiredError,
490
- TokenExpiredError,
491
- UserAlreadyExistsError,
492
- UserDisabledError,
493
- UserNotFoundError,
494
- getAuth,
495
- getAuthAuto,
496
- hasErrorCode,
497
- isAuthError
498
- };
499
- //# sourceMappingURL=index.js.map
192
+ if (options.serverUrl && options.realm) return getAuth({
193
+ ...options,
194
+ type: "keycloak"
195
+ });
196
+ if (options.region && options.userPoolId) return getAuth({
197
+ ...options,
198
+ type: "cognito"
199
+ });
200
+ if (options.relays && Array.isArray(options.relays) && options.relays.length > 0) return getAuth({
201
+ ...options,
202
+ type: "nostr"
203
+ });
204
+ throw new ValidationError("Could not auto-detect auth provider from options", {
205
+ hint: "Please specify a \"type\" field or provide provider-specific configuration",
206
+ supportedTypes: [
207
+ "keycloak",
208
+ "cognito",
209
+ "nostr"
210
+ ],
211
+ providedOptions: Object.keys(options)
212
+ });
213
+ }
214
+ //#endregion
215
+ export { AccessDeniedError, AuthError, AuthErrorCode, ChallengeExpiredError, ConfigurationError, ExtensionNotFoundError, InsufficientScopeError, InvalidClientError, InvalidCredentialsError, InvalidGrantError, InvalidKeyError, InvalidMfaCodeError, InvalidNonceError, InvalidRedirectUriError, InvalidRefreshTokenError, InvalidSignatureError, InvalidStateError, InvalidTokenError, MfaRequiredError, NetworkError, NotImplementedError, ProviderError, RelayError, SessionExpiredError, TokenExpiredError, UserAlreadyExistsError, UserDisabledError, UserNotFoundError, getAuth, getAuthAuto, hasErrorCode, isAuthError };
216
+
217
+ //# sourceMappingURL=index.js.map