@juspay/neurolink 9.31.1 → 9.32.0

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 (162) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/auth/AuthProviderFactory.d.ts +71 -0
  3. package/dist/auth/AuthProviderFactory.js +111 -0
  4. package/dist/auth/AuthProviderRegistry.d.ts +33 -0
  5. package/dist/auth/AuthProviderRegistry.js +190 -0
  6. package/dist/auth/RequestContext.d.ts +23 -0
  7. package/dist/auth/RequestContext.js +78 -0
  8. package/dist/auth/authContext.d.ts +198 -0
  9. package/dist/auth/authContext.js +314 -0
  10. package/dist/auth/errors.d.ts +63 -0
  11. package/dist/auth/errors.js +39 -0
  12. package/dist/auth/index.d.ts +20 -8
  13. package/dist/auth/index.js +35 -7
  14. package/dist/auth/middleware/AuthMiddleware.d.ts +181 -0
  15. package/dist/auth/middleware/AuthMiddleware.js +519 -0
  16. package/dist/auth/middleware/rateLimitByUser.d.ts +282 -0
  17. package/dist/auth/middleware/rateLimitByUser.js +554 -0
  18. package/dist/auth/providers/BaseAuthProvider.d.ts +259 -0
  19. package/dist/auth/providers/BaseAuthProvider.js +723 -0
  20. package/dist/auth/providers/CognitoProvider.d.ts +61 -0
  21. package/dist/auth/providers/CognitoProvider.js +304 -0
  22. package/dist/auth/providers/KeycloakProvider.d.ts +61 -0
  23. package/dist/auth/providers/KeycloakProvider.js +393 -0
  24. package/dist/auth/providers/auth0.d.ts +59 -0
  25. package/dist/auth/providers/auth0.js +274 -0
  26. package/dist/auth/providers/betterAuth.d.ts +51 -0
  27. package/dist/auth/providers/betterAuth.js +182 -0
  28. package/dist/auth/providers/clerk.d.ts +65 -0
  29. package/dist/auth/providers/clerk.js +317 -0
  30. package/dist/auth/providers/custom.d.ts +64 -0
  31. package/dist/auth/providers/custom.js +112 -0
  32. package/dist/auth/providers/firebase.d.ts +63 -0
  33. package/dist/auth/providers/firebase.js +226 -0
  34. package/dist/auth/providers/jwt.d.ts +68 -0
  35. package/dist/auth/providers/jwt.js +212 -0
  36. package/dist/auth/providers/oauth2.d.ts +73 -0
  37. package/dist/auth/providers/oauth2.js +303 -0
  38. package/dist/auth/providers/supabase.d.ts +63 -0
  39. package/dist/auth/providers/supabase.js +259 -0
  40. package/dist/auth/providers/workos.d.ts +61 -0
  41. package/dist/auth/providers/workos.js +284 -0
  42. package/dist/auth/serverBridge.d.ts +14 -0
  43. package/dist/auth/serverBridge.js +25 -0
  44. package/dist/auth/sessionManager.d.ts +142 -0
  45. package/dist/auth/sessionManager.js +437 -0
  46. package/dist/cli/commands/authProviders.d.ts +43 -0
  47. package/dist/cli/commands/authProviders.js +399 -0
  48. package/dist/cli/commands/proxy.js +4 -2
  49. package/dist/cli/factories/authCommandFactory.d.ts +23 -5
  50. package/dist/cli/factories/authCommandFactory.js +108 -5
  51. package/dist/cli/parser.js +1 -1
  52. package/dist/client/auth/AuthProviderFactory.js +111 -0
  53. package/dist/client/auth/AuthProviderRegistry.js +190 -0
  54. package/dist/client/auth/RequestContext.js +78 -0
  55. package/dist/client/auth/accountPool.js +178 -0
  56. package/dist/client/auth/authContext.js +314 -0
  57. package/dist/client/auth/errors.js +39 -0
  58. package/dist/client/auth/index.js +61 -0
  59. package/dist/client/auth/middleware/AuthMiddleware.js +519 -0
  60. package/dist/client/auth/middleware/rateLimitByUser.js +554 -0
  61. package/dist/client/auth/providers/BaseAuthProvider.js +723 -0
  62. package/dist/client/auth/providers/CognitoProvider.js +304 -0
  63. package/dist/client/auth/providers/KeycloakProvider.js +393 -0
  64. package/dist/client/auth/providers/auth0.js +274 -0
  65. package/dist/client/auth/providers/betterAuth.js +182 -0
  66. package/dist/client/auth/providers/clerk.js +317 -0
  67. package/dist/client/auth/providers/custom.js +112 -0
  68. package/dist/client/auth/providers/firebase.js +226 -0
  69. package/dist/client/auth/providers/jwt.js +212 -0
  70. package/dist/client/auth/providers/oauth2.js +303 -0
  71. package/dist/client/auth/providers/supabase.js +259 -0
  72. package/dist/client/auth/providers/workos.js +284 -0
  73. package/dist/client/auth/serverBridge.js +25 -0
  74. package/dist/client/auth/sessionManager.js +437 -0
  75. package/dist/client/core/infrastructure/baseRegistry.js +5 -1
  76. package/dist/client/index.js +25 -0
  77. package/dist/client/mcp/toolRegistry.js +11 -1
  78. package/dist/client/neurolink.js +218 -0
  79. package/dist/client/rag/ChunkerRegistry.js +2 -2
  80. package/dist/client/rag/metadata/MetadataExtractorRegistry.js +2 -2
  81. package/dist/client/rag/reranker/RerankerRegistry.js +2 -2
  82. package/dist/client/server/routes/agentRoutes.js +20 -2
  83. package/dist/client/types/authTypes.js +2 -1
  84. package/dist/core/infrastructure/baseRegistry.d.ts +3 -1
  85. package/dist/core/infrastructure/baseRegistry.js +5 -1
  86. package/dist/index.d.ts +1 -0
  87. package/dist/index.js +25 -0
  88. package/dist/lib/auth/AuthProviderFactory.d.ts +71 -0
  89. package/dist/lib/auth/AuthProviderFactory.js +112 -0
  90. package/dist/lib/auth/AuthProviderRegistry.d.ts +33 -0
  91. package/dist/lib/auth/AuthProviderRegistry.js +191 -0
  92. package/dist/lib/auth/RequestContext.d.ts +23 -0
  93. package/dist/lib/auth/RequestContext.js +79 -0
  94. package/dist/lib/auth/authContext.d.ts +198 -0
  95. package/dist/lib/auth/authContext.js +315 -0
  96. package/dist/lib/auth/errors.d.ts +63 -0
  97. package/dist/lib/auth/errors.js +40 -0
  98. package/dist/lib/auth/index.d.ts +20 -8
  99. package/dist/lib/auth/index.js +35 -7
  100. package/dist/lib/auth/middleware/AuthMiddleware.d.ts +181 -0
  101. package/dist/lib/auth/middleware/AuthMiddleware.js +520 -0
  102. package/dist/lib/auth/middleware/rateLimitByUser.d.ts +282 -0
  103. package/dist/lib/auth/middleware/rateLimitByUser.js +555 -0
  104. package/dist/lib/auth/providers/BaseAuthProvider.d.ts +259 -0
  105. package/dist/lib/auth/providers/BaseAuthProvider.js +724 -0
  106. package/dist/lib/auth/providers/CognitoProvider.d.ts +61 -0
  107. package/dist/lib/auth/providers/CognitoProvider.js +305 -0
  108. package/dist/lib/auth/providers/KeycloakProvider.d.ts +61 -0
  109. package/dist/lib/auth/providers/KeycloakProvider.js +394 -0
  110. package/dist/lib/auth/providers/auth0.d.ts +59 -0
  111. package/dist/lib/auth/providers/auth0.js +275 -0
  112. package/dist/lib/auth/providers/betterAuth.d.ts +51 -0
  113. package/dist/lib/auth/providers/betterAuth.js +183 -0
  114. package/dist/lib/auth/providers/clerk.d.ts +65 -0
  115. package/dist/lib/auth/providers/clerk.js +318 -0
  116. package/dist/lib/auth/providers/custom.d.ts +64 -0
  117. package/dist/lib/auth/providers/custom.js +113 -0
  118. package/dist/lib/auth/providers/firebase.d.ts +63 -0
  119. package/dist/lib/auth/providers/firebase.js +227 -0
  120. package/dist/lib/auth/providers/jwt.d.ts +68 -0
  121. package/dist/lib/auth/providers/jwt.js +213 -0
  122. package/dist/lib/auth/providers/oauth2.d.ts +73 -0
  123. package/dist/lib/auth/providers/oauth2.js +304 -0
  124. package/dist/lib/auth/providers/supabase.d.ts +63 -0
  125. package/dist/lib/auth/providers/supabase.js +260 -0
  126. package/dist/lib/auth/providers/workos.d.ts +61 -0
  127. package/dist/lib/auth/providers/workos.js +285 -0
  128. package/dist/lib/auth/serverBridge.d.ts +14 -0
  129. package/dist/lib/auth/serverBridge.js +26 -0
  130. package/dist/lib/auth/sessionManager.d.ts +142 -0
  131. package/dist/lib/auth/sessionManager.js +438 -0
  132. package/dist/lib/core/infrastructure/baseRegistry.d.ts +3 -1
  133. package/dist/lib/core/infrastructure/baseRegistry.js +5 -1
  134. package/dist/lib/index.d.ts +1 -0
  135. package/dist/lib/index.js +25 -0
  136. package/dist/lib/mcp/toolRegistry.js +11 -1
  137. package/dist/lib/neurolink.d.ts +42 -1
  138. package/dist/lib/neurolink.js +218 -0
  139. package/dist/lib/rag/ChunkerRegistry.js +2 -2
  140. package/dist/lib/rag/metadata/MetadataExtractorRegistry.js +2 -2
  141. package/dist/lib/rag/reranker/RerankerRegistry.js +2 -2
  142. package/dist/lib/server/routes/agentRoutes.js +20 -2
  143. package/dist/lib/types/authTypes.d.ts +937 -1
  144. package/dist/lib/types/authTypes.js +2 -1
  145. package/dist/lib/types/configTypes.d.ts +46 -0
  146. package/dist/lib/types/generateTypes.d.ts +6 -0
  147. package/dist/lib/types/index.d.ts +1 -0
  148. package/dist/lib/types/streamTypes.d.ts +6 -0
  149. package/dist/mcp/toolRegistry.js +11 -1
  150. package/dist/neurolink.d.ts +42 -1
  151. package/dist/neurolink.js +218 -0
  152. package/dist/rag/ChunkerRegistry.js +2 -2
  153. package/dist/rag/metadata/MetadataExtractorRegistry.js +2 -2
  154. package/dist/rag/reranker/RerankerRegistry.js +2 -2
  155. package/dist/server/routes/agentRoutes.js +20 -2
  156. package/dist/types/authTypes.d.ts +937 -1
  157. package/dist/types/authTypes.js +2 -1
  158. package/dist/types/configTypes.d.ts +46 -0
  159. package/dist/types/generateTypes.d.ts +6 -0
  160. package/dist/types/index.d.ts +1 -0
  161. package/dist/types/streamTypes.d.ts +6 -0
  162. package/package.json +2 -1
package/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ## [9.32.0](https://github.com/juspay/neurolink/compare/v9.31.2...v9.32.0) (2026-03-25)
2
+
3
+ ### Features
4
+
5
+ - **(auth):** add authentication providers system with 12 providers, middleware, RBAC, and session management ([97dabd9](https://github.com/juspay/neurolink/commit/97dabd9f58b3506d13faa626359b5c9e0b1cadd9))
6
+
7
+ ## [9.31.2](https://github.com/juspay/neurolink/compare/v9.31.1...v9.31.2) (2026-03-25)
8
+
9
+ ### Bug Fixes
10
+
11
+ - **(proxy):** skip launchd guard when launched by launchd itself ([183996d](https://github.com/juspay/neurolink/commit/183996d40e6c718d87f1a0d3ccfc6107328cd728))
12
+
1
13
  ## [9.31.1](https://github.com/juspay/neurolink/compare/v9.31.0...v9.31.1) (2026-03-25)
2
14
 
3
15
  ### Bug Fixes
@@ -0,0 +1,71 @@
1
+ /**
2
+ * AuthProviderFactory - Static factory for authentication providers
3
+ *
4
+ * Matches the ProviderFactory pattern: all-static class, no BaseFactory
5
+ * extension, no singleton instance. Providers are registered by
6
+ * AuthProviderRegistry using dynamic imports to avoid circular dependencies.
7
+ */
8
+ import type { AuthProviderConfig, AuthProviderMetadata, MastraAuthProvider } from "../types/authTypes.js";
9
+ type AuthProviderConstructor = (config: AuthProviderConfig) => Promise<MastraAuthProvider>;
10
+ /**
11
+ * AuthProviderFactory - Creates authentication provider instances
12
+ *
13
+ * Pure static factory with no hardcoded imports. All providers are
14
+ * registered dynamically by AuthProviderRegistry to avoid circular
15
+ * dependencies and enable lazy loading.
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * // Create a provider (after AuthProviderRegistry.registerAllProviders())
20
+ * const provider = await AuthProviderFactory.createProvider("auth0", {
21
+ * type: "auth0",
22
+ * domain: "your-tenant.auth0.com",
23
+ * clientId: "your-client-id",
24
+ * });
25
+ * ```
26
+ */
27
+ export declare class AuthProviderFactory {
28
+ private static readonly providers;
29
+ private static readonly aliasMap;
30
+ /**
31
+ * Register a provider with the factory
32
+ */
33
+ static registerProvider(type: string, factory: AuthProviderConstructor, aliases?: string[], metadata?: AuthProviderMetadata): void;
34
+ /**
35
+ * Create a provider instance
36
+ */
37
+ static createProvider(typeOrAlias: string, config: AuthProviderConfig): Promise<MastraAuthProvider>;
38
+ /**
39
+ * Check if a provider is registered
40
+ */
41
+ static hasProvider(typeOrAlias: string): boolean;
42
+ /**
43
+ * Get list of available provider types (excludes aliases)
44
+ */
45
+ static getAvailableProviders(): string[];
46
+ /**
47
+ * Get provider metadata
48
+ */
49
+ static getProviderMetadata(typeOrAlias: string): AuthProviderMetadata | undefined;
50
+ /**
51
+ * Get all registered providers with their metadata
52
+ */
53
+ static getAllProviderInfo(): Array<{
54
+ type: string;
55
+ aliases: string[];
56
+ metadata?: AuthProviderMetadata;
57
+ }>;
58
+ /**
59
+ * Clear all registrations (for testing)
60
+ */
61
+ static clearRegistrations(): void;
62
+ /**
63
+ * Resolve an alias to its canonical provider type
64
+ */
65
+ private static resolveType;
66
+ }
67
+ /**
68
+ * Create an auth provider using the factory
69
+ */
70
+ export declare function createAuthProvider(type: string, config: AuthProviderConfig): Promise<MastraAuthProvider>;
71
+ export {};
@@ -0,0 +1,111 @@
1
+ /**
2
+ * AuthProviderFactory - Static factory for authentication providers
3
+ *
4
+ * Matches the ProviderFactory pattern: all-static class, no BaseFactory
5
+ * extension, no singleton instance. Providers are registered by
6
+ * AuthProviderRegistry using dynamic imports to avoid circular dependencies.
7
+ */
8
+ import { logger } from "../utils/logger.js";
9
+ import { AuthError } from "./errors.js";
10
+ // =============================================================================
11
+ // FACTORY IMPLEMENTATION
12
+ // =============================================================================
13
+ /**
14
+ * AuthProviderFactory - Creates authentication provider instances
15
+ *
16
+ * Pure static factory with no hardcoded imports. All providers are
17
+ * registered dynamically by AuthProviderRegistry to avoid circular
18
+ * dependencies and enable lazy loading.
19
+ *
20
+ * @example
21
+ * ```typescript
22
+ * // Create a provider (after AuthProviderRegistry.registerAllProviders())
23
+ * const provider = await AuthProviderFactory.createProvider("auth0", {
24
+ * type: "auth0",
25
+ * domain: "your-tenant.auth0.com",
26
+ * clientId: "your-client-id",
27
+ * });
28
+ * ```
29
+ */
30
+ export class AuthProviderFactory {
31
+ static providers = new Map();
32
+ static aliasMap = new Map();
33
+ /**
34
+ * Register a provider with the factory
35
+ */
36
+ static registerProvider(type, factory, aliases = [], metadata) {
37
+ AuthProviderFactory.providers.set(type, { factory, aliases, metadata });
38
+ for (const alias of aliases) {
39
+ AuthProviderFactory.aliasMap.set(alias.toLowerCase(), type);
40
+ }
41
+ logger.debug(`Registered auth provider: ${type}`);
42
+ }
43
+ /**
44
+ * Create a provider instance
45
+ */
46
+ static async createProvider(typeOrAlias, config) {
47
+ const resolvedType = AuthProviderFactory.resolveType(typeOrAlias);
48
+ const registration = AuthProviderFactory.providers.get(resolvedType);
49
+ if (!registration) {
50
+ throw AuthError.create("PROVIDER_NOT_FOUND", `Auth provider not found: ${typeOrAlias}. Available: ${AuthProviderFactory.getAvailableProviders().join(", ")}`);
51
+ }
52
+ try {
53
+ return await registration.factory(config);
54
+ }
55
+ catch (error) {
56
+ throw AuthError.create("CREATION_FAILED", `Failed to create auth provider ${typeOrAlias}: ${error instanceof Error ? error.message : String(error)}`, { cause: error instanceof Error ? error : undefined });
57
+ }
58
+ }
59
+ /**
60
+ * Check if a provider is registered
61
+ */
62
+ static hasProvider(typeOrAlias) {
63
+ return (AuthProviderFactory.providers.has(typeOrAlias) ||
64
+ AuthProviderFactory.aliasMap.has(typeOrAlias.toLowerCase()));
65
+ }
66
+ /**
67
+ * Get list of available provider types (excludes aliases)
68
+ */
69
+ static getAvailableProviders() {
70
+ return Array.from(AuthProviderFactory.providers.keys());
71
+ }
72
+ /**
73
+ * Get provider metadata
74
+ */
75
+ static getProviderMetadata(typeOrAlias) {
76
+ const resolvedType = AuthProviderFactory.resolveType(typeOrAlias);
77
+ return AuthProviderFactory.providers.get(resolvedType)?.metadata;
78
+ }
79
+ /**
80
+ * Get all registered providers with their metadata
81
+ */
82
+ static getAllProviderInfo() {
83
+ return Array.from(AuthProviderFactory.providers.entries()).map(([type, reg]) => ({
84
+ type,
85
+ aliases: reg.aliases,
86
+ metadata: reg.metadata,
87
+ }));
88
+ }
89
+ /**
90
+ * Clear all registrations (for testing)
91
+ */
92
+ static clearRegistrations() {
93
+ AuthProviderFactory.providers.clear();
94
+ AuthProviderFactory.aliasMap.clear();
95
+ }
96
+ /**
97
+ * Resolve an alias to its canonical provider type
98
+ */
99
+ static resolveType(typeOrAlias) {
100
+ return (AuthProviderFactory.aliasMap.get(typeOrAlias.toLowerCase()) || typeOrAlias);
101
+ }
102
+ }
103
+ // =============================================================================
104
+ // CONVENIENCE EXPORTS
105
+ // =============================================================================
106
+ /**
107
+ * Create an auth provider using the factory
108
+ */
109
+ export async function createAuthProvider(type, config) {
110
+ return AuthProviderFactory.createProvider(type, config);
111
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * AuthProviderRegistry - Static one-shot registry for authentication providers
3
+ *
4
+ * Matches the ProviderRegistry pattern: static class with a single
5
+ * `registerAllProviders()` entry point that registers all 11 auth
6
+ * providers with AuthProviderFactory using dynamic imports.
7
+ */
8
+ /**
9
+ * AuthProviderRegistry - registers all auth providers with the factory
10
+ *
11
+ * Call `AuthProviderRegistry.registerAllProviders()` once during
12
+ * application startup. The method is idempotent and concurrency-safe.
13
+ */
14
+ export declare class AuthProviderRegistry {
15
+ private static registered;
16
+ private static registrationPromise;
17
+ /**
18
+ * Register all auth providers with the factory
19
+ */
20
+ static registerAllProviders(): Promise<void>;
21
+ /**
22
+ * Internal registration implementation
23
+ */
24
+ private static _doRegister;
25
+ /**
26
+ * Check if providers are registered
27
+ */
28
+ static isRegistered(): boolean;
29
+ /**
30
+ * Clear registrations (for testing)
31
+ */
32
+ static clearRegistrations(): void;
33
+ }
@@ -0,0 +1,190 @@
1
+ /**
2
+ * AuthProviderRegistry - Static one-shot registry for authentication providers
3
+ *
4
+ * Matches the ProviderRegistry pattern: static class with a single
5
+ * `registerAllProviders()` entry point that registers all 11 auth
6
+ * providers with AuthProviderFactory using dynamic imports.
7
+ */
8
+ import { logger } from "../utils/logger.js";
9
+ import { AuthProviderFactory } from "./AuthProviderFactory.js";
10
+ /**
11
+ * Narrow `AuthProviderConfig` to a specific provider variant.
12
+ *
13
+ * Each factory lambda calls this to assert the config is the expected
14
+ * variant — safe because the factory is only ever invoked with a config
15
+ * whose `type` matches the registered provider key.
16
+ */
17
+ function narrowConfig(config) {
18
+ return config;
19
+ }
20
+ /**
21
+ * AuthProviderRegistry - registers all auth providers with the factory
22
+ *
23
+ * Call `AuthProviderRegistry.registerAllProviders()` once during
24
+ * application startup. The method is idempotent and concurrency-safe.
25
+ */
26
+ export class AuthProviderRegistry {
27
+ static registered = false;
28
+ static registrationPromise = null;
29
+ /**
30
+ * Register all auth providers with the factory
31
+ */
32
+ static async registerAllProviders() {
33
+ if (AuthProviderRegistry.registered) {
34
+ return;
35
+ }
36
+ if (AuthProviderRegistry.registrationPromise) {
37
+ return AuthProviderRegistry.registrationPromise;
38
+ }
39
+ AuthProviderRegistry.registrationPromise =
40
+ AuthProviderRegistry._doRegister();
41
+ try {
42
+ await AuthProviderRegistry.registrationPromise;
43
+ AuthProviderRegistry.registered = true;
44
+ }
45
+ catch (error) {
46
+ AuthProviderRegistry.registrationPromise = null;
47
+ throw error;
48
+ }
49
+ }
50
+ /**
51
+ * Internal registration implementation
52
+ */
53
+ static async _doRegister() {
54
+ // Auth0 Provider
55
+ AuthProviderFactory.registerProvider("auth0", async (config) => {
56
+ const { Auth0Provider } = await import("./providers/auth0.js");
57
+ return new Auth0Provider(narrowConfig(config));
58
+ }, ["auth0-jwt", "auth0-oauth"], {
59
+ type: "auth0",
60
+ name: "Auth0",
61
+ description: "Auth0 identity platform integration",
62
+ documentation: "https://auth0.com/docs",
63
+ aliases: ["auth0-jwt", "auth0-oauth"],
64
+ });
65
+ // Clerk Provider
66
+ AuthProviderFactory.registerProvider("clerk", async (config) => {
67
+ const { ClerkProvider } = await import("./providers/clerk.js");
68
+ return new ClerkProvider(narrowConfig(config));
69
+ }, ["clerk-jwt"], {
70
+ type: "clerk",
71
+ name: "Clerk",
72
+ description: "Clerk authentication platform integration",
73
+ documentation: "https://clerk.com/docs",
74
+ aliases: ["clerk-jwt"],
75
+ });
76
+ // Firebase Provider
77
+ AuthProviderFactory.registerProvider("firebase", async (config) => {
78
+ const { FirebaseAuthProvider } = await import("./providers/firebase.js");
79
+ return new FirebaseAuthProvider(narrowConfig(config));
80
+ }, ["firebase-auth", "google-firebase"], {
81
+ type: "firebase",
82
+ name: "Firebase",
83
+ description: "Firebase Authentication integration",
84
+ documentation: "https://firebase.google.com/docs/auth",
85
+ aliases: ["firebase-auth", "google-firebase"],
86
+ });
87
+ // Supabase Provider
88
+ AuthProviderFactory.registerProvider("supabase", async (config) => {
89
+ const { SupabaseAuthProvider } = await import("./providers/supabase.js");
90
+ return new SupabaseAuthProvider(narrowConfig(config));
91
+ }, ["supabase-auth"], {
92
+ type: "supabase",
93
+ name: "Supabase",
94
+ description: "Supabase Auth integration",
95
+ documentation: "https://supabase.com/docs/guides/auth",
96
+ aliases: ["supabase-auth"],
97
+ });
98
+ // AWS Cognito Provider
99
+ AuthProviderFactory.registerProvider("cognito", async (config) => {
100
+ const { CognitoProvider } = await import("./providers/CognitoProvider.js");
101
+ return new CognitoProvider(config);
102
+ }, ["aws-cognito", "amazon-cognito"], {
103
+ type: "cognito",
104
+ name: "AWS Cognito",
105
+ description: "Amazon Cognito User Pools integration",
106
+ documentation: "https://docs.aws.amazon.com/cognito",
107
+ aliases: ["aws-cognito", "amazon-cognito"],
108
+ });
109
+ // Keycloak Provider
110
+ AuthProviderFactory.registerProvider("keycloak", async (config) => {
111
+ const { KeycloakProvider } = await import("./providers/KeycloakProvider.js");
112
+ return new KeycloakProvider(config);
113
+ }, ["keycloak-oidc"], {
114
+ type: "keycloak",
115
+ name: "Keycloak",
116
+ description: "Keycloak OpenID Connect integration",
117
+ documentation: "https://www.keycloak.org/documentation",
118
+ aliases: ["keycloak-oidc"],
119
+ });
120
+ // Better Auth Provider
121
+ AuthProviderFactory.registerProvider("better-auth", async (config) => {
122
+ const { BetterAuthProvider } = await import("./providers/betterAuth.js");
123
+ return new BetterAuthProvider(narrowConfig(config));
124
+ }, ["betterauth", "better_auth"], {
125
+ type: "better-auth",
126
+ name: "Better Auth",
127
+ description: "Self-hosted open-source authentication solution",
128
+ documentation: "https://better-auth.com/docs",
129
+ aliases: ["betterauth", "better_auth"],
130
+ });
131
+ // WorkOS Provider
132
+ AuthProviderFactory.registerProvider("workos", async (config) => {
133
+ const { WorkOSProvider } = await import("./providers/workos.js");
134
+ return new WorkOSProvider(narrowConfig(config));
135
+ }, ["workos-sso", "work-os"], {
136
+ type: "workos",
137
+ name: "WorkOS",
138
+ description: "Enterprise SSO and user management",
139
+ documentation: "https://workos.com/docs",
140
+ aliases: ["workos-sso", "work-os"],
141
+ });
142
+ // OAuth2 Provider
143
+ AuthProviderFactory.registerProvider("oauth2", async (config) => {
144
+ const { OAuth2Provider } = await import("./providers/oauth2.js");
145
+ return new OAuth2Provider(narrowConfig(config));
146
+ }, ["oauth", "oidc", "openid-connect"], {
147
+ type: "oauth2",
148
+ name: "OAuth2",
149
+ description: "Generic OAuth2/OIDC provider with JWKS and userinfo support",
150
+ documentation: "https://oauth.net/2/",
151
+ aliases: ["oauth", "oidc", "openid-connect"],
152
+ });
153
+ // JWT Provider
154
+ AuthProviderFactory.registerProvider("jwt", async (config) => {
155
+ const { JWTProvider } = await import("./providers/jwt.js");
156
+ return new JWTProvider(narrowConfig(config));
157
+ }, ["jwt-auth", "jwt-token"], {
158
+ type: "jwt",
159
+ name: "JWT",
160
+ description: "Generic JWT token validation with symmetric/asymmetric keys",
161
+ documentation: "https://jwt.io/",
162
+ aliases: ["jwt-auth", "jwt-token"],
163
+ });
164
+ // Custom Provider
165
+ AuthProviderFactory.registerProvider("custom", async (config) => {
166
+ const { CustomAuthProvider } = await import("./providers/custom.js");
167
+ return new CustomAuthProvider(narrowConfig(config));
168
+ }, ["custom-auth"], {
169
+ type: "custom",
170
+ name: "Custom",
171
+ description: "Custom authentication with user-provided validation logic",
172
+ aliases: ["custom-auth"],
173
+ });
174
+ logger.debug("All auth providers registered");
175
+ }
176
+ /**
177
+ * Check if providers are registered
178
+ */
179
+ static isRegistered() {
180
+ return AuthProviderRegistry.registered;
181
+ }
182
+ /**
183
+ * Clear registrations (for testing)
184
+ */
185
+ static clearRegistrations() {
186
+ AuthProviderRegistry.registered = false;
187
+ AuthProviderRegistry.registrationPromise = null;
188
+ AuthProviderFactory.clearRegistrations();
189
+ }
190
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Type-safe Map wrapper for request-scoped context.
3
+ * Flows from auth middleware through generate/stream/tools/memory.
4
+ * Reserved keys (prefixed neurolink__) cannot be overridden by client code.
5
+ */
6
+ export declare const NEUROLINK_RESOURCE_ID_KEY = "neurolink__resourceId";
7
+ export declare const NEUROLINK_THREAD_ID_KEY = "neurolink__threadId";
8
+ export declare class RequestContext<T extends Record<string, unknown> = Record<string, unknown>> {
9
+ private registry;
10
+ constructor(initial?: Partial<T> | [string, unknown][]);
11
+ set<K extends string>(key: K, value: unknown): void;
12
+ get<K extends string>(key: K): unknown;
13
+ has(key: string): boolean;
14
+ delete(key: string): boolean;
15
+ get size(): number;
16
+ /**
17
+ * Merge client-provided values, but SKIP reserved keys that are already set.
18
+ * This prevents clients from overriding auth middleware values.
19
+ */
20
+ mergeClientContext(clientContext: Record<string, unknown>): void;
21
+ toJSON(): Record<string, unknown>;
22
+ private isSerializable;
23
+ }
@@ -0,0 +1,78 @@
1
+ // src/lib/auth/RequestContext.ts
2
+ /**
3
+ * Type-safe Map wrapper for request-scoped context.
4
+ * Flows from auth middleware through generate/stream/tools/memory.
5
+ * Reserved keys (prefixed neurolink__) cannot be overridden by client code.
6
+ */
7
+ export const NEUROLINK_RESOURCE_ID_KEY = "neurolink__resourceId";
8
+ export const NEUROLINK_THREAD_ID_KEY = "neurolink__threadId";
9
+ const RESERVED_PREFIX = "neurolink__";
10
+ export class RequestContext {
11
+ registry = new Map();
12
+ constructor(initial) {
13
+ if (Array.isArray(initial)) {
14
+ for (const [key, value] of initial) {
15
+ this.registry.set(key, value);
16
+ }
17
+ }
18
+ else if (initial) {
19
+ for (const [key, value] of Object.entries(initial)) {
20
+ this.registry.set(key, value);
21
+ }
22
+ }
23
+ }
24
+ set(key, value) {
25
+ this.registry.set(key, value);
26
+ }
27
+ get(key) {
28
+ return this.registry.get(key);
29
+ }
30
+ has(key) {
31
+ return this.registry.has(key);
32
+ }
33
+ delete(key) {
34
+ return this.registry.delete(key);
35
+ }
36
+ get size() {
37
+ return this.registry.size;
38
+ }
39
+ /**
40
+ * Merge client-provided values, but SKIP reserved keys that are already set.
41
+ * This prevents clients from overriding auth middleware values.
42
+ */
43
+ mergeClientContext(clientContext) {
44
+ for (const [key, value] of Object.entries(clientContext)) {
45
+ if (key.startsWith(RESERVED_PREFIX) && this.registry.has(key)) {
46
+ continue; // Server-set reserved keys cannot be overridden
47
+ }
48
+ if (!this.registry.has(key)) {
49
+ this.registry.set(key, value);
50
+ }
51
+ }
52
+ }
53
+ toJSON() {
54
+ const result = {};
55
+ for (const [key, value] of this.registry.entries()) {
56
+ if (this.isSerializable(value)) {
57
+ result[key] = value;
58
+ }
59
+ }
60
+ return result;
61
+ }
62
+ isSerializable(value) {
63
+ if (value === null || value === undefined) {
64
+ return true;
65
+ }
66
+ const type = typeof value;
67
+ if (type === "function" || type === "symbol") {
68
+ return false;
69
+ }
70
+ try {
71
+ JSON.stringify(value);
72
+ return true;
73
+ }
74
+ catch {
75
+ return false;
76
+ }
77
+ }
78
+ }