@juspay/neurolink 9.14.0 → 9.15.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 (60) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +15 -15
  3. package/dist/auth/anthropicOAuth.d.ts +377 -0
  4. package/dist/auth/anthropicOAuth.js +914 -0
  5. package/dist/auth/index.d.ts +20 -0
  6. package/dist/auth/index.js +29 -0
  7. package/dist/auth/tokenStore.d.ts +225 -0
  8. package/dist/auth/tokenStore.js +521 -0
  9. package/dist/cli/commands/auth.d.ts +50 -0
  10. package/dist/cli/commands/auth.js +1115 -0
  11. package/dist/cli/factories/authCommandFactory.d.ts +52 -0
  12. package/dist/cli/factories/authCommandFactory.js +146 -0
  13. package/dist/cli/factories/commandFactory.d.ts +6 -0
  14. package/dist/cli/factories/commandFactory.js +92 -2
  15. package/dist/cli/parser.js +11 -2
  16. package/dist/constants/enums.d.ts +20 -0
  17. package/dist/constants/enums.js +30 -0
  18. package/dist/constants/index.d.ts +3 -1
  19. package/dist/constants/index.js +11 -1
  20. package/dist/index.d.ts +1 -1
  21. package/dist/lib/auth/anthropicOAuth.d.ts +377 -0
  22. package/dist/lib/auth/anthropicOAuth.js +915 -0
  23. package/dist/lib/auth/index.d.ts +20 -0
  24. package/dist/lib/auth/index.js +30 -0
  25. package/dist/lib/auth/tokenStore.d.ts +225 -0
  26. package/dist/lib/auth/tokenStore.js +522 -0
  27. package/dist/lib/constants/enums.d.ts +20 -0
  28. package/dist/lib/constants/enums.js +30 -0
  29. package/dist/lib/constants/index.d.ts +3 -1
  30. package/dist/lib/constants/index.js +11 -1
  31. package/dist/lib/index.d.ts +1 -1
  32. package/dist/lib/models/anthropicModels.d.ts +267 -0
  33. package/dist/lib/models/anthropicModels.js +528 -0
  34. package/dist/lib/providers/anthropic.d.ts +123 -2
  35. package/dist/lib/providers/anthropic.js +800 -10
  36. package/dist/lib/types/errors.d.ts +62 -0
  37. package/dist/lib/types/errors.js +107 -0
  38. package/dist/lib/types/index.d.ts +2 -1
  39. package/dist/lib/types/index.js +2 -0
  40. package/dist/lib/types/providers.d.ts +107 -0
  41. package/dist/lib/types/providers.js +69 -0
  42. package/dist/lib/types/subscriptionTypes.d.ts +893 -0
  43. package/dist/lib/types/subscriptionTypes.js +8 -0
  44. package/dist/lib/utils/providerConfig.d.ts +167 -0
  45. package/dist/lib/utils/providerConfig.js +619 -9
  46. package/dist/models/anthropicModels.d.ts +267 -0
  47. package/dist/models/anthropicModels.js +527 -0
  48. package/dist/providers/anthropic.d.ts +123 -2
  49. package/dist/providers/anthropic.js +800 -10
  50. package/dist/types/errors.d.ts +62 -0
  51. package/dist/types/errors.js +107 -0
  52. package/dist/types/index.d.ts +2 -1
  53. package/dist/types/index.js +2 -0
  54. package/dist/types/providers.d.ts +107 -0
  55. package/dist/types/providers.js +69 -0
  56. package/dist/types/subscriptionTypes.d.ts +893 -0
  57. package/dist/types/subscriptionTypes.js +7 -0
  58. package/dist/utils/providerConfig.d.ts +167 -0
  59. package/dist/utils/providerConfig.js +619 -9
  60. package/package.json +2 -1
@@ -42,3 +42,65 @@ export declare class RateLimitError extends ProviderError {
42
42
  export declare class InvalidModelError extends ProviderError {
43
43
  constructor(message: string, provider?: string);
44
44
  }
45
+ /**
46
+ * Base class for OAuth-specific errors
47
+ */
48
+ export declare class OAuthError extends BaseError {
49
+ code?: string | undefined;
50
+ constructor(message: string, code?: string | undefined);
51
+ }
52
+ /**
53
+ * Thrown when OAuth configuration is invalid or missing
54
+ */
55
+ export declare class OAuthConfigurationError extends OAuthError {
56
+ constructor(message: string);
57
+ }
58
+ /**
59
+ * Thrown when authorization code exchange fails
60
+ */
61
+ export declare class OAuthTokenExchangeError extends OAuthError {
62
+ statusCode?: number | undefined;
63
+ constructor(message: string, statusCode?: number | undefined);
64
+ }
65
+ /**
66
+ * Thrown when token refresh fails
67
+ */
68
+ export declare class OAuthTokenRefreshError extends OAuthError {
69
+ statusCode?: number | undefined;
70
+ constructor(message: string, statusCode?: number | undefined);
71
+ }
72
+ /**
73
+ * Thrown when token validation fails
74
+ */
75
+ export declare class OAuthTokenValidationError extends OAuthError {
76
+ constructor(message: string);
77
+ }
78
+ /**
79
+ * Thrown when token revocation fails
80
+ */
81
+ export declare class OAuthTokenRevocationError extends OAuthError {
82
+ statusCode?: number | undefined;
83
+ constructor(message: string, statusCode?: number | undefined);
84
+ }
85
+ /**
86
+ * Thrown when callback server operations fail
87
+ */
88
+ export declare class OAuthCallbackServerError extends OAuthError {
89
+ constructor(message: string);
90
+ }
91
+ /**
92
+ * Token storage error for authentication-related failures
93
+ */
94
+ export declare class TokenStoreError extends BaseError {
95
+ readonly code: "STORAGE_ERROR" | "ENCRYPTION_ERROR" | "VALIDATION_ERROR" | "NOT_FOUND" | "REFRESH_ERROR";
96
+ constructor(message: string, code?: "STORAGE_ERROR" | "ENCRYPTION_ERROR" | "VALIDATION_ERROR" | "NOT_FOUND" | "REFRESH_ERROR");
97
+ }
98
+ /**
99
+ * Error thrown when model access is denied based on subscription tier
100
+ */
101
+ export declare class ModelAccessError extends BaseError {
102
+ readonly model: string;
103
+ readonly tier: string;
104
+ readonly requiredTier: string;
105
+ constructor(model: string, tier: string, requiredTier: string);
106
+ }
@@ -58,3 +58,110 @@ export class InvalidModelError extends ProviderError {
58
58
  super(message, provider);
59
59
  }
60
60
  }
61
+ // =============================================================================
62
+ // OAUTH ERROR CLASSES
63
+ // =============================================================================
64
+ /**
65
+ * Base class for OAuth-specific errors
66
+ */
67
+ export class OAuthError extends BaseError {
68
+ code;
69
+ constructor(message, code) {
70
+ super(message);
71
+ this.code = code;
72
+ this.name = "OAuthError";
73
+ }
74
+ }
75
+ /**
76
+ * Thrown when OAuth configuration is invalid or missing
77
+ */
78
+ export class OAuthConfigurationError extends OAuthError {
79
+ constructor(message) {
80
+ super(message, "CONFIGURATION_ERROR");
81
+ this.name = "OAuthConfigurationError";
82
+ }
83
+ }
84
+ /**
85
+ * Thrown when authorization code exchange fails
86
+ */
87
+ export class OAuthTokenExchangeError extends OAuthError {
88
+ statusCode;
89
+ constructor(message, statusCode) {
90
+ super(message, "TOKEN_EXCHANGE_ERROR");
91
+ this.statusCode = statusCode;
92
+ this.name = "OAuthTokenExchangeError";
93
+ }
94
+ }
95
+ /**
96
+ * Thrown when token refresh fails
97
+ */
98
+ export class OAuthTokenRefreshError extends OAuthError {
99
+ statusCode;
100
+ constructor(message, statusCode) {
101
+ super(message, "TOKEN_REFRESH_ERROR");
102
+ this.statusCode = statusCode;
103
+ this.name = "OAuthTokenRefreshError";
104
+ }
105
+ }
106
+ /**
107
+ * Thrown when token validation fails
108
+ */
109
+ export class OAuthTokenValidationError extends OAuthError {
110
+ constructor(message) {
111
+ super(message, "TOKEN_VALIDATION_ERROR");
112
+ this.name = "OAuthTokenValidationError";
113
+ }
114
+ }
115
+ /**
116
+ * Thrown when token revocation fails
117
+ */
118
+ export class OAuthTokenRevocationError extends OAuthError {
119
+ statusCode;
120
+ constructor(message, statusCode) {
121
+ super(message, "TOKEN_REVOCATION_ERROR");
122
+ this.statusCode = statusCode;
123
+ this.name = "OAuthTokenRevocationError";
124
+ }
125
+ }
126
+ /**
127
+ * Thrown when callback server operations fail
128
+ */
129
+ export class OAuthCallbackServerError extends OAuthError {
130
+ constructor(message) {
131
+ super(message, "CALLBACK_SERVER_ERROR");
132
+ this.name = "OAuthCallbackServerError";
133
+ }
134
+ }
135
+ // =============================================================================
136
+ // TOKEN STORE ERROR
137
+ // =============================================================================
138
+ /**
139
+ * Token storage error for authentication-related failures
140
+ */
141
+ export class TokenStoreError extends BaseError {
142
+ code;
143
+ constructor(message, code = "STORAGE_ERROR") {
144
+ super(message);
145
+ this.code = code;
146
+ this.name = "TokenStoreError";
147
+ }
148
+ }
149
+ // =============================================================================
150
+ // MODEL ACCESS ERROR
151
+ // =============================================================================
152
+ /**
153
+ * Error thrown when model access is denied based on subscription tier
154
+ */
155
+ export class ModelAccessError extends BaseError {
156
+ model;
157
+ tier;
158
+ requiredTier;
159
+ constructor(model, tier, requiredTier) {
160
+ super(`Model "${model}" is not available for tier "${tier}". ` +
161
+ `Required tier: "${requiredTier}" or higher.`);
162
+ this.name = "ModelAccessError";
163
+ this.model = model;
164
+ this.tier = tier;
165
+ this.requiredTier = requiredTier;
166
+ }
167
+ }
@@ -6,7 +6,7 @@ export * from "./cli.js";
6
6
  export * from "./common.js";
7
7
  export type { AnalyticsConfig, BackupInfo, BackupMetadata, CacheConfig, ConfigUpdateOptions, ConfigValidationResult, FallbackConfig, NeuroLinkConfig, PerformanceConfig, RetryConfig, ToolConfig, } from "./configTypes.js";
8
8
  export type { ExternalMCPConfigValidation, ExternalMCPManagerConfig, ExternalMCPOperationResult, ExternalMCPServerEvents, ExternalMCPServerHealth, ExternalMCPServerInstance, ExternalMCPServerStatus, ExternalMCPToolContext, ExternalMCPToolInfo, ExternalMCPToolResult, } from "./externalMcp.js";
9
- export type { AuthorizationUrlResult, CircuitBreakerConfig, CircuitBreakerEvents, CircuitBreakerState, CircuitBreakerStats, DiscoveredMcp, ExternalToolExecutionOptions, FlexibleValidationResult, HTTPRetryConfig, MCPClientResult, MCPConnectedServer, MCPDiscoveredServer, MCPExecutableTool, MCPOAuthConfig, MCPServerCategory, MCPServerConfig, MCPServerConnectionStatus, MCPServerMetadata, MCPServerRegistryEntry, MCPServerStatus, MCPToolInfo, MCPToolMetadata, MCPTransportType, McpMetadata, McpRegistry, NeuroLinkExecutionContext, NeuroLinkMCPServer, NeuroLinkMCPTool, OAuthClientInformation, OAuthTokens, RateLimitConfig, TokenBucketRateLimitConfig, TokenExchangeRequest, TokenStorage, ToolDiscoveryResult, ToolRegistryEvents, ToolValidationResult, } from "./mcpTypes.js";
9
+ export type { AuthorizationUrlResult, CircuitBreakerConfig, CircuitBreakerEvents, CircuitBreakerState, CircuitBreakerStats, DiscoveredMcp, ExternalToolExecutionOptions, FlexibleValidationResult, HTTPRetryConfig, MCPClientResult, MCPConnectedServer, MCPDiscoveredServer, MCPExecutableTool, MCPOAuthConfig, MCPServerCategory, MCPServerConfig, MCPServerConnectionStatus, MCPServerMetadata, MCPServerRegistryEntry, MCPServerStatus, MCPToolInfo, MCPToolMetadata, MCPTransportType, McpMetadata, McpRegistry, NeuroLinkExecutionContext, NeuroLinkMCPServer, NeuroLinkMCPTool, OAuthClientInformation, OAuthTokens as McpOAuthTokens, RateLimitConfig, TokenBucketRateLimitConfig, TokenExchangeRequest, TokenStorage, ToolDiscoveryResult, ToolRegistryEvents, ToolValidationResult, } from "./mcpTypes.js";
10
10
  export type { ModelCapability, ModelFilter, ModelPricing, ModelResolutionContext, ModelStats, ModelUseCase, } from "./providers.js";
11
11
  export * from "./providers.js";
12
12
  export * from "./taskClassificationTypes.js";
@@ -38,3 +38,4 @@ export * from "./contextTypes.js";
38
38
  export * from "./fileReferenceTypes.js";
39
39
  export * from "./ragTypes.js";
40
40
  export * from "./conversationMemoryInterface.js";
41
+ export * from "./subscriptionTypes.js";
@@ -48,3 +48,5 @@ export * from "./fileReferenceTypes.js";
48
48
  export * from "./ragTypes.js";
49
49
  // Conversation memory manager type
50
50
  export * from "./conversationMemoryInterface.js";
51
+ // Subscription types (Claude subscription tiers, authentication, usage tracking)
52
+ export * from "./subscriptionTypes.js";
@@ -8,6 +8,8 @@ import type { ValidationSchema } from "./typeAliases.js";
8
8
  import type { EnhancedGenerateResult, GenerateResult, TextGenerationOptions } from "./generateTypes.js";
9
9
  import type { StreamOptions, StreamResult } from "./streamTypes.js";
10
10
  import type { ExternalMCPToolInfo } from "./externalMcp.js";
11
+ import type { ClaudeSubscriptionTier, AnthropicAuthMethod, AnthropicAuthConfig, SubscriptionInfo } from "./subscriptionTypes.js";
12
+ export type { ClaudeSubscriptionTier, AnthropicAuthMethod, AnthropicAuthConfig, SubscriptionInfo, } from "./subscriptionTypes.js";
11
13
  /**
12
14
  * Generic AI SDK model interface
13
15
  */
@@ -33,6 +35,15 @@ export type ProviderStatus = {
33
35
  error?: string;
34
36
  responseTime?: number;
35
37
  model?: string;
38
+ /**
39
+ * Subscription information for providers that support subscription tiers
40
+ * (e.g., Anthropic Claude with Pro/Max/Team/Enterprise subscriptions)
41
+ */
42
+ subscription?: SubscriptionInfo;
43
+ /**
44
+ * The authentication method currently in use for this provider
45
+ */
46
+ authMethod?: AnthropicAuthMethod;
36
47
  };
37
48
  /**
38
49
  * Provider error information
@@ -185,6 +196,16 @@ export type ProviderCapabilities = {
185
196
  supportsAudio: boolean;
186
197
  maxTokens?: number;
187
198
  supportedModels: string[];
199
+ /**
200
+ * Whether the provider supports subscription-based features and tier management
201
+ * When true, the provider can adapt behavior based on subscription tier
202
+ */
203
+ subscriptionAware?: boolean;
204
+ /**
205
+ * List of authentication methods supported by this provider
206
+ * e.g., ["api_key", "oauth", "session_token", "environment"]
207
+ */
208
+ supportedAuthMethods?: string[];
188
209
  };
189
210
  /**
190
211
  * Provider configuration specifying provider and its available models (from core types)
@@ -202,8 +223,94 @@ export type IndividualProviderConfig = {
202
223
  timeout?: number;
203
224
  retries?: number;
204
225
  model?: string;
226
+ /**
227
+ * The subscription tier for the provider (e.g., Claude Pro, Max, Team, Enterprise)
228
+ * Used to determine rate limits, available features, and pricing
229
+ */
230
+ subscriptionTier?: ClaudeSubscriptionTier;
231
+ /**
232
+ * The authentication method to use for the provider
233
+ * Supports API key, OAuth, session token, or environment variable
234
+ */
235
+ authMethod?: AnthropicAuthMethod;
236
+ /**
237
+ * Detailed authentication configuration including credentials and options
238
+ */
239
+ authConfig?: AnthropicAuthConfig;
240
+ /**
241
+ * Whether to enable beta features for the provider
242
+ * Beta features may be unstable or subject to change
243
+ */
244
+ enableBetaFeatures?: boolean;
205
245
  [key: string]: unknown;
206
246
  };
247
+ /**
248
+ * Anthropic-specific provider configuration
249
+ *
250
+ * @description Extends the base provider configuration with Anthropic-specific
251
+ * options for OAuth, subscription management, and beta features.
252
+ */
253
+ export type AnthropicProviderConfig = IndividualProviderConfig & {
254
+ /**
255
+ * The subscription tier for Claude access
256
+ */
257
+ subscriptionTier?: ClaudeSubscriptionTier;
258
+ /**
259
+ * The authentication method to use
260
+ */
261
+ authMethod?: AnthropicAuthMethod;
262
+ /**
263
+ * Whether to enable beta features
264
+ */
265
+ enableBetaFeatures?: boolean;
266
+ /**
267
+ * OAuth token for OAuth authentication.
268
+ * Required when authMethod is "oauth".
269
+ */
270
+ oauthToken?: import("./subscriptionTypes.js").OAuthToken;
271
+ /**
272
+ * OAuth configuration for OAuth-based authentication
273
+ */
274
+ oauthConfig?: {
275
+ /**
276
+ * OAuth client ID for the application
277
+ */
278
+ clientId?: string;
279
+ /**
280
+ * OAuth redirect URI for the callback
281
+ */
282
+ redirectUri?: string;
283
+ /**
284
+ * OAuth scopes to request
285
+ */
286
+ scopes?: string[];
287
+ /**
288
+ * OAuth authorization endpoint URL
289
+ */
290
+ authorizationEndpoint?: string;
291
+ /**
292
+ * OAuth token endpoint URL
293
+ */
294
+ tokenEndpoint?: string;
295
+ };
296
+ };
297
+ /**
298
+ * Type guard to check if a configuration is an AnthropicProviderConfig
299
+ *
300
+ * @param config - The configuration object to check
301
+ * @returns True if the configuration is an AnthropicProviderConfig
302
+ *
303
+ * @example
304
+ * ```typescript
305
+ * const config = getProviderConfig();
306
+ * if (isAnthropicConfig(config)) {
307
+ * // TypeScript knows config is AnthropicProviderConfig here
308
+ * console.log(config.subscriptionTier);
309
+ * console.log(config.oauthConfig?.clientId);
310
+ * }
311
+ * ```
312
+ */
313
+ export declare function isAnthropicConfig(config: unknown): config is AnthropicProviderConfig;
207
314
  /**
208
315
  * Configuration options for provider validation
209
316
  */
@@ -2,6 +2,75 @@
2
2
  * Provider-specific type definitions for NeuroLink
3
3
  */
4
4
  import { AIProviderName, AnthropicModels, BedrockModels, GoogleAIModels, OpenAIModels, VertexModels, } from "../constants/enums.js";
5
+ /**
6
+ * Type guard to check if a configuration is an AnthropicProviderConfig
7
+ *
8
+ * @param config - The configuration object to check
9
+ * @returns True if the configuration is an AnthropicProviderConfig
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * const config = getProviderConfig();
14
+ * if (isAnthropicConfig(config)) {
15
+ * // TypeScript knows config is AnthropicProviderConfig here
16
+ * console.log(config.subscriptionTier);
17
+ * console.log(config.oauthConfig?.clientId);
18
+ * }
19
+ * ```
20
+ */
21
+ export function isAnthropicConfig(config) {
22
+ if (config === null || config === undefined) {
23
+ return false;
24
+ }
25
+ if (typeof config !== "object") {
26
+ return false;
27
+ }
28
+ const configObj = config;
29
+ // Check for Anthropic-specific properties
30
+ // A config is considered Anthropic if it has:
31
+ // 1. An authMethod that is a valid AnthropicAuthMethod, OR
32
+ // 2. A subscriptionTier that is a valid ClaudeSubscriptionTier, OR
33
+ // 3. An oauthConfig object
34
+ const validAuthMethods = ["api_key", "oauth"];
35
+ const validSubscriptionTiers = [
36
+ "free",
37
+ "pro",
38
+ "max",
39
+ "max_5",
40
+ "max_20",
41
+ "api",
42
+ ];
43
+ // Check for authMethod
44
+ if (configObj.authMethod !== undefined &&
45
+ typeof configObj.authMethod === "string" &&
46
+ validAuthMethods.includes(configObj.authMethod)) {
47
+ return true;
48
+ }
49
+ // Check for subscriptionTier
50
+ if (configObj.subscriptionTier !== undefined &&
51
+ typeof configObj.subscriptionTier === "string" &&
52
+ validSubscriptionTiers.includes(configObj.subscriptionTier)) {
53
+ return true;
54
+ }
55
+ // Check for oauthConfig
56
+ if (configObj.oauthConfig !== undefined &&
57
+ typeof configObj.oauthConfig === "object" &&
58
+ configObj.oauthConfig !== null) {
59
+ return true;
60
+ }
61
+ // Check for authConfig (AnthropicAuthConfig)
62
+ if (configObj.authConfig !== undefined &&
63
+ typeof configObj.authConfig === "object" &&
64
+ configObj.authConfig !== null) {
65
+ const authConfig = configObj.authConfig;
66
+ if (authConfig.method !== undefined &&
67
+ typeof authConfig.method === "string" &&
68
+ validAuthMethods.includes(authConfig.method)) {
69
+ return true;
70
+ }
71
+ }
72
+ return false;
73
+ }
5
74
  /**
6
75
  * Default model aliases for easy reference
7
76
  */