@mcp-abap-adt/connection 0.1.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/LICENSE +21 -0
- package/README.md +80 -0
- package/bin/sap-abap-auth.js +600 -0
- package/dist/config/sapConfig.d.ts +43 -0
- package/dist/config/sapConfig.d.ts.map +1 -0
- package/dist/config/sapConfig.js +202 -0
- package/dist/connection/AbapConnection.d.ts +22 -0
- package/dist/connection/AbapConnection.d.ts.map +1 -0
- package/dist/connection/AbapConnection.js +2 -0
- package/dist/connection/AbstractAbapConnection.d.ts +115 -0
- package/dist/connection/AbstractAbapConnection.d.ts.map +1 -0
- package/dist/connection/AbstractAbapConnection.js +716 -0
- package/dist/connection/BaseAbapConnection.d.ts +17 -0
- package/dist/connection/BaseAbapConnection.d.ts.map +1 -0
- package/dist/connection/BaseAbapConnection.js +68 -0
- package/dist/connection/JwtAbapConnection.d.ts +33 -0
- package/dist/connection/JwtAbapConnection.d.ts.map +1 -0
- package/dist/connection/JwtAbapConnection.js +305 -0
- package/dist/connection/connectionFactory.d.ts +5 -0
- package/dist/connection/connectionFactory.d.ts.map +1 -0
- package/dist/connection/connectionFactory.js +15 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -0
- package/dist/logger.d.ts +67 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +2 -0
- package/dist/utils/FileSessionStorage.d.ts +73 -0
- package/dist/utils/FileSessionStorage.d.ts.map +1 -0
- package/dist/utils/FileSessionStorage.js +191 -0
- package/dist/utils/timeouts.d.ts +8 -0
- package/dist/utils/timeouts.d.ts.map +1 -0
- package/dist/utils/timeouts.js +21 -0
- package/dist/utils/tokenRefresh.d.ts +17 -0
- package/dist/utils/tokenRefresh.d.ts.map +1 -0
- package/dist/utils/tokenRefresh.js +53 -0
- package/package.json +63 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export type SapAuthType = "basic" | "jwt";
|
|
2
|
+
export interface SapConfig {
|
|
3
|
+
url: string;
|
|
4
|
+
client?: string;
|
|
5
|
+
authType: SapAuthType;
|
|
6
|
+
username?: string;
|
|
7
|
+
password?: string;
|
|
8
|
+
jwtToken?: string;
|
|
9
|
+
refreshToken?: string;
|
|
10
|
+
uaaUrl?: string;
|
|
11
|
+
uaaClientId?: string;
|
|
12
|
+
uaaClientSecret?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Produces a stable string signature for a SAP configuration.
|
|
16
|
+
* Used internally for caching connection instances when configuration changes.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Load .env file if dotenv is available and file exists
|
|
20
|
+
* @param envPath - Path to .env file (default: .env in current working directory or project root)
|
|
21
|
+
* @returns true if .env was loaded, false otherwise
|
|
22
|
+
*/
|
|
23
|
+
export declare function loadEnvFile(envPath?: string): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Get SAP configuration from environment variables
|
|
26
|
+
* Used by tests and applications to create connection config
|
|
27
|
+
*
|
|
28
|
+
* Automatically detects auth type:
|
|
29
|
+
* - If SAP_JWT_TOKEN is present → uses 'jwt'
|
|
30
|
+
* - If SAP_AUTH_TYPE is set → uses that value
|
|
31
|
+
* - Otherwise → uses 'basic'
|
|
32
|
+
*/
|
|
33
|
+
export declare function getConfigFromEnv(): SapConfig;
|
|
34
|
+
/**
|
|
35
|
+
* Load .env file and get SAP configuration from environment variables
|
|
36
|
+
* Convenience function that combines loadEnvFile() and getConfigFromEnv()
|
|
37
|
+
*
|
|
38
|
+
* @param envPath - Optional path to .env file (default: auto-detect)
|
|
39
|
+
* @returns SAP configuration
|
|
40
|
+
*/
|
|
41
|
+
export declare function loadConfigFromEnvFile(envPath?: string): SapConfig;
|
|
42
|
+
export declare function sapConfigSignature(config: SapConfig): string;
|
|
43
|
+
//# sourceMappingURL=sapConfig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sapConfig.d.ts","sourceRoot":"","sources":["../../src/config/sapConfig.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,KAAK,CAAC;AAE1C,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,WAAW,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;GAGG;AACH;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAuDrD;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,IAAI,SAAS,CAyD5C;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAGjE;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM,CAmB5D"}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.loadEnvFile = loadEnvFile;
|
|
37
|
+
exports.getConfigFromEnv = getConfigFromEnv;
|
|
38
|
+
exports.loadConfigFromEnvFile = loadConfigFromEnvFile;
|
|
39
|
+
exports.sapConfigSignature = sapConfigSignature;
|
|
40
|
+
const path = __importStar(require("path"));
|
|
41
|
+
const fs = __importStar(require("fs"));
|
|
42
|
+
/**
|
|
43
|
+
* Produces a stable string signature for a SAP configuration.
|
|
44
|
+
* Used internally for caching connection instances when configuration changes.
|
|
45
|
+
*/
|
|
46
|
+
/**
|
|
47
|
+
* Load .env file if dotenv is available and file exists
|
|
48
|
+
* @param envPath - Path to .env file (default: .env in current working directory or project root)
|
|
49
|
+
* @returns true if .env was loaded, false otherwise
|
|
50
|
+
*/
|
|
51
|
+
function loadEnvFile(envPath) {
|
|
52
|
+
// Determine .env file path
|
|
53
|
+
let resolvedPath;
|
|
54
|
+
if (envPath) {
|
|
55
|
+
resolvedPath = path.resolve(envPath);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
// Try current directory first
|
|
59
|
+
const currentDirEnv = path.resolve(process.cwd(), '.env');
|
|
60
|
+
if (fs.existsSync(currentDirEnv)) {
|
|
61
|
+
resolvedPath = currentDirEnv;
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
// Try project root (go up from node_modules or dist)
|
|
65
|
+
const projectRoot = path.resolve(__dirname, '../../..');
|
|
66
|
+
resolvedPath = path.resolve(projectRoot, '.env');
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (!fs.existsSync(resolvedPath)) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
// Try to use dotenv if available
|
|
73
|
+
try {
|
|
74
|
+
const dotenv = require('dotenv');
|
|
75
|
+
const result = dotenv.config({ path: resolvedPath, override: false });
|
|
76
|
+
if (!result.error) {
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
// dotenv not available - fallback to manual parsing
|
|
82
|
+
}
|
|
83
|
+
// Manual fallback parser (supports KEY=VALUE, ignores comments)
|
|
84
|
+
try {
|
|
85
|
+
const content = fs.readFileSync(resolvedPath, 'utf8');
|
|
86
|
+
const lines = content.split(/\r?\n/);
|
|
87
|
+
for (const line of lines) {
|
|
88
|
+
const trimmed = line.trim();
|
|
89
|
+
if (!trimmed || trimmed.startsWith('#')) {
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
const eqIndex = trimmed.indexOf('=');
|
|
93
|
+
if (eqIndex === -1) {
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
const key = trimmed.substring(0, eqIndex).trim();
|
|
97
|
+
const value = trimmed.substring(eqIndex + 1).trim();
|
|
98
|
+
if (!process.env[key]) {
|
|
99
|
+
process.env[key] = value;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Get SAP configuration from environment variables
|
|
110
|
+
* Used by tests and applications to create connection config
|
|
111
|
+
*
|
|
112
|
+
* Automatically detects auth type:
|
|
113
|
+
* - If SAP_JWT_TOKEN is present → uses 'jwt'
|
|
114
|
+
* - If SAP_AUTH_TYPE is set → uses that value
|
|
115
|
+
* - Otherwise → uses 'basic'
|
|
116
|
+
*/
|
|
117
|
+
function getConfigFromEnv() {
|
|
118
|
+
const rawUrl = process.env.SAP_URL;
|
|
119
|
+
const url = rawUrl ? rawUrl.split('#')[0].trim() : rawUrl;
|
|
120
|
+
const rawClient = process.env.SAP_CLIENT;
|
|
121
|
+
const client = rawClient ? rawClient.split('#')[0].trim() : rawClient;
|
|
122
|
+
// Auto-detect auth type: if JWT token is present, use JWT; otherwise check SAP_AUTH_TYPE or default to basic
|
|
123
|
+
// Priority: SAP_JWT_TOKEN presence > SAP_AUTH_TYPE > default to basic
|
|
124
|
+
let rawAuthType = process.env.SAP_AUTH_TYPE;
|
|
125
|
+
if (process.env.SAP_JWT_TOKEN) {
|
|
126
|
+
rawAuthType = 'jwt'; // Auto-detect JWT if token is present (overrides SAP_AUTH_TYPE)
|
|
127
|
+
}
|
|
128
|
+
rawAuthType = rawAuthType || 'basic';
|
|
129
|
+
const authType = rawAuthType.split('#')[0].trim();
|
|
130
|
+
if (!url || !/^https?:\/\//.test(url)) {
|
|
131
|
+
throw new Error(`Missing or invalid SAP_URL: ${url}`);
|
|
132
|
+
}
|
|
133
|
+
const config = {
|
|
134
|
+
url,
|
|
135
|
+
authType: authType === 'xsuaa' ? 'jwt' : authType,
|
|
136
|
+
};
|
|
137
|
+
if (client) {
|
|
138
|
+
config.client = client;
|
|
139
|
+
}
|
|
140
|
+
if (authType === 'jwt' || authType === 'xsuaa') {
|
|
141
|
+
const jwtToken = process.env.SAP_JWT_TOKEN;
|
|
142
|
+
if (!jwtToken) {
|
|
143
|
+
throw new Error('Missing SAP_JWT_TOKEN for JWT authentication');
|
|
144
|
+
}
|
|
145
|
+
config.jwtToken = jwtToken;
|
|
146
|
+
// Refresh token is optional but recommended for automatic token renewal
|
|
147
|
+
const refreshToken = process.env.SAP_REFRESH_TOKEN;
|
|
148
|
+
if (refreshToken) {
|
|
149
|
+
config.refreshToken = refreshToken;
|
|
150
|
+
}
|
|
151
|
+
// UAA credentials for token refresh (optional but recommended)
|
|
152
|
+
const uaaUrl = process.env.SAP_UAA_URL || process.env.UAA_URL;
|
|
153
|
+
const uaaClientId = process.env.SAP_UAA_CLIENT_ID || process.env.UAA_CLIENT_ID;
|
|
154
|
+
const uaaClientSecret = process.env.SAP_UAA_CLIENT_SECRET || process.env.UAA_CLIENT_SECRET;
|
|
155
|
+
if (uaaUrl)
|
|
156
|
+
config.uaaUrl = uaaUrl;
|
|
157
|
+
if (uaaClientId)
|
|
158
|
+
config.uaaClientId = uaaClientId;
|
|
159
|
+
if (uaaClientSecret)
|
|
160
|
+
config.uaaClientSecret = uaaClientSecret;
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
const username = process.env.SAP_USERNAME;
|
|
164
|
+
const password = process.env.SAP_PASSWORD;
|
|
165
|
+
if (!username || !password) {
|
|
166
|
+
throw new Error('Missing SAP_USERNAME or SAP_PASSWORD for basic authentication');
|
|
167
|
+
}
|
|
168
|
+
config.username = username;
|
|
169
|
+
config.password = password;
|
|
170
|
+
}
|
|
171
|
+
return config;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Load .env file and get SAP configuration from environment variables
|
|
175
|
+
* Convenience function that combines loadEnvFile() and getConfigFromEnv()
|
|
176
|
+
*
|
|
177
|
+
* @param envPath - Optional path to .env file (default: auto-detect)
|
|
178
|
+
* @returns SAP configuration
|
|
179
|
+
*/
|
|
180
|
+
function loadConfigFromEnvFile(envPath) {
|
|
181
|
+
loadEnvFile(envPath);
|
|
182
|
+
return getConfigFromEnv();
|
|
183
|
+
}
|
|
184
|
+
function sapConfigSignature(config) {
|
|
185
|
+
// Include token preview (first 10 and last 10 chars) to detect token changes
|
|
186
|
+
// This allows connection recreation when token is updated via HTTP headers
|
|
187
|
+
const jwtTokenPreview = config.jwtToken
|
|
188
|
+
? `${config.jwtToken.substring(0, 10)}...${config.jwtToken.substring(Math.max(0, config.jwtToken.length - 10))}`
|
|
189
|
+
: null;
|
|
190
|
+
const refreshTokenPreview = config.refreshToken
|
|
191
|
+
? `${config.refreshToken.substring(0, 10)}...${config.refreshToken.substring(Math.max(0, config.refreshToken.length - 10))}`
|
|
192
|
+
: null;
|
|
193
|
+
return JSON.stringify({
|
|
194
|
+
url: config.url,
|
|
195
|
+
client: config.client ?? null,
|
|
196
|
+
authType: config.authType,
|
|
197
|
+
username: config.username ?? null,
|
|
198
|
+
password: config.password ? "set" : null,
|
|
199
|
+
jwtToken: jwtTokenPreview,
|
|
200
|
+
refreshToken: refreshTokenPreview
|
|
201
|
+
});
|
|
202
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { AxiosResponse } from "axios";
|
|
2
|
+
import { SapConfig } from "../config/sapConfig.js";
|
|
3
|
+
import { SessionState } from "../logger.js";
|
|
4
|
+
export interface AbapRequestOptions {
|
|
5
|
+
url: string;
|
|
6
|
+
method: string;
|
|
7
|
+
timeout: number;
|
|
8
|
+
data?: any;
|
|
9
|
+
params?: any;
|
|
10
|
+
headers?: Record<string, string>;
|
|
11
|
+
}
|
|
12
|
+
export interface AbapConnection {
|
|
13
|
+
getConfig(): SapConfig;
|
|
14
|
+
getBaseUrl(): Promise<string>;
|
|
15
|
+
getAuthHeaders(): Promise<Record<string, string>>;
|
|
16
|
+
makeAdtRequest(options: AbapRequestOptions): Promise<AxiosResponse>;
|
|
17
|
+
connect(): Promise<void>;
|
|
18
|
+
reset(): void;
|
|
19
|
+
getSessionState(): SessionState | null;
|
|
20
|
+
setSessionState(state: SessionState): void;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=AbapConnection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AbapConnection.d.ts","sourceRoot":"","sources":["../../src/connection/AbapConnection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,MAAM,WAAW,kBAAkB;IACjC,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,MAAM,CAAC,EAAE,GAAG,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED,MAAM,WAAW,cAAc;IAC7B,SAAS,IAAI,SAAS,CAAC;IACvB,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAC9B,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAClD,cAAc,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;IACpE,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACzB,KAAK,IAAI,IAAI,CAAC;IACd,eAAe,IAAI,YAAY,GAAG,IAAI,CAAC;IACvC,eAAe,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI,CAAC;CAC5C"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { AxiosResponse } from "axios";
|
|
2
|
+
import { ILogger, ISessionStorage, SessionState } from "../logger.js";
|
|
3
|
+
import { SapConfig } from "../config/sapConfig.js";
|
|
4
|
+
import { AbapConnection, AbapRequestOptions } from "./AbapConnection.js";
|
|
5
|
+
declare abstract class AbstractAbapConnection implements AbapConnection {
|
|
6
|
+
private readonly config;
|
|
7
|
+
protected readonly logger: ILogger;
|
|
8
|
+
private axiosInstance;
|
|
9
|
+
private csrfToken;
|
|
10
|
+
private cookies;
|
|
11
|
+
private cookieStore;
|
|
12
|
+
private cachedBaseUrl;
|
|
13
|
+
private sessionId;
|
|
14
|
+
private sessionStorage;
|
|
15
|
+
private sessionMode;
|
|
16
|
+
protected constructor(config: SapConfig, logger: ILogger, sessionStorage?: ISessionStorage, sessionId?: string);
|
|
17
|
+
/**
|
|
18
|
+
* Enable stateful session mode with storage
|
|
19
|
+
* @param sessionId - Unique session identifier
|
|
20
|
+
* @param storage - Storage implementation for persisting session state
|
|
21
|
+
*/
|
|
22
|
+
enableStatefulSession(sessionId: string, storage: ISessionStorage): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Disable stateful session mode (switch to stateless)
|
|
25
|
+
* Optionally saves current state before switching
|
|
26
|
+
*/
|
|
27
|
+
disableStatefulSession(saveBeforeDisable?: boolean): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Get current session mode
|
|
30
|
+
*/
|
|
31
|
+
getSessionMode(): "stateless" | "stateful";
|
|
32
|
+
/**
|
|
33
|
+
* Set session ID for stateful operations
|
|
34
|
+
* When session ID is set, session state (cookies, CSRF token) will be persisted
|
|
35
|
+
* @deprecated Use enableStatefulSession() instead
|
|
36
|
+
*/
|
|
37
|
+
setSessionId(sessionId: string): void;
|
|
38
|
+
/**
|
|
39
|
+
* Get current session ID
|
|
40
|
+
*/
|
|
41
|
+
getSessionId(): string | null;
|
|
42
|
+
/**
|
|
43
|
+
* Set session storage (can be changed at runtime)
|
|
44
|
+
*/
|
|
45
|
+
setSessionStorage(storage: ISessionStorage | null): void;
|
|
46
|
+
/**
|
|
47
|
+
* Get current session storage
|
|
48
|
+
*/
|
|
49
|
+
getSessionStorage(): ISessionStorage | null;
|
|
50
|
+
/**
|
|
51
|
+
* Load session state from storage
|
|
52
|
+
*/
|
|
53
|
+
loadSessionState(): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Save session state to storage
|
|
56
|
+
* Only saves if in stateful mode
|
|
57
|
+
*/
|
|
58
|
+
saveSessionState(): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Get current session state
|
|
61
|
+
* Returns cookies, CSRF token, and cookie store for manual persistence
|
|
62
|
+
* @returns Current session state or null if no session data
|
|
63
|
+
*/
|
|
64
|
+
getSessionState(): SessionState | null;
|
|
65
|
+
/**
|
|
66
|
+
* Set session state manually
|
|
67
|
+
* Allows user to restore session from custom storage (e.g., database, Redis)
|
|
68
|
+
* @param state - Session state with cookies, CSRF token, and cookie store
|
|
69
|
+
*/
|
|
70
|
+
setSessionState(state: SessionState): void;
|
|
71
|
+
/**
|
|
72
|
+
* Clear session state from storage
|
|
73
|
+
*/
|
|
74
|
+
clearSessionState(): Promise<void>;
|
|
75
|
+
getConfig(): SapConfig;
|
|
76
|
+
reset(): void;
|
|
77
|
+
getBaseUrl(): Promise<string>;
|
|
78
|
+
getAuthHeaders(): Promise<Record<string, string>>;
|
|
79
|
+
/**
|
|
80
|
+
* Connect to SAP system and initialize session (get CSRF token and cookies)
|
|
81
|
+
* This should be called explicitly before making the first request to ensure
|
|
82
|
+
* proper authentication and session initialization.
|
|
83
|
+
*
|
|
84
|
+
* Concrete implementations must provide auth-specific connection logic:
|
|
85
|
+
* - BaseAbapConnection: Basic auth with CSRF token fetch
|
|
86
|
+
* - JwtAbapConnection: JWT auth with token refresh on 401/403
|
|
87
|
+
*/
|
|
88
|
+
abstract connect(): Promise<void>;
|
|
89
|
+
makeAdtRequest(options: AbapRequestOptions): Promise<AxiosResponse>;
|
|
90
|
+
protected abstract buildAuthorizationHeader(): string;
|
|
91
|
+
/**
|
|
92
|
+
* Fetch CSRF token from SAP system
|
|
93
|
+
* Protected method for use by concrete implementations in their connect() method
|
|
94
|
+
*/
|
|
95
|
+
protected fetchCsrfToken(url: string, retryCount?: number, retryDelay?: number): Promise<string>;
|
|
96
|
+
/**
|
|
97
|
+
* Get CSRF token (protected for use by subclasses)
|
|
98
|
+
*/
|
|
99
|
+
protected getCsrfToken(): string | null;
|
|
100
|
+
/**
|
|
101
|
+
* Set CSRF token (protected for use by subclasses)
|
|
102
|
+
*/
|
|
103
|
+
protected setCsrfToken(token: string | null): void;
|
|
104
|
+
/**
|
|
105
|
+
* Get cookies (protected for use by subclasses)
|
|
106
|
+
*/
|
|
107
|
+
protected getCookies(): string | null;
|
|
108
|
+
private updateCookiesFromResponse;
|
|
109
|
+
private getAxiosInstance;
|
|
110
|
+
private normalizeRequestUrl;
|
|
111
|
+
private ensureFreshCsrfToken;
|
|
112
|
+
private shouldRetryCsrf;
|
|
113
|
+
}
|
|
114
|
+
export { AbstractAbapConnection };
|
|
115
|
+
//# sourceMappingURL=AbstractAbapConnection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AbstractAbapConnection.d.ts","sourceRoot":"","sources":["../../src/connection/AbstractAbapConnection.ts"],"names":[],"mappings":"AAAA,OAAc,EAAiD,aAAa,EAAE,MAAM,OAAO,CAAC;AAE5F,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEtE,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAEzE,uBAAe,sBAAuB,YAAW,cAAc;IAW3D,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,OAAO;IAXpC,OAAO,CAAC,aAAa,CAA8B;IACnD,OAAO,CAAC,SAAS,CAAuB;IACxC,OAAO,CAAC,OAAO,CAAuB;IACtC,OAAO,CAAC,WAAW,CAAkC;IACrD,OAAO,CAAC,aAAa,CAAuB;IAC5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