@juspay/neurolink 9.13.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 (76) hide show
  1. package/CHANGELOG.md +12 -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/commands/docs.d.ts +10 -0
  12. package/dist/cli/commands/docs.js +48 -0
  13. package/dist/cli/factories/authCommandFactory.d.ts +52 -0
  14. package/dist/cli/factories/authCommandFactory.js +146 -0
  15. package/dist/cli/factories/commandFactory.d.ts +6 -0
  16. package/dist/cli/factories/commandFactory.js +92 -2
  17. package/dist/cli/parser.js +14 -2
  18. package/dist/constants/enums.d.ts +20 -0
  19. package/dist/constants/enums.js +30 -0
  20. package/dist/constants/index.d.ts +3 -1
  21. package/dist/constants/index.js +11 -1
  22. package/dist/index.d.ts +4 -4
  23. package/dist/index.js +3 -3
  24. package/dist/lib/auth/anthropicOAuth.d.ts +377 -0
  25. package/dist/lib/auth/anthropicOAuth.js +915 -0
  26. package/dist/lib/auth/index.d.ts +20 -0
  27. package/dist/lib/auth/index.js +30 -0
  28. package/dist/lib/auth/tokenStore.d.ts +225 -0
  29. package/dist/lib/auth/tokenStore.js +522 -0
  30. package/dist/lib/constants/enums.d.ts +20 -0
  31. package/dist/lib/constants/enums.js +30 -0
  32. package/dist/lib/constants/index.d.ts +3 -1
  33. package/dist/lib/constants/index.js +11 -1
  34. package/dist/lib/index.d.ts +4 -4
  35. package/dist/lib/index.js +3 -3
  36. package/dist/lib/models/anthropicModels.d.ts +267 -0
  37. package/dist/lib/models/anthropicModels.js +528 -0
  38. package/dist/lib/neurolink.d.ts +2 -2
  39. package/dist/lib/neurolink.js +2 -2
  40. package/dist/lib/providers/anthropic.d.ts +123 -2
  41. package/dist/lib/providers/anthropic.js +800 -10
  42. package/dist/lib/types/errors.d.ts +62 -0
  43. package/dist/lib/types/errors.js +107 -0
  44. package/dist/lib/types/index.d.ts +2 -1
  45. package/dist/lib/types/index.js +2 -0
  46. package/dist/lib/types/providers.d.ts +107 -0
  47. package/dist/lib/types/providers.js +69 -0
  48. package/dist/lib/types/subscriptionTypes.d.ts +893 -0
  49. package/dist/lib/types/subscriptionTypes.js +8 -0
  50. package/dist/lib/utils/providerConfig.d.ts +167 -0
  51. package/dist/lib/utils/providerConfig.js +619 -9
  52. package/dist/models/anthropicModels.d.ts +267 -0
  53. package/dist/models/anthropicModels.js +527 -0
  54. package/dist/neurolink.d.ts +2 -2
  55. package/dist/neurolink.js +2 -2
  56. package/dist/providers/anthropic.d.ts +123 -2
  57. package/dist/providers/anthropic.js +800 -10
  58. package/dist/types/errors.d.ts +62 -0
  59. package/dist/types/errors.js +107 -0
  60. package/dist/types/index.d.ts +2 -1
  61. package/dist/types/index.js +2 -0
  62. package/dist/types/providers.d.ts +107 -0
  63. package/dist/types/providers.js +69 -0
  64. package/dist/types/subscriptionTypes.d.ts +893 -0
  65. package/dist/types/subscriptionTypes.js +7 -0
  66. package/dist/utils/providerConfig.d.ts +167 -0
  67. package/dist/utils/providerConfig.js +619 -9
  68. package/docs-site/mcp-server/index.d.ts +4 -0
  69. package/docs-site/mcp-server/index.js +165 -0
  70. package/docs-site/mcp-server/search.d.ts +13 -0
  71. package/docs-site/mcp-server/search.js +81 -0
  72. package/docs-site/mcp-server/tools.d.ts +96 -0
  73. package/docs-site/mcp-server/tools.js +342 -0
  74. package/docs-site/mcp-server/types.d.ts +32 -0
  75. package/docs-site/mcp-server/types.js +2 -0
  76. package/package.json +7 -1
@@ -0,0 +1,20 @@
1
+ /**
2
+ * NeuroLink Authentication Module
3
+ *
4
+ * Provides OAuth 2.0 authentication support for Claude Pro/Max subscriptions
5
+ * and secure token storage.
6
+ *
7
+ * Key components:
8
+ * - AnthropicOAuth: OAuth 2.0 flow implementation with PKCE support
9
+ * - TokenStore: Secure local storage for OAuth tokens
10
+ * - Callback Server: Local HTTP server for OAuth redirects
11
+ */
12
+ export { ANTHROPIC_OAUTH_BASE_URL, DEFAULT_SCOPES, DEFAULT_REDIRECT_URI, DEFAULT_CALLBACK_PORT, } from "./anthropicOAuth.js";
13
+ export { AnthropicOAuth } from "./anthropicOAuth.js";
14
+ export { OAuthError, OAuthConfigurationError, OAuthTokenExchangeError, OAuthTokenRefreshError, OAuthTokenValidationError, OAuthTokenRevocationError, OAuthCallbackServerError, } from "./anthropicOAuth.js";
15
+ export { createAnthropicOAuth, createAnthropicOAuthConfig, hasAnthropicOAuthCredentials, startCallbackServer, stopCallbackServer, performOAuthFlow, } from "./anthropicOAuth.js";
16
+ export type { OAuthTokenResponse, OAuthFlowTokens, OAuthFlowTokens as OAuthTokens, TokenValidationResult, AnthropicOAuthConfig, PKCEParams, CallbackResult, } from "./anthropicOAuth.js";
17
+ export { TokenStore, tokenStore, defaultTokenStore } from "./tokenStore.js";
18
+ export { TokenStoreError } from "./tokenStore.js";
19
+ export type { StoredOAuthTokens, OAuthTokens as StoredOAuthTokensLegacy, TokenRefresher, } from "./tokenStore.js";
20
+ export type { NeuroLinkAuthOptions, AuthStatus, } from "../types/subscriptionTypes.js";
@@ -0,0 +1,29 @@
1
+ /**
2
+ * NeuroLink Authentication Module
3
+ *
4
+ * Provides OAuth 2.0 authentication support for Claude Pro/Max subscriptions
5
+ * and secure token storage.
6
+ *
7
+ * Key components:
8
+ * - AnthropicOAuth: OAuth 2.0 flow implementation with PKCE support
9
+ * - TokenStore: Secure local storage for OAuth tokens
10
+ * - Callback Server: Local HTTP server for OAuth redirects
11
+ */
12
+ // =============================================================================
13
+ // ANTHROPIC OAUTH - OAuth 2.0 Authentication
14
+ // =============================================================================
15
+ // OAuth Constants
16
+ export { ANTHROPIC_OAUTH_BASE_URL, DEFAULT_SCOPES, DEFAULT_REDIRECT_URI, DEFAULT_CALLBACK_PORT, } from "./anthropicOAuth.js";
17
+ // Main OAuth class
18
+ export { AnthropicOAuth } from "./anthropicOAuth.js";
19
+ // OAuth error classes (canonical definitions in types/errors.ts)
20
+ export { OAuthError, OAuthConfigurationError, OAuthTokenExchangeError, OAuthTokenRefreshError, OAuthTokenValidationError, OAuthTokenRevocationError, OAuthCallbackServerError, } from "./anthropicOAuth.js";
21
+ // OAuth helper functions
22
+ export { createAnthropicOAuth, createAnthropicOAuthConfig, hasAnthropicOAuthCredentials, startCallbackServer, stopCallbackServer, performOAuthFlow, } from "./anthropicOAuth.js";
23
+ // =============================================================================
24
+ // TOKEN STORE - Secure Token Storage
25
+ // =============================================================================
26
+ // Main TokenStore class and instances
27
+ export { TokenStore, tokenStore, defaultTokenStore } from "./tokenStore.js";
28
+ // Token store error class (canonical definition in types/errors.ts)
29
+ export { TokenStoreError } from "./tokenStore.js";
@@ -0,0 +1,225 @@
1
+ /**
2
+ * NeuroLink OAuth Token Store
3
+ *
4
+ * Secure storage for OAuth tokens with encoding support and multi-provider capability.
5
+ * Stores tokens in the user's home directory with restrictive permissions.
6
+ *
7
+ * Features:
8
+ * - Multi-provider token storage in a single tokens.json file
9
+ * - Secure file storage with 0o600 permissions
10
+ * - Token expiration checking with configurable buffer
11
+ * - Simple XOR-based obfuscation (not encryption, but not plaintext)
12
+ * - Automatic token refresh via configurable refresher functions
13
+ * - Cross-platform support (Unix/macOS/Windows)
14
+ */
15
+ export { TokenStoreError } from "../types/errors.js";
16
+ /**
17
+ * OAuth tokens structure for storage.
18
+ * Stricter version of OAuthTokens from subscriptionTypes with required fields.
19
+ */
20
+ export interface StoredOAuthTokens {
21
+ /** The access token for API authentication */
22
+ accessToken: string;
23
+ /** The refresh token for obtaining new access tokens (optional for some OAuth flows) */
24
+ refreshToken?: string;
25
+ /** Unix timestamp (ms) when the access token expires */
26
+ expiresAt: number;
27
+ /** Token type, typically "Bearer" */
28
+ tokenType: string;
29
+ /** Optional OAuth scopes granted */
30
+ scope?: string;
31
+ }
32
+ /**
33
+ * @deprecated Use StoredOAuthTokens instead
34
+ */
35
+ export type OAuthTokens = StoredOAuthTokens;
36
+ /**
37
+ * Token refresher function type
38
+ * Takes a refresh token and returns new tokens
39
+ */
40
+ export type TokenRefresher = (refreshToken: string) => Promise<StoredOAuthTokens>;
41
+ /**
42
+ * Secure token storage for OAuth tokens with multi-provider support
43
+ *
44
+ * Provides persistent storage for OAuth tokens with:
45
+ * - Multi-provider support in a single file
46
+ * - Secure file permissions (0o600)
47
+ * - Optional obfuscation/encoding
48
+ * - Token expiration checking with buffer
49
+ * - Automatic token refresh via configurable refreshers
50
+ *
51
+ * @example
52
+ * ```typescript
53
+ * const store = new TokenStore();
54
+ *
55
+ * // Save tokens for a provider
56
+ * await store.saveTokens("anthropic", {
57
+ * accessToken: "sk-...",
58
+ * refreshToken: "rt-...",
59
+ * expiresAt: Date.now() + 3600000,
60
+ * tokenType: "Bearer",
61
+ * });
62
+ *
63
+ * // Set up automatic refresh
64
+ * store.setTokenRefresher("anthropic", async (refreshToken) => {
65
+ * // Call OAuth refresh endpoint
66
+ * return newTokens;
67
+ * });
68
+ *
69
+ * // Get a valid token (auto-refreshes if needed)
70
+ * const token = await store.getValidToken("anthropic");
71
+ * ```
72
+ */
73
+ export declare class TokenStore {
74
+ private static readonly STORAGE_VERSION;
75
+ private static readonly NEUROLINK_DIR;
76
+ private static readonly TOKEN_FILE;
77
+ private static readonly FILE_PERMISSIONS;
78
+ private static readonly DIR_PERMISSIONS;
79
+ /** Default expiration buffer: 5 minutes */
80
+ private static readonly DEFAULT_EXPIRY_BUFFER_MS;
81
+ private readonly storagePath;
82
+ private readonly encryptionEnabled;
83
+ private readonly encryptionKey;
84
+ private readonly tokenRefreshers;
85
+ /**
86
+ * Creates a new TokenStore instance
87
+ *
88
+ * @param options - Configuration options
89
+ * @param options.encryptionEnabled - Whether to enable token obfuscation (default: true)
90
+ * @param options.customStoragePath - Override the default storage path
91
+ */
92
+ constructor(options?: {
93
+ encryptionEnabled?: boolean;
94
+ customStoragePath?: string;
95
+ });
96
+ /**
97
+ * Gets the path where tokens are stored
98
+ *
99
+ * @returns The absolute path to the token storage file
100
+ */
101
+ getStoragePath(): string;
102
+ /**
103
+ * Saves OAuth tokens for a specific provider
104
+ *
105
+ * @param provider - The provider name (e.g., "anthropic", "openai")
106
+ * @param tokens - The OAuth tokens to save
107
+ * @throws TokenStoreError if storage fails
108
+ */
109
+ saveTokens(provider: string, tokens: StoredOAuthTokens): Promise<void>;
110
+ /**
111
+ * Loads stored OAuth tokens for a specific provider
112
+ *
113
+ * @param provider - The provider name (e.g., "anthropic", "openai")
114
+ * @returns The stored tokens, or null if not found
115
+ * @throws TokenStoreError if reading fails (other than file not found)
116
+ */
117
+ loadTokens(provider: string): Promise<StoredOAuthTokens | null>;
118
+ /**
119
+ * Clears stored tokens for a specific provider
120
+ *
121
+ * @param provider - The provider name (e.g., "anthropic", "openai")
122
+ * @throws TokenStoreError if deletion fails
123
+ */
124
+ clearTokens(provider: string): Promise<void>;
125
+ /**
126
+ * Checks if the given tokens are expired
127
+ *
128
+ * @param tokens - The OAuth tokens to check
129
+ * @param bufferMs - Buffer time in milliseconds before actual expiration (default: 5 minutes)
130
+ * @returns true if token is expired or will expire within buffer time
131
+ */
132
+ isTokenExpired(tokens: StoredOAuthTokens, bufferMs?: number): boolean;
133
+ /**
134
+ * Gets a valid access token for a provider, refreshing if needed
135
+ *
136
+ * If the stored token is expired or about to expire, and a refresher
137
+ * function has been set, it will automatically refresh the token.
138
+ *
139
+ * @param provider - The provider name (e.g., "anthropic", "openai")
140
+ * @returns The valid access token, or null if not available
141
+ * @throws TokenStoreError if refresh fails
142
+ */
143
+ getValidToken(provider: string): Promise<string | null>;
144
+ /**
145
+ * Sets the token refresher function for a provider
146
+ *
147
+ * The refresher function will be called automatically when getValidToken
148
+ * detects that the stored token is expired or about to expire.
149
+ *
150
+ * @param provider - The provider name (e.g., "anthropic", "openai")
151
+ * @param refresher - Function that takes a refresh token and returns new tokens
152
+ */
153
+ setTokenRefresher(provider: string, refresher: TokenRefresher): void;
154
+ /**
155
+ * Removes the token refresher function for a provider
156
+ *
157
+ * @param provider - The provider name (e.g., "anthropic", "openai")
158
+ */
159
+ clearTokenRefresher(provider: string): void;
160
+ /**
161
+ * Checks if tokens exist for a specific provider
162
+ *
163
+ * @param provider - The provider name (e.g., "anthropic", "openai")
164
+ * @returns true if tokens are stored for the provider
165
+ */
166
+ hasTokens(provider: string): Promise<boolean>;
167
+ /**
168
+ * Lists all providers that have stored tokens
169
+ *
170
+ * @returns Array of provider names
171
+ */
172
+ listProviders(): Promise<string[]>;
173
+ /**
174
+ * Clears all stored tokens for all providers
175
+ *
176
+ * @throws TokenStoreError if deletion fails
177
+ */
178
+ clearAllTokens(): Promise<void>;
179
+ /**
180
+ * Loads the storage data from file
181
+ */
182
+ private loadStorageData;
183
+ /**
184
+ * Saves storage data to file
185
+ */
186
+ private saveStorageData;
187
+ /**
188
+ * Deletes the storage file
189
+ */
190
+ private deleteStorageFile;
191
+ /**
192
+ * Validates token structure
193
+ */
194
+ private validateTokens;
195
+ /**
196
+ * Ensures the storage directory exists with proper permissions
197
+ */
198
+ private ensureDirectory;
199
+ /**
200
+ * Derives an encoding key from machine-specific information
201
+ * This provides basic obfuscation - for production use, consider
202
+ * using proper encryption with a user-provided key or system keychain
203
+ */
204
+ private deriveEncryptionKey;
205
+ /**
206
+ * Simple XOR-based obfuscation
207
+ * Note: This is NOT cryptographically secure, just basic obfuscation
208
+ * For production use, consider using node:crypto with proper encryption
209
+ */
210
+ private obfuscate;
211
+ /**
212
+ * Reverses the XOR obfuscation
213
+ */
214
+ private deobfuscate;
215
+ }
216
+ /**
217
+ * Default token store singleton instance
218
+ * Uses default configuration with encryption enabled
219
+ */
220
+ export declare const tokenStore: TokenStore;
221
+ /**
222
+ * Alias for backward compatibility
223
+ * @deprecated Use tokenStore instead
224
+ */
225
+ export declare const defaultTokenStore: TokenStore;