catalyst-relay 0.2.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.
@@ -0,0 +1,438 @@
1
+ /**
2
+ * Authentication types supported by SAP ADT
3
+ */
4
+ type AuthType = 'basic' | 'saml' | 'sso';
5
+ /**
6
+ * Basic authentication configuration
7
+ */
8
+ interface BasicAuthConfig {
9
+ type: 'basic';
10
+ username: string;
11
+ password: string;
12
+ }
13
+ /**
14
+ * SAML authentication configuration
15
+ */
16
+ interface SamlAuthConfig {
17
+ type: 'saml';
18
+ username: string;
19
+ password: string;
20
+ provider?: string;
21
+ }
22
+ /**
23
+ * SSO (Kerberos) authentication configuration
24
+ */
25
+ interface SsoAuthConfig {
26
+ type: 'sso';
27
+ certificate?: string;
28
+ }
29
+ /**
30
+ * Union of all auth configurations
31
+ */
32
+ type AuthConfig = BasicAuthConfig | SamlAuthConfig | SsoAuthConfig;
33
+ /**
34
+ * Client configuration for connecting to SAP ADT
35
+ */
36
+ interface ClientConfig {
37
+ /** ADT server URL (e.g., https://server:port) */
38
+ url: string;
39
+ /** SAP client number (e.g., '100') */
40
+ client: string;
41
+ /** Authentication configuration */
42
+ auth: AuthConfig;
43
+ /** Request timeout in milliseconds (default: 30000) */
44
+ timeout?: number;
45
+ /** Skip SSL verification (dev only) */
46
+ insecure?: boolean;
47
+ }
48
+
49
+ /**
50
+ * Reference to an SAP development object
51
+ */
52
+ interface ObjectRef {
53
+ /** Object name (e.g., 'ZTEST_VIEW') */
54
+ name: string;
55
+ /** File extension indicating object type (e.g., 'asddls') */
56
+ extension: string;
57
+ }
58
+ /**
59
+ * Object with content for create/update operations
60
+ */
61
+ interface ObjectContent extends ObjectRef {
62
+ /** Source code content */
63
+ content: string;
64
+ /** Optional description for transport */
65
+ description?: string;
66
+ }
67
+ /**
68
+ * Tree discovery query for hierarchical browsing
69
+ */
70
+ interface TreeQuery {
71
+ /** Package to browse (e.g., '$TMP', 'ZPACKAGE') */
72
+ package?: string;
73
+ /** Folder type to expand */
74
+ folderType?: 'PACKAGE' | 'TYPE' | 'GROUP' | 'API';
75
+ /** Parent path for nested queries */
76
+ parentPath?: string;
77
+ }
78
+ /**
79
+ * Data preview query
80
+ */
81
+ interface PreviewQuery {
82
+ /** Object name (table or CDS view) */
83
+ objectName: string;
84
+ /** Object type ('table' or 'view') */
85
+ objectType: 'table' | 'view';
86
+ /** WHERE clause filters */
87
+ filters?: Filter[];
88
+ /** ORDER BY columns */
89
+ orderBy?: OrderBy[];
90
+ /** Maximum rows to return (default: 100) */
91
+ limit?: number;
92
+ /** Row offset for pagination */
93
+ offset?: number;
94
+ }
95
+ /**
96
+ * Filter condition for data preview
97
+ */
98
+ interface Filter {
99
+ column: string;
100
+ operator: FilterOperator;
101
+ value: string | number | boolean | null;
102
+ }
103
+ type FilterOperator = 'eq' | 'ne' | 'gt' | 'ge' | 'lt' | 'le' | 'like' | 'in';
104
+ /**
105
+ * Sort specification for data preview
106
+ */
107
+ interface OrderBy {
108
+ column: string;
109
+ direction: 'asc' | 'desc';
110
+ }
111
+
112
+ /**
113
+ * API Response Types
114
+ *
115
+ * Generic response wrappers and error codes only.
116
+ * Domain-specific types live in their colocated modules under core/adt/.
117
+ */
118
+ /**
119
+ * Standard API response wrapper
120
+ */
121
+ interface SuccessResponse<T> {
122
+ success: true;
123
+ data: T;
124
+ }
125
+ interface ErrorResponse {
126
+ success: false;
127
+ error: string;
128
+ code?: ErrorCode;
129
+ details?: unknown;
130
+ }
131
+ type ApiResponse<T> = SuccessResponse<T> | ErrorResponse;
132
+ /**
133
+ * Machine-readable error codes
134
+ */
135
+ type ErrorCode = 'AUTH_FAILED' | 'SESSION_EXPIRED' | 'SESSION_NOT_FOUND' | 'CSRF_INVALID' | 'OBJECT_LOCKED' | 'OBJECT_NOT_FOUND' | 'TRANSPORT_REQUIRED' | 'ACTIVATION_FAILED' | 'VALIDATION_ERROR' | 'NETWORK_ERROR' | 'UNKNOWN_ERROR';
136
+
137
+ /**
138
+ * Result type for error handling (Go-style tuples)
139
+ *
140
+ * Usage:
141
+ * const [data, error] = await someFunction();
142
+ * if (error) {
143
+ * console.error(error);
144
+ * return;
145
+ * }
146
+ * // data is guaranteed non-null
147
+ */
148
+ type Result<T, E = Error> = [T, null] | [null, E];
149
+ /**
150
+ * Async result type alias for convenience
151
+ */
152
+ type AsyncResult<T, E = Error> = Promise<Result<T, E>>;
153
+ /**
154
+ * Create a success result
155
+ */
156
+ declare function ok<T>(value: T): Result<T, never>;
157
+ /**
158
+ * Create an error result
159
+ */
160
+ declare function err<E = Error>(error: E): Result<never, E>;
161
+
162
+ /**
163
+ * Session management type definitions
164
+ */
165
+
166
+ /**
167
+ * Session data returned after successful login
168
+ */
169
+ interface Session {
170
+ /** Unique session identifier */
171
+ sessionId: string;
172
+ /** Authenticated username */
173
+ username: string;
174
+ /** Session expiration timestamp */
175
+ expiresAt: number;
176
+ }
177
+
178
+ interface ObjectConfig {
179
+ /** ADT endpoint path (e.g., 'ddic/ddl/sources') */
180
+ endpoint: string;
181
+ /** XML namespace for creation requests */
182
+ nameSpace: string;
183
+ /** Root element name for creation XML */
184
+ rootName: string;
185
+ /** SAP ADT object type identifier (e.g., 'DDLS/DF') */
186
+ type: string;
187
+ /** Human-readable label (e.g., 'View') */
188
+ label: string;
189
+ /** File extension (e.g., 'asddls') */
190
+ extension: string;
191
+ /** Data preview endpoint (if supported) */
192
+ dpEndpoint?: string;
193
+ /** Data preview parameter name (if supported) */
194
+ dpParam?: string;
195
+ }
196
+ /**
197
+ * Result of upsert operation
198
+ */
199
+ interface UpsertResult {
200
+ name: string;
201
+ extension: string;
202
+ status: 'created' | 'updated' | 'unchanged';
203
+ transport?: string;
204
+ }
205
+
206
+ /**
207
+ * POST /objects/read — Read object source content
208
+ */
209
+
210
+ /**
211
+ * Object metadata
212
+ */
213
+ interface ObjectMetadata {
214
+ name: string;
215
+ extension: string;
216
+ package: string;
217
+ description?: string;
218
+ createdBy?: string;
219
+ createdAt?: string;
220
+ modifiedBy?: string;
221
+ modifiedAt?: string;
222
+ }
223
+ /**
224
+ * Object with content (read response)
225
+ */
226
+ interface ObjectWithContent extends ObjectMetadata {
227
+ content: string;
228
+ }
229
+
230
+ /**
231
+ * Result of activation operation
232
+ */
233
+ interface ActivationResult {
234
+ name: string;
235
+ extension: string;
236
+ status: 'success' | 'warning' | 'error';
237
+ messages: ActivationMessage[];
238
+ }
239
+ interface ActivationMessage {
240
+ severity: 'error' | 'warning' | 'info';
241
+ text: string;
242
+ line?: number;
243
+ column?: number;
244
+ }
245
+
246
+ /**
247
+ * Tree — Hierarchical tree browsing for packages
248
+ */
249
+
250
+ /**
251
+ * Tree node for hierarchical browsing
252
+ */
253
+ interface TreeNode {
254
+ name: string;
255
+ type: 'folder' | 'object';
256
+ objectType?: string;
257
+ extension?: string;
258
+ hasChildren?: boolean;
259
+ children?: TreeNode[];
260
+ }
261
+ /**
262
+ * Package info
263
+ */
264
+ interface Package {
265
+ name: string;
266
+ description?: string;
267
+ parentPackage?: string;
268
+ }
269
+
270
+ /**
271
+ * Transports — List transport requests for a package
272
+ */
273
+
274
+ /**
275
+ * Transport request
276
+ */
277
+ interface Transport {
278
+ id: string;
279
+ description: string;
280
+ owner: string;
281
+ status: 'modifiable' | 'released';
282
+ }
283
+
284
+ /**
285
+ * Preview Parser — Parse data preview XML responses
286
+ *
287
+ * Internal helper used by data.ts, distinct.ts, and count.ts
288
+ */
289
+
290
+ /**
291
+ * Data preview result (columnar format)
292
+ */
293
+ interface DataFrame {
294
+ columns: ColumnInfo[];
295
+ rows: unknown[][];
296
+ totalRows?: number;
297
+ }
298
+ interface ColumnInfo {
299
+ name: string;
300
+ dataType: string;
301
+ label?: string;
302
+ }
303
+
304
+ /**
305
+ * Distinct Values — Get distinct column values with counts
306
+ */
307
+
308
+ /**
309
+ * Distinct values result
310
+ */
311
+ interface DistinctResult {
312
+ column: string;
313
+ values: Array<{
314
+ value: unknown;
315
+ count: number;
316
+ }>;
317
+ }
318
+
319
+ /**
320
+ * Search Objects — Quick search by name pattern
321
+ */
322
+
323
+ /**
324
+ * Search result
325
+ */
326
+ interface SearchResult {
327
+ name: string;
328
+ extension: string;
329
+ package: string;
330
+ description?: string;
331
+ objectType: string;
332
+ }
333
+
334
+ /**
335
+ * Where-Used — Find object dependencies
336
+ */
337
+
338
+ /**
339
+ * Where-used dependency
340
+ */
341
+ interface Dependency {
342
+ name: string;
343
+ extension: string;
344
+ package: string;
345
+ usageType: string;
346
+ }
347
+
348
+ /**
349
+ * Create Transport — Create a new transport request for a package
350
+ */
351
+
352
+ /**
353
+ * Configuration for creating a transport
354
+ */
355
+ interface TransportConfig {
356
+ /** Package name (DEVCLASS) */
357
+ package: string;
358
+ /** Transport description/text */
359
+ description: string;
360
+ }
361
+
362
+ /**
363
+ * Git Diff — Compare local content with server content
364
+ *
365
+ * Uses Myers diff algorithm to compute line-by-line differences.
366
+ */
367
+
368
+ /** Base fields for all diff hunks */
369
+ interface BaseDiffHunk {
370
+ /** Total number of lines in the hunk */
371
+ length: number;
372
+ /** Starting line in the diff output (0-indexed) */
373
+ diffStart: number;
374
+ /** Starting line in the local file (0-indexed) */
375
+ localStart: number;
376
+ }
377
+ /** Addition or deletion hunk */
378
+ interface SimpleDiffHunk extends BaseDiffHunk {
379
+ type: 'addition' | 'deletion';
380
+ /** Lines added or removed */
381
+ changes: string[];
382
+ }
383
+ /** Modification hunk (deletion immediately followed by addition) */
384
+ interface ModifiedDiffHunk extends BaseDiffHunk {
385
+ type: 'modification';
386
+ /** Tuple of [server_lines, local_lines] */
387
+ changes: [string[], string[]];
388
+ }
389
+ /** Any diff hunk */
390
+ type DiffHunk = SimpleDiffHunk | ModifiedDiffHunk;
391
+ /** Result of comparing a single object */
392
+ interface DiffResult {
393
+ name: string;
394
+ extension: string;
395
+ label: string;
396
+ diffs: DiffHunk[];
397
+ }
398
+
399
+ /**
400
+ * ADT Client Core Implementation
401
+ *
402
+ * HTTP client for SAP ADT (ABAP Development Tools) with:
403
+ * - Session management (login/logout)
404
+ * - CSRF token fetching and automatic refresh
405
+ * - Basic authentication (SAML and SSO to be implemented)
406
+ * - Automatic retry on 403 CSRF errors
407
+ * - Session reset on 500 errors
408
+ *
409
+ * Uses web standard APIs (fetch, Request, Response) - runtime-agnostic.
410
+ * High-level ADT operations (CRAUD, preview, etc.) are stubs to be implemented.
411
+ */
412
+
413
+ interface ADTClient {
414
+ /** Current session info (null if not logged in) */
415
+ readonly session: Session | null;
416
+ login(): AsyncResult<Session>;
417
+ logout(): AsyncResult<void>;
418
+ read(objects: ObjectRef[]): AsyncResult<ObjectWithContent[]>;
419
+ create(object: ObjectContent, packageName: string, transport?: string): AsyncResult<void>;
420
+ update(object: ObjectContent, transport?: string): AsyncResult<void>;
421
+ upsert(objects: ObjectContent[], packageName: string, transport?: string): AsyncResult<UpsertResult[]>;
422
+ activate(objects: ObjectRef[]): AsyncResult<ActivationResult[]>;
423
+ delete(objects: ObjectRef[], transport?: string): AsyncResult<void>;
424
+ getPackages(): AsyncResult<Package[]>;
425
+ getTree(query: TreeQuery): AsyncResult<TreeNode[]>;
426
+ getTransports(packageName: string): AsyncResult<Transport[]>;
427
+ previewData(query: PreviewQuery): AsyncResult<DataFrame>;
428
+ getDistinctValues(objectName: string, column: string, objectType?: 'table' | 'view'): AsyncResult<DistinctResult>;
429
+ countRows(objectName: string, objectType: 'table' | 'view'): AsyncResult<number>;
430
+ search(query: string, types?: string[]): AsyncResult<SearchResult[]>;
431
+ whereUsed(object: ObjectRef): AsyncResult<Dependency[]>;
432
+ createTransport(config: TransportConfig): AsyncResult<string>;
433
+ gitDiff(objects: ObjectContent[]): AsyncResult<DiffResult[]>;
434
+ getObjectConfig(): ObjectConfig[];
435
+ }
436
+ declare function createClient(config: ClientConfig): Result<ADTClient, Error>;
437
+
438
+ export { type ADTClient, type ActivationMessage, type ActivationResult, type ApiResponse, type AsyncResult, type AuthConfig, type AuthType, type BasicAuthConfig, type ClientConfig, type ColumnInfo, type DataFrame, type Dependency, type DiffResult, type DistinctResult, type ErrorCode, type ErrorResponse, type Filter, type FilterOperator, type ObjectConfig, type ObjectContent, type ObjectMetadata, type ObjectRef, type ObjectWithContent, type OrderBy, type Package, type PreviewQuery, type Result, type SamlAuthConfig, type SearchResult, type Session, type SsoAuthConfig, type SuccessResponse, type Transport, type TransportConfig, type TreeNode, type TreeQuery, type UpsertResult, createClient, err, ok };