@mcp-abap-adt/connection 1.10.2 → 3.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.
- package/CHANGELOG.md +827 -0
- package/README.md +44 -11
- package/dist/__tests__/helpers/session.d.ts +15 -0
- package/dist/__tests__/helpers/session.d.ts.map +1 -0
- package/dist/__tests__/helpers/session.js +19 -0
- package/dist/auth/ntlm.d.ts +15 -0
- package/dist/auth/ntlm.d.ts.map +1 -1
- package/dist/auth/ntlm.js +38 -0
- package/dist/connection/AbstractAbapConnection.d.ts +180 -12
- package/dist/connection/AbstractAbapConnection.d.ts.map +1 -1
- package/dist/connection/AbstractAbapConnection.js +398 -19
- package/dist/connection/BaseAbapConnection.d.ts +5 -1
- package/dist/connection/BaseAbapConnection.d.ts.map +1 -1
- package/dist/connection/BaseAbapConnection.js +11 -1
- package/dist/connection/CertificateAbapConnection.d.ts +5 -1
- package/dist/connection/CertificateAbapConnection.d.ts.map +1 -1
- package/dist/connection/CertificateAbapConnection.js +11 -1
- package/dist/connection/JwtAbapConnection.d.ts +3 -2
- package/dist/connection/JwtAbapConnection.d.ts.map +1 -1
- package/dist/connection/JwtAbapConnection.js +19 -8
- package/dist/connection/KerberosAbapConnection.d.ts +5 -1
- package/dist/connection/KerberosAbapConnection.d.ts.map +1 -1
- package/dist/connection/KerberosAbapConnection.js +54 -3
- package/dist/connection/SamlAbapConnection.d.ts +5 -1
- package/dist/connection/SamlAbapConnection.d.ts.map +1 -1
- package/dist/connection/SamlAbapConnection.js +11 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/session/SessionLifecycle.d.ts +50 -70
- package/dist/session/SessionLifecycle.d.ts.map +1 -1
- package/dist/session/SessionLifecycle.js +59 -158
- package/docs/INDEX.md +106 -0
- package/docs/INSTALLATION.md +304 -0
- package/docs/JWT_AUTH_TOOLS.md +142 -0
- package/docs/MIGRATION-2.0.md +114 -0
- package/docs/SCOPE.md +44 -0
- package/docs/STATEFUL_SESSION_GUIDE.md +122 -0
- package/docs/USAGE.md +745 -0
- package/examples/README.md +112 -0
- package/examples/basic-connection.js +55 -0
- package/examples/jwt-with-token-refresh.js +87 -0
- package/examples/saml-connection.js +52 -0
- package/examples/websocket-transport.js +87 -0
- package/package.json +11 -4
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
# Installation Guide
|
|
2
|
+
|
|
3
|
+
**Version:** see [CHANGELOG.md](../CHANGELOG.md)
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
- Node.js >= 18.0.0
|
|
8
|
+
- npm or yarn package manager
|
|
9
|
+
- Access to SAP ABAP system (on-premise or BTP)
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
### As NPM Package (Recommended)
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @mcp-abap-adt/connection
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### With Yarn
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
yarn add @mcp-abap-adt/connection
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### From Source
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
git clone https://github.com/fr0ster/mcp-abap-connection.git
|
|
29
|
+
cd mcp-abap-connection
|
|
30
|
+
npm install
|
|
31
|
+
npm run build
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Environment Setup
|
|
35
|
+
|
|
36
|
+
### Basic Authentication (On-Premise)
|
|
37
|
+
|
|
38
|
+
Create a `.env` file in your project root:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
SAP_URL=https://your-sap-server.com:8000
|
|
42
|
+
SAP_CLIENT=100
|
|
43
|
+
SAP_AUTH_TYPE=basic
|
|
44
|
+
SAP_USERNAME=your-username
|
|
45
|
+
SAP_PASSWORD=your-password
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### JWT Authentication (SAP BTP Cloud)
|
|
49
|
+
|
|
50
|
+
When using the `sap-abap-auth` CLI tool, the generated `.env` file will include token expiry information:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
# Token Expiry Information (auto-generated)
|
|
54
|
+
# JWT Token expires: Monday, December 25, 2025 at 10:30:45 AM UTC
|
|
55
|
+
# JWT Token expires at: 2025-12-25T10:30:45.000Z
|
|
56
|
+
# Refresh Token expires: Tuesday, January 25, 2026 at 10:30:45 AM UTC
|
|
57
|
+
# Refresh Token expires at: 2026-01-25T10:30:45.000Z
|
|
58
|
+
|
|
59
|
+
SAP_URL=https://your-instance.abap.cloud.sap
|
|
60
|
+
SAP_CLIENT=100
|
|
61
|
+
SAP_AUTH_TYPE=jwt
|
|
62
|
+
SAP_JWT_TOKEN=your-jwt-token
|
|
63
|
+
|
|
64
|
+
# Note: Token refresh is handled by @mcp-abap-adt/auth-broker package
|
|
65
|
+
# Connection package does not use refresh token credentials
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
**Manual Setup:** If creating `.env` manually (without CLI), you can omit the expiry comments:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
SAP_URL=https://your-instance.abap.cloud.sap
|
|
72
|
+
SAP_CLIENT=100
|
|
73
|
+
SAP_AUTH_TYPE=jwt
|
|
74
|
+
SAP_JWT_TOKEN=your-jwt-token
|
|
75
|
+
|
|
76
|
+
# Note: Token refresh is handled by @mcp-abap-adt/auth-broker package
|
|
77
|
+
# Connection package does not use refresh token credentials
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Loading Environment Variables
|
|
81
|
+
|
|
82
|
+
In your code:
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
import 'dotenv/config'; // or require('dotenv').config();
|
|
86
|
+
import { createAbapConnection } from '@mcp-abap-adt/connection';
|
|
87
|
+
|
|
88
|
+
const config = {
|
|
89
|
+
url: process.env.SAP_URL!,
|
|
90
|
+
client: process.env.SAP_CLIENT,
|
|
91
|
+
authType: process.env.SAP_AUTH_TYPE as 'basic' | 'jwt',
|
|
92
|
+
username: process.env.SAP_USERNAME,
|
|
93
|
+
password: process.env.SAP_PASSWORD,
|
|
94
|
+
jwtToken: process.env.SAP_JWT_TOKEN,
|
|
95
|
+
// Note: Token refresh credentials are not used by connection package
|
|
96
|
+
// Token refresh is handled by @mcp-abap-adt/auth-broker
|
|
97
|
+
};
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## CLI Tool Installation
|
|
101
|
+
|
|
102
|
+
The package includes `sap-abap-auth` CLI tool for browser-based JWT authentication.
|
|
103
|
+
|
|
104
|
+
### Global Installation
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
npm install -g @mcp-abap-adt/connection
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Then use directly:
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
sap-abap-auth auth -k service-key.json
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Local Project Installation
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
npm install --save-dev @mcp-abap-adt/connection
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Use via npx:
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
npx sap-abap-auth auth -k service-key.json
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### On-Demand (No Installation)
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
npx @mcp-abap-adt/connection sap-abap-auth auth -k service-key.json
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
See [JWT_AUTH_TOOLS.md](./JWT_AUTH_TOOLS.md) for detailed CLI documentation.
|
|
135
|
+
|
|
136
|
+
## Verification
|
|
137
|
+
|
|
138
|
+
### Test Installation
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
node -e "const { createAbapConnection } = require('@mcp-abap-adt/connection'); console.log('✓ Package loaded successfully');"
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Test Connection (Basic Auth)
|
|
145
|
+
|
|
146
|
+
Create `test-connection.js`:
|
|
147
|
+
|
|
148
|
+
```javascript
|
|
149
|
+
const { createAbapConnection } = require('@mcp-abap-adt/connection');
|
|
150
|
+
|
|
151
|
+
const config = {
|
|
152
|
+
url: 'https://your-sap-server.com',
|
|
153
|
+
authType: 'basic',
|
|
154
|
+
username: 'your-username',
|
|
155
|
+
password: 'your-password',
|
|
156
|
+
client: '100'
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
const logger = {
|
|
160
|
+
info: (msg) => console.log('[INFO]', msg),
|
|
161
|
+
error: (msg) => console.error('[ERROR]', msg),
|
|
162
|
+
warn: (msg) => console.warn('[WARN]', msg),
|
|
163
|
+
debug: (msg) => console.log('[DEBUG]', msg),
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
const connection = createAbapConnection(config, logger);
|
|
167
|
+
|
|
168
|
+
connection.connect()
|
|
169
|
+
.then(() =>
|
|
170
|
+
connection.makeAdtRequest({
|
|
171
|
+
method: 'GET',
|
|
172
|
+
url: '/sap/bc/adt/discovery',
|
|
173
|
+
}),
|
|
174
|
+
)
|
|
175
|
+
.then(() => console.log('✓ Connection successful'))
|
|
176
|
+
.catch((err) => console.error('✗ Connection failed:', err.message));
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
Run:
|
|
180
|
+
|
|
181
|
+
```bash
|
|
182
|
+
node test-connection.js
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## TypeScript Setup
|
|
186
|
+
|
|
187
|
+
### Install TypeScript
|
|
188
|
+
|
|
189
|
+
```bash
|
|
190
|
+
npm install --save-dev typescript @types/node
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### Create `tsconfig.json`
|
|
194
|
+
|
|
195
|
+
```json
|
|
196
|
+
{
|
|
197
|
+
"compilerOptions": {
|
|
198
|
+
"target": "ES2020",
|
|
199
|
+
"module": "commonjs",
|
|
200
|
+
"lib": ["ES2020"],
|
|
201
|
+
"outDir": "./dist",
|
|
202
|
+
"rootDir": "./src",
|
|
203
|
+
"strict": true,
|
|
204
|
+
"esModuleInterop": true,
|
|
205
|
+
"skipLibCheck": true,
|
|
206
|
+
"forceConsistentCasingInFileNames": true,
|
|
207
|
+
"resolveJsonModule": true
|
|
208
|
+
},
|
|
209
|
+
"include": ["src/**/*"],
|
|
210
|
+
"exclude": ["node_modules", "dist"]
|
|
211
|
+
}
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
### TypeScript Example
|
|
215
|
+
|
|
216
|
+
```typescript
|
|
217
|
+
import { createAbapConnection, SapConfig, ILogger } from '@mcp-abap-adt/connection';
|
|
218
|
+
|
|
219
|
+
const config: SapConfig = {
|
|
220
|
+
url: 'https://your-sap-server.com',
|
|
221
|
+
authType: 'basic',
|
|
222
|
+
username: 'user',
|
|
223
|
+
password: 'pass',
|
|
224
|
+
client: '100'
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
const logger: ILogger = {
|
|
228
|
+
info: (msg: string) => console.log(msg),
|
|
229
|
+
error: (msg: string) => console.error(msg),
|
|
230
|
+
warn: (msg: string) => console.warn(msg),
|
|
231
|
+
debug: (msg: string) => console.log(msg),
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
const connection = createAbapConnection(config, logger);
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
## Troubleshooting
|
|
238
|
+
|
|
239
|
+
### Module not found
|
|
240
|
+
|
|
241
|
+
If you get "Cannot find module" error after installation:
|
|
242
|
+
|
|
243
|
+
```bash
|
|
244
|
+
# Clear cache
|
|
245
|
+
npm cache clean --force
|
|
246
|
+
|
|
247
|
+
# Reinstall
|
|
248
|
+
rm -rf node_modules package-lock.json
|
|
249
|
+
npm install
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
### TypeScript errors
|
|
253
|
+
|
|
254
|
+
Ensure TypeScript version compatibility:
|
|
255
|
+
|
|
256
|
+
```bash
|
|
257
|
+
npm install --save-dev typescript@^5.9.2
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
### Build errors
|
|
261
|
+
|
|
262
|
+
If building from source fails:
|
|
263
|
+
|
|
264
|
+
```bash
|
|
265
|
+
# Check Node version
|
|
266
|
+
node --version # Should be >= 18.0.0
|
|
267
|
+
|
|
268
|
+
# Rebuild
|
|
269
|
+
npm run build
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
### Connection errors
|
|
273
|
+
|
|
274
|
+
**401 Unauthorized**: Check username/password or JWT token
|
|
275
|
+
**403 Forbidden**: Check user permissions in SAP
|
|
276
|
+
**ENOTFOUND**: Check SAP URL is correct and reachable
|
|
277
|
+
**ETIMEDOUT**: Check network/firewall, try increasing timeout
|
|
278
|
+
|
|
279
|
+
### SSL/TLS errors
|
|
280
|
+
|
|
281
|
+
For development with self-signed certificates:
|
|
282
|
+
|
|
283
|
+
```bash
|
|
284
|
+
export NODE_TLS_REJECT_UNAUTHORIZED=0
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
**⚠️ Warning**: Never use this in production!
|
|
288
|
+
|
|
289
|
+
## Version Compatibility
|
|
290
|
+
|
|
291
|
+
| Package Version | Node.js | TypeScript |
|
|
292
|
+
|----------------|---------|------------|
|
|
293
|
+
| 0.1.10 | >= 18.0 | >= 5.0 |
|
|
294
|
+
| 0.1.9 | >= 18.0 | >= 5.0 |
|
|
295
|
+
| 0.1.8 | >= 18.0 | >= 5.0 |
|
|
296
|
+
| 0.1.0 - 0.1.7 | >= 18.0 | >= 4.5 |
|
|
297
|
+
|
|
298
|
+
## Next Steps
|
|
299
|
+
|
|
300
|
+
- 📚 Read [USAGE.md](./USAGE.md) for detailed usage examples
|
|
301
|
+
- 🔄 Token refresh is handled by `@mcp-abap-adt/auth-broker` package
|
|
302
|
+
- 💾 Session state persistence is handled by `@mcp-abap-adt/auth-broker` package
|
|
303
|
+
- 🔑 Use [JWT auth CLI tool](./JWT_AUTH_TOOLS.md)
|
|
304
|
+
- 📖 Review [CHANGELOG.md](../CHANGELOG.md) for version history
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# JWT Auth Tools
|
|
2
|
+
|
|
3
|
+
This package ships with a helper CLI (`sap-abap-auth`) to obtain JWT and refresh tokens for SAP BTP ABAP systems.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
## Prerequisites
|
|
7
|
+
|
|
8
|
+
- Node.js >= 18
|
|
9
|
+
- Service key JSON for your SAP BTP ABAP instance (from SAP BTP Cockpit)
|
|
10
|
+
- Browser access (for OAuth flow)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npx sap-abap-auth auth -k path/to/service-key.json
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
This launches the OAuth browser flow and prints a `.env` file containing `SAP_JWT_TOKEN`, `SAP_REFRESH_TOKEN`, `SAP_UAA_URL`, etc.
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
## Installation Options
|
|
23
|
+
|
|
24
|
+
### Local (Project) Install
|
|
25
|
+
|
|
26
|
+
If `@mcp-abap-adt/connection` is part of your `dependencies` or `devDependencies`, you already have the CLI available:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm install @mcp-abap-adt/connection --save-dev
|
|
30
|
+
npx sap-abap-auth auth -k service-key.json
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Pros:
|
|
34
|
+
- CLI travels with your project.
|
|
35
|
+
- No need for global npm installs.
|
|
36
|
+
|
|
37
|
+
### Global Install
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npm install -g @mcp-abap-adt/connection
|
|
41
|
+
sap-abap-auth auth -k service-key.json
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Pros:
|
|
45
|
+
- Available system-wide.
|
|
46
|
+
- Useful if you run the tool frequently from the terminal.
|
|
47
|
+
|
|
48
|
+
### On-Demand (One-off) Usage
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
npx @mcp-abap-adt/connection sap-abap-auth auth -k service-key.json
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Pros:
|
|
55
|
+
- No install needed.
|
|
56
|
+
- Perfect for quick usage on CI or temporary machines.
|
|
57
|
+
|
|
58
|
+
## CLI Usage
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
# Show help
|
|
62
|
+
sap-abap-auth --help
|
|
63
|
+
|
|
64
|
+
# Authenticate using service key JSON
|
|
65
|
+
sap-abap-auth auth -k service-key.json
|
|
66
|
+
|
|
67
|
+
# Use specific browser (chrome, firefox, edge, system, none)
|
|
68
|
+
sap-abap-auth auth -k service-key.json --browser chrome
|
|
69
|
+
|
|
70
|
+
# Output to custom file (default: .env)
|
|
71
|
+
sap-abap-auth auth -k service-key.json --output .env.production
|
|
72
|
+
|
|
73
|
+
# Print tokens to stdout (no file)
|
|
74
|
+
sap-abap-auth auth -k service-key.json --browser none --output -
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Full Command Reference
|
|
78
|
+
|
|
79
|
+
| Option | Description |
|
|
80
|
+
|-------------------------|------------------------------------------------------|
|
|
81
|
+
| `-k, --key <path>` | Path to service key JSON (required) |
|
|
82
|
+
| `-b, --browser <name>` | Browser to open (chrome, edge, firefox, system, none)|
|
|
83
|
+
| `-o, --output <path>` | Output `.env` path (`-` for stdout, defaults to `.env`) |
|
|
84
|
+
| `--config <path>` | Use config file with saved credentials |
|
|
85
|
+
| `--no-open` | Same as `--browser none` |
|
|
86
|
+
| `--help` | Show help |
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
## Using Generated Tokens
|
|
90
|
+
|
|
91
|
+
After running the CLI, you get `.env` similar to:
|
|
92
|
+
|
|
93
|
+
```
|
|
94
|
+
# Token Expiry Information (auto-generated)
|
|
95
|
+
# JWT Token expires: Monday, December 25, 2025 at 10:30:45 AM UTC
|
|
96
|
+
# JWT Token expires at: 2025-12-25T10:30:45.000Z
|
|
97
|
+
# Refresh Token expires: Tuesday, January 25, 2026 at 10:30:45 AM UTC
|
|
98
|
+
# Refresh Token expires at: 2026-01-25T10:30:45.000Z
|
|
99
|
+
|
|
100
|
+
SAP_URL=https://<your-abap-instance>.abap.whatever.sap
|
|
101
|
+
SAP_AUTH_TYPE=jwt
|
|
102
|
+
SAP_JWT_TOKEN=eyJhbGciOi...
|
|
103
|
+
SAP_REFRESH_TOKEN=eyJraWQiOi...
|
|
104
|
+
SAP_UAA_URL=https://<your>-authentication.<region>.hana.ondemand.com/oauth/token
|
|
105
|
+
SAP_UAA_CLIENT_ID=sb-<id>
|
|
106
|
+
SAP_UAA_CLIENT_SECRET=<secret>
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
**Note:** The token expiry information at the top of the `.env` file is automatically generated by decoding the JWT tokens. This helps you:
|
|
110
|
+
- Know when tokens will expire
|
|
111
|
+
- Plan token refresh in advance
|
|
112
|
+
- Troubleshoot authentication issues related to expired tokens
|
|
113
|
+
|
|
114
|
+
If a token's expiry cannot be determined (e.g., non-standard JWT format), a comment will indicate this.
|
|
115
|
+
|
|
116
|
+
Load it in your project:
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
source .env
|
|
120
|
+
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Or configure `SapConfig` directly:
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
import { createAbapConnection } from "@mcp-abap-adt/connection";
|
|
127
|
+
|
|
128
|
+
const connection = createAbapConnection({
|
|
129
|
+
url: process.env.SAP_URL!,
|
|
130
|
+
authType: "jwt",
|
|
131
|
+
jwtToken: process.env.SAP_JWT_TOKEN!,
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
// Note: Token refresh is handled by @mcp-abap-adt/auth-broker package
|
|
135
|
+
// The refresh token credentials in .env are used by auth-broker, not connection
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
## Automating in CI
|
|
140
|
+
|
|
141
|
+
You can run the CLI once locally, store `.env` in secure storage, then load those variables in CI/CD to feed `@mcp-abap-adt/connection`. بهدف
|
|
142
|
+
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# Migrating to the explicit session lifecycle
|
|
2
|
+
|
|
3
|
+
The connection now owns its session, and says so. If your code never called
|
|
4
|
+
`connect()`, it will fail at startup rather than at the first request — the
|
|
5
|
+
better failure, but a new one.
|
|
6
|
+
|
|
7
|
+
## What breaks, and what to do
|
|
8
|
+
|
|
9
|
+
### 1. `connect()` is required
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
const connection = createAbapConnection(config, logger);
|
|
13
|
+
await connection.connect(); // ← add this
|
|
14
|
+
await connection.makeAdtRequest(...);
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Without it every request is refused with `ADT_NOT_CONNECTED` and nothing
|
|
18
|
+
reaches the server.
|
|
19
|
+
|
|
20
|
+
**Why it changed.** Requests used to establish the session on the fly, which
|
|
21
|
+
meant a caller could never tell whether it had a session, whose it was, or
|
|
22
|
+
whether the one it locked in was still there. That is what let the connector
|
|
23
|
+
replace the session under a caller holding a lock without saying anything.
|
|
24
|
+
|
|
25
|
+
### 2. `connect()` rejects on failure
|
|
26
|
+
|
|
27
|
+
It used to log a warning and resolve anyway, deferring the work to the first
|
|
28
|
+
request. Now a resolved promise means a usable session exists.
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
try {
|
|
32
|
+
await connection.connect();
|
|
33
|
+
} catch (error) {
|
|
34
|
+
// Handle it here, at startup, where it is cheap.
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
If you never checked the result of `connect()`, you were relying on that
|
|
39
|
+
deferral. The failure has not appeared — it has moved to where you can see it.
|
|
40
|
+
|
|
41
|
+
**Kerberos**: `connect()` now surfaces a limitation that used to be hidden. If
|
|
42
|
+
the server continues the SPNEGO exchange (a 401 carrying a `Negotiate` token),
|
|
43
|
+
this client cannot continue it — the GSS context is not retained — and
|
|
44
|
+
`connect()` fails saying so. Previously the same situation resolved and failed
|
|
45
|
+
later, on the first request, as an unrelated-looking 401.
|
|
46
|
+
|
|
47
|
+
### 3. Requests are refused after a teardown
|
|
48
|
+
|
|
49
|
+
`disconnect()` and `reset()` stop the connection from serving requests until the
|
|
50
|
+
next `connect()`. An in-flight request is not cut off and not waited for either:
|
|
51
|
+
it runs to completion, and its result is fenced so it cannot touch a session
|
|
52
|
+
established since.
|
|
53
|
+
|
|
54
|
+
### 4. If you hold locks, do not let a timeout cut the span
|
|
55
|
+
|
|
56
|
+
The connection does **not** track your locks. It does not know one exists, what
|
|
57
|
+
object it covers, or what would release it — pairing every LOCK with its UNLOCK
|
|
58
|
+
belongs to `@mcp-abap-adt/adt-clients`, which holds the handles.
|
|
59
|
+
|
|
60
|
+
What this layer can do is not let a short timeout abort a request mid-span, which
|
|
61
|
+
would leave an operation whose outcome you cannot determine — a `LOCK` that may
|
|
62
|
+
have succeeded server-side, with a handle you never received:
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
connection.beginCriticalSection();
|
|
66
|
+
try {
|
|
67
|
+
const handle = await lock(connection, 'ZCL_MY_CLASS');
|
|
68
|
+
await update(connection, 'ZCL_MY_CLASS', handle);
|
|
69
|
+
await unlock(connection, 'ZCL_MY_CLASS', handle);
|
|
70
|
+
} finally {
|
|
71
|
+
connection.endCriticalSection();
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
This is not new in 2.x — it has been available since 1.9.0 and is unchanged.
|
|
76
|
+
|
|
77
|
+
### 5. A new error you should handle
|
|
78
|
+
|
|
79
|
+
`ADT_SESSION_REPLACED` means the SAP session is gone. It is raised whenever the
|
|
80
|
+
session identity changes under us, and whenever the server itself says the session
|
|
81
|
+
no longer exists. **Your lock handle is dead**: unlocking with it will not work, and the
|
|
82
|
+
object may still be locked on the server. The connector does not retry such
|
|
83
|
+
a request — retrying blindly is what produced further orphaned locks in the
|
|
84
|
+
field.
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
// (connection already established)
|
|
88
|
+
try {
|
|
89
|
+
await connection.makeAdtRequest(...);
|
|
90
|
+
} catch (error) {
|
|
91
|
+
if (error.code === 'ADT_SESSION_REPLACED') {
|
|
92
|
+
// Reconnect, then deal with the lock you can no longer release.
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## What did NOT change
|
|
98
|
+
|
|
99
|
+
- `makeAdtRequest()` keeps its signature and its behaviour on a healthy session.
|
|
100
|
+
- `IAbapConnection` is unchanged: `connect()` was already on it. The rest of the
|
|
101
|
+
lifecycle API lives on the HTTP connection classes for now, so code holding
|
|
102
|
+
the interface type sees no new members and needs no change.
|
|
103
|
+
- Automatic recovery still happens: a CSRF token refresh, a 401 retry, a JWT
|
|
104
|
+
refresh. What changed is that a recovery which **replaces the session** while
|
|
105
|
+
you hold a lock now fails loudly instead of continuing on the new one.
|
|
106
|
+
- RFC connections already required an open client, so nothing there changes for
|
|
107
|
+
callers.
|
|
108
|
+
|
|
109
|
+
## What to check on your side
|
|
110
|
+
|
|
111
|
+
- every place a connection is created — does `connect()` follow it?
|
|
112
|
+
- every place `connect()` is called — is its rejection handled?
|
|
113
|
+
- error handling around lock/unlock flows — is `ADT_SESSION_REPLACED` handled,
|
|
114
|
+
or does it fall into a generic catch that retries?
|
package/docs/SCOPE.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Scope and Boundaries
|
|
2
|
+
|
|
3
|
+
This package is **one component of the `@mcp-abap-adt/*` family**. Each package owns one concern; together they form an SAP ABAP tooling stack. Keeping the boundaries clear is important — several features that look natural to add here actually belong in sibling packages, and some that look missing (like RFC-to-cloud) do not exist anywhere in the ecosystem because the underlying technology does not support them.
|
|
4
|
+
|
|
5
|
+
## What this package does
|
|
6
|
+
|
|
7
|
+
- **HTTP transport to SAP ADT** — request dispatch, CSRF token fetch, cookie and session handling, stateful/stateless session control.
|
|
8
|
+
- **The session lifecycle** — establishing a session and refusing to work without one, tearing it down without cutting in-flight requests, tracking which SAP session it is talking to, and telling the caller when that session is lost while a lock is held. See [USAGE.md — Session Lifecycle](./USAGE.md#session-lifecycle).
|
|
9
|
+
- **RFC transport to on-premise SAP** — via `@mcp-abap-adt/sap-rfc-lite` + NW RFC SDK, calling `SADT_REST_RFC_ENDPOINT` (the same FM Eclipse ADT uses on on-prem).
|
|
10
|
+
- **Applying credentials** handed to it by the caller (Basic user/password, Bearer JWT, SAML session cookies).
|
|
11
|
+
|
|
12
|
+
## What this package does NOT do, and where it lives instead
|
|
13
|
+
|
|
14
|
+
| Concern | Belongs in |
|
|
15
|
+
|---|---|
|
|
16
|
+
| Token acquisition (SAML/OAuth2 flows, browser login, PKCE) | `@mcp-abap-adt/auth-broker` |
|
|
17
|
+
| Token validation, refresh, re-authentication, expiry tracking | consumer via `ITokenProvider` (from `@mcp-abap-adt/interfaces`) |
|
|
18
|
+
| Session state persistence across processes | `@mcp-abap-adt/auth-broker` |
|
|
19
|
+
| Auth-type constants, provider error codes, auth lifecycle contracts | `@mcp-abap-adt/interfaces` |
|
|
20
|
+
|
|
21
|
+
The rule: **if it is about *acquiring* or *refreshing* credentials, it is not our job.** We receive credentials that are valid at call time and use them. The consumer is responsible for handing us fresh ones — they know their IdP, their refresh cadence, their re-auth UX.
|
|
22
|
+
|
|
23
|
+
## Why there is no RFC to SAP BTP / cloud
|
|
24
|
+
|
|
25
|
+
Short answer: because SAP does not support it that way, and Eclipse ADT does not do it that way either.
|
|
26
|
+
|
|
27
|
+
**1. Eclipse ADT talks to cloud over HTTP, not RFC.**
|
|
28
|
+
The `com.sap.adt.communication.http.*` package is the only transport Eclipse ADT uses for ADT itself. Cloud login in Eclipse goes through `SamlWithReentranceTicketLogonFacade` → `IcfEndpointBasedSystemUrlInfoProvider` → `HttpLowLevelConnection.sendRequest`. This is an HTTP flow via the ABAP ICF (Internet Communication Framework) endpoint, with a browser SAML login minting a short-lived reentrance ticket, which is then exchanged for a `MYSAPSSO2` session cookie over HTTP. There is no RFC anywhere in this path. JCo/RFC calls that appear in Eclipse logs come from unrelated features (GUI integration, JCo destination tests) — not ADT.
|
|
29
|
+
|
|
30
|
+
**2. NW RFC SDK has no JWT or SAML-2.0-XML logon parameter.**
|
|
31
|
+
Inspection of `sapnwrfc.h` and the SDK's reference `sapnwrfc.ini` confirms the supported client logon parameters are: `USER`/`PASSWD`, `X509CERT`, `MYSAPSSO2` (accepts SSO2 tickets and SAP-internal "assertion tickets", *not* SAML 2.0 XML assertions), plus SNC (`SNC_QOP`, `SNC_MYNAME`, `SNC_PARTNERNAME`, `SNC_LIB`) for Kerberos/x509 over RFC. For WebSocket-RFC: `WSHOST`/`WSPORT`, `ALIAS_USER`, `TLS_CLIENT_PSE`, `TLS_CLIENT_CERTIFICATE_LOGON`. No `JWT`, no `BEARER`, no `SAML_ASSERTION`, no `OAUTH` keys exist in the SDK headers.
|
|
32
|
+
|
|
33
|
+
**3. `@mcp-abap-adt/sap-rfc-lite` is a pure passthrough.**
|
|
34
|
+
It forwards every `(name, value)` pair from the JS `Client(params)` object to `RFC_CONNECTION_PARAMETER[]` without filtering. So the wrapper is not a constraint — the constraint is the SDK itself.
|
|
35
|
+
|
|
36
|
+
**4. For BTP on-prem scenarios (Cloud Connector), the JWT→x509/SNC swap happens server-side in the CC.** The client-side RFC call still carries classic credentials (x509 + SNC), not the JWT. Supporting that would be adding SNC-over-RFC for on-prem backends behind a CC tunnel — an on-prem extension, not a "cloud RFC" feature.
|
|
37
|
+
|
|
38
|
+
**Conclusion:** "RFC to cloud" is not a missing feature that would be useful to add; it is a category error. ADT to cloud = HTTP (already supported here). RFC to on-prem = supported here via `connectionType: 'rfc'`. Anything claiming a third combination does not map to what the SAP stack actually exposes.
|
|
39
|
+
|
|
40
|
+
## See also
|
|
41
|
+
|
|
42
|
+
- [`INSTALLATION.md`](./INSTALLATION.md)
|
|
43
|
+
- [`USAGE.md`](./USAGE.md)
|
|
44
|
+
- Sibling packages: `@mcp-abap-adt/interfaces`, `@mcp-abap-adt/sap-rfc-lite`, `@mcp-abap-adt/auth-broker`
|