salesflare-mcp-server 1.0.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 (73) hide show
  1. package/API.md +691 -0
  2. package/CHANGELOG.md +49 -0
  3. package/CLAUDE.md +117 -0
  4. package/CONTRIBUTING.md +399 -0
  5. package/FIX_PLAN.md +70 -0
  6. package/INSPECTOR.md +191 -0
  7. package/LICENSE +21 -0
  8. package/PUBLISH.md +73 -0
  9. package/README.md +383 -0
  10. package/dist/auth/api-key-auth.d.ts +75 -0
  11. package/dist/auth/api-key-auth.d.ts.map +1 -0
  12. package/dist/auth/api-key-auth.js +103 -0
  13. package/dist/auth/oauth-auth.d.ts +81 -0
  14. package/dist/auth/oauth-auth.d.ts.map +1 -0
  15. package/dist/auth/oauth-auth.js +123 -0
  16. package/dist/auth/token-manager.d.ts +105 -0
  17. package/dist/auth/token-manager.d.ts.map +1 -0
  18. package/dist/auth/token-manager.js +87 -0
  19. package/dist/client/salesflare-client.d.ts +219 -0
  20. package/dist/client/salesflare-client.d.ts.map +1 -0
  21. package/dist/client/salesflare-client.js +484 -0
  22. package/dist/index.d.ts +15 -0
  23. package/dist/index.d.ts.map +1 -0
  24. package/dist/index.js +82 -0
  25. package/dist/server.d.ts +39 -0
  26. package/dist/server.d.ts.map +1 -0
  27. package/dist/server.js +140 -0
  28. package/dist/tools/companies.d.ts +45 -0
  29. package/dist/tools/companies.d.ts.map +1 -0
  30. package/dist/tools/companies.js +392 -0
  31. package/dist/tools/contacts.d.ts +45 -0
  32. package/dist/tools/contacts.d.ts.map +1 -0
  33. package/dist/tools/contacts.js +290 -0
  34. package/dist/tools/deals.d.ts +46 -0
  35. package/dist/tools/deals.d.ts.map +1 -0
  36. package/dist/tools/deals.js +442 -0
  37. package/dist/tools/pipeline.d.ts +43 -0
  38. package/dist/tools/pipeline.d.ts.map +1 -0
  39. package/dist/tools/pipeline.js +328 -0
  40. package/dist/tools/tasks.d.ts +44 -0
  41. package/dist/tools/tasks.d.ts.map +1 -0
  42. package/dist/tools/tasks.js +406 -0
  43. package/dist/transport/http-transport.d.ts +36 -0
  44. package/dist/transport/http-transport.d.ts.map +1 -0
  45. package/dist/transport/http-transport.js +173 -0
  46. package/dist/transport/stdio-transport.d.ts +37 -0
  47. package/dist/transport/stdio-transport.d.ts.map +1 -0
  48. package/dist/transport/stdio-transport.js +129 -0
  49. package/dist/types/company.d.ts +223 -0
  50. package/dist/types/company.d.ts.map +1 -0
  51. package/dist/types/company.js +8 -0
  52. package/dist/types/contact.d.ts +166 -0
  53. package/dist/types/contact.d.ts.map +1 -0
  54. package/dist/types/contact.js +8 -0
  55. package/dist/types/deal.d.ts +203 -0
  56. package/dist/types/deal.d.ts.map +1 -0
  57. package/dist/types/deal.js +8 -0
  58. package/dist/types/pipeline.d.ts +116 -0
  59. package/dist/types/pipeline.d.ts.map +1 -0
  60. package/dist/types/pipeline.js +8 -0
  61. package/dist/types/task.d.ts +154 -0
  62. package/dist/types/task.d.ts.map +1 -0
  63. package/dist/types/task.js +8 -0
  64. package/dist/utils/errors.d.ts +128 -0
  65. package/dist/utils/errors.d.ts.map +1 -0
  66. package/dist/utils/errors.js +205 -0
  67. package/dist/utils/validation.d.ts +354 -0
  68. package/dist/utils/validation.d.ts.map +1 -0
  69. package/dist/utils/validation.js +716 -0
  70. package/package.json +49 -0
  71. package/test-tasks-debug.js +21 -0
  72. package/test-tasks-params.js +52 -0
  73. package/test-tools.js +171 -0
@@ -0,0 +1,75 @@
1
+ /**
2
+ * API Key Authentication for Salesflare MCP Server
3
+ *
4
+ * Implements AuthProvider interface for API key authentication.
5
+ * Reads API key from SALESFLARE_API_KEY environment variable.
6
+ *
7
+ * Per D-06: Crashes on startup with clear error if SALESFLARE_API_KEY is missing.
8
+ * Per D-08: Uses SALESFLARE_API_KEY environment variable.
9
+ *
10
+ * @module auth/api-key-auth
11
+ */
12
+ import { AuthProvider, AuthHeaders } from './token-manager.js';
13
+ /**
14
+ * API Key authentication provider
15
+ *
16
+ * Implements the AuthProvider interface for API key authentication.
17
+ * Stores the API key in memory and provides it as a Bearer token
18
+ * in Authorization headers.
19
+ *
20
+ * @class
21
+ * @implements {AuthProvider}
22
+ */
23
+ export declare class ApiKeyAuth implements AuthProvider {
24
+ /** The API key for authentication */
25
+ private apiKey;
26
+ /**
27
+ * Create a new ApiKeyAuth instance
28
+ *
29
+ * @param apiKey - The Salesflare API key
30
+ * @throws {SalesflareError} If apiKey is empty or not a string
31
+ */
32
+ constructor(apiKey: string);
33
+ /**
34
+ * Get authentication headers for API requests
35
+ *
36
+ * Returns the Authorization header with the API key as a Bearer token.
37
+ *
38
+ * @returns Promise resolving to auth headers with Bearer token
39
+ */
40
+ getAuthHeaders(): Promise<AuthHeaders>;
41
+ /**
42
+ * Check if currently authenticated
43
+ *
44
+ * Always returns true for API key auth since the key is validated
45
+ * at construction time.
46
+ *
47
+ * @returns Always true
48
+ */
49
+ isAuthenticated(): boolean;
50
+ /**
51
+ * Get the authentication type
52
+ *
53
+ * @returns 'api_key' to identify this as API key authentication
54
+ */
55
+ getAuthType(): 'api_key' | 'oauth';
56
+ }
57
+ /**
58
+ * Create an API key authentication provider from environment
59
+ *
60
+ * Reads SALESFLARE_API_KEY from process.env and creates an ApiKeyAuth instance.
61
+ * Per D-06: Throws a clear error if the environment variable is missing.
62
+ * Per D-08: Uses SALESFLARE_API_KEY environment variable name.
63
+ *
64
+ * @returns Configured ApiKeyAuth instance
65
+ * @throws {SalesflareError} If SALESFLARE_API_KEY environment variable is missing
66
+ *
67
+ * @example
68
+ * ```typescript
69
+ * const auth = createApiKeyAuth();
70
+ * const headers = await auth.getAuthHeaders();
71
+ * // headers = { Authorization: 'Bearer your-api-key' }
72
+ * ```
73
+ */
74
+ export declare function createApiKeyAuth(): ApiKeyAuth;
75
+ //# sourceMappingURL=api-key-auth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-key-auth.d.ts","sourceRoot":"","sources":["../../src/auth/api-key-auth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAG/D;;;;;;;;;GASG;AACH,qBAAa,UAAW,YAAW,YAAY;IAC7C,qCAAqC;IACrC,OAAO,CAAC,MAAM,CAAS;IAEvB;;;;;OAKG;gBACS,MAAM,EAAE,MAAM;IAY1B;;;;;;OAMG;IACG,cAAc,IAAI,OAAO,CAAC,WAAW,CAAC;IAM5C;;;;;;;OAOG;IACH,eAAe,IAAI,OAAO;IAI1B;;;;OAIG;IACH,WAAW,IAAI,SAAS,GAAG,OAAO;CAGnC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,gBAAgB,IAAI,UAAU,CAa7C"}
@@ -0,0 +1,103 @@
1
+ /**
2
+ * API Key Authentication for Salesflare MCP Server
3
+ *
4
+ * Implements AuthProvider interface for API key authentication.
5
+ * Reads API key from SALESFLARE_API_KEY environment variable.
6
+ *
7
+ * Per D-06: Crashes on startup with clear error if SALESFLARE_API_KEY is missing.
8
+ * Per D-08: Uses SALESFLARE_API_KEY environment variable.
9
+ *
10
+ * @module auth/api-key-auth
11
+ */
12
+ import { SalesflareError, ErrorCode } from '../utils/errors.js';
13
+ /**
14
+ * API Key authentication provider
15
+ *
16
+ * Implements the AuthProvider interface for API key authentication.
17
+ * Stores the API key in memory and provides it as a Bearer token
18
+ * in Authorization headers.
19
+ *
20
+ * @class
21
+ * @implements {AuthProvider}
22
+ */
23
+ export class ApiKeyAuth {
24
+ /** The API key for authentication */
25
+ apiKey;
26
+ /**
27
+ * Create a new ApiKeyAuth instance
28
+ *
29
+ * @param apiKey - The Salesflare API key
30
+ * @throws {SalesflareError} If apiKey is empty or not a string
31
+ */
32
+ constructor(apiKey) {
33
+ if (!apiKey || typeof apiKey !== 'string') {
34
+ throw new SalesflareError({
35
+ code: ErrorCode.AUTH_INVALID,
36
+ message: 'API key must be a non-empty string',
37
+ fix: 'Provide a valid Salesflare API key',
38
+ retryable: false,
39
+ });
40
+ }
41
+ this.apiKey = apiKey;
42
+ }
43
+ /**
44
+ * Get authentication headers for API requests
45
+ *
46
+ * Returns the Authorization header with the API key as a Bearer token.
47
+ *
48
+ * @returns Promise resolving to auth headers with Bearer token
49
+ */
50
+ async getAuthHeaders() {
51
+ return {
52
+ Authorization: `Bearer ${this.apiKey}`,
53
+ };
54
+ }
55
+ /**
56
+ * Check if currently authenticated
57
+ *
58
+ * Always returns true for API key auth since the key is validated
59
+ * at construction time.
60
+ *
61
+ * @returns Always true
62
+ */
63
+ isAuthenticated() {
64
+ return true;
65
+ }
66
+ /**
67
+ * Get the authentication type
68
+ *
69
+ * @returns 'api_key' to identify this as API key authentication
70
+ */
71
+ getAuthType() {
72
+ return 'api_key';
73
+ }
74
+ }
75
+ /**
76
+ * Create an API key authentication provider from environment
77
+ *
78
+ * Reads SALESFLARE_API_KEY from process.env and creates an ApiKeyAuth instance.
79
+ * Per D-06: Throws a clear error if the environment variable is missing.
80
+ * Per D-08: Uses SALESFLARE_API_KEY environment variable name.
81
+ *
82
+ * @returns Configured ApiKeyAuth instance
83
+ * @throws {SalesflareError} If SALESFLARE_API_KEY environment variable is missing
84
+ *
85
+ * @example
86
+ * ```typescript
87
+ * const auth = createApiKeyAuth();
88
+ * const headers = await auth.getAuthHeaders();
89
+ * // headers = { Authorization: 'Bearer your-api-key' }
90
+ * ```
91
+ */
92
+ export function createApiKeyAuth() {
93
+ const apiKey = process.env.SALESFLARE_API_KEY;
94
+ if (!apiKey) {
95
+ throw new SalesflareError({
96
+ code: ErrorCode.AUTH_INVALID,
97
+ message: 'SALESFLARE_API_KEY environment variable is required',
98
+ fix: 'Set SALESFLARE_API_KEY to your Salesflare API key',
99
+ retryable: false,
100
+ });
101
+ }
102
+ return new ApiKeyAuth(apiKey);
103
+ }
@@ -0,0 +1,81 @@
1
+ /**
2
+ * OAuth Authentication placeholder for Salesflare MCP Server
3
+ *
4
+ * This is a placeholder implementation for OAuth 2.0 authentication.
5
+ * Per D-01, full OAuth implementation is deferred to Phase 2.
6
+ *
7
+ * The class implements AuthProvider interface but throws errors
8
+ * for any actual usage, directing users to use API key authentication instead.
9
+ *
10
+ * @module auth/oauth-auth
11
+ */
12
+ import { AuthProvider, AuthHeaders } from './token-manager.js';
13
+ /**
14
+ * OAuth authentication provider (Phase 2 placeholder)
15
+ *
16
+ * Implements the AuthProvider interface but is not fully functional.
17
+ * This is a placeholder that will be completed in Phase 2.
18
+ *
19
+ * Per D-01: OAuth deferred to Phase 2.
20
+ *
21
+ * @class
22
+ * @implements {AuthProvider}
23
+ */
24
+ export declare class OAuthAuth implements AuthProvider {
25
+ /** OAuth client ID */
26
+ private clientId;
27
+ /** OAuth client secret */
28
+ private clientSecret;
29
+ /** OAuth redirect URI */
30
+ private redirectUri;
31
+ /** Token manager for OAuth tokens */
32
+ private tokenManager;
33
+ /**
34
+ * Create a new OAuthAuth instance
35
+ *
36
+ * @param clientId - OAuth client ID
37
+ * @param clientSecret - OAuth client secret
38
+ * @param redirectUri - OAuth redirect URI
39
+ */
40
+ constructor(clientId: string, clientSecret: string, redirectUri: string);
41
+ /**
42
+ * Get authentication headers for API requests
43
+ *
44
+ * Returns Authorization header with OAuth access token.
45
+ *
46
+ * TODO(Phase 2): Implement token refresh on AUTH_EXPIRED
47
+ *
48
+ * @returns Promise resolving to auth headers
49
+ * @throws {SalesflareError} If not authenticated or token expired
50
+ */
51
+ getAuthHeaders(): Promise<AuthHeaders>;
52
+ /**
53
+ * Check if currently authenticated
54
+ *
55
+ * Per Phase 1 placeholder: always returns false.
56
+ *
57
+ * TODO(Phase 2): Return tokenManager.hasValidToken()
58
+ *
59
+ * @returns Always false in Phase 1
60
+ */
61
+ isAuthenticated(): boolean;
62
+ /**
63
+ * Get the authentication type
64
+ *
65
+ * @returns 'oauth' to identify this as OAuth authentication
66
+ */
67
+ getAuthType(): 'api_key' | 'oauth';
68
+ /**
69
+ * Initiate OAuth authentication flow
70
+ *
71
+ * This is a placeholder for the full OAuth flow that will be
72
+ * implemented in Phase 2.
73
+ *
74
+ * TODO(Phase 2): Implement built-in local server for OAuth callback
75
+ * TODO(Phase 2): Implement salesflare_auth_initiate tool
76
+ *
77
+ * @throws {SalesflareError} Always throws as OAuth is not yet implemented
78
+ */
79
+ initiateAuth(): void;
80
+ }
81
+ //# sourceMappingURL=oauth-auth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauth-auth.d.ts","sourceRoot":"","sources":["../../src/auth/oauth-auth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,YAAY,EAAE,WAAW,EAAgB,MAAM,oBAAoB,CAAC;AAG7E;;;;;;;;;;GAUG;AACH,qBAAa,SAAU,YAAW,YAAY;IAC5C,sBAAsB;IACtB,OAAO,CAAC,QAAQ,CAAS;IAEzB,0BAA0B;IAC1B,OAAO,CAAC,YAAY,CAAS;IAE7B,yBAAyB;IACzB,OAAO,CAAC,WAAW,CAAS;IAE5B,qCAAqC;IACrC,OAAO,CAAC,YAAY,CAAe;IAEnC;;;;;;OAMG;gBACS,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM;IAOvE;;;;;;;;;OASG;IACG,cAAc,IAAI,OAAO,CAAC,WAAW,CAAC;IA2B5C;;;;;;;;OAQG;IACH,eAAe,IAAI,OAAO;IAM1B;;;;OAIG;IACH,WAAW,IAAI,SAAS,GAAG,OAAO;IAIlC;;;;;;;;;;OAUG;IACH,YAAY,IAAI,IAAI;CAUrB"}
@@ -0,0 +1,123 @@
1
+ /**
2
+ * OAuth Authentication placeholder for Salesflare MCP Server
3
+ *
4
+ * This is a placeholder implementation for OAuth 2.0 authentication.
5
+ * Per D-01, full OAuth implementation is deferred to Phase 2.
6
+ *
7
+ * The class implements AuthProvider interface but throws errors
8
+ * for any actual usage, directing users to use API key authentication instead.
9
+ *
10
+ * @module auth/oauth-auth
11
+ */
12
+ import { TokenManager } from './token-manager.js';
13
+ import { SalesflareError, ErrorCode } from '../utils/errors.js';
14
+ /**
15
+ * OAuth authentication provider (Phase 2 placeholder)
16
+ *
17
+ * Implements the AuthProvider interface but is not fully functional.
18
+ * This is a placeholder that will be completed in Phase 2.
19
+ *
20
+ * Per D-01: OAuth deferred to Phase 2.
21
+ *
22
+ * @class
23
+ * @implements {AuthProvider}
24
+ */
25
+ export class OAuthAuth {
26
+ /** OAuth client ID */
27
+ clientId;
28
+ /** OAuth client secret */
29
+ clientSecret;
30
+ /** OAuth redirect URI */
31
+ redirectUri;
32
+ /** Token manager for OAuth tokens */
33
+ tokenManager;
34
+ /**
35
+ * Create a new OAuthAuth instance
36
+ *
37
+ * @param clientId - OAuth client ID
38
+ * @param clientSecret - OAuth client secret
39
+ * @param redirectUri - OAuth redirect URI
40
+ */
41
+ constructor(clientId, clientSecret, redirectUri) {
42
+ this.clientId = clientId;
43
+ this.clientSecret = clientSecret;
44
+ this.redirectUri = redirectUri;
45
+ this.tokenManager = new TokenManager();
46
+ }
47
+ /**
48
+ * Get authentication headers for API requests
49
+ *
50
+ * Returns Authorization header with OAuth access token.
51
+ *
52
+ * TODO(Phase 2): Implement token refresh on AUTH_EXPIRED
53
+ *
54
+ * @returns Promise resolving to auth headers
55
+ * @throws {SalesflareError} If not authenticated or token expired
56
+ */
57
+ async getAuthHeaders() {
58
+ const token = this.tokenManager.getAccessToken();
59
+ if (!token) {
60
+ throw new SalesflareError({
61
+ code: ErrorCode.AUTH_INVALID,
62
+ message: 'OAuth not authenticated. Call salesflare_auth_initiate first.',
63
+ fix: 'Use API key authentication instead, or wait for Phase 2 OAuth implementation',
64
+ retryable: false,
65
+ });
66
+ }
67
+ if (this.tokenManager.isTokenExpired()) {
68
+ // TODO(Phase 2): Implement token refresh on AUTH_EXPIRED
69
+ throw new SalesflareError({
70
+ code: ErrorCode.AUTH_EXPIRED,
71
+ message: 'OAuth token has expired',
72
+ fix: 'Use API key authentication instead, or wait for Phase 2 OAuth implementation with token refresh',
73
+ retryable: false,
74
+ });
75
+ }
76
+ return {
77
+ Authorization: `Bearer ${token}`,
78
+ };
79
+ }
80
+ /**
81
+ * Check if currently authenticated
82
+ *
83
+ * Per Phase 1 placeholder: always returns false.
84
+ *
85
+ * TODO(Phase 2): Return tokenManager.hasValidToken()
86
+ *
87
+ * @returns Always false in Phase 1
88
+ */
89
+ isAuthenticated() {
90
+ // Phase 1: Return false as placeholder
91
+ // TODO(Phase 2): Return this.tokenManager.hasValidToken()
92
+ return false;
93
+ }
94
+ /**
95
+ * Get the authentication type
96
+ *
97
+ * @returns 'oauth' to identify this as OAuth authentication
98
+ */
99
+ getAuthType() {
100
+ return 'oauth';
101
+ }
102
+ /**
103
+ * Initiate OAuth authentication flow
104
+ *
105
+ * This is a placeholder for the full OAuth flow that will be
106
+ * implemented in Phase 2.
107
+ *
108
+ * TODO(Phase 2): Implement built-in local server for OAuth callback
109
+ * TODO(Phase 2): Implement salesflare_auth_initiate tool
110
+ *
111
+ * @throws {SalesflareError} Always throws as OAuth is not yet implemented
112
+ */
113
+ initiateAuth() {
114
+ // TODO(Phase 2): Implement built-in local server for OAuth callback
115
+ // TODO(Phase 2): Implement salesflare_auth_initiate tool
116
+ throw new SalesflareError({
117
+ code: ErrorCode.AUTH_INVALID,
118
+ message: 'OAuth authentication not yet implemented. Use API key authentication instead.',
119
+ fix: 'Set SALESFLARE_API_KEY environment variable and use API key authentication for Phase 1',
120
+ retryable: false,
121
+ });
122
+ }
123
+ }
@@ -0,0 +1,105 @@
1
+ /**
2
+ * Token manager and authentication provider interfaces
3
+ *
4
+ * Provides abstractions for different authentication methods (API key, OAuth)
5
+ * and token lifecycle management.
6
+ *
7
+ * @module auth/token-manager
8
+ */
9
+ /**
10
+ * HTTP headers for authentication
11
+ *
12
+ * Used by API client to include Authorization header in requests.
13
+ */
14
+ export interface AuthHeaders {
15
+ /** Authorization header with Bearer token */
16
+ Authorization: string;
17
+ /** Additional headers can be added */
18
+ [key: string]: string;
19
+ }
20
+ /**
21
+ * Authentication provider interface
22
+ *
23
+ * All authentication methods must implement this interface.
24
+ * Provides a common way to get auth headers and check auth status.
25
+ *
26
+ * @interface
27
+ */
28
+ export interface AuthProvider {
29
+ /**
30
+ * Get authentication headers for API requests
31
+ *
32
+ * @returns Promise resolving to auth headers object
33
+ */
34
+ getAuthHeaders(): Promise<AuthHeaders>;
35
+ /**
36
+ * Check if currently authenticated
37
+ *
38
+ * @returns True if authenticated and ready for API calls
39
+ */
40
+ isAuthenticated(): boolean;
41
+ /**
42
+ * Get the authentication type
43
+ *
44
+ * @returns 'api_key' for API key auth, 'oauth' for OAuth
45
+ */
46
+ getAuthType(): 'api_key' | 'oauth';
47
+ }
48
+ /**
49
+ * Token manager for OAuth token storage
50
+ *
51
+ * Manages access and refresh tokens in memory only (per D-13, D-14).
52
+ * Tokens are lost on server restart.
53
+ *
54
+ * This is primarily used by OAuth authentication. API key authentication
55
+ * does not use this class.
56
+ *
57
+ * @class
58
+ */
59
+ export declare class TokenManager {
60
+ /** Current access token */
61
+ private accessToken;
62
+ /** Current refresh token */
63
+ private refreshToken;
64
+ /** Token expiration timestamp */
65
+ private expiresAt;
66
+ /**
67
+ * Store new tokens
68
+ *
69
+ * @param access - The access token
70
+ * @param refresh - The refresh token
71
+ * @param expiresIn - Token lifetime in seconds
72
+ */
73
+ setTokens(access: string, refresh: string, expiresIn: number): void;
74
+ /**
75
+ * Get the current access token
76
+ *
77
+ * @returns The access token or null if not set
78
+ */
79
+ getAccessToken(): string | null;
80
+ /**
81
+ * Get the current refresh token
82
+ *
83
+ * @returns The refresh token or null if not set
84
+ */
85
+ getRefreshToken(): string | null;
86
+ /**
87
+ * Check if the access token is expired
88
+ *
89
+ * @returns True if token is expired or not set
90
+ */
91
+ isTokenExpired(): boolean;
92
+ /**
93
+ * Check if a valid token exists
94
+ *
95
+ * @returns True if token exists and is not expired
96
+ */
97
+ hasValidToken(): boolean;
98
+ /**
99
+ * Clear all stored tokens
100
+ *
101
+ * Called on logout or when tokens become invalid.
102
+ */
103
+ clearTokens(): void;
104
+ }
105
+ //# sourceMappingURL=token-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token-manager.d.ts","sourceRoot":"","sources":["../../src/auth/token-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC1B,6CAA6C;IAC7C,aAAa,EAAE,MAAM,CAAC;IACtB,sCAAsC;IACtC,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CACvB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;OAIG;IACH,cAAc,IAAI,OAAO,CAAC,WAAW,CAAC,CAAC;IAEvC;;;;OAIG;IACH,eAAe,IAAI,OAAO,CAAC;IAE3B;;;;OAIG;IACH,WAAW,IAAI,SAAS,GAAG,OAAO,CAAC;CACpC;AAED;;;;;;;;;;GAUG;AACH,qBAAa,YAAY;IACvB,2BAA2B;IAC3B,OAAO,CAAC,WAAW,CAAuB;IAE1C,4BAA4B;IAC5B,OAAO,CAAC,YAAY,CAAuB;IAE3C,iCAAiC;IACjC,OAAO,CAAC,SAAS,CAAqB;IAEtC;;;;;;OAMG;IACH,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI;IAMnE;;;;OAIG;IACH,cAAc,IAAI,MAAM,GAAG,IAAI;IAI/B;;;;OAIG;IACH,eAAe,IAAI,MAAM,GAAG,IAAI;IAIhC;;;;OAIG;IACH,cAAc,IAAI,OAAO;IAUzB;;;;OAIG;IACH,aAAa,IAAI,OAAO;IAIxB;;;;OAIG;IACH,WAAW,IAAI,IAAI;CAKpB"}
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Token manager and authentication provider interfaces
3
+ *
4
+ * Provides abstractions for different authentication methods (API key, OAuth)
5
+ * and token lifecycle management.
6
+ *
7
+ * @module auth/token-manager
8
+ */
9
+ /**
10
+ * Token manager for OAuth token storage
11
+ *
12
+ * Manages access and refresh tokens in memory only (per D-13, D-14).
13
+ * Tokens are lost on server restart.
14
+ *
15
+ * This is primarily used by OAuth authentication. API key authentication
16
+ * does not use this class.
17
+ *
18
+ * @class
19
+ */
20
+ export class TokenManager {
21
+ /** Current access token */
22
+ accessToken = null;
23
+ /** Current refresh token */
24
+ refreshToken = null;
25
+ /** Token expiration timestamp */
26
+ expiresAt = null;
27
+ /**
28
+ * Store new tokens
29
+ *
30
+ * @param access - The access token
31
+ * @param refresh - The refresh token
32
+ * @param expiresIn - Token lifetime in seconds
33
+ */
34
+ setTokens(access, refresh, expiresIn) {
35
+ this.accessToken = access;
36
+ this.refreshToken = refresh;
37
+ this.expiresAt = new Date(Date.now() + expiresIn * 1000);
38
+ }
39
+ /**
40
+ * Get the current access token
41
+ *
42
+ * @returns The access token or null if not set
43
+ */
44
+ getAccessToken() {
45
+ return this.accessToken;
46
+ }
47
+ /**
48
+ * Get the current refresh token
49
+ *
50
+ * @returns The refresh token or null if not set
51
+ */
52
+ getRefreshToken() {
53
+ return this.refreshToken;
54
+ }
55
+ /**
56
+ * Check if the access token is expired
57
+ *
58
+ * @returns True if token is expired or not set
59
+ */
60
+ isTokenExpired() {
61
+ if (!this.expiresAt) {
62
+ return true;
63
+ }
64
+ // Consider token expired 60 seconds before actual expiration
65
+ // to account for clock skew and network latency
66
+ const bufferMs = 60 * 1000;
67
+ return Date.now() > this.expiresAt.getTime() - bufferMs;
68
+ }
69
+ /**
70
+ * Check if a valid token exists
71
+ *
72
+ * @returns True if token exists and is not expired
73
+ */
74
+ hasValidToken() {
75
+ return this.accessToken !== null && !this.isTokenExpired();
76
+ }
77
+ /**
78
+ * Clear all stored tokens
79
+ *
80
+ * Called on logout or when tokens become invalid.
81
+ */
82
+ clearTokens() {
83
+ this.accessToken = null;
84
+ this.refreshToken = null;
85
+ this.expiresAt = null;
86
+ }
87
+ }