@mcp-abap-adt/auth-broker 0.1.5 → 0.1.7

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/CHANGELOG.md +244 -0
  2. package/README.md +181 -16
  3. package/bin/generate-env-from-service-key.ts +128 -0
  4. package/dist/AuthBroker.d.ts +47 -31
  5. package/dist/AuthBroker.d.ts.map +1 -1
  6. package/dist/AuthBroker.js +182 -134
  7. package/dist/__tests__/helpers/configHelpers.d.ts +49 -0
  8. package/dist/__tests__/helpers/configHelpers.d.ts.map +1 -0
  9. package/dist/__tests__/helpers/configHelpers.js +169 -0
  10. package/dist/index.d.ts +4 -4
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +5 -8
  13. package/dist/providers/ITokenProvider.d.ts +49 -0
  14. package/dist/providers/ITokenProvider.d.ts.map +1 -0
  15. package/dist/providers/ITokenProvider.js +10 -0
  16. package/dist/providers/index.d.ts +8 -0
  17. package/dist/providers/index.d.ts.map +1 -0
  18. package/dist/providers/index.js +8 -0
  19. package/dist/stores/index.d.ts +5 -5
  20. package/dist/stores/index.d.ts.map +1 -1
  21. package/dist/stores/index.js +4 -8
  22. package/dist/stores/interfaces.d.ts +88 -22
  23. package/dist/stores/interfaces.d.ts.map +1 -1
  24. package/dist/stores/interfaces.js +1 -2
  25. package/dist/types.d.ts +7 -31
  26. package/dist/types.d.ts.map +1 -1
  27. package/dist/types.js +2 -0
  28. package/package.json +13 -6
  29. package/dist/__tests__/testHelpers.d.ts +0 -44
  30. package/dist/__tests__/testHelpers.d.ts.map +0 -1
  31. package/dist/__tests__/testHelpers.js +0 -136
  32. package/dist/browserAuth.d.ts +0 -17
  33. package/dist/browserAuth.d.ts.map +0 -1
  34. package/dist/browserAuth.js +0 -305
  35. package/dist/cache.d.ts +0 -20
  36. package/dist/cache.d.ts.map +0 -1
  37. package/dist/cache.js +0 -46
  38. package/dist/envLoader.d.ts +0 -12
  39. package/dist/envLoader.d.ts.map +0 -1
  40. package/dist/envLoader.js +0 -90
  41. package/dist/getToken.d.ts +0 -14
  42. package/dist/getToken.d.ts.map +0 -1
  43. package/dist/getToken.js +0 -62
  44. package/dist/logger.d.ts +0 -40
  45. package/dist/logger.d.ts.map +0 -1
  46. package/dist/logger.js +0 -186
  47. package/dist/pathResolver.d.ts +0 -21
  48. package/dist/pathResolver.d.ts.map +0 -1
  49. package/dist/pathResolver.js +0 -105
  50. package/dist/refreshToken.d.ts +0 -14
  51. package/dist/refreshToken.d.ts.map +0 -1
  52. package/dist/refreshToken.js +0 -71
  53. package/dist/serviceKeyLoader.d.ts +0 -12
  54. package/dist/serviceKeyLoader.d.ts.map +0 -1
  55. package/dist/serviceKeyLoader.js +0 -72
  56. package/dist/stores/FileServiceKeyStore.d.ts +0 -38
  57. package/dist/stores/FileServiceKeyStore.d.ts.map +0 -1
  58. package/dist/stores/FileServiceKeyStore.js +0 -47
  59. package/dist/stores/FileSessionStore.d.ts +0 -50
  60. package/dist/stores/FileSessionStore.d.ts.map +0 -1
  61. package/dist/stores/FileSessionStore.js +0 -116
  62. package/dist/stores/SafeSessionStore.d.ts +0 -35
  63. package/dist/stores/SafeSessionStore.d.ts.map +0 -1
  64. package/dist/stores/SafeSessionStore.js +0 -42
  65. package/dist/tokenRefresher.d.ts +0 -17
  66. package/dist/tokenRefresher.d.ts.map +0 -1
  67. package/dist/tokenRefresher.js +0 -53
  68. package/dist/tokenStorage.d.ts +0 -15
  69. package/dist/tokenStorage.d.ts.map +0 -1
  70. package/dist/tokenStorage.js +0 -107
  71. package/dist/tokenValidator.d.ts +0 -11
  72. package/dist/tokenValidator.d.ts.map +0 -1
  73. package/dist/tokenValidator.js +0 -108
package/dist/getToken.js DELETED
@@ -1,62 +0,0 @@
1
- "use strict";
2
- /**
3
- * Get token implementation - loads from .env, validates, refreshes if needed
4
- */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getToken = getToken;
7
- const envLoader_1 = require("./envLoader");
8
- const serviceKeyLoader_1 = require("./serviceKeyLoader");
9
- const tokenValidator_1 = require("./tokenValidator");
10
- const refreshToken_1 = require("./refreshToken");
11
- const cache_1 = require("./cache");
12
- const logger_1 = require("./logger");
13
- /**
14
- * Get authentication token for destination
15
- * @param destination Destination name
16
- * @param searchPaths Array of paths to search for files
17
- * @param logger Optional logger instance. If not provided, uses default logger.
18
- * @returns JWT token string
19
- * @throws Error if neither .env file nor service key found
20
- */
21
- async function getToken(destination, searchPaths, logger) {
22
- // Check cache first
23
- const cachedToken = (0, cache_1.getCachedToken)(destination);
24
- if (cachedToken) {
25
- // Validate cached token
26
- const envConfig = await (0, envLoader_1.loadEnvFile)(destination, searchPaths);
27
- if (envConfig) {
28
- const isValid = await (0, tokenValidator_1.validateToken)(cachedToken, envConfig.sapUrl);
29
- if (isValid) {
30
- return cachedToken;
31
- }
32
- // Token expired, remove from cache
33
- }
34
- }
35
- // Load from .env file
36
- const envConfig = await (0, envLoader_1.loadEnvFile)(destination, searchPaths);
37
- if (envConfig && envConfig.jwtToken) {
38
- // Validate token
39
- const isValid = await (0, tokenValidator_1.validateToken)(envConfig.jwtToken, envConfig.sapUrl);
40
- if (isValid) {
41
- (0, cache_1.setCachedToken)(destination, envConfig.jwtToken);
42
- return envConfig.jwtToken;
43
- }
44
- }
45
- // Token not found or expired, check if we have service key for browser auth
46
- const serviceKey = await (0, serviceKeyLoader_1.loadServiceKey)(destination, searchPaths);
47
- if (!serviceKey) {
48
- // No service key and no valid token - throw error
49
- const searchedPaths = searchPaths.map(p => ` - ${p}`).join('\n');
50
- throw new Error(`No authentication found for destination "${destination}". ` +
51
- `Neither ${destination}.env file nor ${destination}.json service key found.\n` +
52
- `Please create one of:\n` +
53
- ` - ${destination}.env (with SAP_JWT_TOKEN)\n` +
54
- ` - ${destination}.json (service key)\n` +
55
- `Searched in:\n${searchedPaths}`);
56
- }
57
- // Try to refresh (will use browser auth if no refresh token)
58
- const log = logger || logger_1.defaultLogger;
59
- const newToken = await (0, refreshToken_1.refreshToken)(destination, searchPaths, log);
60
- (0, cache_1.setCachedToken)(destination, newToken);
61
- return newToken;
62
- }
package/dist/logger.d.ts DELETED
@@ -1,40 +0,0 @@
1
- /**
2
- * Logger interface and implementations for auth-broker package
3
- */
4
- /**
5
- * Log levels
6
- */
7
- export declare enum LogLevel {
8
- ERROR = 0,
9
- WARN = 1,
10
- INFO = 2,
11
- DEBUG = 3
12
- }
13
- /**
14
- * Logger interface - defines logging methods
15
- */
16
- export interface Logger {
17
- info(message: string): void;
18
- debug(message: string): void;
19
- error(message: string): void;
20
- warn(message: string): void;
21
- browserAuth(message: string): void;
22
- refresh(message: string): void;
23
- success(message: string): void;
24
- browserUrl(url: string): void;
25
- browserOpening(): void;
26
- testSkip(message: string): void;
27
- }
28
- export declare const defaultLogger: Logger;
29
- export declare const testLogger: Logger;
30
- export declare function info(message: string): void;
31
- export declare function debug(message: string): void;
32
- export declare function error(message: string): void;
33
- export declare function browserAuth(message: string): void;
34
- export declare function refresh(message: string): void;
35
- export declare function success(message: string): void;
36
- export declare function browserUrl(url: string): void;
37
- export declare function browserOpening(): void;
38
- export declare function testSkip(message: string): void;
39
- export declare function warn(message: string): void;
40
- //# sourceMappingURL=logger.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,oBAAY,QAAQ;IAClB,KAAK,IAAI;IACT,IAAI,IAAI;IACR,IAAI,IAAI;IACR,KAAK,IAAI;CACV;AAED;;GAEG;AACH,MAAM,WAAW,MAAM;IACrB,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,cAAc,IAAI,IAAI,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACjC;AAoJD,eAAO,MAAM,aAAa,EAAE,MAA4B,CAAC;AAGzD,eAAO,MAAM,UAAU,EAAE,MAAyB,CAAC;AAGnD,wBAAgB,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAE1C;AAED,wBAAgB,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAE3C;AAED,wBAAgB,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAE3C;AAED,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAEjD;AAED,wBAAgB,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAE7C;AAED,wBAAgB,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAE7C;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAE5C;AAED,wBAAgB,cAAc,IAAI,IAAI,CAErC;AAED,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAE9C;AAED,wBAAgB,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAE1C"}
package/dist/logger.js DELETED
@@ -1,186 +0,0 @@
1
- "use strict";
2
- /**
3
- * Logger interface and implementations for auth-broker package
4
- */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.testLogger = exports.defaultLogger = exports.LogLevel = void 0;
7
- exports.info = info;
8
- exports.debug = debug;
9
- exports.error = error;
10
- exports.browserAuth = browserAuth;
11
- exports.refresh = refresh;
12
- exports.success = success;
13
- exports.browserUrl = browserUrl;
14
- exports.browserOpening = browserOpening;
15
- exports.testSkip = testSkip;
16
- exports.warn = warn;
17
- /**
18
- * Log levels
19
- */
20
- var LogLevel;
21
- (function (LogLevel) {
22
- LogLevel[LogLevel["ERROR"] = 0] = "ERROR";
23
- LogLevel[LogLevel["WARN"] = 1] = "WARN";
24
- LogLevel[LogLevel["INFO"] = 2] = "INFO";
25
- LogLevel[LogLevel["DEBUG"] = 3] = "DEBUG";
26
- })(LogLevel || (exports.LogLevel = LogLevel = {}));
27
- /**
28
- * Get log level from environment variable
29
- * AUTH_LOG_LEVEL can be: error, warn, info, debug
30
- * DEBUG_AUTH_LOG=true is also supported for backward compatibility (sets level to debug)
31
- */
32
- function getLogLevel() {
33
- const level = process.env.AUTH_LOG_LEVEL?.toLowerCase();
34
- if (level === 'error')
35
- return LogLevel.ERROR;
36
- if (level === 'warn')
37
- return LogLevel.WARN;
38
- if (level === 'info')
39
- return LogLevel.INFO;
40
- if (level === 'debug')
41
- return LogLevel.DEBUG;
42
- // Backward compatibility
43
- if (process.env.DEBUG_AUTH_LOG === 'true')
44
- return LogLevel.DEBUG;
45
- // Default: info level
46
- return LogLevel.INFO;
47
- }
48
- /**
49
- * Default logger implementation
50
- * Controls output based on AUTH_LOG_LEVEL environment variable:
51
- * - error: only errors
52
- * - warn: errors and warnings
53
- * - info: errors, warnings, and info (default)
54
- * - debug: all messages
55
- */
56
- class DefaultLogger {
57
- logLevel;
58
- constructor(logLevel) {
59
- this.logLevel = logLevel ?? getLogLevel();
60
- }
61
- info(message) {
62
- if (this.logLevel >= LogLevel.INFO) {
63
- console.info(message);
64
- }
65
- }
66
- debug(message) {
67
- if (this.logLevel >= LogLevel.DEBUG) {
68
- console.debug(`[DEBUG] ${message}`);
69
- }
70
- }
71
- error(message) {
72
- if (this.logLevel >= LogLevel.ERROR) {
73
- console.error(message);
74
- }
75
- }
76
- warn(message) {
77
- if (this.logLevel >= LogLevel.WARN) {
78
- console.warn(`[WARN] ${message}`);
79
- }
80
- }
81
- browserAuth(message) {
82
- this.info(`🌐 ${message}`);
83
- }
84
- refresh(message) {
85
- this.info(`🔄 ${message}`);
86
- }
87
- success(message) {
88
- this.info(`✅ ${message}`);
89
- }
90
- browserUrl(url) {
91
- // Always show URL when browser is not opened automatically (user needs to open manually)
92
- this.info(`🔗 Open in browser: ${url}`);
93
- }
94
- browserOpening() {
95
- // Only show when debug is enabled (browser opens automatically)
96
- this.debug(`🌐 Opening browser for authentication...`);
97
- }
98
- testSkip(message) {
99
- this.info(`⏭️ ${message}`);
100
- }
101
- }
102
- /**
103
- * Test logger implementation
104
- * Uses same log levels as DefaultLogger
105
- */
106
- class TestLogger {
107
- logLevel;
108
- constructor(logLevel) {
109
- this.logLevel = logLevel ?? getLogLevel();
110
- }
111
- info(message) {
112
- if (this.logLevel >= LogLevel.INFO) {
113
- console.info(message);
114
- }
115
- }
116
- debug(message) {
117
- if (this.logLevel >= LogLevel.DEBUG) {
118
- console.info(`[DEBUG] ${message}`);
119
- }
120
- }
121
- error(message) {
122
- if (this.logLevel >= LogLevel.ERROR) {
123
- console.error(message);
124
- }
125
- }
126
- warn(message) {
127
- if (this.logLevel >= LogLevel.WARN) {
128
- console.warn(`[WARN] ${message}`);
129
- }
130
- }
131
- browserAuth(message) {
132
- this.info(`🌐 ${message}`);
133
- }
134
- refresh(message) {
135
- this.info(`🔄 ${message}`);
136
- }
137
- success(message) {
138
- this.info(`✅ ${message}`);
139
- }
140
- browserUrl(url) {
141
- // Always show URL when browser is not opened automatically (user needs to open manually)
142
- this.info(`🔗 Open in browser: ${url}`);
143
- }
144
- browserOpening() {
145
- // Only show when debug is enabled (browser opens automatically)
146
- this.debug(`🌐 Opening browser for authentication...`);
147
- }
148
- testSkip(message) {
149
- this.info(`⏭️ ${message}`);
150
- }
151
- }
152
- // Default logger instance (singleton)
153
- exports.defaultLogger = new DefaultLogger();
154
- // Test logger instance
155
- exports.testLogger = new TestLogger();
156
- // Export convenience functions that use default logger (for backward compatibility)
157
- function info(message) {
158
- exports.defaultLogger.info(message);
159
- }
160
- function debug(message) {
161
- exports.defaultLogger.debug(message);
162
- }
163
- function error(message) {
164
- exports.defaultLogger.error(message);
165
- }
166
- function browserAuth(message) {
167
- exports.defaultLogger.browserAuth(message);
168
- }
169
- function refresh(message) {
170
- exports.defaultLogger.refresh(message);
171
- }
172
- function success(message) {
173
- exports.defaultLogger.success(message);
174
- }
175
- function browserUrl(url) {
176
- exports.defaultLogger.browserUrl(url);
177
- }
178
- function browserOpening() {
179
- exports.defaultLogger.browserOpening();
180
- }
181
- function testSkip(message) {
182
- exports.defaultLogger.testSkip(message);
183
- }
184
- function warn(message) {
185
- exports.defaultLogger.warn(message);
186
- }
@@ -1,21 +0,0 @@
1
- /**
2
- * Path resolver - resolves search paths for .env and .json files
3
- */
4
- /**
5
- * Resolve search paths based on priority:
6
- * 1. Constructor parameter (array of paths) - highest priority
7
- * 2. AUTH_BROKER_PATH environment variable (colon/semicolon-separated paths)
8
- * 3. Current working directory - lowest priority
9
- *
10
- * @param constructorPaths Optional array of paths from constructor
11
- * @returns Array of resolved absolute paths to search
12
- */
13
- export declare function resolveSearchPaths(constructorPaths?: string | string[]): string[];
14
- /**
15
- * Find file in multiple search paths
16
- * @param fileName File name to search for
17
- * @param searchPaths Array of paths to search
18
- * @returns Full path to file if found, null otherwise
19
- */
20
- export declare function findFileInPaths(fileName: string, searchPaths: string[]): string | null;
21
- //# sourceMappingURL=pathResolver.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"pathResolver.d.ts","sourceRoot":"","sources":["../src/pathResolver.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,gBAAgB,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,EAAE,CAqCjF;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,IAAI,CAatF"}
@@ -1,105 +0,0 @@
1
- "use strict";
2
- /**
3
- * Path resolver - resolves search paths for .env and .json files
4
- */
5
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- var desc = Object.getOwnPropertyDescriptor(m, k);
8
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
- desc = { enumerable: true, get: function() { return m[k]; } };
10
- }
11
- Object.defineProperty(o, k2, desc);
12
- }) : (function(o, m, k, k2) {
13
- if (k2 === undefined) k2 = k;
14
- o[k2] = m[k];
15
- }));
16
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17
- Object.defineProperty(o, "default", { enumerable: true, value: v });
18
- }) : function(o, v) {
19
- o["default"] = v;
20
- });
21
- var __importStar = (this && this.__importStar) || (function () {
22
- var ownKeys = function(o) {
23
- ownKeys = Object.getOwnPropertyNames || function (o) {
24
- var ar = [];
25
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
26
- return ar;
27
- };
28
- return ownKeys(o);
29
- };
30
- return function (mod) {
31
- if (mod && mod.__esModule) return mod;
32
- var result = {};
33
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
34
- __setModuleDefault(result, mod);
35
- return result;
36
- };
37
- })();
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.resolveSearchPaths = resolveSearchPaths;
40
- exports.findFileInPaths = findFileInPaths;
41
- const path = __importStar(require("path"));
42
- /**
43
- * Resolve search paths based on priority:
44
- * 1. Constructor parameter (array of paths) - highest priority
45
- * 2. AUTH_BROKER_PATH environment variable (colon/semicolon-separated paths)
46
- * 3. Current working directory - lowest priority
47
- *
48
- * @param constructorPaths Optional array of paths from constructor
49
- * @returns Array of resolved absolute paths to search
50
- */
51
- function resolveSearchPaths(constructorPaths) {
52
- const paths = [];
53
- // Priority 1: Constructor parameter
54
- if (constructorPaths) {
55
- if (Array.isArray(constructorPaths)) {
56
- paths.push(...constructorPaths.map(p => path.resolve(p)));
57
- }
58
- else {
59
- paths.push(path.resolve(constructorPaths));
60
- }
61
- }
62
- // Priority 2: AUTH_BROKER_PATH environment variable
63
- const envPath = process.env.AUTH_BROKER_PATH;
64
- if (envPath) {
65
- // Support both colon (Unix) and semicolon (Windows) separators
66
- const envPaths = envPath.split(/[:;]/).map(p => p.trim()).filter(p => p.length > 0);
67
- paths.push(...envPaths.map(p => path.resolve(p)));
68
- }
69
- // Priority 3: Current working directory (only if no other paths specified)
70
- if (paths.length === 0) {
71
- paths.push(process.cwd());
72
- }
73
- // Remove duplicates while preserving order
74
- const uniquePaths = [];
75
- const seen = new Set();
76
- for (const p of paths) {
77
- const normalized = path.normalize(p);
78
- if (!seen.has(normalized)) {
79
- seen.add(normalized);
80
- uniquePaths.push(normalized);
81
- }
82
- }
83
- return uniquePaths;
84
- }
85
- /**
86
- * Find file in multiple search paths
87
- * @param fileName File name to search for
88
- * @param searchPaths Array of paths to search
89
- * @returns Full path to file if found, null otherwise
90
- */
91
- function findFileInPaths(fileName, searchPaths) {
92
- for (const searchPath of searchPaths) {
93
- const filePath = path.join(searchPath, fileName);
94
- try {
95
- const fs = require('fs');
96
- if (fs.existsSync(filePath)) {
97
- return filePath;
98
- }
99
- }
100
- catch {
101
- // Ignore errors, continue searching
102
- }
103
- }
104
- return null;
105
- }
@@ -1,14 +0,0 @@
1
- /**
2
- * Refresh token implementation - uses service key to obtain new token
3
- */
4
- import { Logger } from './logger';
5
- /**
6
- * Refresh token for destination using service key
7
- * If no refresh token exists, starts browser authentication flow
8
- * @param destination Destination name
9
- * @param searchPaths Array of paths to search for files
10
- * @param logger Optional logger instance. If not provided, uses default logger.
11
- * @returns New JWT token string
12
- */
13
- export declare function refreshToken(destination: string, searchPaths: string[], logger?: Logger): Promise<string>;
14
- //# sourceMappingURL=refreshToken.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"refreshToken.d.ts","sourceRoot":"","sources":["../src/refreshToken.ts"],"names":[],"mappings":"AAAA;;GAEG;AAQH,OAAO,EAAE,MAAM,EAAiB,MAAM,UAAU,CAAC;AAEjD;;;;;;;GAOG;AACH,wBAAsB,YAAY,CAAC,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CA+D/G"}
@@ -1,71 +0,0 @@
1
- "use strict";
2
- /**
3
- * Refresh token implementation - uses service key to obtain new token
4
- */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.refreshToken = refreshToken;
7
- const serviceKeyLoader_1 = require("./serviceKeyLoader");
8
- const tokenRefresher_1 = require("./tokenRefresher");
9
- const envLoader_1 = require("./envLoader");
10
- const tokenStorage_1 = require("./tokenStorage");
11
- const browserAuth_1 = require("./browserAuth");
12
- const cache_1 = require("./cache");
13
- const logger_1 = require("./logger");
14
- /**
15
- * Refresh token for destination using service key
16
- * If no refresh token exists, starts browser authentication flow
17
- * @param destination Destination name
18
- * @param searchPaths Array of paths to search for files
19
- * @param logger Optional logger instance. If not provided, uses default logger.
20
- * @returns New JWT token string
21
- */
22
- async function refreshToken(destination, searchPaths, logger) {
23
- const log = logger || logger_1.defaultLogger;
24
- // Load service key
25
- const serviceKey = await (0, serviceKeyLoader_1.loadServiceKey)(destination, searchPaths);
26
- if (!serviceKey) {
27
- const searchedPaths = searchPaths.map(p => ` - ${p}`).join('\n');
28
- throw new Error(`Service key file not found for destination "${destination}".\n` +
29
- `Please create file: ${destination}.json\n` +
30
- `Searched in:\n${searchedPaths}`);
31
- }
32
- // Extract UAA configuration
33
- const { url: uaaUrl, clientid: clientId, clientsecret: clientSecret } = serviceKey.uaa;
34
- if (!uaaUrl || !clientId || !clientSecret) {
35
- throw new Error(`Invalid service key for destination "${destination}". ` +
36
- `Missing required UAA fields: url, clientid, clientsecret`);
37
- }
38
- // Validate SAP URL early (before starting browser auth or refresh)
39
- const sapUrl = serviceKey.url || serviceKey.abap?.url || serviceKey.sap_url;
40
- if (!sapUrl) {
41
- throw new Error(`Service key for destination "${destination}" does not contain SAP URL. ` +
42
- `Expected field: url, abap.url, or sap_url`);
43
- }
44
- // Try to load existing refresh token from .env file
45
- const envConfig = await (0, envLoader_1.loadEnvFile)(destination, searchPaths);
46
- let refreshTokenValue = envConfig?.refreshToken;
47
- let result;
48
- // If no refresh token, start browser authentication flow
49
- if (!refreshTokenValue) {
50
- log.debug(`No refresh token found for destination "${destination}". Starting browser authentication...`);
51
- result = await (0, browserAuth_1.startBrowserAuth)(serviceKey, 'system', log);
52
- }
53
- else {
54
- // Refresh token using refresh token
55
- result = await (0, tokenRefresher_1.refreshJwtToken)(refreshTokenValue, uaaUrl, clientId, clientSecret);
56
- }
57
- // Save new token to .env file
58
- // Save to first search path (highest priority)
59
- const savePath = searchPaths[0];
60
- await (0, tokenStorage_1.saveTokenToEnv)(destination, savePath, {
61
- sapUrl,
62
- jwtToken: result.accessToken,
63
- refreshToken: result.refreshToken || refreshTokenValue,
64
- uaaUrl,
65
- uaaClientId: clientId,
66
- uaaClientSecret: clientSecret,
67
- });
68
- // Update cache with new token
69
- (0, cache_1.setCachedToken)(destination, result.accessToken);
70
- return result.accessToken;
71
- }
@@ -1,12 +0,0 @@
1
- /**
2
- * Service key loader - loads service key JSON files by destination name
3
- */
4
- import { ServiceKey } from './types';
5
- /**
6
- * Load service key from {destination}.json file
7
- * @param destination Destination name
8
- * @param searchPaths Array of paths to search for the file
9
- * @returns ServiceKey object or null if file not found
10
- */
11
- export declare function loadServiceKey(destination: string, searchPaths: string[]): Promise<ServiceKey | null>;
12
- //# sourceMappingURL=serviceKeyLoader.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"serviceKeyLoader.d.ts","sourceRoot":"","sources":["../src/serviceKeyLoader.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAGrC;;;;;GAKG;AACH,wBAAsB,cAAc,CAAC,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAgC3G"}
@@ -1,72 +0,0 @@
1
- "use strict";
2
- /**
3
- * Service key loader - loads service key JSON files by destination name
4
- */
5
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- var desc = Object.getOwnPropertyDescriptor(m, k);
8
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
- desc = { enumerable: true, get: function() { return m[k]; } };
10
- }
11
- Object.defineProperty(o, k2, desc);
12
- }) : (function(o, m, k, k2) {
13
- if (k2 === undefined) k2 = k;
14
- o[k2] = m[k];
15
- }));
16
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17
- Object.defineProperty(o, "default", { enumerable: true, value: v });
18
- }) : function(o, v) {
19
- o["default"] = v;
20
- });
21
- var __importStar = (this && this.__importStar) || (function () {
22
- var ownKeys = function(o) {
23
- ownKeys = Object.getOwnPropertyNames || function (o) {
24
- var ar = [];
25
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
26
- return ar;
27
- };
28
- return ownKeys(o);
29
- };
30
- return function (mod) {
31
- if (mod && mod.__esModule) return mod;
32
- var result = {};
33
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
34
- __setModuleDefault(result, mod);
35
- return result;
36
- };
37
- })();
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.loadServiceKey = loadServiceKey;
40
- const fs = __importStar(require("fs"));
41
- const pathResolver_1 = require("./pathResolver");
42
- /**
43
- * Load service key from {destination}.json file
44
- * @param destination Destination name
45
- * @param searchPaths Array of paths to search for the file
46
- * @returns ServiceKey object or null if file not found
47
- */
48
- async function loadServiceKey(destination, searchPaths) {
49
- const fileName = `${destination}.json`;
50
- const serviceKeyPath = (0, pathResolver_1.findFileInPaths)(fileName, searchPaths);
51
- if (!serviceKeyPath) {
52
- return null;
53
- }
54
- try {
55
- const fileContent = fs.readFileSync(serviceKeyPath, 'utf8');
56
- const serviceKey = JSON.parse(fileContent);
57
- // Validate service key structure
58
- if (!serviceKey.uaa) {
59
- throw new Error('Service key missing "uaa" object');
60
- }
61
- if (!serviceKey.uaa.url || !serviceKey.uaa.clientid || !serviceKey.uaa.clientsecret) {
62
- throw new Error('Service key "uaa" object missing required fields: url, clientid, clientsecret');
63
- }
64
- return serviceKey;
65
- }
66
- catch (error) {
67
- if (error instanceof SyntaxError) {
68
- throw new Error(`Invalid JSON in service key file for destination "${destination}": ${error.message}`);
69
- }
70
- throw new Error(`Failed to load service key for destination "${destination}": ${error instanceof Error ? error.message : String(error)}`);
71
- }
72
- }
@@ -1,38 +0,0 @@
1
- /**
2
- * File-based implementation of ServiceKeyStore
3
- *
4
- * Reads service keys from {destination}.json files in search paths.
5
- */
6
- import { IServiceKeyStore } from './interfaces';
7
- import { ServiceKey } from '../types';
8
- /**
9
- * File-based service key store implementation
10
- *
11
- * Searches for {destination}.json files in configured search paths.
12
- * Search paths priority:
13
- * 1. Constructor parameter (highest)
14
- * 2. AUTH_BROKER_PATH environment variable
15
- * 3. Current working directory (lowest)
16
- */
17
- export declare class FileServiceKeyStore implements IServiceKeyStore {
18
- private searchPaths;
19
- /**
20
- * Create a new FileServiceKeyStore instance
21
- * @param searchPaths Optional search paths for .json files.
22
- * Can be a single path (string) or array of paths.
23
- * If not provided, uses AUTH_BROKER_PATH env var or current working directory.
24
- */
25
- constructor(searchPaths?: string | string[]);
26
- /**
27
- * Get service key for destination
28
- * @param destination Destination name (e.g., "TRIAL")
29
- * @returns ServiceKey object or null if not found
30
- */
31
- getServiceKey(destination: string): Promise<ServiceKey | null>;
32
- /**
33
- * Get search paths (for error messages)
34
- * @returns Array of search paths
35
- */
36
- getSearchPaths(): string[];
37
- }
38
- //# sourceMappingURL=FileServiceKeyStore.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"FileServiceKeyStore.d.ts","sourceRoot":"","sources":["../../src/stores/FileServiceKeyStore.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAItC;;;;;;;;GAQG;AACH,qBAAa,mBAAoB,YAAW,gBAAgB;IAC1D,OAAO,CAAC,WAAW,CAAW;IAE9B;;;;;OAKG;gBACS,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE;IAI3C;;;;OAIG;IACG,aAAa,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;IAIpE;;;OAGG;IACH,cAAc,IAAI,MAAM,EAAE;CAG3B"}