@kadi.build/file-sharing 1.2.0 → 1.3.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,109 @@
1
+ /// <reference types="node" />
2
+ import { EventEmitter } from 'events';
3
+ import type { Server as HttpServer, IncomingMessage } from 'http';
4
+
5
+ export interface S3ServerConfig {
6
+ /** S3 server port (default: 9000) */
7
+ port?: number;
8
+ /** Bind host (default: '0.0.0.0') */
9
+ host?: string;
10
+ /** Root directory for object storage (default: process.cwd()) */
11
+ rootDir?: string;
12
+ /** S3 access key ID (default: 'minioadmin') */
13
+ accessKeyId?: string;
14
+ /** S3 secret access key (default: 'minioadmin') */
15
+ secretAccessKey?: string;
16
+ /** Default bucket name (default: 'local') */
17
+ bucketName?: string;
18
+ /** AWS region (default: 'us-east-1') */
19
+ region?: string;
20
+ /** Maximum file size in bytes (null = unlimited) */
21
+ maxFileSize?: number | null;
22
+ }
23
+
24
+ export interface S3StartResult {
25
+ port: number;
26
+ host: string;
27
+ endpoint: string;
28
+ serverId: string;
29
+ }
30
+
31
+ export interface S3BucketInfo {
32
+ name: string;
33
+ rootDir: string;
34
+ }
35
+
36
+ export interface S3ObjectEntry {
37
+ key: string;
38
+ size: number;
39
+ lastModified: string;
40
+ [key: string]: any;
41
+ }
42
+
43
+ export interface S3AuthResult {
44
+ success: boolean;
45
+ user?: { accessKey: string };
46
+ error?: string;
47
+ }
48
+
49
+ export interface S3TemporaryCredentials {
50
+ accessKey: string;
51
+ secretKey: string;
52
+ expiresAt: string;
53
+ /** Backward-compat alias for expiresAt as Date */
54
+ expiry: Date;
55
+ }
56
+
57
+ export class S3Server extends EventEmitter {
58
+ constructor(config?: S3ServerConfig);
59
+
60
+ config: Required<S3ServerConfig>;
61
+ server: HttpServer | null;
62
+ isRunning: boolean;
63
+ multipartUploads: Map<string, any>;
64
+ requestCount: number;
65
+
66
+ /** Stable server identifier */
67
+ readonly serverId: string;
68
+
69
+ /**
70
+ * Start the S3 server
71
+ */
72
+ start(): Promise<S3StartResult>;
73
+
74
+ /**
75
+ * Stop the S3 server
76
+ */
77
+ stop(): Promise<void>;
78
+
79
+ /**
80
+ * Get bucket configuration
81
+ */
82
+ getBucket(): S3BucketInfo;
83
+
84
+ /**
85
+ * List objects in bucket (programmatic access)
86
+ * @param prefix - Optional prefix filter
87
+ */
88
+ listObjects(prefix?: string): Promise<S3ObjectEntry[]>;
89
+
90
+ /**
91
+ * Validate an incoming request against the server's configured credentials.
92
+ * @param req - HTTP incoming request
93
+ */
94
+ validateAuthentication(req: IncomingMessage): S3AuthResult;
95
+
96
+ /**
97
+ * Programmatically remove a bucket (force-deletes even non-empty directories).
98
+ * @param bucketName - The bucket/directory name to remove
99
+ */
100
+ removeBucket(bucketName: string): Promise<void>;
101
+
102
+ /**
103
+ * Generate temporary S3 credentials with an expiry.
104
+ * @param opts - Options
105
+ */
106
+ generateTemporaryCredentials(opts?: { ttl?: number }): S3TemporaryCredentials;
107
+ }
108
+
109
+ export default S3Server;
@@ -0,0 +1,51 @@
1
+ /// <reference types="node" />
2
+ import { EventEmitter } from 'events';
3
+
4
+ export interface ShutdownManagerConfig {
5
+ /** Timeout in ms for graceful shutdown (default: 30000) */
6
+ gracefulTimeout?: number;
7
+ /** Whether to wait for active downloads before shutting down (default: true) */
8
+ finishActiveDownloads?: boolean;
9
+ /** Timeout in ms before force kill (default: 60000) */
10
+ forceKillTimeout?: number;
11
+ }
12
+
13
+ export class ShutdownManager extends EventEmitter {
14
+ constructor(config?: ShutdownManagerConfig);
15
+
16
+ config: Required<ShutdownManagerConfig>;
17
+ isShuttingDown: boolean;
18
+ shutdownCallbacks: Array<{ callback: () => Promise<void>; priority: number }>;
19
+
20
+ /**
21
+ * Register a shutdown callback with priority.
22
+ * Lower priority numbers execute first.
23
+ * @param callback - Async callback to execute during shutdown
24
+ * @param priority - Execution priority (lower = earlier, default: 10)
25
+ */
26
+ register(callback: () => Promise<void>, priority?: number): void;
27
+
28
+ /**
29
+ * Unregister a previously registered callback
30
+ * @param callback - The callback to remove
31
+ */
32
+ unregister(callback: () => Promise<void>): void;
33
+
34
+ /**
35
+ * Install process signal handlers (SIGINT, SIGTERM)
36
+ */
37
+ installSignalHandlers(): void;
38
+
39
+ /**
40
+ * Perform graceful shutdown.
41
+ * Executes all registered callbacks in priority order with timeout.
42
+ */
43
+ shutdown(): Promise<void>;
44
+
45
+ /**
46
+ * Force shutdown - skip remaining callbacks
47
+ */
48
+ forceShutdown(): Promise<void>;
49
+ }
50
+
51
+ export default ShutdownManager;
@@ -0,0 +1,116 @@
1
+ /**
2
+ * @kadi.build/file-sharing - Type declarations
3
+ *
4
+ * File sharing service with tunneling and local S3-compatible interface.
5
+ */
6
+
7
+ import type { FileSharingServerConfig } from './FileSharingServer.js';
8
+ import type { FileSharingServer } from './FileSharingServer.js';
9
+ import type { HttpAuthConfig } from './HttpServerProvider.js';
10
+
11
+ // Core classes
12
+ export {
13
+ FileSharingServer,
14
+ FileSharingServerConfig,
15
+ TunnelConfig,
16
+ MonitoringConfig,
17
+ ShutdownConfig,
18
+ ServerInfo,
19
+ TunnelInfo,
20
+ FileEntry,
21
+ } from './FileSharingServer.js';
22
+
23
+ export {
24
+ HttpServerProvider,
25
+ HttpServerProviderConfig,
26
+ HttpAuthConfig,
27
+ SslConfig,
28
+ HttpStartResult,
29
+ MiddlewareInfo,
30
+ CustomRouteInfo,
31
+ } from './HttpServerProvider.js';
32
+
33
+ export {
34
+ S3Server,
35
+ S3ServerConfig,
36
+ S3StartResult,
37
+ S3BucketInfo,
38
+ S3ObjectEntry,
39
+ S3AuthResult,
40
+ S3TemporaryCredentials,
41
+ } from './S3Server.js';
42
+
43
+ export {
44
+ DownloadMonitor,
45
+ DownloadRecord,
46
+ DownloadMetadata,
47
+ DownloadStats,
48
+ } from './DownloadMonitor.js';
49
+
50
+ export {
51
+ ShutdownManager,
52
+ ShutdownManagerConfig,
53
+ } from './ShutdownManager.js';
54
+
55
+ export {
56
+ MonitoringDashboard,
57
+ MonitoringDashboardConfig,
58
+ DashboardStats,
59
+ DashboardServerInfo,
60
+ } from './MonitoringDashboard.js';
61
+
62
+ export {
63
+ EventNotifier,
64
+ EventNotifierConfig,
65
+ WebhookOptions,
66
+ WebhookInfo,
67
+ NotificationHistoryEntry,
68
+ } from './EventNotifier.js';
69
+
70
+ // Default export
71
+ export { FileSharingServer as default } from './FileSharingServer.js';
72
+
73
+ /**
74
+ * Create a FileSharingServer with default options
75
+ */
76
+ export function createFileSharingServer(options?: FileSharingServerConfig): FileSharingServer;
77
+
78
+ export interface QuickShareOptions {
79
+ /** HTTP port (default: 3000) */
80
+ port?: number;
81
+ /** Enable tunnel (default: false) */
82
+ tunnel?: boolean;
83
+ /** Tunnel service name (default: 'kadi') */
84
+ tunnelService?: string;
85
+ /** KĀDI auth token */
86
+ kadiToken?: string;
87
+ /** Ngrok auth token */
88
+ ngrokAuthToken?: string;
89
+ /** HTTP auth config */
90
+ auth?: HttpAuthConfig | null;
91
+ /** Extra tunnel options */
92
+ tunnelOptions?: Record<string, any>;
93
+ }
94
+
95
+ export interface QuickShareResult {
96
+ server: FileSharingServer;
97
+ localUrl: string;
98
+ publicUrl?: string;
99
+ }
100
+
101
+ /**
102
+ * Quick share - one-liner to share a directory
103
+ * @param directory - Directory to share
104
+ * @param options - Options
105
+ */
106
+ export function createQuickShare(
107
+ directory: string,
108
+ options?: QuickShareOptions
109
+ ): Promise<QuickShareResult>;
110
+
111
+ // Re-exports from dependencies (convenience)
112
+ // Note: These types come from the respective packages.
113
+ // If those packages don't have types, consumers should install them separately.
114
+ export declare const FileManager: any;
115
+ export declare const createFileManager: (...args: any[]) => any;
116
+ export declare const TunnelManager: any;