@juspay/neurolink 7.29.0 → 7.29.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 (61) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cli/commands/config.d.ts +3 -3
  3. package/dist/cli/commands/mcp.js +25 -0
  4. package/dist/cli/factories/commandFactory.d.ts +1 -0
  5. package/dist/cli/factories/commandFactory.js +115 -21
  6. package/dist/cli/index.js +8 -0
  7. package/dist/core/factory.js +77 -4
  8. package/dist/factories/providerFactory.js +3 -0
  9. package/dist/factories/providerRegistry.js +2 -2
  10. package/dist/lib/core/factory.js +77 -4
  11. package/dist/lib/factories/providerFactory.js +3 -0
  12. package/dist/lib/factories/providerRegistry.js +2 -2
  13. package/dist/lib/mcp/externalServerManager.js +13 -14
  14. package/dist/lib/mcp/flexibleToolValidator.d.ts +50 -0
  15. package/dist/lib/mcp/flexibleToolValidator.js +161 -0
  16. package/dist/lib/mcp/toolRegistry.d.ts +2 -2
  17. package/dist/lib/mcp/toolRegistry.js +25 -50
  18. package/dist/lib/neurolink.d.ts +299 -4
  19. package/dist/lib/neurolink.js +434 -73
  20. package/dist/lib/providers/amazonBedrock.d.ts +47 -6
  21. package/dist/lib/providers/amazonBedrock.js +282 -23
  22. package/dist/lib/providers/aws/credentialProvider.d.ts +58 -0
  23. package/dist/lib/providers/aws/credentialProvider.js +267 -0
  24. package/dist/lib/providers/aws/credentialTester.d.ts +49 -0
  25. package/dist/lib/providers/aws/credentialTester.js +394 -0
  26. package/dist/lib/providers/googleVertex.js +13 -4
  27. package/dist/lib/proxy/awsProxyIntegration.d.ts +23 -0
  28. package/dist/lib/proxy/awsProxyIntegration.js +285 -0
  29. package/dist/lib/proxy/proxyFetch.d.ts +9 -5
  30. package/dist/lib/proxy/proxyFetch.js +232 -98
  31. package/dist/lib/proxy/utils/noProxyUtils.d.ts +39 -0
  32. package/dist/lib/proxy/utils/noProxyUtils.js +149 -0
  33. package/dist/lib/types/providers.d.ts +43 -0
  34. package/dist/lib/utils/providerConfig.d.ts +1 -0
  35. package/dist/lib/utils/providerConfig.js +2 -1
  36. package/dist/lib/utils/providerHealth.js +123 -5
  37. package/dist/mcp/externalServerManager.js +13 -14
  38. package/dist/mcp/flexibleToolValidator.d.ts +50 -0
  39. package/dist/mcp/flexibleToolValidator.js +161 -0
  40. package/dist/mcp/toolRegistry.d.ts +2 -2
  41. package/dist/mcp/toolRegistry.js +25 -50
  42. package/dist/neurolink.d.ts +299 -4
  43. package/dist/neurolink.js +434 -73
  44. package/dist/providers/amazonBedrock.d.ts +47 -6
  45. package/dist/providers/amazonBedrock.js +282 -23
  46. package/dist/providers/aws/credentialProvider.d.ts +58 -0
  47. package/dist/providers/aws/credentialProvider.js +267 -0
  48. package/dist/providers/aws/credentialTester.d.ts +49 -0
  49. package/dist/providers/aws/credentialTester.js +394 -0
  50. package/dist/providers/googleVertex.js +13 -4
  51. package/dist/proxy/awsProxyIntegration.d.ts +23 -0
  52. package/dist/proxy/awsProxyIntegration.js +285 -0
  53. package/dist/proxy/proxyFetch.d.ts +9 -5
  54. package/dist/proxy/proxyFetch.js +232 -98
  55. package/dist/proxy/utils/noProxyUtils.d.ts +39 -0
  56. package/dist/proxy/utils/noProxyUtils.js +149 -0
  57. package/dist/types/providers.d.ts +43 -0
  58. package/dist/utils/providerConfig.d.ts +1 -0
  59. package/dist/utils/providerConfig.js +2 -1
  60. package/dist/utils/providerHealth.js +123 -5
  61. package/package.json +5 -1
@@ -0,0 +1,267 @@
1
+ /**
2
+ * AWS Credential Provider for NeuroLink
3
+ *
4
+ * Provides 100% compatibility with Bedrock-MCP-Connector authentication patterns
5
+ * by leveraging AWS SDK v3's official defaultProvider credential chain.
6
+ *
7
+ * Supports all 9 AWS credential sources:
8
+ * 1. Environment Variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)
9
+ * 2. AWS Credentials File (~/.aws/credentials)
10
+ * 3. AWS Config File (~/.aws/config)
11
+ * 4. IAM Roles (EC2/ECS/Lambda)
12
+ * 5. AWS SSO
13
+ * 6. STS Assume Role
14
+ * 7. Credential Process
15
+ * 8. Container Credentials
16
+ * 9. Instance Metadata Service (IMDS)
17
+ */
18
+ import { defaultProvider } from "@aws-sdk/credential-provider-node";
19
+ import { fromEnv } from "@aws-sdk/credential-providers";
20
+ import { logger } from "../../utils/logger.js";
21
+ /**
22
+ * AWS Credential Provider class that wraps AWS SDK v3's defaultProvider
23
+ * to provide seamless compatibility with Bedrock-MCP-Connector authentication
24
+ */
25
+ export class AWSCredentialProvider {
26
+ credentialProvider;
27
+ config;
28
+ isInitialized = false;
29
+ lastCredentials = null;
30
+ lastRefresh = 0;
31
+ constructor(config = {}) {
32
+ // Set default configuration values
33
+ this.config = {
34
+ region: config.region || process.env.AWS_REGION || "us-east-1",
35
+ profile: config.profile || process.env.AWS_PROFILE || "default",
36
+ roleArn: config.roleArn || process.env.AWS_ROLE_ARN || "",
37
+ roleSessionName: config.roleSessionName || process.env.AWS_ROLE_SESSION_NAME || "",
38
+ timeout: config.timeout || 30000,
39
+ maxRetries: config.maxRetries || 3,
40
+ maxAttempts: config.maxAttempts || config.maxRetries || 3,
41
+ endpoint: config.endpoint || "",
42
+ enableDebugLogging: config.enableDebugLogging || false,
43
+ };
44
+ // Check if environment variables are set - if so, prioritize them
45
+ const hasEnvCredentials = !!(process.env.AWS_ACCESS_KEY_ID && process.env.AWS_SECRET_ACCESS_KEY);
46
+ if (hasEnvCredentials) {
47
+ // Force use of environment variables when they're explicitly set
48
+ this.credentialProvider = fromEnv();
49
+ if (this.config.enableDebugLogging) {
50
+ logger.debug("AWS Credential Provider: Using environment variables", {
51
+ accessKeyId: process.env.AWS_ACCESS_KEY_ID?.substring(0, 8) + "***",
52
+ hasSessionToken: !!process.env.AWS_SESSION_TOKEN,
53
+ region: this.config.region,
54
+ });
55
+ }
56
+ }
57
+ else {
58
+ // Use default provider chain when no environment variables
59
+ this.credentialProvider = defaultProvider({
60
+ profile: this.config.profile,
61
+ roleArn: this.config.roleArn || undefined,
62
+ roleSessionName: this.config.roleSessionName || undefined,
63
+ timeout: this.config.timeout,
64
+ maxRetries: this.config.maxRetries,
65
+ });
66
+ if (this.config.enableDebugLogging) {
67
+ logger.debug("AWS Credential Provider: Using default provider chain", {
68
+ profile: this.config.profile,
69
+ roleArn: this.config.roleArn ? "***" : "none",
70
+ timeout: this.config.timeout,
71
+ maxRetries: this.config.maxRetries,
72
+ });
73
+ }
74
+ }
75
+ if (this.config.enableDebugLogging) {
76
+ logger.debug("AWS Credential Provider initialized", {
77
+ credentialSource: hasEnvCredentials ? "environment" : "default-chain",
78
+ region: this.config.region,
79
+ profile: this.config.profile,
80
+ roleArn: this.config.roleArn ? "***" : "none",
81
+ timeout: this.config.timeout,
82
+ maxRetries: this.config.maxRetries,
83
+ });
84
+ }
85
+ this.isInitialized = true;
86
+ }
87
+ /**
88
+ * Get AWS credentials using the default provider chain
89
+ * Implements caching to avoid unnecessary credential resolution calls
90
+ */
91
+ async getCredentials() {
92
+ if (this.config.enableDebugLogging) {
93
+ logger.debug("getCredentials() called", {
94
+ isInitialized: this.isInitialized,
95
+ hasLastCredentials: !!this.lastCredentials,
96
+ config: {
97
+ region: this.config.region,
98
+ profile: this.config.profile,
99
+ roleArn: this.config.roleArn ? "***" : "none",
100
+ timeout: this.config.timeout,
101
+ maxRetries: this.config.maxRetries,
102
+ },
103
+ environment: {
104
+ AWS_ACCESS_KEY_ID: process.env.AWS_ACCESS_KEY_ID
105
+ ? process.env.AWS_ACCESS_KEY_ID.substring(0, 8) + "***"
106
+ : "not set",
107
+ AWS_SECRET_ACCESS_KEY: process.env.AWS_SECRET_ACCESS_KEY
108
+ ? "***"
109
+ : "not set",
110
+ AWS_SESSION_TOKEN: process.env.AWS_SESSION_TOKEN ? "set" : "not set",
111
+ AWS_REGION: process.env.AWS_REGION || "not set",
112
+ AWS_PROFILE: process.env.AWS_PROFILE || "not set",
113
+ },
114
+ });
115
+ }
116
+ try {
117
+ if (!this.isInitialized) {
118
+ throw new Error("AWSCredentialProvider not initialized");
119
+ }
120
+ // Check if cached credentials are still valid (within 5 minutes)
121
+ const now = Date.now();
122
+ if (this.lastCredentials && now - this.lastRefresh < 300000) {
123
+ // Check if credentials have expiration and are still valid
124
+ if (!this.lastCredentials.expiration ||
125
+ this.lastCredentials.expiration > new Date(now + 60000)) {
126
+ if (this.config.enableDebugLogging) {
127
+ logger.debug("Using cached AWS credentials", {
128
+ cacheAge: now - this.lastRefresh,
129
+ hasExpiration: !!this.lastCredentials.expiration,
130
+ expiration: this.lastCredentials.expiration?.toISOString(),
131
+ });
132
+ }
133
+ return this.lastCredentials;
134
+ }
135
+ else {
136
+ if (this.config.enableDebugLogging) {
137
+ logger.debug("Cached credentials expired, refreshing", {
138
+ cacheAge: now - this.lastRefresh,
139
+ expiration: this.lastCredentials.expiration?.toISOString(),
140
+ });
141
+ }
142
+ }
143
+ }
144
+ if (this.config.enableDebugLogging) {
145
+ logger.debug("Calling AWS SDK credential provider", {
146
+ providerType: "defaultProvider",
147
+ timeout: this.config.timeout,
148
+ maxRetries: this.config.maxRetries,
149
+ });
150
+ }
151
+ // Resolve credentials using AWS SDK default provider chain
152
+ const credentials = await this.credentialProvider();
153
+ if (this.config.enableDebugLogging) {
154
+ logger.debug("AWS SDK credential provider returned", {
155
+ hasAccessKeyId: !!credentials.accessKeyId,
156
+ accessKeyIdPrefix: credentials.accessKeyId
157
+ ? credentials.accessKeyId.substring(0, 8)
158
+ : "none",
159
+ hasSecretAccessKey: !!credentials.secretAccessKey,
160
+ hasSessionToken: !!credentials.sessionToken,
161
+ hasExpiration: !!credentials.expiration,
162
+ expiration: credentials.expiration?.toISOString() || "none",
163
+ credentialType: credentials.accessKeyId?.startsWith("ASIA")
164
+ ? "temporary"
165
+ : "long-term",
166
+ });
167
+ }
168
+ // Cache the credentials
169
+ this.lastCredentials = credentials;
170
+ this.lastRefresh = now;
171
+ if (this.config.enableDebugLogging) {
172
+ logger.debug("AWS credentials resolved and cached successfully", {
173
+ accessKeyId: credentials.accessKeyId.substring(0, 8) + "***",
174
+ hasSessionToken: !!credentials.sessionToken,
175
+ expiration: credentials.expiration?.toISOString() || "none",
176
+ credentialSource: "AWS SDK defaultProvider chain",
177
+ });
178
+ }
179
+ return credentials;
180
+ }
181
+ catch (error) {
182
+ const errorMessage = error instanceof Error ? error.message : String(error);
183
+ logger.error("Failed to resolve AWS credentials", {
184
+ error: errorMessage,
185
+ errorType: error instanceof Error ? error.constructor.name : "unknown",
186
+ stack: error instanceof Error ? error.stack : "no stack trace",
187
+ config: this.config,
188
+ environment: {
189
+ AWS_ACCESS_KEY_ID: process.env.AWS_ACCESS_KEY_ID ? "set" : "not set",
190
+ AWS_SECRET_ACCESS_KEY: process.env.AWS_SECRET_ACCESS_KEY
191
+ ? "set"
192
+ : "not set",
193
+ AWS_SESSION_TOKEN: process.env.AWS_SESSION_TOKEN ? "set" : "not set",
194
+ AWS_REGION: process.env.AWS_REGION || "not set",
195
+ AWS_PROFILE: process.env.AWS_PROFILE || "not set",
196
+ },
197
+ });
198
+ // Provide helpful error messages for common credential issues
199
+ if (errorMessage.includes("No credentials found")) {
200
+ throw new Error("No AWS credentials found. Please configure one of the following:\n" +
201
+ "1. Environment variables: AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY\n" +
202
+ "2. AWS credentials file: ~/.aws/credentials\n" +
203
+ "3. IAM role (if running on EC2/ECS/Lambda)\n" +
204
+ "4. AWS SSO: aws configure sso\n" +
205
+ "Original error: " +
206
+ errorMessage);
207
+ }
208
+ if (errorMessage.includes("Credential is expired")) {
209
+ throw new Error("AWS credentials have expired. Please refresh your credentials:\n" +
210
+ "1. Re-run aws configure\n" +
211
+ "2. Refresh SSO: aws sso login\n" +
212
+ "3. Assume new role if using temporary credentials\n" +
213
+ "Original error: " +
214
+ errorMessage);
215
+ }
216
+ throw new Error(`AWS credential resolution failed: ${errorMessage}`);
217
+ }
218
+ }
219
+ /**
220
+ * Get the raw credential provider for direct use with AWS SDK clients
221
+ * This allows the credential provider to be passed directly to BedrockRuntimeClient
222
+ */
223
+ getCredentialProvider() {
224
+ if (!this.isInitialized) {
225
+ throw new Error("AWSCredentialProvider not initialized");
226
+ }
227
+ return this.credentialProvider;
228
+ }
229
+ /**
230
+ * Force refresh of cached credentials
231
+ * Useful when credentials may have been updated externally
232
+ */
233
+ async refreshCredentials() {
234
+ this.lastCredentials = null;
235
+ this.lastRefresh = 0;
236
+ return await this.getCredentials();
237
+ }
238
+ /**
239
+ * Check if credentials are currently available without throwing errors
240
+ */
241
+ async isCredentialsAvailable() {
242
+ try {
243
+ await this.getCredentials();
244
+ return true;
245
+ }
246
+ catch {
247
+ return false;
248
+ }
249
+ }
250
+ /**
251
+ * Get configuration information for debugging
252
+ */
253
+ getConfig() {
254
+ return { ...this.config };
255
+ }
256
+ /**
257
+ * Clean up resources and clear cached credentials
258
+ */
259
+ dispose() {
260
+ this.lastCredentials = null;
261
+ this.lastRefresh = 0;
262
+ this.isInitialized = false;
263
+ if (this.config.enableDebugLogging) {
264
+ logger.debug("AWS Credential Provider disposed");
265
+ }
266
+ }
267
+ }
@@ -0,0 +1,49 @@
1
+ /**
2
+ * AWS Credential Testing Utilities for NeuroLink
3
+ *
4
+ * Provides comprehensive validation and debugging capabilities for AWS credentials
5
+ * to ensure compatibility with Bedrock-MCP-Connector authentication patterns.
6
+ */
7
+ import { AWSCredentialProvider } from "./credentialProvider.js";
8
+ import type { CredentialValidationResult, ServiceConnectivityResult } from "../../types/providers.js";
9
+ /**
10
+ * Credential testing and validation utility class
11
+ */
12
+ export declare class CredentialTester {
13
+ /**
14
+ * Validate AWS credentials and detect their source
15
+ */
16
+ static validateCredentials(provider: AWSCredentialProvider): Promise<CredentialValidationResult>;
17
+ /**
18
+ * Test AWS Bedrock service connectivity
19
+ */
20
+ static testBedrockConnectivity(provider: AWSCredentialProvider, region?: string): Promise<ServiceConnectivityResult>;
21
+ /**
22
+ * Perform comprehensive credential and service testing
23
+ */
24
+ static runComprehensiveTest(provider: AWSCredentialProvider, testRegions?: string[]): Promise<{
25
+ credentialValidation: CredentialValidationResult;
26
+ connectivityTests: Array<{
27
+ region: string;
28
+ result: ServiceConnectivityResult;
29
+ }>;
30
+ overallStatus: "success" | "partial" | "failed";
31
+ summary: string;
32
+ }>;
33
+ /**
34
+ * Detect the source of AWS credentials based on credential properties and environment
35
+ */
36
+ private static detectCredentialSource;
37
+ /**
38
+ * Get credential source name for debugging
39
+ */
40
+ static getCredentialSource(provider: AWSCredentialProvider): Promise<string>;
41
+ /**
42
+ * Test credential refresh functionality
43
+ */
44
+ static testCredentialRefresh(provider: AWSCredentialProvider): Promise<{
45
+ refreshSuccessful: boolean;
46
+ refreshTimeMs: number;
47
+ error?: string;
48
+ }>;
49
+ }