@mcp-abap-adt/auth-broker 0.2.8 → 0.2.10

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.
package/CHANGELOG.md CHANGED
@@ -11,6 +11,48 @@ Thank you to all contributors! See [CONTRIBUTORS.md](CONTRIBUTORS.md) for the co
11
11
 
12
12
  ## [Unreleased]
13
13
 
14
+ ## [0.2.10] - 2025-12-22
15
+
16
+ ### Changed
17
+ - **Biome Migration**: Migrated from ESLint/Prettier to Biome for linting and formatting
18
+ - Added `@biomejs/biome` as dev dependency
19
+ - Added `lint`, `lint:check`, and `format` scripts to package.json
20
+ - Integrated Biome check into build process (`npx biome check src --diagnostic-level=error`)
21
+ - Replaced `unknown` with `any` in catch blocks (Biome requirement)
22
+ - Added `ErrorWithCode` type for better error type safety
23
+ - Refactored `getToken()` method into smaller private methods for better maintainability:
24
+ - `loadSessionData()` - loads session connection and authorization configs
25
+ - `getServiceUrl()` - gets serviceUrl from session or service key store
26
+ - `getUaaCredentials()` - gets UAA credentials from session or service key
27
+ - `saveTokenToSession()` - saves token and config to session
28
+ - `initializeSessionFromServiceKey()` - Step 0: initializes session from service key
29
+ - `validateExistingToken()` - Step 1: validates existing token
30
+ - `refreshTokenFromSession()` - Step 2a: refreshes token from session
31
+ - `refreshTokenFromServiceKey()` - Step 2b: refreshes token from service key
32
+
33
+ ### Fixed
34
+ - Fixed type safety issues by replacing `unknown` with `any` in error handling
35
+ - Removed unnecessary type assertions by using `ErrorWithCode` type
36
+ - Improved code organization and readability through method extraction
37
+
38
+ ## [0.2.9] - 2025-12-21
39
+
40
+ ### Added
41
+ - **`createTokenRefresher()` Method**: New factory method to create `ITokenRefresher` for dependency injection
42
+ - Returns `ITokenRefresher` implementation for a specific destination
43
+ - `getToken()` - returns cached token if valid, otherwise refreshes
44
+ - `refreshToken()` - forces token refresh and saves to session store
45
+ - Designed to be injected into `JwtAbapConnection` via DI
46
+ - Enables connections to handle 401/403 transparently without knowing auth internals
47
+
48
+ ### Changed
49
+ - **Dependencies**: Updated `@mcp-abap-adt/interfaces` to `^0.2.5`
50
+ - New `ITokenRefresher` interface for token management DI
51
+ - Simplified `IAbapConnection` interface (consumer-facing methods only)
52
+
53
+ ### Exports
54
+ - Re-export `ITokenRefresher` type from `@mcp-abap-adt/interfaces` for convenience
55
+
14
56
  ## [0.2.8] - 2025-12-21
15
57
 
16
58
  ### Changed
package/README.md CHANGED
@@ -110,6 +110,38 @@ const token = await broker.getToken('TRIAL');
110
110
  const newToken = await broker.refreshToken('TRIAL');
111
111
  ```
112
112
 
113
+ ### Creating Token Refresher for DI
114
+
115
+ The `createTokenRefresher()` method creates an `ITokenRefresher` implementation that can be injected into connections. This enables connections to handle token refresh transparently without knowing about authentication internals.
116
+
117
+ ```typescript
118
+ import { AuthBroker } from '@mcp-abap-adt/auth-broker';
119
+ import { JwtAbapConnection } from '@mcp-abap-adt/connection';
120
+
121
+ // Create broker
122
+ const broker = new AuthBroker({
123
+ sessionStore: mySessionStore,
124
+ serviceKeyStore: myServiceKeyStore,
125
+ tokenProvider: myTokenProvider,
126
+ });
127
+
128
+ // Create token refresher for specific destination
129
+ const tokenRefresher = broker.createTokenRefresher('TRIAL');
130
+
131
+ // Inject into connection (connection can handle 401/403 automatically)
132
+ const connection = new JwtAbapConnection(config, tokenRefresher);
133
+
134
+ // Token refresher methods:
135
+ // - getToken(): Returns cached token if valid, otherwise refreshes
136
+ // - refreshToken(): Forces token refresh and saves to session store
137
+ ```
138
+
139
+ **Benefits of Token Refresher:**
140
+ - 🔄 **Transparent Refresh**: Connection handles 401/403 errors automatically
141
+ - 🧩 **Dependency Injection**: Clean separation of concerns
142
+ - 💾 **Automatic Persistence**: Tokens saved to session store after refresh
143
+ - 🎯 **Destination-Scoped**: Each refresher is bound to specific destination
144
+
113
145
  ## Configuration
114
146
 
115
147
  ### Environment Variables
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * Main AuthBroker class for managing JWT tokens based on destinations
3
3
  */
4
- import { ILogger } from '@mcp-abap-adt/interfaces';
5
- import { IServiceKeyStore, ISessionStore, IAuthorizationConfig, IConnectionConfig } from './stores/interfaces';
6
- import { ITokenProvider } from './providers';
4
+ import { type ILogger, type ITokenRefresher } from '@mcp-abap-adt/interfaces';
5
+ import type { ITokenProvider } from './providers';
6
+ import type { IAuthorizationConfig, IConnectionConfig, IServiceKeyStore, ISessionStore } from './stores/interfaces';
7
7
  /**
8
8
  * Configuration object for AuthBroker constructor
9
9
  */
@@ -44,6 +44,38 @@ export declare class AuthBroker {
44
44
  * @param logger Optional logger instance implementing ILogger interface. If not provided, uses no-op logger.
45
45
  */
46
46
  constructor(config: AuthBrokerConfig, browser?: string, logger?: ILogger);
47
+ /**
48
+ * Load session data (connection and authorization configs)
49
+ */
50
+ private loadSessionData;
51
+ /**
52
+ * Get serviceUrl from session or service key store
53
+ */
54
+ private getServiceUrl;
55
+ /**
56
+ * Get UAA credentials from session or service key
57
+ */
58
+ private getUaaCredentials;
59
+ /**
60
+ * Save token and config to session
61
+ */
62
+ private saveTokenToSession;
63
+ /**
64
+ * Initialize session from service key (Step 0)
65
+ */
66
+ private initializeSessionFromServiceKey;
67
+ /**
68
+ * Validate existing token (Step 1)
69
+ */
70
+ private validateExistingToken;
71
+ /**
72
+ * Refresh token from session (Step 2a)
73
+ */
74
+ private refreshTokenFromSession;
75
+ /**
76
+ * Refresh token from service key (Step 2b)
77
+ */
78
+ private refreshTokenFromServiceKey;
47
79
  /**
48
80
  * Get authentication token for destination.
49
81
  * Uses tokenProvider for all authentication operations (browser-based authorization).
@@ -104,5 +136,23 @@ export declare class AuthBroker {
104
136
  * @returns Promise that resolves to IConnectionConfig or null if not found
105
137
  */
106
138
  getConnectionConfig(destination: string): Promise<IConnectionConfig | null>;
139
+ /**
140
+ * Create a token refresher for a specific destination.
141
+ *
142
+ * The token refresher is designed to be injected into JwtAbapConnection via DI,
143
+ * allowing the connection to handle token refresh transparently without knowing
144
+ * about authentication internals.
145
+ *
146
+ * **Usage:**
147
+ * ```typescript
148
+ * const broker = new AuthBroker(config);
149
+ * const tokenRefresher = broker.createTokenRefresher('TRIAL');
150
+ * const connection = new JwtAbapConnection(config, tokenRefresher);
151
+ * ```
152
+ *
153
+ * @param destination Destination name (e.g., "TRIAL")
154
+ * @returns ITokenRefresher implementation for the given destination
155
+ */
156
+ createTokenRefresher(destination: string): ITokenRefresher;
107
157
  }
108
158
  //# sourceMappingURL=AuthBroker.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"AuthBroker.d.ts","sourceRoot":"","sources":["../src/AuthBroker.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAA8C,MAAM,0BAA0B,CAAC;AAC/F,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC/G,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAa7C;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,mEAAmE;IACnE,YAAY,EAAE,aAAa,CAAC;IAC5B,uEAAuE;IACvE,eAAe,CAAC,EAAE,gBAAgB,CAAC;IACnC,4IAA4I;IAC5I,aAAa,EAAE,cAAc,CAAC;IAC9B;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED;;GAEG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,OAAO,CAAqB;IACpC,OAAO,CAAC,MAAM,CAAU;IACxB,OAAO,CAAC,eAAe,CAA+B;IACtD,OAAO,CAAC,YAAY,CAAgB;IACpC,OAAO,CAAC,aAAa,CAAiB;IACtC,OAAO,CAAC,gBAAgB,CAAU;IAElC;;;;;;;;;;;OAWG;gBAED,MAAM,EAAE,gBAAgB,EACxB,OAAO,CAAC,EAAE,MAAM,EAChB,MAAM,CAAC,EAAE,OAAO;IAuElB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAuCG;IACG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