@mcp-abap-adt/connection 0.1.15 → 0.2.2

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.
@@ -1,191 +0,0 @@
1
- "use strict";
2
- /**
3
- * File-based session storage implementation
4
- * Stores session state (cookies, CSRF tokens) in JSON files on disk
5
- */
6
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
- if (k2 === undefined) k2 = k;
8
- var desc = Object.getOwnPropertyDescriptor(m, k);
9
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
- desc = { enumerable: true, get: function() { return m[k]; } };
11
- }
12
- Object.defineProperty(o, k2, desc);
13
- }) : (function(o, m, k, k2) {
14
- if (k2 === undefined) k2 = k;
15
- o[k2] = m[k];
16
- }));
17
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
18
- Object.defineProperty(o, "default", { enumerable: true, value: v });
19
- }) : function(o, v) {
20
- o["default"] = v;
21
- });
22
- var __importStar = (this && this.__importStar) || (function () {
23
- var ownKeys = function(o) {
24
- ownKeys = Object.getOwnPropertyNames || function (o) {
25
- var ar = [];
26
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
27
- return ar;
28
- };
29
- return ownKeys(o);
30
- };
31
- return function (mod) {
32
- if (mod && mod.__esModule) return mod;
33
- var result = {};
34
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
35
- __setModuleDefault(result, mod);
36
- return result;
37
- };
38
- })();
39
- Object.defineProperty(exports, "__esModule", { value: true });
40
- exports.FileSessionStorage = void 0;
41
- const fs = __importStar(require("fs"));
42
- const path = __importStar(require("path"));
43
- /**
44
- * File-based session storage
45
- * Stores each session in a separate JSON file: .sessions/<sessionId>.json
46
- */
47
- class FileSessionStorage {
48
- sessionDir;
49
- prettyPrint;
50
- constructor(options = {}) {
51
- const { sessionDir = '.sessions', createDir = true, prettyPrint = false } = options;
52
- this.sessionDir = path.resolve(process.cwd(), sessionDir);
53
- this.prettyPrint = prettyPrint;
54
- if (createDir && !fs.existsSync(this.sessionDir)) {
55
- fs.mkdirSync(this.sessionDir, { recursive: true });
56
- }
57
- }
58
- /**
59
- * Get file path for session
60
- */
61
- getSessionFilePath(sessionId) {
62
- // Sanitize session ID to prevent path traversal
63
- const sanitizedId = sessionId.replace(/[^a-zA-Z0-9_-]/g, '_');
64
- return path.join(this.sessionDir, `${sanitizedId}.json`);
65
- }
66
- /**
67
- * Save session state to file
68
- */
69
- async save(sessionId, state) {
70
- const filePath = this.getSessionFilePath(sessionId);
71
- const data = {
72
- sessionId,
73
- timestamp: Date.now(),
74
- pid: process.pid,
75
- state
76
- };
77
- const json = this.prettyPrint
78
- ? JSON.stringify(data, null, 2)
79
- : JSON.stringify(data);
80
- await fs.promises.writeFile(filePath, json, 'utf-8');
81
- }
82
- /**
83
- * Load session state from file
84
- */
85
- async load(sessionId) {
86
- const filePath = this.getSessionFilePath(sessionId);
87
- if (!fs.existsSync(filePath)) {
88
- return null;
89
- }
90
- try {
91
- const json = await fs.promises.readFile(filePath, 'utf-8');
92
- const data = JSON.parse(json);
93
- return data.state || null;
94
- }
95
- catch (error) {
96
- // File corrupted or invalid JSON
97
- return null;
98
- }
99
- }
100
- /**
101
- * Delete session state file
102
- */
103
- async delete(sessionId) {
104
- const filePath = this.getSessionFilePath(sessionId);
105
- if (fs.existsSync(filePath)) {
106
- await fs.promises.unlink(filePath);
107
- }
108
- }
109
- /**
110
- * List all session IDs
111
- */
112
- async listSessions() {
113
- if (!fs.existsSync(this.sessionDir)) {
114
- return [];
115
- }
116
- const files = await fs.promises.readdir(this.sessionDir);
117
- return files
118
- .filter(f => f.endsWith('.json'))
119
- .map(f => f.replace('.json', ''));
120
- }
121
- /**
122
- * Get session metadata (without loading full state)
123
- */
124
- async getSessionMetadata(sessionId) {
125
- const filePath = this.getSessionFilePath(sessionId);
126
- if (!fs.existsSync(filePath)) {
127
- return null;
128
- }
129
- try {
130
- const json = await fs.promises.readFile(filePath, 'utf-8');
131
- const data = JSON.parse(json);
132
- return {
133
- sessionId: data.sessionId,
134
- timestamp: data.timestamp,
135
- pid: data.pid,
136
- age: Date.now() - data.timestamp
137
- };
138
- }
139
- catch (error) {
140
- return null;
141
- }
142
- }
143
- /**
144
- * Clean up stale sessions (older than maxAge)
145
- */
146
- async cleanupStaleSessions(maxAgeMs = 30 * 60 * 1000) {
147
- const sessions = await this.listSessions();
148
- const stale = [];
149
- const now = Date.now();
150
- for (const sessionId of sessions) {
151
- const metadata = await this.getSessionMetadata(sessionId);
152
- if (metadata && (now - metadata.timestamp) > maxAgeMs) {
153
- await this.delete(sessionId);
154
- stale.push(sessionId);
155
- }
156
- }
157
- return stale;
158
- }
159
- /**
160
- * Clean up sessions from dead processes
161
- */
162
- async cleanupDeadProcessSessions() {
163
- const sessions = await this.listSessions();
164
- const dead = [];
165
- for (const sessionId of sessions) {
166
- const metadata = await this.getSessionMetadata(sessionId);
167
- if (metadata) {
168
- try {
169
- // Check if process is still running
170
- process.kill(metadata.pid, 0);
171
- }
172
- catch (e) {
173
- // Process doesn't exist
174
- await this.delete(sessionId);
175
- dead.push(sessionId);
176
- }
177
- }
178
- }
179
- return dead;
180
- }
181
- /**
182
- * Clear all sessions
183
- */
184
- async clearAll() {
185
- const sessions = await this.listSessions();
186
- for (const sessionId of sessions) {
187
- await this.delete(sessionId);
188
- }
189
- }
190
- }
191
- exports.FileSessionStorage = FileSessionStorage;