@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
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Claude Subscription Types for NeuroLink
3
+ *
4
+ * Type definitions for Claude subscription tiers, authentication methods,
5
+ * and usage tracking for Anthropic API access.
6
+ */
7
+ export {};
8
+ //# sourceMappingURL=subscriptionTypes.js.map
@@ -3,14 +3,22 @@
3
3
  * Consolidated configuration helpers for all AI providers
4
4
  * Eliminates duplicate error messages and configuration logic
5
5
  * Enhanced with format validation and advanced error classification
6
+ * Extended with Claude subscription OAuth support
6
7
  */
7
8
  import type { APIValidationResult } from "../types/utilities.js";
8
9
  import type { ProviderConfigOptions } from "../types/providers.js";
10
+ import type { AnthropicAuthMethod, ClaudeSubscriptionTier, AnthropicAuthConfig, AnthropicAuthConfigResult } from "../types/subscriptionTypes.js";
11
+ export type { AnthropicAuthMethod, ClaudeSubscriptionTier, AnthropicAuthConfig, OAuthToken, AnthropicAuthConfigResult, } from "../types/subscriptionTypes.js";
9
12
  /**
10
13
  * API key format validation patterns (extracted from advanced validation system)
11
14
  * Exported for use across the codebase to replace scattered regex patterns
12
15
  */
13
16
  export declare const API_KEY_FORMATS: Record<string, RegExp>;
17
+ /**
18
+ * OAuth token format validation patterns
19
+ * These patterns are more flexible as OAuth tokens can vary by provider
20
+ */
21
+ export declare const OAUTH_TOKEN_FORMATS: Record<string, RegExp>;
14
22
  /**
15
23
  * API key length constants to replace scattered magic numbers
16
24
  */
@@ -67,6 +75,7 @@ export declare function getProviderModel(envVar: string, defaultModel: string):
67
75
  export declare function hasProviderCredentials(envVars: string[]): boolean;
68
76
  /**
69
77
  * Creates Anthropic provider configuration
78
+ * Supports both API key and OAuth authentication methods
70
79
  */
71
80
  export declare function createAnthropicConfig(): ProviderConfigOptions;
72
81
  /**
@@ -126,3 +135,161 @@ export declare function getAWSSessionToken(): string | undefined;
126
135
  * Checks if HuggingFace credentials are available
127
136
  */
128
137
  export declare function hasHuggingFaceCredentials(): boolean;
138
+ /**
139
+ * Gets the configured Anthropic authentication method
140
+ * Defaults to "api_key" for backward compatibility
141
+ * @returns The configured authentication method
142
+ */
143
+ export declare function getAnthropicAuthMethod(): AnthropicAuthMethod;
144
+ /**
145
+ * Gets the configured Claude subscription tier
146
+ * Defaults to "api" for backward compatibility (API key users)
147
+ * @returns The configured subscription tier
148
+ */
149
+ export declare function getAnthropicSubscriptionTier(): ClaudeSubscriptionTier;
150
+ /**
151
+ * Validates OAuth access token format
152
+ * @param token The token to validate
153
+ * @returns True if the token format is valid
154
+ */
155
+ export declare function validateOAuthAccessToken(token: string): boolean;
156
+ /**
157
+ * Validates OAuth refresh token format
158
+ * @param token The token to validate
159
+ * @returns True if the token format is valid
160
+ */
161
+ export declare function validateOAuthRefreshToken(token: string): boolean;
162
+ /**
163
+ * Detects the best available authentication method for Anthropic
164
+ * Checks environment variables and returns the most appropriate auth configuration
165
+ * @returns Complete authentication configuration
166
+ */
167
+ export declare function detectAnthropicAuth(): AnthropicAuthConfigResult;
168
+ /**
169
+ * Checks if Anthropic credentials are available (either API key or OAuth)
170
+ * @returns True if any valid authentication is configured
171
+ */
172
+ export declare function hasAnthropicCredentials(): boolean;
173
+ /**
174
+ * Gets the authentication token or key for Anthropic API calls
175
+ * Returns the appropriate credential based on configured auth method
176
+ * @returns The API key or OAuth access token, or undefined if not configured
177
+ */
178
+ export declare function getAnthropicCredential(): string | undefined;
179
+ /**
180
+ * Checks if OAuth refresh is needed based on token state
181
+ * This is a placeholder for actual token expiration checking
182
+ * @returns True if refresh is needed
183
+ */
184
+ export declare function needsOAuthRefresh(): boolean;
185
+ /**
186
+ * Gets subscription tier limits for informational purposes
187
+ * These are approximate limits and may change
188
+ * @param tier The subscription tier
189
+ * @returns Object with tier limit information
190
+ */
191
+ export declare function getSubscriptionTierLimits(tier: ClaudeSubscriptionTier): {
192
+ messagesPerDay: number | "unlimited";
193
+ contextWindow: number;
194
+ priorityAccess: boolean;
195
+ description: string;
196
+ };
197
+ /**
198
+ * Environment variables for Anthropic/Claude subscription configuration
199
+ * These control authentication method, subscription tier, and feature flags
200
+ */
201
+ export declare const ANTHROPIC_ENV_VARS: {
202
+ /** Authentication method: "api_key" or "oauth" */
203
+ readonly AUTH_METHOD: "ANTHROPIC_AUTH_METHOD";
204
+ /** Subscription tier: "free", "pro", "max", "max_5", "max_20", or "api" */
205
+ readonly SUBSCRIPTION_TIER: "ANTHROPIC_SUBSCRIPTION_TIER";
206
+ /** Enable beta features: "true" or "false" */
207
+ readonly ENABLE_BETA_FEATURES: "ANTHROPIC_ENABLE_BETA_FEATURES";
208
+ /** API key for api_key authentication */
209
+ readonly API_KEY: "ANTHROPIC_API_KEY";
210
+ /** OAuth access token for oauth authentication (canonical, with BC fallbacks) */
211
+ readonly OAUTH_ACCESS_TOKEN: "ANTHROPIC_OAUTH_TOKEN";
212
+ /** OAuth refresh token for oauth authentication */
213
+ readonly OAUTH_REFRESH_TOKEN: "ANTHROPIC_OAUTH_REFRESH_TOKEN";
214
+ /** OAuth token expiry timestamp (Unix epoch in seconds) */
215
+ readonly OAUTH_TOKEN_EXPIRY: "ANTHROPIC_OAUTH_TOKEN_EXPIRY";
216
+ };
217
+ /**
218
+ * Valid subscription tier values for validation
219
+ */
220
+ export declare const VALID_SUBSCRIPTION_TIERS: readonly ClaudeSubscriptionTier[];
221
+ /**
222
+ * Valid authentication method values for validation
223
+ */
224
+ export declare const VALID_AUTH_METHODS: readonly AnthropicAuthMethod[];
225
+ /**
226
+ * Validates a subscription tier value
227
+ * @param tier The tier value to validate
228
+ * @returns True if the tier is valid, false otherwise
229
+ */
230
+ export declare function isValidSubscriptionTier(tier: string | undefined): tier is ClaudeSubscriptionTier;
231
+ /**
232
+ * Validates an authentication method value
233
+ * @param method The method value to validate
234
+ * @returns True if the method is valid, false otherwise
235
+ */
236
+ export declare function isValidAuthMethod(method: string | undefined): method is AnthropicAuthMethod;
237
+ /**
238
+ * Validates subscription tier and returns a detailed result
239
+ * @param tier The tier value to validate
240
+ * @returns Validation result with error details if invalid
241
+ */
242
+ export declare function validateSubscriptionTier(tier: string | undefined): {
243
+ isValid: boolean;
244
+ tier?: ClaudeSubscriptionTier;
245
+ error?: string;
246
+ };
247
+ /**
248
+ * Gets the complete Anthropic authentication configuration
249
+ * Detects auth method from environment or config and loads appropriate credentials
250
+ *
251
+ * @returns Complete AnthropicAuthConfig with method, credentials, and tier
252
+ */
253
+ export declare function getAnthropicAuthConfig(): AnthropicAuthConfig;
254
+ /**
255
+ * Detects the subscription tier from environment variables or config
256
+ * Checks environment variable first, then config, defaults to "api" if using API key
257
+ *
258
+ * @returns The detected subscription tier
259
+ */
260
+ export declare function detectSubscriptionTier(): ClaudeSubscriptionTier;
261
+ /**
262
+ * Determines whether beta features should be enabled
263
+ * Checks environment/config and defaults based on authentication method
264
+ *
265
+ * @returns True if beta features should be enabled
266
+ */
267
+ export declare function shouldEnableBetaFeatures(): boolean;
268
+ /**
269
+ * Gets complete subscription configuration including auth, tier, and features
270
+ * Combines all configuration sources into a unified config object
271
+ *
272
+ * @returns Complete subscription configuration
273
+ */
274
+ export declare function getAnthropicSubscriptionConfig(): {
275
+ auth: AnthropicAuthConfig;
276
+ tier: ClaudeSubscriptionTier;
277
+ betaFeaturesEnabled: boolean;
278
+ limits: ReturnType<typeof getSubscriptionTierLimits>;
279
+ isConfigured: boolean;
280
+ error?: string;
281
+ };
282
+ /**
283
+ * Checks if the current subscription tier has access to a specific feature
284
+ * @param feature The feature to check
285
+ * @param currentTier The current subscription tier (optional, auto-detects if not provided)
286
+ * @returns True if the tier has access to the feature
287
+ */
288
+ export declare function hasSubscriptionFeature(feature: "extended_thinking" | "priority_access" | "vision" | "file_analysis" | "mcp_tools" | "computer_use" | "web_search", currentTier?: ClaudeSubscriptionTier): boolean;
289
+ /**
290
+ * Gets a human-readable description of the current authentication configuration
291
+ * Useful for debugging and user feedback
292
+ *
293
+ * @returns Human-readable configuration description
294
+ */
295
+ export declare function describeAnthropicConfig(): string;