@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.
Files changed (44) hide show
  1. package/CHANGELOG.md +827 -0
  2. package/README.md +44 -11
  3. package/dist/__tests__/helpers/session.d.ts +15 -0
  4. package/dist/__tests__/helpers/session.d.ts.map +1 -0
  5. package/dist/__tests__/helpers/session.js +19 -0
  6. package/dist/auth/ntlm.d.ts +15 -0
  7. package/dist/auth/ntlm.d.ts.map +1 -1
  8. package/dist/auth/ntlm.js +38 -0
  9. package/dist/connection/AbstractAbapConnection.d.ts +180 -12
  10. package/dist/connection/AbstractAbapConnection.d.ts.map +1 -1
  11. package/dist/connection/AbstractAbapConnection.js +398 -19
  12. package/dist/connection/BaseAbapConnection.d.ts +5 -1
  13. package/dist/connection/BaseAbapConnection.d.ts.map +1 -1
  14. package/dist/connection/BaseAbapConnection.js +11 -1
  15. package/dist/connection/CertificateAbapConnection.d.ts +5 -1
  16. package/dist/connection/CertificateAbapConnection.d.ts.map +1 -1
  17. package/dist/connection/CertificateAbapConnection.js +11 -1
  18. package/dist/connection/JwtAbapConnection.d.ts +3 -2
  19. package/dist/connection/JwtAbapConnection.d.ts.map +1 -1
  20. package/dist/connection/JwtAbapConnection.js +19 -8
  21. package/dist/connection/KerberosAbapConnection.d.ts +5 -1
  22. package/dist/connection/KerberosAbapConnection.d.ts.map +1 -1
  23. package/dist/connection/KerberosAbapConnection.js +54 -3
  24. package/dist/connection/SamlAbapConnection.d.ts +5 -1
  25. package/dist/connection/SamlAbapConnection.d.ts.map +1 -1
  26. package/dist/connection/SamlAbapConnection.js +11 -1
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +4 -0
  29. package/dist/session/SessionLifecycle.d.ts +50 -70
  30. package/dist/session/SessionLifecycle.d.ts.map +1 -1
  31. package/dist/session/SessionLifecycle.js +59 -158
  32. package/docs/INDEX.md +106 -0
  33. package/docs/INSTALLATION.md +304 -0
  34. package/docs/JWT_AUTH_TOOLS.md +142 -0
  35. package/docs/MIGRATION-2.0.md +114 -0
  36. package/docs/SCOPE.md +44 -0
  37. package/docs/STATEFUL_SESSION_GUIDE.md +122 -0
  38. package/docs/USAGE.md +745 -0
  39. package/examples/README.md +112 -0
  40. package/examples/basic-connection.js +55 -0
  41. package/examples/jwt-with-token-refresh.js +87 -0
  42. package/examples/saml-connection.js +52 -0
  43. package/examples/websocket-transport.js +87 -0
  44. package/package.json +11 -4
@@ -0,0 +1,122 @@
1
+ # Stateful Session Guide (Connection Layer)
2
+
3
+ > **The header is not what tracks your lock.** `setSessionType('stateful')` sets
4
+ > a per-request header and nothing more — another handler can flip it back while
5
+ > your lock is genuinely open, and a batch never sets it at all. Nothing in this
6
+ > layer tracks locks: that belongs to `@mcp-abap-adt/adt-clients`, which holds the
7
+ > handles and pairs each LOCK with its UNLOCK per object. What the connection
8
+ > offers is `beginCriticalSection()` / `endCriticalSection()`, so a short timeout
9
+ > cannot abort a request mid-span. See
10
+ > [USAGE.md — Session Lifecycle](./USAGE.md#session-lifecycle).
11
+
12
+
13
+ This document explains how `@mcp-abap-adt/connection` manages HTTP-level session state for SAP ADT requests.
14
+
15
+ ---
16
+
17
+ ## Session Responsibilities
18
+
19
+ - Fetch and cache CSRF token (per connection instance)
20
+ - Store/reuse SAP cookies (`SAP_SESSIONID`, `sap-usercontext`, etc.)
21
+ - Track WHICH SAP session a connection is in, and refuse to work once it is lost
22
+
23
+ The connection layer **does not** decide when to lock/unlock objects—that logic lives in the ADT clients. Instead it ensures every request shares the same HTTP session when desired.
24
+
25
+ ---
26
+
27
+ ## Enabling Stateful Sessions
28
+
29
+ ```ts
30
+ import { createAbapConnection } from '@mcp-abap-adt/connection';
31
+
32
+ const connection = createAbapConnection(config, logger);
33
+ await connection.connect(); // required before any request
34
+
35
+ // Enable stateful session mode (adds x-sap-adt-sessiontype: stateful header)
36
+ connection.setSessionType('stateful');
37
+
38
+ // Now all requests share the same session (cookies, CSRF token)
39
+ await connection.makeAdtRequest({ method: 'GET', url: '/sap/bc/adt/discovery' });
40
+
41
+ // Switch back to stateless
42
+ connection.setSessionType('stateless');
43
+ ```
44
+
45
+ ---
46
+
47
+ ## Knowing Which Session You Are In
48
+
49
+ ```ts
50
+ import { BaseAbapConnection } from '@mcp-abap-adt/connection';
51
+
52
+ // getSessionIdentity() is on the HTTP connection classes, NOT on the
53
+ // IAbapConnection type that createAbapConnection() returns.
54
+ const connection = new BaseAbapConnection(config, logger);
55
+ await connection.connect();
56
+
57
+ // Which SAP session this connection is talking to. Changes only when the
58
+ // session itself is replaced — the CSRF cookie is deliberately excluded, since
59
+ // it rotates on a token refresh within one and the same session.
60
+ const identity = connection.getSessionIdentity(); // e.g. 'SAP_SESSIONID_A4H_001=...'
61
+ ```
62
+
63
+ Exporting and importing session state is **not** part of this package: the
64
+ methods that once did it were removed in 0.2.0, and persistence belongs to
65
+ [`@mcp-abap-adt/auth-broker`](https://www.npmjs.com/package/@mcp-abap-adt/auth-broker).
66
+
67
+ Handing a session to another worker, or resuming one in a CLI tool, therefore
68
+ goes through that package — and whatever it restores, the locks do not come
69
+ back with it: a lock handle from a session this connection did not open is
70
+ dead, and the connection says so rather than letting you use it.
71
+
72
+ ---
73
+
74
+ ## Request Hooks
75
+
76
+ Every ADT request issued through `makeAdtRequest` automatically:
77
+
78
+ 1. Ensures a CSRF token is available (`HEAD ...` with `x-csrf-token: fetch` if missing).
79
+ 2. Adds the cached token + cookies to headers.
80
+ 3. Updates stored cookies if SAP returns `set-cookie`.
81
+ 4. Retries once when CSRF token is invalid/expired.
82
+
83
+ This logic is transparent to callers (Builders, handlers, CLI scripts).
84
+
85
+ ---
86
+
87
+ ## Interaction With ADT Clients
88
+
89
+ - Builders receive the `AbapConnection` instance and optionally a `sessionId`.
90
+ - `@mcp-abap-adt/connection` keeps the HTTP session alive; Builders keep the ADT session consistent.
91
+ - A workflow cannot be resumed by restoring HTTP state into this package: the
92
+ methods that once did that were removed in 0.2.0. Establish a session with
93
+ `connect()` and take the locks again — a lock handle from a previous session
94
+ is dead, and the connection will say so with `ADT_SESSION_REPLACED` rather
95
+ than let you use it.
96
+
97
+ ---
98
+
99
+ ## Troubleshooting
100
+
101
+ - **CSRF token errors**: discard the session and establish a new one. `reset()`
102
+ does that, but it lives on the HTTP connection classes and is **not** on the
103
+ `IAbapConnection` type `createAbapConnection()` returns — reach it through a
104
+ concrete type:
105
+
106
+ ```ts
107
+ import { BaseAbapConnection } from '@mcp-abap-adt/connection';
108
+
109
+ const connection = new BaseAbapConnection(config, logger);
110
+ connection.reset(); // queues the cleanup; refuses requests meanwhile
111
+ await connection.connect(); // a new session, explicitly
112
+ ```
113
+ - **Session expired**: reauthenticate to obtain a new session.
114
+ - **Multiple connections**: each `createAbapConnection` instance maintains its own cookie jar; share the instance if you need continuity.
115
+
116
+ ---
117
+
118
+ ## Related Docs
119
+
120
+ - [USAGE.md — Session Lifecycle](./USAGE.md#session-lifecycle) – connect/disconnect, lock windows, a lost session
121
+ - [MIGRATION-2.0.md](./MIGRATION-2.0.md) – what the explicit lifecycle changed for callers
122
+