@zero-transfer/sdk 0.1.0-alpha.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/CHANGELOG.md +177 -0
- package/LICENSE +21 -0
- package/README.md +285 -0
- package/assets/zero-transfer-logo.svg +201 -0
- package/dist/index.cjs +11812 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.mts +4186 -0
- package/dist/index.d.ts +4186 -0
- package/dist/index.mjs +11650 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +94 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,4186 @@
|
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
2
|
+
import { SecureVersion, PeerCertificate } from 'node:tls';
|
|
3
|
+
import { Readable } from 'node:stream';
|
|
4
|
+
import { BaseAgent, Algorithms, ConnectConfig, Client, SFTPWrapper } from 'ssh2';
|
|
5
|
+
import { Buffer as Buffer$1 } from 'node:buffer';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Structured logging contracts and helpers for ZeroTransfer.
|
|
9
|
+
*
|
|
10
|
+
* The logger shape is intentionally compatible with popular structured loggers while
|
|
11
|
+
* staying small enough for applications to implement directly.
|
|
12
|
+
*
|
|
13
|
+
* @module logging/Logger
|
|
14
|
+
*/
|
|
15
|
+
/** Supported ZeroTransfer log levels. */
|
|
16
|
+
type LogLevel = "trace" | "debug" | "info" | "warn" | "error";
|
|
17
|
+
/**
|
|
18
|
+
* Complete structured log record emitted by ZeroTransfer helpers.
|
|
19
|
+
*/
|
|
20
|
+
interface LogRecord {
|
|
21
|
+
/** Severity level for the record. */
|
|
22
|
+
level: LogLevel;
|
|
23
|
+
/** Human-readable summary message. */
|
|
24
|
+
message: string;
|
|
25
|
+
/** SDK component that produced the record. */
|
|
26
|
+
component?: string;
|
|
27
|
+
/** Active protocol for the record. */
|
|
28
|
+
protocol?: string;
|
|
29
|
+
/** Remote host associated with the record. */
|
|
30
|
+
host?: string;
|
|
31
|
+
/** Correlation id for a connection lifecycle. */
|
|
32
|
+
connectionId?: string;
|
|
33
|
+
/** Correlation id for a protocol command. */
|
|
34
|
+
commandId?: string;
|
|
35
|
+
/** Correlation id for a transfer lifecycle. */
|
|
36
|
+
transferId?: string;
|
|
37
|
+
/** Remote or local path associated with the record. */
|
|
38
|
+
path?: string;
|
|
39
|
+
/** Operation duration in milliseconds. */
|
|
40
|
+
durationMs?: number;
|
|
41
|
+
/** Byte count associated with the operation. */
|
|
42
|
+
bytes?: number;
|
|
43
|
+
/** Additional structured fields supplied by adapters or services. */
|
|
44
|
+
[key: string]: unknown;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Log record input accepted by {@link emitLog}; the helper adds the level.
|
|
48
|
+
*/
|
|
49
|
+
interface LogRecordInput extends Omit<LogRecord, "level"> {
|
|
50
|
+
/** Human-readable summary message. */
|
|
51
|
+
message: string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Logger method signature used for each severity level.
|
|
55
|
+
*
|
|
56
|
+
* @param record - Structured log record.
|
|
57
|
+
* @param message - Convenience message argument for console-like loggers.
|
|
58
|
+
*/
|
|
59
|
+
type LoggerMethod = (record: LogRecord, message?: string) => void;
|
|
60
|
+
/**
|
|
61
|
+
* Partial structured logger accepted by ZeroTransfer.
|
|
62
|
+
*/
|
|
63
|
+
interface ZeroTransferLogger {
|
|
64
|
+
/** Receives highly detailed diagnostic records. */
|
|
65
|
+
trace?: LoggerMethod;
|
|
66
|
+
/** Receives development/debugging records. */
|
|
67
|
+
debug?: LoggerMethod;
|
|
68
|
+
/** Receives normal lifecycle records. */
|
|
69
|
+
info?: LoggerMethod;
|
|
70
|
+
/** Receives recoverable issue records. */
|
|
71
|
+
warn?: LoggerMethod;
|
|
72
|
+
/** Receives failed operation records. */
|
|
73
|
+
error?: LoggerMethod;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Logger implementation that intentionally drops every record.
|
|
77
|
+
*/
|
|
78
|
+
declare const noopLogger: Required<ZeroTransferLogger>;
|
|
79
|
+
/**
|
|
80
|
+
* Emits a structured log record if the logger implements the requested level.
|
|
81
|
+
*
|
|
82
|
+
* @param logger - Logger that may contain a method for the requested level.
|
|
83
|
+
* @param level - Severity level to emit.
|
|
84
|
+
* @param record - Log record fields without the level property.
|
|
85
|
+
* @returns Nothing; missing logger methods are ignored.
|
|
86
|
+
*/
|
|
87
|
+
declare function emitLog(logger: ZeroTransferLogger, level: LogLevel, record: LogRecordInput): void;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Provider identifiers used by the provider-neutral ZeroTransfer core.
|
|
91
|
+
*
|
|
92
|
+
* @module core/ProviderId
|
|
93
|
+
*/
|
|
94
|
+
/** Classic remote-transfer providers kept compatible with the original protocol field. */
|
|
95
|
+
declare const CLASSIC_PROVIDER_IDS: readonly ["ftp", "ftps", "sftp"];
|
|
96
|
+
/** Provider ids that map directly to the original protocol-focused alpha facade. */
|
|
97
|
+
type ClassicProviderId = (typeof CLASSIC_PROVIDER_IDS)[number];
|
|
98
|
+
/** Provider ids reserved for first-party ZeroTransfer adapters. */
|
|
99
|
+
type BuiltInProviderId = ClassicProviderId | "memory" | "local" | "http" | "https" | "webdav" | "s3" | "azure-blob" | "gcs" | "dropbox" | "google-drive" | "one-drive";
|
|
100
|
+
/** Provider identifier accepted by registries, profiles, and provider factories. */
|
|
101
|
+
type ProviderId = BuiltInProviderId | (string & {});
|
|
102
|
+
/** Minimal shape used to resolve a provider from new and compatibility profile fields. */
|
|
103
|
+
interface ProviderSelection {
|
|
104
|
+
/** Provider id for provider-neutral ZeroTransfer profiles. */
|
|
105
|
+
provider?: ProviderId;
|
|
106
|
+
/** Compatibility protocol field accepted while the provider-neutral API rolls out. */
|
|
107
|
+
protocol?: ClassicProviderId;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Checks whether a provider id belongs to the classic FTP/FTPS/SFTP family.
|
|
111
|
+
*
|
|
112
|
+
* @param providerId - Provider id to inspect.
|
|
113
|
+
* @returns `true` when the id is one of the classic protocol providers.
|
|
114
|
+
*/
|
|
115
|
+
declare function isClassicProviderId(providerId: ProviderId | undefined): providerId is ClassicProviderId;
|
|
116
|
+
/**
|
|
117
|
+
* Resolves the provider id from a profile, preferring the new `provider` field.
|
|
118
|
+
*
|
|
119
|
+
* @param selection - Profile-like object containing provider and/or protocol fields.
|
|
120
|
+
* @returns The selected provider id, or `undefined` when neither field is present.
|
|
121
|
+
*/
|
|
122
|
+
declare function resolveProviderId(selection: ProviderSelection): ProviderId | undefined;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Provider capability contracts for the provider-neutral ZeroTransfer core.
|
|
126
|
+
*
|
|
127
|
+
* @module core/CapabilitySet
|
|
128
|
+
*/
|
|
129
|
+
|
|
130
|
+
/** Authentication mechanisms a provider can advertise. */
|
|
131
|
+
type AuthenticationCapability = "anonymous" | "password" | "private-key" | "token" | "oauth" | "service-account" | (string & {});
|
|
132
|
+
/** Checksum or integrity mechanisms a provider can advertise. */
|
|
133
|
+
type ChecksumCapability = "crc32" | "crc32c" | "etag" | "md5" | "sha1" | "sha256" | (string & {});
|
|
134
|
+
/** Metadata fields a provider can preserve or report. */
|
|
135
|
+
type MetadataCapability = "accessedAt" | "createdAt" | "group" | "mimeType" | "modifiedAt" | "owner" | "permissions" | "storageClass" | "symlinkTarget" | "tags" | "uniqueId" | (string & {});
|
|
136
|
+
/**
|
|
137
|
+
* Capability snapshot advertised by a provider factory and active session.
|
|
138
|
+
*/
|
|
139
|
+
interface CapabilitySet {
|
|
140
|
+
/** Provider this capability set describes. */
|
|
141
|
+
provider: ProviderId;
|
|
142
|
+
/** Authentication mechanisms accepted by the provider. */
|
|
143
|
+
authentication: AuthenticationCapability[];
|
|
144
|
+
/** Whether the provider can list child entries. */
|
|
145
|
+
list: boolean;
|
|
146
|
+
/** Whether the provider can read metadata for a path. */
|
|
147
|
+
stat: boolean;
|
|
148
|
+
/** Whether the provider can produce readable streams. */
|
|
149
|
+
readStream: boolean;
|
|
150
|
+
/** Whether the provider can accept writable streams. */
|
|
151
|
+
writeStream: boolean;
|
|
152
|
+
/** Whether the provider can copy data without routing bytes through the client. */
|
|
153
|
+
serverSideCopy: boolean;
|
|
154
|
+
/** Whether the provider can move data without routing bytes through the client. */
|
|
155
|
+
serverSideMove: boolean;
|
|
156
|
+
/** Whether the provider can resume partial downloads. */
|
|
157
|
+
resumeDownload: boolean;
|
|
158
|
+
/** Whether the provider can resume partial uploads. */
|
|
159
|
+
resumeUpload: boolean;
|
|
160
|
+
/** Checksum or provider hash mechanisms available for verification. */
|
|
161
|
+
checksum: ChecksumCapability[];
|
|
162
|
+
/** Whether rename operations are atomic within the provider. */
|
|
163
|
+
atomicRename: boolean;
|
|
164
|
+
/** Whether chmod-style permission changes are supported. */
|
|
165
|
+
chmod: boolean;
|
|
166
|
+
/** Whether owner changes are supported. */
|
|
167
|
+
chown: boolean;
|
|
168
|
+
/** Whether symbolic links are supported. */
|
|
169
|
+
symlink: boolean;
|
|
170
|
+
/** Metadata fields the provider can preserve or report. */
|
|
171
|
+
metadata: MetadataCapability[];
|
|
172
|
+
/** Recommended maximum concurrent operations for this provider. */
|
|
173
|
+
maxConcurrency?: number;
|
|
174
|
+
/** Human-readable caveats for diagnostics or provider matrices. */
|
|
175
|
+
notes?: string[];
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Secret source contracts and resolution helpers for connection profiles.
|
|
180
|
+
*
|
|
181
|
+
* @module profiles/SecretSource
|
|
182
|
+
*/
|
|
183
|
+
|
|
184
|
+
/** Resolved secret value accepted by profile credential fields. */
|
|
185
|
+
type SecretValue = string | Buffer$1;
|
|
186
|
+
/** Callback source used by applications to integrate vaults or credential brokers. */
|
|
187
|
+
type SecretProvider = () => SecretValue | Promise<SecretValue>;
|
|
188
|
+
/** Inline secret descriptor. Prefer env, path, or callback sources for real applications. */
|
|
189
|
+
interface ValueSecretSource {
|
|
190
|
+
/** Inline secret value. */
|
|
191
|
+
value: SecretValue;
|
|
192
|
+
}
|
|
193
|
+
/** Environment variable descriptor for text secrets. */
|
|
194
|
+
interface EnvSecretSource {
|
|
195
|
+
/** Environment variable containing the secret. */
|
|
196
|
+
env: string;
|
|
197
|
+
}
|
|
198
|
+
/** Environment variable descriptor for base64-encoded binary secrets. */
|
|
199
|
+
interface Base64EnvSecretSource {
|
|
200
|
+
/** Environment variable containing a base64-encoded secret. */
|
|
201
|
+
base64Env: string;
|
|
202
|
+
}
|
|
203
|
+
/** File-backed secret descriptor. */
|
|
204
|
+
interface FileSecretSource {
|
|
205
|
+
/** Path to the file containing the secret. */
|
|
206
|
+
path: string;
|
|
207
|
+
/** Text encoding to use, or `buffer` to return raw bytes. Defaults to `utf8`. */
|
|
208
|
+
encoding?: BufferEncoding | "buffer";
|
|
209
|
+
}
|
|
210
|
+
/** Secret source accepted by profile credential fields. */
|
|
211
|
+
type SecretSource = SecretValue | SecretProvider | ValueSecretSource | EnvSecretSource | Base64EnvSecretSource | FileSecretSource;
|
|
212
|
+
/** Injectable dependencies used by tests or host applications during secret resolution. */
|
|
213
|
+
interface ResolveSecretOptions {
|
|
214
|
+
/** Environment source. Defaults to `process.env`. */
|
|
215
|
+
env?: NodeJS.ProcessEnv;
|
|
216
|
+
/** File reader. Defaults to `fs.promises.readFile`. */
|
|
217
|
+
readFile?: (path: string) => Promise<Buffer$1> | Buffer$1;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Resolves a secret source into a string or Buffer without logging the value.
|
|
221
|
+
*
|
|
222
|
+
* @param source - Secret source to resolve.
|
|
223
|
+
* @param options - Optional env and file-reader overrides.
|
|
224
|
+
* @returns Resolved secret value.
|
|
225
|
+
* @throws {@link ConfigurationError} When a descriptor is invalid or unavailable.
|
|
226
|
+
*/
|
|
227
|
+
declare function resolveSecret(source: SecretSource, options?: ResolveSecretOptions): Promise<SecretValue>;
|
|
228
|
+
/**
|
|
229
|
+
* Redacts a secret source or resolved secret for safe diagnostics.
|
|
230
|
+
*
|
|
231
|
+
* @param source - Secret source or resolved value to sanitize.
|
|
232
|
+
* @returns Redacted placeholder or descriptor shape.
|
|
233
|
+
*/
|
|
234
|
+
declare function redactSecretSource(source: SecretSource | SecretValue): unknown;
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Public data contracts shared by the ZeroTransfer facade, adapters, and services.
|
|
238
|
+
*
|
|
239
|
+
* These types are intentionally protocol-neutral so FTP, FTPS, and SFTP adapters can
|
|
240
|
+
* report the same metadata, transfer, and connection shapes to application code.
|
|
241
|
+
*
|
|
242
|
+
* @module types/public
|
|
243
|
+
*/
|
|
244
|
+
|
|
245
|
+
/** Supported remote file-transfer protocols. */
|
|
246
|
+
type RemoteProtocol = ClassicProviderId;
|
|
247
|
+
/** Normalized remote entry kinds returned by listing and metadata operations. */
|
|
248
|
+
type RemoteEntryType = "file" | "directory" | "symlink" | "unknown";
|
|
249
|
+
/**
|
|
250
|
+
* Portable permission metadata for a remote entry.
|
|
251
|
+
*/
|
|
252
|
+
interface RemotePermissions {
|
|
253
|
+
/** Raw protocol permission text, such as Unix mode characters or MLSD `perm` facts. */
|
|
254
|
+
raw?: string;
|
|
255
|
+
/** User/owner permission component when the protocol exposes it. */
|
|
256
|
+
user?: string;
|
|
257
|
+
/** Group permission component when the protocol exposes it. */
|
|
258
|
+
group?: string;
|
|
259
|
+
/** Other/world permission component when the protocol exposes it. */
|
|
260
|
+
other?: string;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Normalized remote file-system entry.
|
|
264
|
+
*/
|
|
265
|
+
interface RemoteEntry {
|
|
266
|
+
/** Absolute or normalized remote path for the entry. */
|
|
267
|
+
path: string;
|
|
268
|
+
/** Entry basename without parent directory segments. */
|
|
269
|
+
name: string;
|
|
270
|
+
/** Normalized entry kind. */
|
|
271
|
+
type: RemoteEntryType;
|
|
272
|
+
/** Entry size in bytes when known. */
|
|
273
|
+
size?: number;
|
|
274
|
+
/** Last modification time when known. */
|
|
275
|
+
modifiedAt?: Date;
|
|
276
|
+
/** Creation time when the protocol exposes it. */
|
|
277
|
+
createdAt?: Date;
|
|
278
|
+
/** Last access time when the protocol exposes it. */
|
|
279
|
+
accessedAt?: Date;
|
|
280
|
+
/** Portable permission details when known. */
|
|
281
|
+
permissions?: RemotePermissions;
|
|
282
|
+
/** Owner name or id when known. */
|
|
283
|
+
owner?: string;
|
|
284
|
+
/** Group name or id when known. */
|
|
285
|
+
group?: string;
|
|
286
|
+
/** Target path for symbolic links when known. */
|
|
287
|
+
symlinkTarget?: string;
|
|
288
|
+
/** Protocol-specific stable identity when available. */
|
|
289
|
+
uniqueId?: string;
|
|
290
|
+
/** Raw protocol payload retained for diagnostics or advanced callers. */
|
|
291
|
+
raw?: unknown;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Metadata for a remote entry that is known to exist.
|
|
295
|
+
*/
|
|
296
|
+
interface RemoteStat extends RemoteEntry {
|
|
297
|
+
/** Existence discriminator for successful stat operations. */
|
|
298
|
+
exists: true;
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* TLS material source accepted by certificate-aware connection profiles.
|
|
302
|
+
*
|
|
303
|
+
* A single source is used for most fields; `ca` may use an array to preserve an
|
|
304
|
+
* ordered certificate authority bundle.
|
|
305
|
+
*/
|
|
306
|
+
type TlsSecretSource = SecretSource | SecretSource[];
|
|
307
|
+
/** Known-hosts material source accepted by SSH connection profiles. */
|
|
308
|
+
type SshKnownHostsSource = SecretSource | SecretSource[];
|
|
309
|
+
/** SSH agent source accepted by SFTP providers. */
|
|
310
|
+
type SshAgentSource = string | BaseAgent;
|
|
311
|
+
/** SSH transport algorithm overrides accepted by SFTP providers. */
|
|
312
|
+
type SshAlgorithms = Algorithms;
|
|
313
|
+
/** Context passed to SSH socket factories before opening an SSH session. */
|
|
314
|
+
interface SshSocketFactoryContext {
|
|
315
|
+
/** Target SSH host from the resolved connection profile. */
|
|
316
|
+
host: string;
|
|
317
|
+
/** Target SSH port from the resolved connection profile. */
|
|
318
|
+
port: number;
|
|
319
|
+
/** Resolved username, when configured on the connection profile. */
|
|
320
|
+
username?: string;
|
|
321
|
+
/** Abort signal from the connection profile, when one is configured. */
|
|
322
|
+
signal?: AbortSignal;
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Creates a preconnected socket-like stream for SSH sessions.
|
|
326
|
+
*
|
|
327
|
+
* Use this hook for HTTP CONNECT, SOCKS, bastion, or custom tunnel integrations.
|
|
328
|
+
*
|
|
329
|
+
* @param context - Resolved SSH target information for the socket being opened.
|
|
330
|
+
* @returns Preconnected readable stream, or a promise for one, passed to ssh2's `sock` option.
|
|
331
|
+
*/
|
|
332
|
+
type SshSocketFactory = (context: SshSocketFactoryContext) => Readable | Promise<Readable>;
|
|
333
|
+
/** Prompt metadata supplied by an SSH keyboard-interactive server challenge. */
|
|
334
|
+
interface SshKeyboardInteractivePrompt {
|
|
335
|
+
/** Human-readable prompt text supplied by the SSH server. */
|
|
336
|
+
prompt: string;
|
|
337
|
+
/** Whether the answer may be echoed to a terminal or UI. */
|
|
338
|
+
echo?: boolean;
|
|
339
|
+
}
|
|
340
|
+
/** Input passed to SSH keyboard-interactive answer providers. */
|
|
341
|
+
interface SshKeyboardInteractiveChallenge {
|
|
342
|
+
/** Server-provided challenge title. */
|
|
343
|
+
name: string;
|
|
344
|
+
/** Server-provided instructions for the prompt set. */
|
|
345
|
+
instructions: string;
|
|
346
|
+
/** Server-provided language tag, when supplied. */
|
|
347
|
+
language: string;
|
|
348
|
+
/** Ordered prompts that require answers. */
|
|
349
|
+
prompts: readonly SshKeyboardInteractivePrompt[];
|
|
350
|
+
}
|
|
351
|
+
/** Provides ordered answers for an SSH keyboard-interactive authentication challenge. */
|
|
352
|
+
type SshKeyboardInteractiveHandler = (challenge: SshKeyboardInteractiveChallenge) => readonly string[] | Promise<readonly string[]>;
|
|
353
|
+
/**
|
|
354
|
+
* TLS settings shared by certificate-aware providers such as FTPS and future HTTPS/WebDAV adapters.
|
|
355
|
+
*
|
|
356
|
+
* Secret-bearing fields accept inline values, environment-backed values, or file-backed values,
|
|
357
|
+
* and are resolved by providers before opening TLS sockets.
|
|
358
|
+
*/
|
|
359
|
+
interface TlsProfile {
|
|
360
|
+
/** Certificate authority bundle used to validate private or self-signed endpoints. */
|
|
361
|
+
ca?: TlsSecretSource;
|
|
362
|
+
/** Client certificate PEM used for mutual TLS when a provider requires it. */
|
|
363
|
+
cert?: SecretSource;
|
|
364
|
+
/** Client private key PEM used with `cert`. */
|
|
365
|
+
key?: SecretSource;
|
|
366
|
+
/** PFX/P12 client certificate bundle. */
|
|
367
|
+
pfx?: SecretSource;
|
|
368
|
+
/** Passphrase for an encrypted private key or PFX/P12 bundle. */
|
|
369
|
+
passphrase?: SecretSource;
|
|
370
|
+
/** Server name used for SNI and certificate identity checks. Defaults to the profile host. */
|
|
371
|
+
servername?: string;
|
|
372
|
+
/** Whether TLS certificate validation is required. Defaults to `true`. */
|
|
373
|
+
rejectUnauthorized?: boolean;
|
|
374
|
+
/** Minimum TLS protocol version accepted by the client. */
|
|
375
|
+
minVersion?: SecureVersion;
|
|
376
|
+
/** Maximum TLS protocol version accepted by the client. */
|
|
377
|
+
maxVersion?: SecureVersion;
|
|
378
|
+
/** Expected server certificate SHA-256 fingerprint or fingerprints, using hex with optional colons. */
|
|
379
|
+
pinnedFingerprint256?: string | readonly string[];
|
|
380
|
+
/** Optional custom server identity checker for private PKI or certificate pinning. */
|
|
381
|
+
checkServerIdentity?: (host: string, cert: PeerCertificate) => Error | undefined;
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* SSH authentication material for SFTP-style providers.
|
|
385
|
+
*
|
|
386
|
+
* Secret-bearing fields accept inline values, environment-backed values, or file-backed values,
|
|
387
|
+
* and are resolved by providers before opening SSH sessions.
|
|
388
|
+
*/
|
|
389
|
+
interface SshProfile {
|
|
390
|
+
/** SSH agent socket path or agent instance used for agent-based public-key authentication. */
|
|
391
|
+
agent?: SshAgentSource;
|
|
392
|
+
/** Explicit SSH transport algorithm overrides for ciphers, KEX, host keys, MACs, and compression. */
|
|
393
|
+
algorithms?: SshAlgorithms;
|
|
394
|
+
/** Private key material used for public-key authentication. */
|
|
395
|
+
privateKey?: SecretSource;
|
|
396
|
+
/** Passphrase used to decrypt an encrypted private key. */
|
|
397
|
+
passphrase?: SecretSource;
|
|
398
|
+
/** OpenSSH known_hosts content used for strict SFTP host-key verification. */
|
|
399
|
+
knownHosts?: SshKnownHostsSource;
|
|
400
|
+
/** Expected SSH host-key SHA-256 fingerprint or fingerprints, using OpenSSH `SHA256:` form, base64, or hex. */
|
|
401
|
+
pinnedHostKeySha256?: string | readonly string[];
|
|
402
|
+
/** Runtime callback that answers SSH keyboard-interactive authentication prompts. */
|
|
403
|
+
keyboardInteractive?: SshKeyboardInteractiveHandler;
|
|
404
|
+
/** Runtime callback that returns a preconnected stream used instead of opening a direct TCP socket. */
|
|
405
|
+
socketFactory?: SshSocketFactory;
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* Connection settings accepted by facade and adapter implementations.
|
|
409
|
+
*/
|
|
410
|
+
interface ConnectionProfile {
|
|
411
|
+
/** Provider to use for this connection. Prefer this over the compatibility protocol field. */
|
|
412
|
+
provider?: ProviderId;
|
|
413
|
+
/** Protocol to use for this connection, overriding the client default. */
|
|
414
|
+
protocol?: RemoteProtocol;
|
|
415
|
+
/** Remote hostname or IP address. */
|
|
416
|
+
host: string;
|
|
417
|
+
/** Remote port; adapters should apply protocol defaults when omitted. */
|
|
418
|
+
port?: number;
|
|
419
|
+
/** Username, account identifier, or deferred secret source for authentication. */
|
|
420
|
+
username?: SecretSource;
|
|
421
|
+
/** Password or deferred secret source for password-based authentication. */
|
|
422
|
+
password?: SecretSource;
|
|
423
|
+
/** Whether encrypted transport should be requested for protocols that support it. */
|
|
424
|
+
secure?: boolean;
|
|
425
|
+
/** TLS settings for encrypted providers such as FTPS. */
|
|
426
|
+
tls?: TlsProfile;
|
|
427
|
+
/** SSH settings for SFTP providers. */
|
|
428
|
+
ssh?: SshProfile;
|
|
429
|
+
/** Operation or connection timeout in milliseconds. */
|
|
430
|
+
timeoutMs?: number;
|
|
431
|
+
/** Abort signal used to cancel connection setup or long-running operations. */
|
|
432
|
+
signal?: AbortSignal;
|
|
433
|
+
/** Per-profile logger override. */
|
|
434
|
+
logger?: ZeroTransferLogger;
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* Options for remote directory listing operations.
|
|
438
|
+
*/
|
|
439
|
+
interface ListOptions {
|
|
440
|
+
/** Recursively walk child directories when supported by the adapter. */
|
|
441
|
+
recursive?: boolean;
|
|
442
|
+
/** Include hidden or dot-prefixed entries when the protocol/listing format supports it. */
|
|
443
|
+
includeHidden?: boolean;
|
|
444
|
+
/** Abort signal used to cancel the listing operation. */
|
|
445
|
+
signal?: AbortSignal;
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* Options for remote metadata lookup operations.
|
|
449
|
+
*/
|
|
450
|
+
interface StatOptions {
|
|
451
|
+
/** Abort signal used to cancel the metadata operation. */
|
|
452
|
+
signal?: AbortSignal;
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Progress snapshot emitted while a transfer is running.
|
|
456
|
+
*/
|
|
457
|
+
interface TransferProgressEvent {
|
|
458
|
+
/** Stable transfer identifier used to correlate logs and events. */
|
|
459
|
+
transferId: string;
|
|
460
|
+
/** Bytes successfully transferred so far. */
|
|
461
|
+
bytesTransferred: number;
|
|
462
|
+
/** Total expected bytes when the adapter can determine the remote or local size. */
|
|
463
|
+
totalBytes?: number;
|
|
464
|
+
/** Time at which the transfer began. */
|
|
465
|
+
startedAt: Date;
|
|
466
|
+
/** Elapsed transfer time in milliseconds. */
|
|
467
|
+
elapsedMs: number;
|
|
468
|
+
/** Current average throughput in bytes per second. */
|
|
469
|
+
bytesPerSecond: number;
|
|
470
|
+
/** Completion percentage when `totalBytes` is known. */
|
|
471
|
+
percent?: number;
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Final summary for a completed transfer.
|
|
475
|
+
*/
|
|
476
|
+
interface TransferResult {
|
|
477
|
+
/** Local or remote source path when known for the operation. */
|
|
478
|
+
sourcePath?: string;
|
|
479
|
+
/** Local or remote destination path for the completed transfer. */
|
|
480
|
+
destinationPath: string;
|
|
481
|
+
/** Total bytes transferred. */
|
|
482
|
+
bytesTransferred: number;
|
|
483
|
+
/** Time at which the transfer began. */
|
|
484
|
+
startedAt: Date;
|
|
485
|
+
/** Time at which the transfer completed. */
|
|
486
|
+
completedAt: Date;
|
|
487
|
+
/** Total transfer duration in milliseconds. */
|
|
488
|
+
durationMs: number;
|
|
489
|
+
/** Average throughput in bytes per second. */
|
|
490
|
+
averageBytesPerSecond: number;
|
|
491
|
+
/** Whether the transfer resumed from a prior partial state. */
|
|
492
|
+
resumed: boolean;
|
|
493
|
+
/** Whether post-transfer verification completed successfully. */
|
|
494
|
+
verified: boolean;
|
|
495
|
+
/** Optional checksum value produced or verified by the transfer workflow. */
|
|
496
|
+
checksum?: string;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* Provider-neutral remote file-system contract.
|
|
501
|
+
*
|
|
502
|
+
* @module providers/RemoteFileSystem
|
|
503
|
+
*/
|
|
504
|
+
|
|
505
|
+
/** Minimal file-system surface shared by provider sessions. */
|
|
506
|
+
interface RemoteFileSystem {
|
|
507
|
+
/** Lists entries for a provider path. */
|
|
508
|
+
list(path: string, options?: ListOptions): Promise<RemoteEntry[]>;
|
|
509
|
+
/** Reads metadata for a provider path. */
|
|
510
|
+
stat(path: string, options?: StatOptions): Promise<RemoteStat>;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* Transfer job and receipt contracts used by the transfer engine foundation.
|
|
515
|
+
*
|
|
516
|
+
* @module transfers/TransferJob
|
|
517
|
+
*/
|
|
518
|
+
|
|
519
|
+
/** Provider-neutral transfer operation names. */
|
|
520
|
+
type TransferOperation = "copy" | "delete" | "download" | "move" | "sync" | "upload" | (string & {});
|
|
521
|
+
/** Endpoint referenced by a transfer job or receipt. */
|
|
522
|
+
interface TransferEndpoint {
|
|
523
|
+
/** Provider that owns the endpoint when known. */
|
|
524
|
+
provider?: ProviderId;
|
|
525
|
+
/** Provider, remote, or local path for the endpoint. */
|
|
526
|
+
path: string;
|
|
527
|
+
}
|
|
528
|
+
/** Transfer job input consumed by {@link TransferEngine}. */
|
|
529
|
+
interface TransferJob {
|
|
530
|
+
/** Stable job identifier for correlation. */
|
|
531
|
+
id: string;
|
|
532
|
+
/** Operation the job performs. */
|
|
533
|
+
operation: TransferOperation;
|
|
534
|
+
/** Source endpoint for operations that read data. */
|
|
535
|
+
source?: TransferEndpoint;
|
|
536
|
+
/** Destination endpoint for operations that write data. */
|
|
537
|
+
destination?: TransferEndpoint;
|
|
538
|
+
/** Expected total bytes when known before execution. */
|
|
539
|
+
totalBytes?: number;
|
|
540
|
+
/** Whether this job is resuming prior partial work. */
|
|
541
|
+
resumed?: boolean;
|
|
542
|
+
/** Caller-defined metadata retained for diagnostics. */
|
|
543
|
+
metadata?: Record<string, unknown>;
|
|
544
|
+
}
|
|
545
|
+
/** Optional throughput limit shape that concrete transfer executors may honor. */
|
|
546
|
+
interface TransferBandwidthLimit {
|
|
547
|
+
/** Maximum sustained transfer rate in bytes per second. */
|
|
548
|
+
bytesPerSecond: number;
|
|
549
|
+
/** Optional burst allowance in bytes for token-bucket-style implementations. */
|
|
550
|
+
burstBytes?: number;
|
|
551
|
+
}
|
|
552
|
+
/** Timeout policy applied by the transfer engine. */
|
|
553
|
+
interface TransferTimeoutPolicy {
|
|
554
|
+
/** Maximum duration for the full engine execution, including retries, in milliseconds. */
|
|
555
|
+
timeoutMs?: number;
|
|
556
|
+
/** Whether timeout failures are retryable. Defaults to `true`. */
|
|
557
|
+
retryable?: boolean;
|
|
558
|
+
}
|
|
559
|
+
/** Normalized post-transfer verification details. */
|
|
560
|
+
interface TransferVerificationResult {
|
|
561
|
+
/** Whether verification completed successfully. */
|
|
562
|
+
verified: boolean;
|
|
563
|
+
/** Verification method, such as checksum, size, timestamp, or provider-native. */
|
|
564
|
+
method?: string;
|
|
565
|
+
/** Checksum value produced or verified by the operation. */
|
|
566
|
+
checksum?: string;
|
|
567
|
+
/** Expected checksum when a checksum comparison was performed. */
|
|
568
|
+
expectedChecksum?: string;
|
|
569
|
+
/** Actual checksum observed by the operation. */
|
|
570
|
+
actualChecksum?: string;
|
|
571
|
+
/** Caller-defined verification details retained for diagnostics. */
|
|
572
|
+
details?: Record<string, unknown>;
|
|
573
|
+
}
|
|
574
|
+
/** Result returned by a transfer operation implementation. */
|
|
575
|
+
interface TransferExecutionResult {
|
|
576
|
+
/** Bytes transferred by the completed operation. */
|
|
577
|
+
bytesTransferred: number;
|
|
578
|
+
/** Total expected bytes when discovered during execution. */
|
|
579
|
+
totalBytes?: number;
|
|
580
|
+
/** Whether the operation resumed prior partial work. */
|
|
581
|
+
resumed?: boolean;
|
|
582
|
+
/** Whether post-transfer verification completed successfully. */
|
|
583
|
+
verified?: boolean;
|
|
584
|
+
/** Normalized post-transfer verification details. */
|
|
585
|
+
verification?: TransferVerificationResult;
|
|
586
|
+
/** Optional checksum value produced or verified by the operation. */
|
|
587
|
+
checksum?: string;
|
|
588
|
+
/** Non-fatal warnings produced during execution. */
|
|
589
|
+
warnings?: string[];
|
|
590
|
+
}
|
|
591
|
+
/** Serializable error summary retained in failed attempts. */
|
|
592
|
+
interface TransferAttemptError {
|
|
593
|
+
/** Error class or constructor name. */
|
|
594
|
+
name: string;
|
|
595
|
+
/** Human-readable error message. */
|
|
596
|
+
message: string;
|
|
597
|
+
/** Stable SDK error code when available. */
|
|
598
|
+
code?: string;
|
|
599
|
+
/** Whether retry policy may retry the failure. */
|
|
600
|
+
retryable?: boolean;
|
|
601
|
+
}
|
|
602
|
+
/** Execution attempt retained in a transfer receipt. */
|
|
603
|
+
interface TransferAttempt {
|
|
604
|
+
/** One-based attempt number. */
|
|
605
|
+
attempt: number;
|
|
606
|
+
/** Time this attempt began. */
|
|
607
|
+
startedAt: Date;
|
|
608
|
+
/** Time this attempt finished or failed. */
|
|
609
|
+
completedAt: Date;
|
|
610
|
+
/** Attempt duration in milliseconds. */
|
|
611
|
+
durationMs: number;
|
|
612
|
+
/** Bytes reported by the attempt before completion or failure. */
|
|
613
|
+
bytesTransferred: number;
|
|
614
|
+
/** Error summary for failed attempts. */
|
|
615
|
+
error?: TransferAttemptError;
|
|
616
|
+
}
|
|
617
|
+
/** Audit-friendly receipt for a completed transfer job. */
|
|
618
|
+
interface TransferReceipt {
|
|
619
|
+
/** Stable transfer identifier used for progress and log correlation. */
|
|
620
|
+
transferId: string;
|
|
621
|
+
/** Original job identifier. */
|
|
622
|
+
jobId: string;
|
|
623
|
+
/** Operation performed by the job. */
|
|
624
|
+
operation: TransferOperation;
|
|
625
|
+
/** Source endpoint when supplied by the job. */
|
|
626
|
+
source?: TransferEndpoint;
|
|
627
|
+
/** Destination endpoint when supplied by the job. */
|
|
628
|
+
destination?: TransferEndpoint;
|
|
629
|
+
/** Total bytes transferred by the successful operation. */
|
|
630
|
+
bytesTransferred: number;
|
|
631
|
+
/** Expected total bytes when known. */
|
|
632
|
+
totalBytes?: number;
|
|
633
|
+
/** Time the first attempt began. */
|
|
634
|
+
startedAt: Date;
|
|
635
|
+
/** Time the successful attempt completed. */
|
|
636
|
+
completedAt: Date;
|
|
637
|
+
/** Total elapsed time in milliseconds. */
|
|
638
|
+
durationMs: number;
|
|
639
|
+
/** Average throughput in bytes per second. */
|
|
640
|
+
averageBytesPerSecond: number;
|
|
641
|
+
/** Whether the transfer resumed prior partial work. */
|
|
642
|
+
resumed: boolean;
|
|
643
|
+
/** Whether post-transfer verification completed successfully. */
|
|
644
|
+
verified: boolean;
|
|
645
|
+
/** Normalized post-transfer verification details when supplied by the operation. */
|
|
646
|
+
verification?: TransferVerificationResult;
|
|
647
|
+
/** Optional checksum value produced or verified by the operation. */
|
|
648
|
+
checksum?: string;
|
|
649
|
+
/** Attempt history, including retry failures. */
|
|
650
|
+
attempts: TransferAttempt[];
|
|
651
|
+
/** Non-fatal warnings produced during execution. */
|
|
652
|
+
warnings: string[];
|
|
653
|
+
/** Caller-defined metadata retained from the job. */
|
|
654
|
+
metadata?: Record<string, unknown>;
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
/** Context passed to a concrete transfer operation. */
|
|
658
|
+
interface TransferExecutionContext {
|
|
659
|
+
/** Job being executed. */
|
|
660
|
+
job: TransferJob;
|
|
661
|
+
/** One-based attempt number. */
|
|
662
|
+
attempt: number;
|
|
663
|
+
/** Abort signal active for this execution when supplied. */
|
|
664
|
+
signal?: AbortSignal;
|
|
665
|
+
/** Optional throughput limit shape for concrete executors to honor. */
|
|
666
|
+
bandwidthLimit?: TransferBandwidthLimit;
|
|
667
|
+
/** Throws an SDK abort error when the active signal has been cancelled. */
|
|
668
|
+
throwIfAborted(): void;
|
|
669
|
+
/** Emits a normalized progress event through engine options. */
|
|
670
|
+
reportProgress(bytesTransferred: number, totalBytes?: number): TransferProgressEvent;
|
|
671
|
+
}
|
|
672
|
+
/** Concrete transfer operation implementation used by the engine. */
|
|
673
|
+
type TransferExecutor = (context: TransferExecutionContext) => Promise<TransferExecutionResult> | TransferExecutionResult;
|
|
674
|
+
/** Input used by retry policy hooks. */
|
|
675
|
+
interface TransferRetryDecisionInput {
|
|
676
|
+
/** Error thrown by the failed attempt. */
|
|
677
|
+
error: unknown;
|
|
678
|
+
/** One-based attempt number that failed. */
|
|
679
|
+
attempt: number;
|
|
680
|
+
/** Job being executed. */
|
|
681
|
+
job: TransferJob;
|
|
682
|
+
}
|
|
683
|
+
/** Retry policy for transfer execution. */
|
|
684
|
+
interface TransferRetryPolicy {
|
|
685
|
+
/** Maximum total attempts, including the first attempt. Defaults to `1`. */
|
|
686
|
+
maxAttempts?: number;
|
|
687
|
+
/** Decides whether a failed attempt should be retried. Defaults to SDK retryability metadata. */
|
|
688
|
+
shouldRetry?(input: TransferRetryDecisionInput): boolean;
|
|
689
|
+
/** Observes retry decisions before the next attempt starts. */
|
|
690
|
+
onRetry?(input: TransferRetryDecisionInput): void;
|
|
691
|
+
}
|
|
692
|
+
/** Options used by {@link TransferEngine.execute}. */
|
|
693
|
+
interface TransferEngineExecuteOptions {
|
|
694
|
+
/** Abort signal used to cancel the job. */
|
|
695
|
+
signal?: AbortSignal;
|
|
696
|
+
/** Retry policy used for failed attempts. */
|
|
697
|
+
retry?: TransferRetryPolicy;
|
|
698
|
+
/** Progress observer for normalized transfer progress events. */
|
|
699
|
+
onProgress?(event: TransferProgressEvent): void;
|
|
700
|
+
/** Timeout policy enforced by the engine. */
|
|
701
|
+
timeout?: TransferTimeoutPolicy;
|
|
702
|
+
/** Optional throughput limit shape passed through to concrete executors. */
|
|
703
|
+
bandwidthLimit?: TransferBandwidthLimit;
|
|
704
|
+
}
|
|
705
|
+
/** Construction options for deterministic tests and host integration. */
|
|
706
|
+
interface TransferEngineOptions {
|
|
707
|
+
/** Clock used for receipts and progress events. Defaults to `new Date()`. */
|
|
708
|
+
now?: () => Date;
|
|
709
|
+
}
|
|
710
|
+
/** Executes transfer jobs and produces audit-friendly receipts. */
|
|
711
|
+
declare class TransferEngine {
|
|
712
|
+
private readonly now;
|
|
713
|
+
/**
|
|
714
|
+
* Creates a transfer engine.
|
|
715
|
+
*
|
|
716
|
+
* @param options - Optional clock override for deterministic tests.
|
|
717
|
+
*/
|
|
718
|
+
constructor(options?: TransferEngineOptions);
|
|
719
|
+
/**
|
|
720
|
+
* Executes a transfer job through a caller-supplied operation.
|
|
721
|
+
*
|
|
722
|
+
* @param job - Job metadata used for correlation and receipts.
|
|
723
|
+
* @param executor - Concrete transfer operation implementation.
|
|
724
|
+
* @param options - Optional abort, retry, and progress hooks.
|
|
725
|
+
* @returns Receipt for the completed transfer.
|
|
726
|
+
* @throws {@link AbortError} When execution is cancelled.
|
|
727
|
+
* @throws {@link TransferError} When all attempts fail.
|
|
728
|
+
*/
|
|
729
|
+
execute(job: TransferJob, executor: TransferExecutor, options?: TransferEngineExecuteOptions): Promise<TransferReceipt>;
|
|
730
|
+
private createExecutionContext;
|
|
731
|
+
private throwIfAborted;
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
/**
|
|
735
|
+
* Provider-backed transfer read/write contracts.
|
|
736
|
+
*
|
|
737
|
+
* @module providers/ProviderTransferOperations
|
|
738
|
+
*/
|
|
739
|
+
|
|
740
|
+
/** Binary chunk shape used by provider transfer streams. */
|
|
741
|
+
type TransferDataChunk = Uint8Array;
|
|
742
|
+
/** Provider-neutral transfer content source. Node readable streams satisfy this shape. */
|
|
743
|
+
type TransferDataSource = AsyncIterable<TransferDataChunk>;
|
|
744
|
+
/** Byte range requested from a readable provider endpoint. */
|
|
745
|
+
interface TransferByteRange {
|
|
746
|
+
/** Zero-based byte offset where reading should begin. */
|
|
747
|
+
offset: number;
|
|
748
|
+
/** Maximum number of bytes to read when known. */
|
|
749
|
+
length?: number;
|
|
750
|
+
}
|
|
751
|
+
/** Shared provider transfer request fields. */
|
|
752
|
+
interface ProviderTransferRequest extends TransferExecutionContext {
|
|
753
|
+
/** Endpoint owned by the provider handling this request. */
|
|
754
|
+
endpoint: TransferEndpoint;
|
|
755
|
+
}
|
|
756
|
+
/** Request passed to provider read implementations. */
|
|
757
|
+
interface ProviderTransferReadRequest extends ProviderTransferRequest {
|
|
758
|
+
/** Optional byte range for resumed or partial reads. */
|
|
759
|
+
range?: TransferByteRange;
|
|
760
|
+
}
|
|
761
|
+
/** Result returned by provider read implementations. */
|
|
762
|
+
interface ProviderTransferReadResult {
|
|
763
|
+
/** Content stream produced by the provider. */
|
|
764
|
+
content: TransferDataSource;
|
|
765
|
+
/** Bytes already read by the provider before returning the content stream, if any. */
|
|
766
|
+
bytesRead?: number;
|
|
767
|
+
/** Expected total bytes for the content stream when known. */
|
|
768
|
+
totalBytes?: number;
|
|
769
|
+
/** Verification details produced while opening or reading the source. */
|
|
770
|
+
verification?: TransferVerificationResult;
|
|
771
|
+
/** Checksum produced while opening or reading the source. */
|
|
772
|
+
checksum?: string;
|
|
773
|
+
/** Non-fatal warnings produced by the read side. */
|
|
774
|
+
warnings?: string[];
|
|
775
|
+
}
|
|
776
|
+
/** Request passed to provider write implementations. */
|
|
777
|
+
interface ProviderTransferWriteRequest extends ProviderTransferRequest {
|
|
778
|
+
/** Content stream to write to the provider endpoint. */
|
|
779
|
+
content: TransferDataSource;
|
|
780
|
+
/** Expected total bytes for the content stream when known. */
|
|
781
|
+
totalBytes?: number;
|
|
782
|
+
/** Resume offset for partial writes when supported by the provider. */
|
|
783
|
+
offset?: number;
|
|
784
|
+
/** Verification details from the read side that a writer may preserve or compare. */
|
|
785
|
+
verification?: TransferVerificationResult;
|
|
786
|
+
}
|
|
787
|
+
/** Result returned by provider write implementations. */
|
|
788
|
+
type ProviderTransferWriteResult = TransferExecutionResult;
|
|
789
|
+
/** Optional read/write surface exposed by provider sessions that support transfer streaming. */
|
|
790
|
+
interface ProviderTransferOperations {
|
|
791
|
+
/** Opens readable content for a provider endpoint. */
|
|
792
|
+
read(request: ProviderTransferReadRequest): Promise<ProviderTransferReadResult> | ProviderTransferReadResult;
|
|
793
|
+
/** Writes readable content to a provider endpoint. */
|
|
794
|
+
write(request: ProviderTransferWriteRequest): Promise<ProviderTransferWriteResult> | ProviderTransferWriteResult;
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
/**
|
|
798
|
+
* Active provider session contract returned by provider-neutral connections.
|
|
799
|
+
*
|
|
800
|
+
* @module core/TransferSession
|
|
801
|
+
*/
|
|
802
|
+
|
|
803
|
+
/**
|
|
804
|
+
* Connected provider session exposed through {@link TransferClient.connect}.
|
|
805
|
+
*/
|
|
806
|
+
interface TransferSession<TRaw = unknown> {
|
|
807
|
+
/** Provider backing this session. */
|
|
808
|
+
provider: ProviderId;
|
|
809
|
+
/** Provider capabilities available for this connected session. */
|
|
810
|
+
capabilities: CapabilitySet;
|
|
811
|
+
/** Provider-neutral remote file-system operations. */
|
|
812
|
+
fs: RemoteFileSystem;
|
|
813
|
+
/** Optional provider-backed transfer read/write operations. */
|
|
814
|
+
transfers?: ProviderTransferOperations;
|
|
815
|
+
/** Disconnects and releases provider resources. */
|
|
816
|
+
disconnect(): Promise<void>;
|
|
817
|
+
/** Returns a provider-specific advanced interface when one exists. */
|
|
818
|
+
raw?(): TRaw;
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
/**
|
|
822
|
+
* Provider implementation contracts for ZeroTransfer adapters.
|
|
823
|
+
*
|
|
824
|
+
* @module providers/Provider
|
|
825
|
+
*/
|
|
826
|
+
|
|
827
|
+
/** Provider implementation that can open transfer sessions. */
|
|
828
|
+
interface TransferProvider<TSession extends TransferSession = TransferSession> {
|
|
829
|
+
/** Stable provider id. */
|
|
830
|
+
id: ProviderId;
|
|
831
|
+
/** Capabilities advertised by this provider implementation. */
|
|
832
|
+
capabilities: CapabilitySet;
|
|
833
|
+
/** Opens a connected provider session. */
|
|
834
|
+
connect(profile: ConnectionProfile): Promise<TSession>;
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
/**
|
|
838
|
+
* Provider factory contracts used by the provider registry.
|
|
839
|
+
*
|
|
840
|
+
* @module providers/ProviderFactory
|
|
841
|
+
*/
|
|
842
|
+
|
|
843
|
+
/** Factory registered with {@link ProviderRegistry} to create providers on demand. */
|
|
844
|
+
interface ProviderFactory<TProvider extends TransferProvider = TransferProvider> {
|
|
845
|
+
/** Provider id created by this factory. */
|
|
846
|
+
id: ProviderId;
|
|
847
|
+
/** Capability snapshot available without opening a network connection. */
|
|
848
|
+
capabilities: CapabilitySet;
|
|
849
|
+
/** Creates an isolated provider instance for a connection attempt. */
|
|
850
|
+
create(): TProvider;
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
/** Mutable registry of provider factories available to a transfer client. */
|
|
854
|
+
declare class ProviderRegistry {
|
|
855
|
+
private readonly factories;
|
|
856
|
+
/**
|
|
857
|
+
* Creates a registry and optionally seeds it with provider factories.
|
|
858
|
+
*
|
|
859
|
+
* @param providers - Provider factories to register immediately.
|
|
860
|
+
*/
|
|
861
|
+
constructor(providers?: Iterable<ProviderFactory>);
|
|
862
|
+
/**
|
|
863
|
+
* Registers a provider factory.
|
|
864
|
+
*
|
|
865
|
+
* @param provider - Provider factory to add.
|
|
866
|
+
* @returns This registry for fluent setup.
|
|
867
|
+
* @throws {@link ConfigurationError} When a provider id is registered twice.
|
|
868
|
+
*/
|
|
869
|
+
register(provider: ProviderFactory): this;
|
|
870
|
+
/**
|
|
871
|
+
* Removes a provider factory from the registry.
|
|
872
|
+
*
|
|
873
|
+
* @param providerId - Provider id to remove.
|
|
874
|
+
* @returns `true` when a provider was removed.
|
|
875
|
+
*/
|
|
876
|
+
unregister(providerId: ProviderId): boolean;
|
|
877
|
+
/**
|
|
878
|
+
* Checks whether a provider id is registered.
|
|
879
|
+
*
|
|
880
|
+
* @param providerId - Provider id to inspect.
|
|
881
|
+
* @returns `true` when a provider factory exists.
|
|
882
|
+
*/
|
|
883
|
+
has(providerId: ProviderId): boolean;
|
|
884
|
+
/**
|
|
885
|
+
* Gets a provider factory when registered.
|
|
886
|
+
*
|
|
887
|
+
* @param providerId - Provider id to retrieve.
|
|
888
|
+
* @returns The provider factory, or `undefined` when missing.
|
|
889
|
+
*/
|
|
890
|
+
get(providerId: ProviderId): ProviderFactory | undefined;
|
|
891
|
+
/**
|
|
892
|
+
* Gets a registered provider factory or throws a typed SDK error.
|
|
893
|
+
*
|
|
894
|
+
* @param providerId - Provider id to retrieve.
|
|
895
|
+
* @returns The registered provider factory.
|
|
896
|
+
* @throws {@link UnsupportedFeatureError} When no provider has been registered.
|
|
897
|
+
*/
|
|
898
|
+
require(providerId: ProviderId): ProviderFactory;
|
|
899
|
+
/**
|
|
900
|
+
* Gets a provider capability snapshot when registered.
|
|
901
|
+
*
|
|
902
|
+
* @param providerId - Provider id to inspect.
|
|
903
|
+
* @returns Capability snapshot, or `undefined` when missing.
|
|
904
|
+
*/
|
|
905
|
+
getCapabilities(providerId: ProviderId): CapabilitySet | undefined;
|
|
906
|
+
/**
|
|
907
|
+
* Gets a provider capability snapshot or throws a typed SDK error.
|
|
908
|
+
*
|
|
909
|
+
* @param providerId - Provider id to inspect.
|
|
910
|
+
* @returns Capability snapshot for the registered provider.
|
|
911
|
+
* @throws {@link UnsupportedFeatureError} When no provider has been registered.
|
|
912
|
+
*/
|
|
913
|
+
requireCapabilities(providerId: ProviderId): CapabilitySet;
|
|
914
|
+
/**
|
|
915
|
+
* Lists registered provider factories in insertion order.
|
|
916
|
+
*
|
|
917
|
+
* @returns Registered provider factories.
|
|
918
|
+
*/
|
|
919
|
+
list(): ProviderFactory[];
|
|
920
|
+
/**
|
|
921
|
+
* Lists registered provider capabilities in insertion order.
|
|
922
|
+
*
|
|
923
|
+
* @returns Capability snapshots for every registered provider.
|
|
924
|
+
*/
|
|
925
|
+
listCapabilities(): CapabilitySet[];
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
/** Options used to create a provider-neutral transfer client. */
|
|
929
|
+
interface TransferClientOptions {
|
|
930
|
+
/** Existing registry to reuse. When omitted, a fresh empty registry is created. */
|
|
931
|
+
registry?: ProviderRegistry;
|
|
932
|
+
/** Provider factories to register with the client registry. */
|
|
933
|
+
providers?: ProviderFactory[];
|
|
934
|
+
/** Structured logger used for client lifecycle records. */
|
|
935
|
+
logger?: ZeroTransferLogger;
|
|
936
|
+
}
|
|
937
|
+
/** Small provider-neutral client that owns provider lookup and connection setup. */
|
|
938
|
+
declare class TransferClient {
|
|
939
|
+
/** Provider registry used by this client. */
|
|
940
|
+
readonly registry: ProviderRegistry;
|
|
941
|
+
private readonly logger;
|
|
942
|
+
/**
|
|
943
|
+
* Creates a transfer client without opening any provider connections.
|
|
944
|
+
*
|
|
945
|
+
* @param options - Optional registry, provider factories, and logger.
|
|
946
|
+
*/
|
|
947
|
+
constructor(options?: TransferClientOptions);
|
|
948
|
+
/**
|
|
949
|
+
* Registers a provider factory with this client's registry.
|
|
950
|
+
*
|
|
951
|
+
* @param provider - Provider factory to register.
|
|
952
|
+
* @returns This client for fluent setup.
|
|
953
|
+
*/
|
|
954
|
+
registerProvider(provider: ProviderFactory): this;
|
|
955
|
+
/**
|
|
956
|
+
* Checks whether this client can create sessions for a provider id.
|
|
957
|
+
*
|
|
958
|
+
* @param providerId - Provider id to inspect.
|
|
959
|
+
* @returns `true` when a provider factory is registered.
|
|
960
|
+
*/
|
|
961
|
+
hasProvider(providerId: ProviderId): boolean;
|
|
962
|
+
/** Lists all registered provider capability snapshots. */
|
|
963
|
+
getCapabilities(): CapabilitySet[];
|
|
964
|
+
/** Gets a specific provider capability snapshot. */
|
|
965
|
+
getCapabilities(providerId: ProviderId): CapabilitySet;
|
|
966
|
+
/**
|
|
967
|
+
* Opens a provider session using `profile.provider`, with `profile.protocol` as compatibility fallback.
|
|
968
|
+
*
|
|
969
|
+
* @param profile - Connection profile containing a provider or legacy protocol field.
|
|
970
|
+
* @returns A connected provider session.
|
|
971
|
+
* @throws {@link ConfigurationError} When neither provider nor protocol is present.
|
|
972
|
+
*/
|
|
973
|
+
connect(profile: ConnectionProfile): Promise<TransferSession>;
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
/**
|
|
977
|
+
* Factory for provider-neutral ZeroTransfer clients.
|
|
978
|
+
*
|
|
979
|
+
* @module core/createTransferClient
|
|
980
|
+
*/
|
|
981
|
+
|
|
982
|
+
/**
|
|
983
|
+
* Creates a provider-neutral transfer client.
|
|
984
|
+
*
|
|
985
|
+
* @param options - Optional registry, provider factories, and logger.
|
|
986
|
+
* @returns A disconnected {@link TransferClient} instance.
|
|
987
|
+
*/
|
|
988
|
+
declare function createTransferClient(options?: TransferClientOptions): TransferClient;
|
|
989
|
+
|
|
990
|
+
/**
|
|
991
|
+
* Shared protocol adapter contract used by the ZeroTransfer facade.
|
|
992
|
+
*
|
|
993
|
+
* Protocol-specific implementations for FTP, FTPS, and SFTP should conform to this
|
|
994
|
+
* interface so high-level client code can remain protocol-neutral.
|
|
995
|
+
*
|
|
996
|
+
* @module protocols/RemoteFileAdapter
|
|
997
|
+
*/
|
|
998
|
+
|
|
999
|
+
/**
|
|
1000
|
+
* Minimal remote-file adapter required by the current alpha facade.
|
|
1001
|
+
*/
|
|
1002
|
+
interface RemoteFileAdapter {
|
|
1003
|
+
/**
|
|
1004
|
+
* Opens a remote connection.
|
|
1005
|
+
*
|
|
1006
|
+
* @param profile - Host, authentication, protocol, timeout, signal, and logger settings.
|
|
1007
|
+
* @returns A promise that resolves when the remote session is ready for operations.
|
|
1008
|
+
*/
|
|
1009
|
+
connect(profile: ConnectionProfile): Promise<void>;
|
|
1010
|
+
/**
|
|
1011
|
+
* Closes the remote connection and releases protocol resources.
|
|
1012
|
+
*
|
|
1013
|
+
* @returns A promise that resolves when the remote session is fully closed.
|
|
1014
|
+
*/
|
|
1015
|
+
disconnect(): Promise<void>;
|
|
1016
|
+
/**
|
|
1017
|
+
* Lists entries for a remote directory.
|
|
1018
|
+
*
|
|
1019
|
+
* @param path - Remote directory path to list.
|
|
1020
|
+
* @param options - Optional listing controls such as recursion and abort signal.
|
|
1021
|
+
* @returns Normalized remote entries contained by the requested path.
|
|
1022
|
+
*/
|
|
1023
|
+
list(path: string, options?: ListOptions): Promise<RemoteEntry[]>;
|
|
1024
|
+
/**
|
|
1025
|
+
* Reads metadata for a remote entry.
|
|
1026
|
+
*
|
|
1027
|
+
* @param path - Remote path to inspect.
|
|
1028
|
+
* @param options - Optional stat controls such as abort signal.
|
|
1029
|
+
* @returns Normalized metadata for an existing remote entry.
|
|
1030
|
+
*/
|
|
1031
|
+
stat(path: string, options?: StatOptions): Promise<RemoteStat>;
|
|
1032
|
+
}
|
|
1033
|
+
|
|
1034
|
+
/**
|
|
1035
|
+
* Client facade for the ZeroTransfer SDK foundation.
|
|
1036
|
+
*
|
|
1037
|
+
* This module intentionally keeps the top-level API small while protocol-specific
|
|
1038
|
+
* behavior is delegated to injected adapters. The facade owns lifecycle state,
|
|
1039
|
+
* event emission, logging coordination, and common capability discovery.
|
|
1040
|
+
*
|
|
1041
|
+
* @module client/ZeroTransfer
|
|
1042
|
+
*/
|
|
1043
|
+
|
|
1044
|
+
/**
|
|
1045
|
+
* Construction options for a {@link ZeroTransfer} instance.
|
|
1046
|
+
*
|
|
1047
|
+
* @remarks
|
|
1048
|
+
* The adapter option is primarily used by protocol implementations and tests. Until
|
|
1049
|
+
* the built-in FTP, FTPS, and SFTP adapters are implemented, callers can inject a
|
|
1050
|
+
* compatible adapter to exercise the facade contract.
|
|
1051
|
+
*/
|
|
1052
|
+
interface ZeroTransferOptions {
|
|
1053
|
+
/** Protocol used when the connection profile does not provide one. */
|
|
1054
|
+
protocol?: RemoteProtocol;
|
|
1055
|
+
/** Structured logger used for lifecycle and operation records. */
|
|
1056
|
+
logger?: ZeroTransferLogger;
|
|
1057
|
+
/** Protocol adapter that performs concrete remote file operations. */
|
|
1058
|
+
adapter?: RemoteFileAdapter;
|
|
1059
|
+
}
|
|
1060
|
+
/**
|
|
1061
|
+
* Lightweight capability snapshot for the current client instance.
|
|
1062
|
+
*/
|
|
1063
|
+
interface ZeroTransferCapabilities {
|
|
1064
|
+
/** The protocol selected for this client facade. */
|
|
1065
|
+
protocol: RemoteProtocol;
|
|
1066
|
+
/** Whether a concrete protocol adapter has been supplied. */
|
|
1067
|
+
adapterReady: boolean;
|
|
1068
|
+
}
|
|
1069
|
+
/**
|
|
1070
|
+
* SDK entry point for FTP, FTPS, and SFTP workflows.
|
|
1071
|
+
*
|
|
1072
|
+
* @remarks
|
|
1073
|
+
* ZeroTransfer extends Node.js EventEmitter so applications can observe lifecycle
|
|
1074
|
+
* events while still using promise-based APIs for operations. The facade is
|
|
1075
|
+
* deliberately protocol-neutral; concrete behavior lives behind
|
|
1076
|
+
* {@link RemoteFileAdapter}.
|
|
1077
|
+
*
|
|
1078
|
+
*/
|
|
1079
|
+
declare class ZeroTransfer extends EventEmitter {
|
|
1080
|
+
/** Creates a provider-neutral transfer client with the built-in provider registry. */
|
|
1081
|
+
static readonly createTransferClient: typeof createTransferClient;
|
|
1082
|
+
/** Protocol selected for this client instance. */
|
|
1083
|
+
readonly protocol: RemoteProtocol;
|
|
1084
|
+
private readonly logger;
|
|
1085
|
+
private readonly adapter;
|
|
1086
|
+
private connected;
|
|
1087
|
+
/**
|
|
1088
|
+
* Creates a client facade without opening a network connection.
|
|
1089
|
+
*
|
|
1090
|
+
* @param options - Optional facade configuration, logger, and protocol adapter.
|
|
1091
|
+
*/
|
|
1092
|
+
constructor(options?: ZeroTransferOptions);
|
|
1093
|
+
/**
|
|
1094
|
+
* Creates a new client facade using the provided options.
|
|
1095
|
+
*
|
|
1096
|
+
* @param options - Optional facade configuration, logger, and adapter.
|
|
1097
|
+
* @returns A disconnected {@link ZeroTransfer} instance.
|
|
1098
|
+
*/
|
|
1099
|
+
static create(options?: ZeroTransferOptions): ZeroTransfer;
|
|
1100
|
+
/**
|
|
1101
|
+
* Creates a client and connects it in one step.
|
|
1102
|
+
*
|
|
1103
|
+
* @param profile - Remote host, authentication, and protocol connection settings.
|
|
1104
|
+
* @param options - Optional facade settings that can be overridden by the profile.
|
|
1105
|
+
* @returns A connected {@link ZeroTransfer} instance.
|
|
1106
|
+
* @throws {@link UnsupportedFeatureError} When no adapter is available for the protocol.
|
|
1107
|
+
*/
|
|
1108
|
+
static connect(profile: ConnectionProfile, options?: ZeroTransferOptions): Promise<ZeroTransfer>;
|
|
1109
|
+
/**
|
|
1110
|
+
* Opens a remote connection through the configured protocol adapter.
|
|
1111
|
+
*
|
|
1112
|
+
* @param profile - Remote host, authentication, timeout, logger, and protocol settings.
|
|
1113
|
+
* @returns A promise that resolves after the adapter reports a successful connection.
|
|
1114
|
+
* @throws {@link UnsupportedFeatureError} When the client does not have an adapter.
|
|
1115
|
+
*/
|
|
1116
|
+
connect(profile: ConnectionProfile): Promise<void>;
|
|
1117
|
+
/**
|
|
1118
|
+
* Closes the active remote connection if one exists.
|
|
1119
|
+
*
|
|
1120
|
+
* @returns A promise that resolves after the adapter disconnects or immediately when idle.
|
|
1121
|
+
*/
|
|
1122
|
+
disconnect(): Promise<void>;
|
|
1123
|
+
/**
|
|
1124
|
+
* Checks whether the facade currently considers the adapter connected.
|
|
1125
|
+
*
|
|
1126
|
+
* @returns `true` after a successful connection and before disconnection.
|
|
1127
|
+
*/
|
|
1128
|
+
isConnected(): boolean;
|
|
1129
|
+
/**
|
|
1130
|
+
* Describes protocol and adapter readiness for feature discovery.
|
|
1131
|
+
*
|
|
1132
|
+
* @returns A capability snapshot for diagnostics and UI state.
|
|
1133
|
+
*/
|
|
1134
|
+
getCapabilities(): ZeroTransferCapabilities;
|
|
1135
|
+
/**
|
|
1136
|
+
* Lists remote entries for a path using the configured adapter.
|
|
1137
|
+
*
|
|
1138
|
+
* @param path - Remote directory path to inspect.
|
|
1139
|
+
* @param options - Optional listing controls such as recursion and abort signal.
|
|
1140
|
+
* @returns Normalized remote entries for the requested directory.
|
|
1141
|
+
* @throws {@link UnsupportedFeatureError} When the client does not have an adapter.
|
|
1142
|
+
*/
|
|
1143
|
+
list(path: string, options?: ListOptions): Promise<RemoteEntry[]>;
|
|
1144
|
+
/**
|
|
1145
|
+
* Reads metadata for a remote path using the configured adapter.
|
|
1146
|
+
*
|
|
1147
|
+
* @param path - Remote file, directory, or symbolic-link path to inspect.
|
|
1148
|
+
* @param options - Optional stat controls such as abort signal.
|
|
1149
|
+
* @returns Normalized metadata for an existing remote entry.
|
|
1150
|
+
* @throws {@link UnsupportedFeatureError} When the client does not have an adapter.
|
|
1151
|
+
*/
|
|
1152
|
+
stat(path: string, options?: StatOptions): Promise<RemoteStat>;
|
|
1153
|
+
/**
|
|
1154
|
+
* Returns the configured adapter or raises the alpha unsupported-feature error.
|
|
1155
|
+
*
|
|
1156
|
+
* @returns A concrete remote file adapter ready to execute operations.
|
|
1157
|
+
* @throws {@link UnsupportedFeatureError} When no adapter has been provided.
|
|
1158
|
+
*/
|
|
1159
|
+
private requireAdapter;
|
|
1160
|
+
}
|
|
1161
|
+
|
|
1162
|
+
/**
|
|
1163
|
+
* MFT route definitions.
|
|
1164
|
+
*
|
|
1165
|
+
* Routes are named, declarative source→destination policies that bind a pair
|
|
1166
|
+
* of {@link ConnectionProfile} values, the paths being moved, and optional
|
|
1167
|
+
* filtering metadata. Routes are pure data; the {@link runRoute} executor and
|
|
1168
|
+
* the {@link RouteRegistry} wrap them with execution and lookup behavior.
|
|
1169
|
+
*
|
|
1170
|
+
* @module mft/MftRoute
|
|
1171
|
+
*/
|
|
1172
|
+
|
|
1173
|
+
/** Endpoint inside an MFT route. */
|
|
1174
|
+
interface MftRouteEndpoint {
|
|
1175
|
+
/** Connection profile used to open a provider session for the endpoint. */
|
|
1176
|
+
profile: ConnectionProfile;
|
|
1177
|
+
/** Provider, remote, or local path the route operates on. */
|
|
1178
|
+
path: string;
|
|
1179
|
+
}
|
|
1180
|
+
/** Optional filter metadata reserved for tree-aware route execution. */
|
|
1181
|
+
interface MftRouteFilter {
|
|
1182
|
+
/** Glob patterns whose matches should be included. */
|
|
1183
|
+
include?: readonly string[];
|
|
1184
|
+
/** Glob patterns whose matches should be excluded. */
|
|
1185
|
+
exclude?: readonly string[];
|
|
1186
|
+
}
|
|
1187
|
+
/** Transfer operations supported by route executors. */
|
|
1188
|
+
type MftRouteOperation = Extract<TransferOperation, "copy" | "download" | "upload">;
|
|
1189
|
+
/** Declarative source→destination policy bound to provider profiles. */
|
|
1190
|
+
interface MftRoute {
|
|
1191
|
+
/** Stable route identifier. */
|
|
1192
|
+
id: string;
|
|
1193
|
+
/** Optional human-readable route name. */
|
|
1194
|
+
name?: string;
|
|
1195
|
+
/** Optional human-readable description. */
|
|
1196
|
+
description?: string;
|
|
1197
|
+
/** Source endpoint resolved through the transfer client. */
|
|
1198
|
+
source: MftRouteEndpoint;
|
|
1199
|
+
/** Destination endpoint resolved through the transfer client. */
|
|
1200
|
+
destination: MftRouteEndpoint;
|
|
1201
|
+
/** Optional include/exclude filter, reserved for tree-aware executors. */
|
|
1202
|
+
filter?: MftRouteFilter;
|
|
1203
|
+
/** Transfer operation performed by the route. Defaults to `"copy"`. */
|
|
1204
|
+
operation?: MftRouteOperation;
|
|
1205
|
+
/** Whether the route is enabled. Defaults to `true`. */
|
|
1206
|
+
enabled?: boolean;
|
|
1207
|
+
/** Caller-defined metadata retained for diagnostics and audit records. */
|
|
1208
|
+
metadata?: Record<string, unknown>;
|
|
1209
|
+
}
|
|
1210
|
+
|
|
1211
|
+
/**
|
|
1212
|
+
* Route executor that dispatches a single transfer through {@link TransferEngine}.
|
|
1213
|
+
*
|
|
1214
|
+
* `runRoute` opens both endpoints through the supplied {@link TransferClient},
|
|
1215
|
+
* builds a {@link TransferJob} with route correlation metadata, and runs the
|
|
1216
|
+
* provider read/write executor under retry, abort, progress, timeout, and
|
|
1217
|
+
* bandwidth-limit hooks. Sessions are released in `finally` blocks even when
|
|
1218
|
+
* the transfer fails, throws, or is aborted.
|
|
1219
|
+
*
|
|
1220
|
+
* @module mft/runRoute
|
|
1221
|
+
*/
|
|
1222
|
+
|
|
1223
|
+
/** Options accepted by {@link runRoute}. */
|
|
1224
|
+
interface RunRouteOptions {
|
|
1225
|
+
/** Transfer client whose registry can resolve both endpoint providers. */
|
|
1226
|
+
client: TransferClient;
|
|
1227
|
+
/** Route to execute. */
|
|
1228
|
+
route: MftRoute;
|
|
1229
|
+
/** Optional transfer engine override. A fresh engine is created when omitted. */
|
|
1230
|
+
engine?: TransferEngine;
|
|
1231
|
+
/** Optional explicit job id. Defaults to a deterministic route-derived id. */
|
|
1232
|
+
jobId?: string;
|
|
1233
|
+
/** Optional clock used to derive the default job id. Defaults to `Date.now`. */
|
|
1234
|
+
now?: () => Date;
|
|
1235
|
+
/** Abort signal used to cancel the route execution. */
|
|
1236
|
+
signal?: AbortSignal;
|
|
1237
|
+
/** Retry policy forwarded to the engine. */
|
|
1238
|
+
retry?: TransferRetryPolicy;
|
|
1239
|
+
/** Progress observer forwarded to the engine. */
|
|
1240
|
+
onProgress?: (event: TransferProgressEvent) => void;
|
|
1241
|
+
/** Timeout policy forwarded to the engine. */
|
|
1242
|
+
timeout?: TransferTimeoutPolicy;
|
|
1243
|
+
/** Optional bandwidth limit forwarded to the engine. */
|
|
1244
|
+
bandwidthLimit?: TransferBandwidthLimit;
|
|
1245
|
+
/** Caller-defined metadata merged into the resulting transfer job. */
|
|
1246
|
+
metadata?: Record<string, unknown>;
|
|
1247
|
+
}
|
|
1248
|
+
/**
|
|
1249
|
+
* Executes an MFT route as a single transfer through the supplied client.
|
|
1250
|
+
*
|
|
1251
|
+
* @param options - Client, route, and optional engine/abort/retry hooks.
|
|
1252
|
+
* @returns Receipt produced by the underlying transfer engine.
|
|
1253
|
+
* @throws {@link ConfigurationError} When the route is disabled.
|
|
1254
|
+
*/
|
|
1255
|
+
declare function runRoute(options: RunRouteOptions): Promise<TransferReceipt>;
|
|
1256
|
+
|
|
1257
|
+
/** Endpoint shape accepted by the friendly helpers. */
|
|
1258
|
+
interface RemoteFileEndpoint {
|
|
1259
|
+
/** Provider profile used to open the session. */
|
|
1260
|
+
profile: ConnectionProfile;
|
|
1261
|
+
/** Provider, remote, or local path the helper operates on. */
|
|
1262
|
+
path: string;
|
|
1263
|
+
}
|
|
1264
|
+
/** Shared options consumed by {@link uploadFile}, {@link downloadFile}, and {@link copyBetween}. */
|
|
1265
|
+
type FriendlyTransferOptions = Omit<RunRouteOptions, "client" | "route"> & {
|
|
1266
|
+
/** Stable route id assigned to the synthetic route. Defaults to `"upload:..."`, `"download:..."`, or `"copy:..."`. */
|
|
1267
|
+
routeId?: string;
|
|
1268
|
+
/** Optional human-readable route name forwarded to telemetry. */
|
|
1269
|
+
routeName?: string;
|
|
1270
|
+
};
|
|
1271
|
+
/** Options for {@link uploadFile}. */
|
|
1272
|
+
interface UploadFileOptions extends FriendlyTransferOptions {
|
|
1273
|
+
/** Transfer client used to resolve both endpoint providers. */
|
|
1274
|
+
client: TransferClient;
|
|
1275
|
+
/** Local source path. Relative paths are resolved against `process.cwd()`. */
|
|
1276
|
+
localPath: string;
|
|
1277
|
+
/** Remote destination endpoint. */
|
|
1278
|
+
destination: RemoteFileEndpoint;
|
|
1279
|
+
}
|
|
1280
|
+
/**
|
|
1281
|
+
* Uploads a single local file to a remote endpoint.
|
|
1282
|
+
*
|
|
1283
|
+
* @param options - Friendly upload options.
|
|
1284
|
+
* @returns Receipt produced by the underlying transfer engine.
|
|
1285
|
+
*/
|
|
1286
|
+
declare function uploadFile(options: UploadFileOptions): Promise<TransferReceipt>;
|
|
1287
|
+
/** Options for {@link downloadFile}. */
|
|
1288
|
+
interface DownloadFileOptions extends FriendlyTransferOptions {
|
|
1289
|
+
/** Transfer client used to resolve both endpoint providers. */
|
|
1290
|
+
client: TransferClient;
|
|
1291
|
+
/** Remote source endpoint. */
|
|
1292
|
+
source: RemoteFileEndpoint;
|
|
1293
|
+
/** Local destination path. Relative paths are resolved against `process.cwd()`. */
|
|
1294
|
+
localPath: string;
|
|
1295
|
+
}
|
|
1296
|
+
/**
|
|
1297
|
+
* Downloads a single remote file to a local path.
|
|
1298
|
+
*
|
|
1299
|
+
* @param options - Friendly download options.
|
|
1300
|
+
* @returns Receipt produced by the underlying transfer engine.
|
|
1301
|
+
*/
|
|
1302
|
+
declare function downloadFile(options: DownloadFileOptions): Promise<TransferReceipt>;
|
|
1303
|
+
/** Options for {@link copyBetween}. */
|
|
1304
|
+
interface CopyBetweenOptions extends FriendlyTransferOptions {
|
|
1305
|
+
/** Transfer client used to resolve both endpoint providers. */
|
|
1306
|
+
client: TransferClient;
|
|
1307
|
+
/** Source remote endpoint. */
|
|
1308
|
+
source: RemoteFileEndpoint;
|
|
1309
|
+
/** Destination remote endpoint. */
|
|
1310
|
+
destination: RemoteFileEndpoint;
|
|
1311
|
+
}
|
|
1312
|
+
/**
|
|
1313
|
+
* Copies a file between two remote endpoints in a single call.
|
|
1314
|
+
*
|
|
1315
|
+
* @param options - Friendly copy options.
|
|
1316
|
+
* @returns Receipt produced by the underlying transfer engine.
|
|
1317
|
+
*/
|
|
1318
|
+
declare function copyBetween(options: CopyBetweenOptions): Promise<TransferReceipt>;
|
|
1319
|
+
|
|
1320
|
+
/**
|
|
1321
|
+
* Diagnostics helpers for inspecting a {@link TransferClient} and probing connection profiles.
|
|
1322
|
+
*
|
|
1323
|
+
* These helpers are intentionally side-effect-light: they exercise an existing client without
|
|
1324
|
+
* mutating registry state and never log secret material. Use them to render setup screens,
|
|
1325
|
+
* collect bug-report payloads, or verify a profile after an importer run.
|
|
1326
|
+
*
|
|
1327
|
+
* @module diagnostics
|
|
1328
|
+
*/
|
|
1329
|
+
|
|
1330
|
+
/** Snapshot of the providers registered with a client. */
|
|
1331
|
+
interface ClientDiagnostics {
|
|
1332
|
+
/** Providers currently registered, keyed by id. */
|
|
1333
|
+
providers: ReadonlyArray<{
|
|
1334
|
+
id: ProviderId;
|
|
1335
|
+
capabilities: CapabilitySet;
|
|
1336
|
+
}>;
|
|
1337
|
+
}
|
|
1338
|
+
/**
|
|
1339
|
+
* Returns a redaction-safe snapshot of the providers registered with a client.
|
|
1340
|
+
*
|
|
1341
|
+
* @param client - Transfer client to inspect.
|
|
1342
|
+
* @returns Provider id and capability snapshot tuples.
|
|
1343
|
+
*/
|
|
1344
|
+
declare function summarizeClientDiagnostics(client: TransferClient): ClientDiagnostics;
|
|
1345
|
+
/** Per-step duration measurements collected by {@link runConnectionDiagnostics}. */
|
|
1346
|
+
interface ConnectionDiagnosticTimings {
|
|
1347
|
+
/** Total time spent inside `client.connect`. */
|
|
1348
|
+
connectMs?: number;
|
|
1349
|
+
/** Time spent inside the optional `fs.list` probe. */
|
|
1350
|
+
listMs?: number;
|
|
1351
|
+
/** Time spent inside the optional `session.disconnect`. */
|
|
1352
|
+
disconnectMs?: number;
|
|
1353
|
+
}
|
|
1354
|
+
/** Result returned by {@link runConnectionDiagnostics}. */
|
|
1355
|
+
interface ConnectionDiagnosticsResult {
|
|
1356
|
+
/** Resolved provider id used to open the session. */
|
|
1357
|
+
provider?: ProviderId;
|
|
1358
|
+
/** Profile host (after redaction). */
|
|
1359
|
+
host: string;
|
|
1360
|
+
/** Capability snapshot reported by the connected session. */
|
|
1361
|
+
capabilities?: CapabilitySet;
|
|
1362
|
+
/** Redacted connection profile mirroring {@link redactConnectionProfile}. */
|
|
1363
|
+
redactedProfile: Record<string, unknown>;
|
|
1364
|
+
/** Per-step duration measurements. */
|
|
1365
|
+
timings: ConnectionDiagnosticTimings;
|
|
1366
|
+
/** Sample of entries returned by the optional `fs.list` probe. */
|
|
1367
|
+
sample?: readonly RemoteEntry[];
|
|
1368
|
+
/** Whether all probes ran without throwing. */
|
|
1369
|
+
ok: boolean;
|
|
1370
|
+
/** Captured error summary when the diagnostics could not complete. */
|
|
1371
|
+
error?: {
|
|
1372
|
+
message: string;
|
|
1373
|
+
name?: string;
|
|
1374
|
+
code?: string;
|
|
1375
|
+
};
|
|
1376
|
+
}
|
|
1377
|
+
/** Options accepted by {@link runConnectionDiagnostics}. */
|
|
1378
|
+
interface RunConnectionDiagnosticsOptions {
|
|
1379
|
+
/** Transfer client used to open the session. */
|
|
1380
|
+
client: TransferClient;
|
|
1381
|
+
/** Connection profile to probe. */
|
|
1382
|
+
profile: ConnectionProfile;
|
|
1383
|
+
/** Path passed to the optional `fs.list` probe. Defaults to `"/"`. */
|
|
1384
|
+
listPath?: string;
|
|
1385
|
+
/** When `false`, skips the `fs.list` probe. Defaults to `true`. */
|
|
1386
|
+
probeList?: boolean;
|
|
1387
|
+
/** Maximum number of entries retained in the result sample. Defaults to `5`. */
|
|
1388
|
+
sampleSize?: number;
|
|
1389
|
+
/** Optional clock injected for deterministic test timings. Defaults to `performance.now`. */
|
|
1390
|
+
now?: () => number;
|
|
1391
|
+
}
|
|
1392
|
+
/**
|
|
1393
|
+
* Connects to a profile, captures capability and listing samples, and returns a redaction-safe report.
|
|
1394
|
+
*
|
|
1395
|
+
* @param options - Diagnostic probe options.
|
|
1396
|
+
* @returns Diagnostic report including timings and any captured error.
|
|
1397
|
+
*/
|
|
1398
|
+
declare function runConnectionDiagnostics(options: RunConnectionDiagnosticsOptions): Promise<ConnectionDiagnosticsResult>;
|
|
1399
|
+
|
|
1400
|
+
/**
|
|
1401
|
+
* Built-in provider capability matrix.
|
|
1402
|
+
*
|
|
1403
|
+
* Aggregates the {@link CapabilitySet} advertised by every shipped provider
|
|
1404
|
+
* factory so applications, docs, and diagnostics can compare features across
|
|
1405
|
+
* providers without instantiating each one. The S3 entry is captured twice —
|
|
1406
|
+
* once with multipart upload disabled (default) and once with multipart
|
|
1407
|
+
* upload enabled — because that flag flips `resumeUpload`.
|
|
1408
|
+
*
|
|
1409
|
+
* @module providers/capabilityMatrix
|
|
1410
|
+
*/
|
|
1411
|
+
|
|
1412
|
+
/** Identifier for an entry in {@link getBuiltinCapabilityMatrix}. */
|
|
1413
|
+
type BuiltinProviderMatrixId = ProviderId | "s3:multipart";
|
|
1414
|
+
/** Single entry in the built-in capability matrix. */
|
|
1415
|
+
interface BuiltinCapabilityMatrixEntry {
|
|
1416
|
+
/** Stable matrix identifier (provider id, or `s3:multipart` for the multipart variant). */
|
|
1417
|
+
id: BuiltinProviderMatrixId;
|
|
1418
|
+
/** Human-readable label, suitable for documentation tables. */
|
|
1419
|
+
label: string;
|
|
1420
|
+
/** Capability snapshot advertised by the provider factory. */
|
|
1421
|
+
capabilities: CapabilitySet;
|
|
1422
|
+
}
|
|
1423
|
+
/**
|
|
1424
|
+
* Returns the capability matrix for every shipped provider factory.
|
|
1425
|
+
*
|
|
1426
|
+
* Each call constructs a fresh factory snapshot, so the result reflects the
|
|
1427
|
+
* current build (including any future new metadata or notes). Web providers
|
|
1428
|
+
* are constructed with a no-op fetch since capability advertisement does not
|
|
1429
|
+
* require a live transport.
|
|
1430
|
+
*/
|
|
1431
|
+
declare function getBuiltinCapabilityMatrix(): BuiltinCapabilityMatrixEntry[];
|
|
1432
|
+
/**
|
|
1433
|
+
* Renders the matrix returned by {@link getBuiltinCapabilityMatrix} as a
|
|
1434
|
+
* GitHub-flavored Markdown table covering the most commonly-compared
|
|
1435
|
+
* capability flags.
|
|
1436
|
+
*/
|
|
1437
|
+
declare function formatCapabilityMatrixMarkdown(matrix?: ReadonlyArray<BuiltinCapabilityMatrixEntry>): string;
|
|
1438
|
+
|
|
1439
|
+
/** Options used to create a local file-system provider factory. */
|
|
1440
|
+
interface LocalProviderOptions {
|
|
1441
|
+
/** Root directory exposed as `/`. When omitted, `profile.host` is treated as the root path. */
|
|
1442
|
+
rootPath?: string;
|
|
1443
|
+
}
|
|
1444
|
+
/**
|
|
1445
|
+
* Creates a provider factory backed by the local filesystem.
|
|
1446
|
+
*
|
|
1447
|
+
* @param options - Optional local root path exposed through provider sessions.
|
|
1448
|
+
* @returns Provider factory suitable for `createTransferClient({ providers: [...] })`.
|
|
1449
|
+
*/
|
|
1450
|
+
declare function createLocalProviderFactory(options?: LocalProviderOptions): ProviderFactory;
|
|
1451
|
+
|
|
1452
|
+
/** Fetch implementation accepted by web-family providers. */
|
|
1453
|
+
type HttpFetch = (input: string, init?: RequestInit) => Promise<Response>;
|
|
1454
|
+
|
|
1455
|
+
/** Options accepted by {@link createDropboxProviderFactory}. */
|
|
1456
|
+
interface DropboxProviderOptions {
|
|
1457
|
+
/** Provider id to register. Defaults to `"dropbox"`. */
|
|
1458
|
+
id?: ProviderId;
|
|
1459
|
+
/** Override the RPC base URL. Defaults to `https://api.dropboxapi.com`. */
|
|
1460
|
+
apiBaseUrl?: string;
|
|
1461
|
+
/** Override the content base URL. Defaults to `https://content.dropboxapi.com`. */
|
|
1462
|
+
contentBaseUrl?: string;
|
|
1463
|
+
/** Custom fetch implementation. Defaults to global `fetch`. */
|
|
1464
|
+
fetch?: HttpFetch;
|
|
1465
|
+
/** Default headers applied to every request before bearer auth. */
|
|
1466
|
+
defaultHeaders?: Record<string, string>;
|
|
1467
|
+
}
|
|
1468
|
+
/**
|
|
1469
|
+
* Creates a Dropbox provider factory.
|
|
1470
|
+
*
|
|
1471
|
+
* The bearer token is resolved per-connection from `profile.password`. The
|
|
1472
|
+
* `profile.host` field is unused; Dropbox connections are identified solely by
|
|
1473
|
+
* their token.
|
|
1474
|
+
*/
|
|
1475
|
+
declare function createDropboxProviderFactory(options?: DropboxProviderOptions): ProviderFactory;
|
|
1476
|
+
|
|
1477
|
+
/** Options accepted by {@link createGoogleDriveProviderFactory}. */
|
|
1478
|
+
interface GoogleDriveProviderOptions {
|
|
1479
|
+
/** Provider id to register. Defaults to `"google-drive"`. */
|
|
1480
|
+
id?: ProviderId;
|
|
1481
|
+
/** Override the API base URL. Defaults to `https://www.googleapis.com/drive/v3`. */
|
|
1482
|
+
apiBaseUrl?: string;
|
|
1483
|
+
/** Override the upload base URL. Defaults to `https://www.googleapis.com/upload/drive/v3`. */
|
|
1484
|
+
uploadBaseUrl?: string;
|
|
1485
|
+
/**
|
|
1486
|
+
* Folder id used as the root for path resolution. Defaults to `"root"` (the
|
|
1487
|
+
* authenticated user's My Drive root). Pass a folder id when the SDK should
|
|
1488
|
+
* scope to a shared drive subtree.
|
|
1489
|
+
*/
|
|
1490
|
+
rootFolderId?: string;
|
|
1491
|
+
/** Custom fetch implementation. Defaults to global `fetch`. */
|
|
1492
|
+
fetch?: HttpFetch;
|
|
1493
|
+
/** Default headers applied to every request before bearer auth. */
|
|
1494
|
+
defaultHeaders?: Record<string, string>;
|
|
1495
|
+
}
|
|
1496
|
+
/**
|
|
1497
|
+
* Creates a Google Drive provider factory.
|
|
1498
|
+
*
|
|
1499
|
+
* The bearer token is resolved per-connection from `profile.password`
|
|
1500
|
+
* (typically an OAuth 2 access token). `profile.host` is unused.
|
|
1501
|
+
*/
|
|
1502
|
+
declare function createGoogleDriveProviderFactory(options?: GoogleDriveProviderOptions): ProviderFactory;
|
|
1503
|
+
|
|
1504
|
+
/** Options accepted by {@link createOneDriveProviderFactory}. */
|
|
1505
|
+
interface OneDriveProviderOptions {
|
|
1506
|
+
/** Provider id to register. Defaults to `"one-drive"`. */
|
|
1507
|
+
id?: ProviderId;
|
|
1508
|
+
/**
|
|
1509
|
+
* Drive root URL used as the prefix for every Graph call. Defaults to
|
|
1510
|
+
* `https://graph.microsoft.com/v1.0/me/drive`. Override with a SharePoint
|
|
1511
|
+
* drive URL like `https://graph.microsoft.com/v1.0/drives/{driveId}`.
|
|
1512
|
+
*/
|
|
1513
|
+
driveBaseUrl?: string;
|
|
1514
|
+
/** Custom fetch implementation. Defaults to global `fetch`. */
|
|
1515
|
+
fetch?: HttpFetch;
|
|
1516
|
+
/** Default headers applied before bearer auth on every request. */
|
|
1517
|
+
defaultHeaders?: Record<string, string>;
|
|
1518
|
+
}
|
|
1519
|
+
/**
|
|
1520
|
+
* Creates a OneDrive/SharePoint provider factory backed by Microsoft Graph.
|
|
1521
|
+
*
|
|
1522
|
+
* The bearer token is resolved per-connection from `profile.password`.
|
|
1523
|
+
* `profile.host` is unused.
|
|
1524
|
+
*/
|
|
1525
|
+
declare function createOneDriveProviderFactory(options?: OneDriveProviderOptions): ProviderFactory;
|
|
1526
|
+
|
|
1527
|
+
/** Options accepted by {@link createAzureBlobProviderFactory}. */
|
|
1528
|
+
interface AzureBlobProviderOptions {
|
|
1529
|
+
/** Provider id to register. Defaults to `"azure-blob"`. */
|
|
1530
|
+
id?: ProviderId;
|
|
1531
|
+
/** Storage account name; combined with `endpoint` when no full URL is supplied. */
|
|
1532
|
+
account?: string;
|
|
1533
|
+
/** Container name. Required. */
|
|
1534
|
+
container: string;
|
|
1535
|
+
/**
|
|
1536
|
+
* Override the endpoint host. Defaults to
|
|
1537
|
+
* `https://{account}.blob.core.windows.net`. Provide for sovereign clouds
|
|
1538
|
+
* or Azurite (`http://127.0.0.1:10000/devstoreaccount1`).
|
|
1539
|
+
*/
|
|
1540
|
+
endpoint?: string;
|
|
1541
|
+
/** SAS token query string (without leading `?`). Mutually compatible with bearer auth. */
|
|
1542
|
+
sasToken?: string;
|
|
1543
|
+
/** Override the `x-ms-version` header. */
|
|
1544
|
+
apiVersion?: string;
|
|
1545
|
+
/** Custom fetch implementation. Defaults to global `fetch`. */
|
|
1546
|
+
fetch?: HttpFetch;
|
|
1547
|
+
/** Default headers applied before bearer auth on every request. */
|
|
1548
|
+
defaultHeaders?: Record<string, string>;
|
|
1549
|
+
}
|
|
1550
|
+
/** Creates an Azure Blob Storage provider factory. */
|
|
1551
|
+
declare function createAzureBlobProviderFactory(options: AzureBlobProviderOptions): ProviderFactory;
|
|
1552
|
+
|
|
1553
|
+
/** Options accepted by {@link createGcsProviderFactory}. */
|
|
1554
|
+
interface GcsProviderOptions {
|
|
1555
|
+
/** Provider id to register. Defaults to `"gcs"`. */
|
|
1556
|
+
id?: ProviderId;
|
|
1557
|
+
/** Bucket name. Required. */
|
|
1558
|
+
bucket: string;
|
|
1559
|
+
/** Override the JSON API base URL. */
|
|
1560
|
+
apiBaseUrl?: string;
|
|
1561
|
+
/** Override the upload API base URL. */
|
|
1562
|
+
uploadBaseUrl?: string;
|
|
1563
|
+
/** Custom fetch implementation. Defaults to global `fetch`. */
|
|
1564
|
+
fetch?: HttpFetch;
|
|
1565
|
+
/** Default headers applied before bearer auth on every request. */
|
|
1566
|
+
defaultHeaders?: Record<string, string>;
|
|
1567
|
+
}
|
|
1568
|
+
/** Creates a Google Cloud Storage provider factory. */
|
|
1569
|
+
declare function createGcsProviderFactory(options: GcsProviderOptions): ProviderFactory;
|
|
1570
|
+
|
|
1571
|
+
/** Fixture entry used to seed a memory provider instance. */
|
|
1572
|
+
interface MemoryProviderEntry extends Omit<RemoteEntry, "name"> {
|
|
1573
|
+
/** Entry basename. When omitted, it is derived from `path`. */
|
|
1574
|
+
name?: string;
|
|
1575
|
+
/** Optional byte content for file entries. Strings are encoded as UTF-8. */
|
|
1576
|
+
content?: string | Uint8Array;
|
|
1577
|
+
}
|
|
1578
|
+
/** Options used to create a deterministic memory provider factory. */
|
|
1579
|
+
interface MemoryProviderOptions {
|
|
1580
|
+
/** Entries available to sessions created by this provider factory. */
|
|
1581
|
+
entries?: Iterable<MemoryProviderEntry>;
|
|
1582
|
+
}
|
|
1583
|
+
/**
|
|
1584
|
+
* Creates a provider factory backed by deterministic in-memory fixture entries.
|
|
1585
|
+
*
|
|
1586
|
+
* @param options - Optional fixture entries to expose through the memory provider.
|
|
1587
|
+
* @returns Provider factory suitable for `createTransferClient({ providers: [...] })`.
|
|
1588
|
+
*/
|
|
1589
|
+
declare function createMemoryProviderFactory(options?: MemoryProviderOptions): ProviderFactory;
|
|
1590
|
+
|
|
1591
|
+
/** Options accepted by {@link createHttpProviderFactory}. */
|
|
1592
|
+
interface HttpProviderOptions {
|
|
1593
|
+
/** Provider id to register. Defaults to `"http"`. Set to `"https"` for the HTTPS variant. */
|
|
1594
|
+
id?: ProviderId;
|
|
1595
|
+
/** Whether the provider should treat connections as TLS-only. Defaults to `true` when `id === "https"`. */
|
|
1596
|
+
secure?: boolean;
|
|
1597
|
+
/** Base URL prefix prepended to relative endpoint paths. Defaults to `""`. */
|
|
1598
|
+
basePath?: string;
|
|
1599
|
+
/** Custom fetch implementation. Defaults to global `fetch`. */
|
|
1600
|
+
fetch?: HttpFetch;
|
|
1601
|
+
/** Default headers applied to every request. */
|
|
1602
|
+
defaultHeaders?: Record<string, string>;
|
|
1603
|
+
}
|
|
1604
|
+
/**
|
|
1605
|
+
* Creates a provider factory backed by HTTP(S) GET/HEAD.
|
|
1606
|
+
*
|
|
1607
|
+
* @param options - Optional provider configuration.
|
|
1608
|
+
* @returns Provider factory suitable for `createTransferClient({ providers: [...] })`.
|
|
1609
|
+
*/
|
|
1610
|
+
declare function createHttpProviderFactory(options?: HttpProviderOptions): ProviderFactory;
|
|
1611
|
+
|
|
1612
|
+
/** Options accepted by {@link createWebDavProviderFactory}. */
|
|
1613
|
+
interface WebDavProviderOptions {
|
|
1614
|
+
/** Provider id to register. Defaults to `"webdav"`. */
|
|
1615
|
+
id?: ProviderId;
|
|
1616
|
+
/** Whether the transport is TLS. Defaults to `false`; set `true` or use https `port`. */
|
|
1617
|
+
secure?: boolean;
|
|
1618
|
+
/** Path prefix prepended to remote paths. Defaults to `""`. */
|
|
1619
|
+
basePath?: string;
|
|
1620
|
+
/** Custom fetch implementation. Defaults to global `fetch`. */
|
|
1621
|
+
fetch?: HttpFetch;
|
|
1622
|
+
/** Default headers applied to every request. */
|
|
1623
|
+
defaultHeaders?: Record<string, string>;
|
|
1624
|
+
}
|
|
1625
|
+
/**
|
|
1626
|
+
* Creates a WebDAV provider factory.
|
|
1627
|
+
*
|
|
1628
|
+
* @param options - Optional provider configuration.
|
|
1629
|
+
* @returns Provider factory suitable for `createTransferClient({ providers: [...] })`.
|
|
1630
|
+
*/
|
|
1631
|
+
declare function createWebDavProviderFactory(options?: WebDavProviderOptions): ProviderFactory;
|
|
1632
|
+
|
|
1633
|
+
/** Options accepted by {@link createS3ProviderFactory}. */
|
|
1634
|
+
interface S3ProviderOptions {
|
|
1635
|
+
/** Provider id to register. Defaults to `"s3"`. */
|
|
1636
|
+
id?: ProviderId;
|
|
1637
|
+
/** Required bucket name; can be overridden per connection via `profile.host`. */
|
|
1638
|
+
bucket?: string;
|
|
1639
|
+
/** AWS region. Defaults to `"us-east-1"`. */
|
|
1640
|
+
region?: string;
|
|
1641
|
+
/** Service identifier for SigV4. Defaults to `"s3"`. */
|
|
1642
|
+
service?: string;
|
|
1643
|
+
/** Custom endpoint base URL (e.g. MinIO, R2). Defaults to `https://s3.<region>.amazonaws.com`. */
|
|
1644
|
+
endpoint?: string;
|
|
1645
|
+
/** Whether to use path-style URLs (`endpoint/bucket/key`). Defaults to `true`. */
|
|
1646
|
+
pathStyle?: boolean;
|
|
1647
|
+
/** Custom fetch implementation. Defaults to global `fetch`. */
|
|
1648
|
+
fetch?: HttpFetch;
|
|
1649
|
+
/** Default headers applied to every request before signing. */
|
|
1650
|
+
defaultHeaders?: Record<string, string>;
|
|
1651
|
+
/** Optional STS session token applied to every request. */
|
|
1652
|
+
sessionToken?: SecretSource;
|
|
1653
|
+
/** Multipart upload tuning. Disabled by default; enable for objects above ~5 GiB or when streaming. */
|
|
1654
|
+
multipart?: S3MultipartOptions;
|
|
1655
|
+
}
|
|
1656
|
+
/** Multipart upload tuning for the S3 provider. */
|
|
1657
|
+
interface S3MultipartOptions {
|
|
1658
|
+
/** Enable multipart upload. Defaults to `false`. */
|
|
1659
|
+
enabled?: boolean;
|
|
1660
|
+
/** Object size threshold in bytes above which multipart is used. Defaults to 8 MiB. */
|
|
1661
|
+
thresholdBytes?: number;
|
|
1662
|
+
/** Target part size in bytes. Must be ≥ 5 MiB except for the final part. Defaults to 8 MiB. */
|
|
1663
|
+
partSizeBytes?: number;
|
|
1664
|
+
/**
|
|
1665
|
+
* Optional persistent store enabling cross-process resume of incomplete
|
|
1666
|
+
* multipart uploads. When provided, in-flight `uploadId` plus uploaded part
|
|
1667
|
+
* etags are checkpointed after every part; on retry the upload reuses the
|
|
1668
|
+
* stored state and skips the bytes already transferred.
|
|
1669
|
+
*/
|
|
1670
|
+
resumeStore?: S3MultipartResumeStore;
|
|
1671
|
+
}
|
|
1672
|
+
/** Resume key identifying an in-flight multipart upload. */
|
|
1673
|
+
interface S3MultipartResumeKey {
|
|
1674
|
+
bucket: string;
|
|
1675
|
+
jobId: string;
|
|
1676
|
+
path: string;
|
|
1677
|
+
}
|
|
1678
|
+
/** Persisted multipart-upload checkpoint. */
|
|
1679
|
+
interface S3MultipartCheckpoint {
|
|
1680
|
+
uploadId: string;
|
|
1681
|
+
/** Parts already accepted by S3, in upload order. */
|
|
1682
|
+
parts: ReadonlyArray<S3MultipartPart>;
|
|
1683
|
+
}
|
|
1684
|
+
/** Single part recorded in a multipart-upload checkpoint. */
|
|
1685
|
+
interface S3MultipartPart {
|
|
1686
|
+
partNumber: number;
|
|
1687
|
+
etag: string;
|
|
1688
|
+
/** Cumulative byte offset reached after this part (exclusive). */
|
|
1689
|
+
byteEnd: number;
|
|
1690
|
+
}
|
|
1691
|
+
/**
|
|
1692
|
+
* Persistence contract for resuming partial multipart uploads across
|
|
1693
|
+
* processes or retries. Implementations may be synchronous or asynchronous;
|
|
1694
|
+
* `clear` is invoked once the multipart upload completes successfully (or is
|
|
1695
|
+
* explicitly aborted via {@link abortS3MultipartUpload}).
|
|
1696
|
+
*/
|
|
1697
|
+
interface S3MultipartResumeStore {
|
|
1698
|
+
load(key: S3MultipartResumeKey): Promise<S3MultipartCheckpoint | undefined> | S3MultipartCheckpoint | undefined;
|
|
1699
|
+
save(key: S3MultipartResumeKey, checkpoint: S3MultipartCheckpoint): Promise<void> | void;
|
|
1700
|
+
clear(key: S3MultipartResumeKey): Promise<void> | void;
|
|
1701
|
+
}
|
|
1702
|
+
/** Creates an in-memory {@link S3MultipartResumeStore}. */
|
|
1703
|
+
declare function createMemoryS3MultipartResumeStore(): S3MultipartResumeStore;
|
|
1704
|
+
/**
|
|
1705
|
+
* Creates an S3-compatible provider factory.
|
|
1706
|
+
*
|
|
1707
|
+
* Credentials must be supplied via the connection profile: `username` is the
|
|
1708
|
+
* access key id and `password` is the secret access key. `profile.host` may
|
|
1709
|
+
* be set to the bucket name (taking precedence over `options.bucket`).
|
|
1710
|
+
*/
|
|
1711
|
+
declare function createS3ProviderFactory(options?: S3ProviderOptions): ProviderFactory;
|
|
1712
|
+
|
|
1713
|
+
/**
|
|
1714
|
+
* Connection profile redaction helpers.
|
|
1715
|
+
*
|
|
1716
|
+
* @module profiles/ProfileRedactor
|
|
1717
|
+
*/
|
|
1718
|
+
|
|
1719
|
+
/**
|
|
1720
|
+
* Produces a diagnostics-safe profile copy with credentials and runtime hooks redacted.
|
|
1721
|
+
*
|
|
1722
|
+
* @param profile - Connection profile to sanitize.
|
|
1723
|
+
* @returns Plain object safe to include in logs, traces, or validation reports.
|
|
1724
|
+
*/
|
|
1725
|
+
declare function redactConnectionProfile(profile: ConnectionProfile): Record<string, unknown>;
|
|
1726
|
+
|
|
1727
|
+
/**
|
|
1728
|
+
* Validates provider-neutral connection profile fields before provider lookup.
|
|
1729
|
+
*
|
|
1730
|
+
* @param profile - Profile to validate.
|
|
1731
|
+
* @returns The original profile when valid.
|
|
1732
|
+
* @throws {@link ConfigurationError} When required provider, host, or numeric fields are invalid.
|
|
1733
|
+
*/
|
|
1734
|
+
declare function validateConnectionProfile(profile: ConnectionProfile): ConnectionProfile;
|
|
1735
|
+
|
|
1736
|
+
/**
|
|
1737
|
+
* Connection profile secret resolution helpers.
|
|
1738
|
+
*
|
|
1739
|
+
* @module profiles/resolveConnectionProfileSecrets
|
|
1740
|
+
*/
|
|
1741
|
+
|
|
1742
|
+
/** SSH profile with private-key and known-host material resolved. */
|
|
1743
|
+
interface ResolvedSshProfile extends Omit<SshProfile, "knownHosts" | "passphrase" | "privateKey"> {
|
|
1744
|
+
/** Resolved private key material. */
|
|
1745
|
+
privateKey?: SecretValue;
|
|
1746
|
+
/** Resolved private-key passphrase. */
|
|
1747
|
+
passphrase?: SecretValue;
|
|
1748
|
+
/** Resolved OpenSSH known_hosts material. */
|
|
1749
|
+
knownHosts?: SecretValue | SecretValue[];
|
|
1750
|
+
}
|
|
1751
|
+
/** TLS profile with certificate-bearing secret sources resolved. */
|
|
1752
|
+
interface ResolvedTlsProfile extends Omit<TlsProfile, "ca" | "cert" | "key" | "passphrase" | "pfx"> {
|
|
1753
|
+
/** Resolved certificate authority bundle. */
|
|
1754
|
+
ca?: SecretValue | SecretValue[];
|
|
1755
|
+
/** Resolved client certificate PEM. */
|
|
1756
|
+
cert?: SecretValue;
|
|
1757
|
+
/** Resolved client private key PEM. */
|
|
1758
|
+
key?: SecretValue;
|
|
1759
|
+
/** Resolved encrypted private-key or PFX/P12 passphrase. */
|
|
1760
|
+
passphrase?: SecretValue;
|
|
1761
|
+
/** Resolved PFX/P12 client certificate bundle. */
|
|
1762
|
+
pfx?: SecretValue;
|
|
1763
|
+
}
|
|
1764
|
+
/** Connection profile with username, password, TLS, and SSH material sources resolved. */
|
|
1765
|
+
interface ResolvedConnectionProfile extends Omit<ConnectionProfile, "password" | "ssh" | "tls" | "username"> {
|
|
1766
|
+
/** Resolved username or account identifier. */
|
|
1767
|
+
username?: SecretValue;
|
|
1768
|
+
/** Resolved password or credential bytes. */
|
|
1769
|
+
password?: SecretValue;
|
|
1770
|
+
/** Resolved TLS profile when certificate material is configured. */
|
|
1771
|
+
tls?: ResolvedTlsProfile;
|
|
1772
|
+
/** Resolved SSH profile when private-key material is configured. */
|
|
1773
|
+
ssh?: ResolvedSshProfile;
|
|
1774
|
+
}
|
|
1775
|
+
/**
|
|
1776
|
+
* Resolves credential and TLS material secret sources without mutating the original profile.
|
|
1777
|
+
*
|
|
1778
|
+
* @param profile - Profile containing optional secret sources.
|
|
1779
|
+
* @param options - Optional env and file-reader overrides.
|
|
1780
|
+
* @returns Profile copy with username, password, TLS material, and SSH material resolved when present.
|
|
1781
|
+
*/
|
|
1782
|
+
declare function resolveConnectionProfileSecrets(profile: ConnectionProfile, options?: ResolveSecretOptions): Promise<ResolvedConnectionProfile>;
|
|
1783
|
+
|
|
1784
|
+
/** Token material returned by {@link OAuthRefreshCallback}. */
|
|
1785
|
+
interface OAuthAccessToken {
|
|
1786
|
+
/** Access token value. Required. */
|
|
1787
|
+
accessToken: string;
|
|
1788
|
+
/**
|
|
1789
|
+
* Lifetime in seconds (`expires_in`-style). When provided, the helper caches
|
|
1790
|
+
* the token until `now + (expiresInSeconds - skewSeconds)`.
|
|
1791
|
+
*/
|
|
1792
|
+
expiresInSeconds?: number;
|
|
1793
|
+
/** Absolute expiry. Wins over `expiresInSeconds` when both are provided. */
|
|
1794
|
+
expiresAt?: Date;
|
|
1795
|
+
}
|
|
1796
|
+
/** Refresh callback invoked when no valid cached token is available. */
|
|
1797
|
+
type OAuthRefreshCallback = () => OAuthAccessToken | Promise<OAuthAccessToken>;
|
|
1798
|
+
/** Options accepted by {@link createOAuthTokenSecretSource}. */
|
|
1799
|
+
interface OAuthTokenSecretSourceOptions {
|
|
1800
|
+
/**
|
|
1801
|
+
* Safety margin (in milliseconds) subtracted from the token's expiry to
|
|
1802
|
+
* trigger a refresh before the wire deadline. Defaults to `60_000` (60s).
|
|
1803
|
+
*/
|
|
1804
|
+
skewMs?: number;
|
|
1805
|
+
/** Clock used to evaluate expiry. Defaults to `Date.now`. */
|
|
1806
|
+
now?: () => number;
|
|
1807
|
+
}
|
|
1808
|
+
/**
|
|
1809
|
+
* Builds a {@link SecretProvider} that exchanges a refresh callback for
|
|
1810
|
+
* cached, auto-renewing access tokens.
|
|
1811
|
+
*
|
|
1812
|
+
* The returned function can be passed directly as `profile.password` for any
|
|
1813
|
+
* provider that accepts bearer tokens (Dropbox, Google Drive, OneDrive, GCS,
|
|
1814
|
+
* Azure Blob via AAD).
|
|
1815
|
+
*
|
|
1816
|
+
* @example
|
|
1817
|
+
* ```ts
|
|
1818
|
+
* const password = createOAuthTokenSecretSource(async () => {
|
|
1819
|
+
* const res = await fetch("https://example.com/oauth/token", { ... });
|
|
1820
|
+
* const body = (await res.json()) as { access_token: string; expires_in: number };
|
|
1821
|
+
* return { accessToken: body.access_token, expiresInSeconds: body.expires_in };
|
|
1822
|
+
* });
|
|
1823
|
+
* const session = await factory.create().connect({ host: "", protocol: "ftp", password });
|
|
1824
|
+
* ```
|
|
1825
|
+
*/
|
|
1826
|
+
declare function createOAuthTokenSecretSource(refresh: OAuthRefreshCallback, options?: OAuthTokenSecretSourceOptions): SecretProvider;
|
|
1827
|
+
|
|
1828
|
+
/** Marker prefixing a known_hosts line (`@cert-authority` or `@revoked`). */
|
|
1829
|
+
type KnownHostsMarker = "cert-authority" | "revoked";
|
|
1830
|
+
/** Parsed entry from an OpenSSH `known_hosts` file. */
|
|
1831
|
+
interface KnownHostsEntry {
|
|
1832
|
+
/** Optional line marker (`@cert-authority` or `@revoked`). */
|
|
1833
|
+
marker?: KnownHostsMarker;
|
|
1834
|
+
/** Raw, comma-separated host patterns. Negation patterns retain their leading `!`. */
|
|
1835
|
+
hostPatterns: readonly string[];
|
|
1836
|
+
/** Hashed-salt component for `|1|salt|hash` entries. Mutually exclusive with plain patterns. */
|
|
1837
|
+
hashedSalt?: string;
|
|
1838
|
+
/** Hashed-hash component for `|1|salt|hash` entries. Mutually exclusive with plain patterns. */
|
|
1839
|
+
hashedHash?: string;
|
|
1840
|
+
/** SSH key algorithm identifier (e.g. `ssh-ed25519`, `ecdsa-sha2-nistp256`). */
|
|
1841
|
+
keyType: string;
|
|
1842
|
+
/** Base64-encoded public key blob. */
|
|
1843
|
+
keyBase64: string;
|
|
1844
|
+
/** Trailing comment text, if any. */
|
|
1845
|
+
comment?: string;
|
|
1846
|
+
/** Original line text without trailing newline. */
|
|
1847
|
+
raw: string;
|
|
1848
|
+
}
|
|
1849
|
+
/**
|
|
1850
|
+
* Parses OpenSSH `known_hosts` content into structured entries. Comment and blank lines are skipped.
|
|
1851
|
+
* Lines that cannot be parsed are silently dropped so callers can tolerate hand-edited files.
|
|
1852
|
+
*
|
|
1853
|
+
* @param text - Raw `known_hosts` file contents.
|
|
1854
|
+
* @returns Parsed entries in source order.
|
|
1855
|
+
*/
|
|
1856
|
+
declare function parseKnownHosts(text: string): KnownHostsEntry[];
|
|
1857
|
+
/**
|
|
1858
|
+
* Returns true when the given host (and optional port) matches the entry's host patterns.
|
|
1859
|
+
* Hashed entries use HMAC-SHA1 verification per OpenSSH semantics.
|
|
1860
|
+
*
|
|
1861
|
+
* @param entry - Parsed `known_hosts` entry to test.
|
|
1862
|
+
* @param host - Hostname or IP literal to match.
|
|
1863
|
+
* @param port - Optional connection port. Defaults to {@link DEFAULT_SSH_PORT}.
|
|
1864
|
+
* @returns Whether the entry matches and is not negated.
|
|
1865
|
+
*/
|
|
1866
|
+
declare function matchKnownHostsEntry(entry: KnownHostsEntry, host: string, port?: number): boolean;
|
|
1867
|
+
/**
|
|
1868
|
+
* Filters parsed entries down to those that match the given host/port. Negations are honored.
|
|
1869
|
+
*
|
|
1870
|
+
* @param entries - Entries returned by {@link parseKnownHosts}.
|
|
1871
|
+
* @param host - Hostname or IP literal to match.
|
|
1872
|
+
* @param port - Optional connection port. Defaults to {@link DEFAULT_SSH_PORT}.
|
|
1873
|
+
* @returns Matching entries in source order.
|
|
1874
|
+
*/
|
|
1875
|
+
declare function matchKnownHosts(entries: readonly KnownHostsEntry[], host: string, port?: number): KnownHostsEntry[];
|
|
1876
|
+
|
|
1877
|
+
/** Parsed `Host` block from an OpenSSH config file. */
|
|
1878
|
+
interface OpenSshConfigEntry {
|
|
1879
|
+
/** Host patterns declared on the `Host` line. */
|
|
1880
|
+
patterns: readonly string[];
|
|
1881
|
+
/** Lower-cased directive name to ordered values. Multi-valued directives (e.g. `IdentityFile`) preserve order. */
|
|
1882
|
+
options: Readonly<Record<string, readonly string[]>>;
|
|
1883
|
+
}
|
|
1884
|
+
/**
|
|
1885
|
+
* Parses OpenSSH `ssh_config` text into structured `Host` blocks.
|
|
1886
|
+
*
|
|
1887
|
+
* The parser is intentionally permissive: unknown directives are retained and `Match` blocks are skipped.
|
|
1888
|
+
*
|
|
1889
|
+
* @param text - Contents of the `ssh_config` file.
|
|
1890
|
+
* @returns Parsed `Host` entries in source order.
|
|
1891
|
+
*/
|
|
1892
|
+
declare function parseOpenSshConfig(text: string): OpenSshConfigEntry[];
|
|
1893
|
+
/**
|
|
1894
|
+
* Resolved set of directives for a given host alias. Values from later-declared blocks are
|
|
1895
|
+
* merged after earlier ones so wildcard fallbacks (e.g. `Host *`) only fill gaps.
|
|
1896
|
+
*/
|
|
1897
|
+
interface ResolvedOpenSshHost {
|
|
1898
|
+
/** Host alias the lookup was performed against. */
|
|
1899
|
+
alias: string;
|
|
1900
|
+
/** Per-directive ordered values, keyed by lower-cased directive name. */
|
|
1901
|
+
options: Readonly<Record<string, readonly string[]>>;
|
|
1902
|
+
/** Source entries that contributed to the resolved set, in match order. */
|
|
1903
|
+
matched: readonly OpenSshConfigEntry[];
|
|
1904
|
+
}
|
|
1905
|
+
/**
|
|
1906
|
+
* Resolves the merged option set for an OpenSSH host alias.
|
|
1907
|
+
*
|
|
1908
|
+
* @param entries - Parsed entries from {@link parseOpenSshConfig}.
|
|
1909
|
+
* @param alias - Host alias to resolve.
|
|
1910
|
+
* @returns Merged directive set with the matching entries.
|
|
1911
|
+
*/
|
|
1912
|
+
declare function resolveOpenSshHost(entries: readonly OpenSshConfigEntry[], alias: string): ResolvedOpenSshHost;
|
|
1913
|
+
/** Options accepted by {@link importOpenSshConfig}. */
|
|
1914
|
+
interface ImportOpenSshConfigOptions {
|
|
1915
|
+
/** Raw `ssh_config` text. Either this or {@link entries} must be provided. */
|
|
1916
|
+
text?: string;
|
|
1917
|
+
/** Pre-parsed entries from {@link parseOpenSshConfig}. */
|
|
1918
|
+
entries?: readonly OpenSshConfigEntry[];
|
|
1919
|
+
/** Host alias to import. */
|
|
1920
|
+
alias: string;
|
|
1921
|
+
}
|
|
1922
|
+
/** Result of {@link importOpenSshConfig}. */
|
|
1923
|
+
interface ImportOpenSshConfigResult {
|
|
1924
|
+
/** Generated SFTP connection profile. */
|
|
1925
|
+
profile: ConnectionProfile;
|
|
1926
|
+
/** Resolved directive set used to build the profile. */
|
|
1927
|
+
resolved: ResolvedOpenSshHost;
|
|
1928
|
+
/** Identity file paths declared in the config, in declaration order. */
|
|
1929
|
+
identityFiles: readonly string[];
|
|
1930
|
+
/** Optional `ProxyJump` value preserved from the config. */
|
|
1931
|
+
proxyJump?: string;
|
|
1932
|
+
}
|
|
1933
|
+
/**
|
|
1934
|
+
* Builds a {@link ConnectionProfile} for the given SSH alias from `ssh_config` text or pre-parsed entries.
|
|
1935
|
+
*
|
|
1936
|
+
* @param options - Import options.
|
|
1937
|
+
* @returns Importer result with the generated profile and supporting metadata.
|
|
1938
|
+
* @throws {@link ConfigurationError} When neither text nor entries is supplied.
|
|
1939
|
+
*/
|
|
1940
|
+
declare function importOpenSshConfig(options: ImportOpenSshConfigOptions): ImportOpenSshConfigResult;
|
|
1941
|
+
|
|
1942
|
+
/** Imported FileZilla site with the folder hierarchy that contained it. */
|
|
1943
|
+
interface FileZillaSite {
|
|
1944
|
+
/** Site display name. */
|
|
1945
|
+
name: string;
|
|
1946
|
+
/** Ordered folder names leading to the site (top-level first). Empty for root sites. */
|
|
1947
|
+
folder: readonly string[];
|
|
1948
|
+
/** Generated connection profile. */
|
|
1949
|
+
profile: ConnectionProfile;
|
|
1950
|
+
/** Encoded password value retained from the file, if any. */
|
|
1951
|
+
password?: string;
|
|
1952
|
+
/** Logon type code preserved from the file (`0`=anonymous, `1`=normal, etc.). */
|
|
1953
|
+
logonType?: number;
|
|
1954
|
+
}
|
|
1955
|
+
/** Result returned by {@link importFileZillaSites}. */
|
|
1956
|
+
interface ImportFileZillaSitesResult {
|
|
1957
|
+
/** Sites successfully mapped to a connection profile. */
|
|
1958
|
+
sites: readonly FileZillaSite[];
|
|
1959
|
+
/** Sites that were skipped because their protocol is not supported. */
|
|
1960
|
+
skipped: readonly {
|
|
1961
|
+
name: string;
|
|
1962
|
+
folder: readonly string[];
|
|
1963
|
+
protocol?: number;
|
|
1964
|
+
}[];
|
|
1965
|
+
}
|
|
1966
|
+
/**
|
|
1967
|
+
* Parses FileZilla `sitemanager.xml` text and returns generated profiles.
|
|
1968
|
+
*
|
|
1969
|
+
* @param xml - Contents of `sitemanager.xml`.
|
|
1970
|
+
* @returns Imported sites and any skipped entries.
|
|
1971
|
+
* @throws {@link ConfigurationError} When the XML root cannot be located.
|
|
1972
|
+
*/
|
|
1973
|
+
declare function importFileZillaSites(xml: string): ImportFileZillaSitesResult;
|
|
1974
|
+
|
|
1975
|
+
/** Imported WinSCP session entry. */
|
|
1976
|
+
interface WinScpSession {
|
|
1977
|
+
/** Decoded session name (URL-decoded path under the `Sessions\\` namespace). */
|
|
1978
|
+
name: string;
|
|
1979
|
+
/** Hierarchical path segments derived from the session name (folders separated by `/`). */
|
|
1980
|
+
folder: readonly string[];
|
|
1981
|
+
/** Generated connection profile. */
|
|
1982
|
+
profile: ConnectionProfile;
|
|
1983
|
+
/** Raw FSProtocol code preserved from the file. */
|
|
1984
|
+
fsProtocol?: number;
|
|
1985
|
+
/** Raw Ftps code preserved from the file (`0`=none, `1`=implicit, `2`/`3`=explicit). */
|
|
1986
|
+
ftps?: number;
|
|
1987
|
+
}
|
|
1988
|
+
/** Result of {@link importWinScpSessions}. */
|
|
1989
|
+
interface ImportWinScpSessionsResult {
|
|
1990
|
+
/** Successfully mapped sessions. */
|
|
1991
|
+
sessions: readonly WinScpSession[];
|
|
1992
|
+
/** Sessions skipped because their protocol is not supported. */
|
|
1993
|
+
skipped: readonly {
|
|
1994
|
+
name: string;
|
|
1995
|
+
folder: readonly string[];
|
|
1996
|
+
fsProtocol?: number;
|
|
1997
|
+
}[];
|
|
1998
|
+
}
|
|
1999
|
+
/**
|
|
2000
|
+
* Parses WinSCP `WinSCP.ini` text and returns generated profiles.
|
|
2001
|
+
*
|
|
2002
|
+
* @param ini - Contents of the WinSCP configuration file.
|
|
2003
|
+
* @returns Imported sessions and any skipped entries.
|
|
2004
|
+
* @throws {@link ConfigurationError} When no session sections are found.
|
|
2005
|
+
*/
|
|
2006
|
+
declare function importWinScpSessions(ini: string): ImportWinScpSessionsResult;
|
|
2007
|
+
|
|
2008
|
+
/**
|
|
2009
|
+
* Structured ZeroTransfer error hierarchy.
|
|
2010
|
+
*
|
|
2011
|
+
* The classes in this module preserve protocol details, retryability, command/path
|
|
2012
|
+
* context, and machine-readable codes so application code does not need to parse
|
|
2013
|
+
* human error messages.
|
|
2014
|
+
*
|
|
2015
|
+
* @module errors/ZeroTransferError
|
|
2016
|
+
*/
|
|
2017
|
+
|
|
2018
|
+
/**
|
|
2019
|
+
* Complete set of fields required to create a ZeroTransfer error.
|
|
2020
|
+
*/
|
|
2021
|
+
interface ZeroTransferErrorDetails {
|
|
2022
|
+
/** Stable machine-readable error code. */
|
|
2023
|
+
code: string;
|
|
2024
|
+
/** Human-readable error message safe to show in logs or diagnostics. */
|
|
2025
|
+
message: string;
|
|
2026
|
+
/** Original error or exception that caused this error. */
|
|
2027
|
+
cause?: unknown;
|
|
2028
|
+
/** Protocol active when the error occurred. */
|
|
2029
|
+
protocol?: RemoteProtocol;
|
|
2030
|
+
/** Remote host associated with the failing operation. */
|
|
2031
|
+
host?: string;
|
|
2032
|
+
/** Protocol command associated with the failure, if any. */
|
|
2033
|
+
command?: string;
|
|
2034
|
+
/** FTP response code associated with the failure. */
|
|
2035
|
+
ftpCode?: number;
|
|
2036
|
+
/** SFTP status code associated with the failure. */
|
|
2037
|
+
sftpCode?: number;
|
|
2038
|
+
/** Remote path associated with the failure. */
|
|
2039
|
+
path?: string;
|
|
2040
|
+
/** Whether retry policy may safely retry this failure. */
|
|
2041
|
+
retryable: boolean;
|
|
2042
|
+
/** Additional structured details for diagnostics. */
|
|
2043
|
+
details?: Record<string, unknown>;
|
|
2044
|
+
}
|
|
2045
|
+
/**
|
|
2046
|
+
* Error construction input for subclasses that provide default codes.
|
|
2047
|
+
*/
|
|
2048
|
+
type SpecializedErrorDetails = Omit<ZeroTransferErrorDetails, "code"> & {
|
|
2049
|
+
/** Optional override for the subclass default code. */
|
|
2050
|
+
code?: string;
|
|
2051
|
+
};
|
|
2052
|
+
/**
|
|
2053
|
+
* Base class for all typed ZeroTransfer errors.
|
|
2054
|
+
*/
|
|
2055
|
+
declare class ZeroTransferError extends Error {
|
|
2056
|
+
/** Stable machine-readable error code. */
|
|
2057
|
+
readonly code: string;
|
|
2058
|
+
/** Protocol active when the error occurred. */
|
|
2059
|
+
readonly protocol?: RemoteProtocol;
|
|
2060
|
+
/** Remote host associated with the failing operation. */
|
|
2061
|
+
readonly host?: string;
|
|
2062
|
+
/** Protocol command associated with the failure, if any. */
|
|
2063
|
+
readonly command?: string;
|
|
2064
|
+
/** FTP response code associated with the failure. */
|
|
2065
|
+
readonly ftpCode?: number;
|
|
2066
|
+
/** SFTP status code associated with the failure. */
|
|
2067
|
+
readonly sftpCode?: number;
|
|
2068
|
+
/** Remote path associated with the failure. */
|
|
2069
|
+
readonly path?: string;
|
|
2070
|
+
/** Whether retry policy may safely retry this failure. */
|
|
2071
|
+
readonly retryable: boolean;
|
|
2072
|
+
/** Additional structured details for diagnostics. */
|
|
2073
|
+
readonly details?: Record<string, unknown>;
|
|
2074
|
+
/**
|
|
2075
|
+
* Creates a structured SDK error.
|
|
2076
|
+
*
|
|
2077
|
+
* @param details - Code, message, retryability, and optional protocol context.
|
|
2078
|
+
*/
|
|
2079
|
+
constructor(details: ZeroTransferErrorDetails);
|
|
2080
|
+
/**
|
|
2081
|
+
* Serializes the error into a plain object suitable for logs or API responses.
|
|
2082
|
+
*
|
|
2083
|
+
* @returns A JSON-safe object containing public structured error fields.
|
|
2084
|
+
*/
|
|
2085
|
+
toJSON(): Record<string, unknown>;
|
|
2086
|
+
}
|
|
2087
|
+
/** Error raised when a remote connection cannot be opened or is lost unexpectedly. */
|
|
2088
|
+
declare class ConnectionError extends ZeroTransferError {
|
|
2089
|
+
/**
|
|
2090
|
+
* Creates a connection failure.
|
|
2091
|
+
*
|
|
2092
|
+
* @param details - Error context with optional host, protocol, and retryability details.
|
|
2093
|
+
*/
|
|
2094
|
+
constructor(details: SpecializedErrorDetails);
|
|
2095
|
+
}
|
|
2096
|
+
/** Error raised when authentication credentials are rejected. */
|
|
2097
|
+
declare class AuthenticationError extends ZeroTransferError {
|
|
2098
|
+
/**
|
|
2099
|
+
* Creates an authentication failure.
|
|
2100
|
+
*
|
|
2101
|
+
* @param details - Error context with optional host, protocol, and command details.
|
|
2102
|
+
*/
|
|
2103
|
+
constructor(details: SpecializedErrorDetails);
|
|
2104
|
+
}
|
|
2105
|
+
/** Error raised when authenticated credentials are not authorized for an operation. */
|
|
2106
|
+
declare class AuthorizationError extends ZeroTransferError {
|
|
2107
|
+
/**
|
|
2108
|
+
* Creates an authorization failure.
|
|
2109
|
+
*
|
|
2110
|
+
* @param details - Error context with optional path and protocol details.
|
|
2111
|
+
*/
|
|
2112
|
+
constructor(details: SpecializedErrorDetails);
|
|
2113
|
+
}
|
|
2114
|
+
/** Error raised when a requested remote path does not exist. */
|
|
2115
|
+
declare class PathNotFoundError extends ZeroTransferError {
|
|
2116
|
+
/**
|
|
2117
|
+
* Creates a missing-path failure.
|
|
2118
|
+
*
|
|
2119
|
+
* @param details - Error context with optional path and protocol details.
|
|
2120
|
+
*/
|
|
2121
|
+
constructor(details: SpecializedErrorDetails);
|
|
2122
|
+
}
|
|
2123
|
+
/** Error raised when a create or rename operation targets an existing path. */
|
|
2124
|
+
declare class PathAlreadyExistsError extends ZeroTransferError {
|
|
2125
|
+
/**
|
|
2126
|
+
* Creates an already-exists failure.
|
|
2127
|
+
*
|
|
2128
|
+
* @param details - Error context with optional path and command details.
|
|
2129
|
+
*/
|
|
2130
|
+
constructor(details: SpecializedErrorDetails);
|
|
2131
|
+
}
|
|
2132
|
+
/** Error raised when the remote server denies access to a path or command. */
|
|
2133
|
+
declare class PermissionDeniedError extends ZeroTransferError {
|
|
2134
|
+
/**
|
|
2135
|
+
* Creates a permission failure.
|
|
2136
|
+
*
|
|
2137
|
+
* @param details - Error context with optional path, command, and protocol details.
|
|
2138
|
+
*/
|
|
2139
|
+
constructor(details: SpecializedErrorDetails);
|
|
2140
|
+
}
|
|
2141
|
+
/** Error raised when an operation exceeds its configured timeout. */
|
|
2142
|
+
declare class TimeoutError extends ZeroTransferError {
|
|
2143
|
+
/**
|
|
2144
|
+
* Creates a timeout failure.
|
|
2145
|
+
*
|
|
2146
|
+
* @param details - Error context with optional duration and retryability details.
|
|
2147
|
+
*/
|
|
2148
|
+
constructor(details: SpecializedErrorDetails);
|
|
2149
|
+
}
|
|
2150
|
+
/** Error raised when an operation is cancelled by an AbortSignal or caller action. */
|
|
2151
|
+
declare class AbortError extends ZeroTransferError {
|
|
2152
|
+
/**
|
|
2153
|
+
* Creates an aborted-operation failure.
|
|
2154
|
+
*
|
|
2155
|
+
* @param details - Error context with optional operation and path details.
|
|
2156
|
+
*/
|
|
2157
|
+
constructor(details: SpecializedErrorDetails);
|
|
2158
|
+
}
|
|
2159
|
+
/** Error raised when a server response violates protocol expectations. */
|
|
2160
|
+
declare class ProtocolError extends ZeroTransferError {
|
|
2161
|
+
/**
|
|
2162
|
+
* Creates a protocol failure.
|
|
2163
|
+
*
|
|
2164
|
+
* @param details - Error context with optional response code and command details.
|
|
2165
|
+
*/
|
|
2166
|
+
constructor(details: SpecializedErrorDetails);
|
|
2167
|
+
}
|
|
2168
|
+
/** Error raised when protocol text or metadata cannot be parsed safely. */
|
|
2169
|
+
declare class ParseError extends ZeroTransferError {
|
|
2170
|
+
/**
|
|
2171
|
+
* Creates a parser failure.
|
|
2172
|
+
*
|
|
2173
|
+
* @param details - Error context with malformed input details.
|
|
2174
|
+
*/
|
|
2175
|
+
constructor(details: SpecializedErrorDetails);
|
|
2176
|
+
}
|
|
2177
|
+
/** Error raised when an upload, download, or stream transfer fails. */
|
|
2178
|
+
declare class TransferError extends ZeroTransferError {
|
|
2179
|
+
/**
|
|
2180
|
+
* Creates a transfer failure.
|
|
2181
|
+
*
|
|
2182
|
+
* @param details - Error context with optional path, bytes, and retryability details.
|
|
2183
|
+
*/
|
|
2184
|
+
constructor(details: SpecializedErrorDetails);
|
|
2185
|
+
}
|
|
2186
|
+
/** Error raised when post-transfer verification fails. */
|
|
2187
|
+
declare class VerificationError extends ZeroTransferError {
|
|
2188
|
+
/**
|
|
2189
|
+
* Creates a verification failure.
|
|
2190
|
+
*
|
|
2191
|
+
* @param details - Error context with checksum, size, or timestamp mismatch details.
|
|
2192
|
+
*/
|
|
2193
|
+
constructor(details: SpecializedErrorDetails);
|
|
2194
|
+
}
|
|
2195
|
+
/** Error raised when a requested protocol feature is not implemented or unavailable. */
|
|
2196
|
+
declare class UnsupportedFeatureError extends ZeroTransferError {
|
|
2197
|
+
/**
|
|
2198
|
+
* Creates an unsupported-feature failure.
|
|
2199
|
+
*
|
|
2200
|
+
* @param details - Error context describing the missing feature or adapter.
|
|
2201
|
+
*/
|
|
2202
|
+
constructor(details: SpecializedErrorDetails);
|
|
2203
|
+
}
|
|
2204
|
+
/** Error raised when user-provided options or paths are invalid before network I/O. */
|
|
2205
|
+
declare class ConfigurationError extends ZeroTransferError {
|
|
2206
|
+
/**
|
|
2207
|
+
* Creates a configuration failure.
|
|
2208
|
+
*
|
|
2209
|
+
* @param details - Error context describing the invalid option or argument.
|
|
2210
|
+
*/
|
|
2211
|
+
constructor(details: SpecializedErrorDetails);
|
|
2212
|
+
}
|
|
2213
|
+
|
|
2214
|
+
/**
|
|
2215
|
+
* Protocol error factory helpers.
|
|
2216
|
+
*
|
|
2217
|
+
* This module translates raw FTP status replies into typed ZeroTransfer errors so
|
|
2218
|
+
* adapters can keep protocol parsing separate from application-facing failures.
|
|
2219
|
+
*
|
|
2220
|
+
* @module errors/errorFactory
|
|
2221
|
+
*/
|
|
2222
|
+
|
|
2223
|
+
/**
|
|
2224
|
+
* Input used to map an FTP reply into a structured ZeroTransfer error.
|
|
2225
|
+
*/
|
|
2226
|
+
interface FtpReplyErrorInput {
|
|
2227
|
+
/** Numeric FTP response code returned by the server. */
|
|
2228
|
+
ftpCode: number;
|
|
2229
|
+
/** Server-provided response message. */
|
|
2230
|
+
message: string;
|
|
2231
|
+
/** FTP command that produced the response, if known. */
|
|
2232
|
+
command?: string;
|
|
2233
|
+
/** Remote path involved in the command, if any. */
|
|
2234
|
+
path?: string;
|
|
2235
|
+
/** Protocol variant used by the adapter. */
|
|
2236
|
+
protocol?: RemoteProtocol;
|
|
2237
|
+
/** Original lower-level failure that accompanied the reply. */
|
|
2238
|
+
cause?: unknown;
|
|
2239
|
+
}
|
|
2240
|
+
/**
|
|
2241
|
+
* Maps an FTP reply into the closest typed ZeroTransfer error.
|
|
2242
|
+
*
|
|
2243
|
+
* @param input - FTP code, message, and optional operation context.
|
|
2244
|
+
* @returns A structured error subclass with stable code and retryability metadata.
|
|
2245
|
+
*/
|
|
2246
|
+
declare function errorFromFtpReply(input: FtpReplyErrorInput): ZeroTransferError;
|
|
2247
|
+
|
|
2248
|
+
/**
|
|
2249
|
+
* Secret redaction helpers for logs, events, and diagnostics.
|
|
2250
|
+
*
|
|
2251
|
+
* These functions focus on preserving useful operational context while removing
|
|
2252
|
+
* credentials and command payloads that should not appear in logs.
|
|
2253
|
+
*
|
|
2254
|
+
* @module logging/redaction
|
|
2255
|
+
*/
|
|
2256
|
+
/** Placeholder used when sensitive content has been removed. */
|
|
2257
|
+
declare const REDACTED = "[REDACTED]";
|
|
2258
|
+
/**
|
|
2259
|
+
* Checks whether an object key is likely to contain sensitive data.
|
|
2260
|
+
*
|
|
2261
|
+
* @param key - Object key to inspect.
|
|
2262
|
+
* @returns `true` when the key name should be redacted.
|
|
2263
|
+
*/
|
|
2264
|
+
declare function isSensitiveKey(key: string): boolean;
|
|
2265
|
+
/**
|
|
2266
|
+
* Redacts sensitive FTP command payloads while preserving the command name.
|
|
2267
|
+
*
|
|
2268
|
+
* @param command - Raw command text such as `PASS secret` or `USER deploy`.
|
|
2269
|
+
* @returns Command text with secret arguments replaced by {@link REDACTED}.
|
|
2270
|
+
*/
|
|
2271
|
+
declare function redactCommand(command: string): string;
|
|
2272
|
+
/**
|
|
2273
|
+
* Recursively redacts strings, arrays, and plain object values.
|
|
2274
|
+
*
|
|
2275
|
+
* @param value - Arbitrary value to sanitize for diagnostics.
|
|
2276
|
+
* @returns A redacted copy for arrays and objects, or the original primitive value.
|
|
2277
|
+
*/
|
|
2278
|
+
declare function redactValue(value: unknown): unknown;
|
|
2279
|
+
/**
|
|
2280
|
+
* Redacts sensitive keys and nested values in a plain object.
|
|
2281
|
+
*
|
|
2282
|
+
* @param input - Object containing diagnostic fields.
|
|
2283
|
+
* @returns A shallow object copy with sensitive fields and nested secrets redacted.
|
|
2284
|
+
*/
|
|
2285
|
+
declare function redactObject(input: Record<string, unknown>): Record<string, unknown>;
|
|
2286
|
+
|
|
2287
|
+
/**
|
|
2288
|
+
* FTPS control-channel TLS mode.
|
|
2289
|
+
*
|
|
2290
|
+
* `explicit` connects on a plain FTP control socket and upgrades with `AUTH TLS`;
|
|
2291
|
+
* `implicit` starts TLS immediately, typically on port 990.
|
|
2292
|
+
*/
|
|
2293
|
+
type FtpsMode = "explicit" | "implicit";
|
|
2294
|
+
/**
|
|
2295
|
+
* FTPS data-channel protection level requested after TLS negotiation.
|
|
2296
|
+
*
|
|
2297
|
+
* `private` sends `PROT P` and wraps passive data sockets in TLS. `clear` sends
|
|
2298
|
+
* `PROT C`, keeping the control channel encrypted while leaving data sockets plain.
|
|
2299
|
+
*/
|
|
2300
|
+
type FtpsDataProtection = "clear" | "private";
|
|
2301
|
+
/**
|
|
2302
|
+
* Host selection strategy for PASV data endpoints.
|
|
2303
|
+
*
|
|
2304
|
+
* `control` connects data sockets back to the control connection host, which avoids
|
|
2305
|
+
* broken private or unroutable PASV addresses from NATed servers. `advertised` uses
|
|
2306
|
+
* the host supplied by the server's PASV response for deployments that require it.
|
|
2307
|
+
*/
|
|
2308
|
+
type FtpPassiveHostStrategy = "advertised" | "control";
|
|
2309
|
+
/** Options used to create the classic FTP provider factory. */
|
|
2310
|
+
interface FtpProviderOptions {
|
|
2311
|
+
/** Default control port used when a connection profile omits `port`. */
|
|
2312
|
+
defaultPort?: number;
|
|
2313
|
+
/** PASV host selection strategy. Defaults to `control` for NAT-friendly compatibility. */
|
|
2314
|
+
passiveHostStrategy?: FtpPassiveHostStrategy;
|
|
2315
|
+
}
|
|
2316
|
+
/** Options used to create the FTPS provider factory. */
|
|
2317
|
+
interface FtpsProviderOptions extends FtpProviderOptions {
|
|
2318
|
+
/** TLS mode used for the control connection. Defaults to explicit FTPS on port 21. */
|
|
2319
|
+
mode?: FtpsMode;
|
|
2320
|
+
/** Data channel protection requested through PROT. Defaults to private/encrypted data. */
|
|
2321
|
+
dataProtection?: FtpsDataProtection;
|
|
2322
|
+
}
|
|
2323
|
+
/**
|
|
2324
|
+
* Creates a provider factory for classic FTP connections.
|
|
2325
|
+
*
|
|
2326
|
+
* @param options - Optional provider defaults.
|
|
2327
|
+
* @returns Provider factory suitable for `createTransferClient({ providers: [...] })`.
|
|
2328
|
+
*/
|
|
2329
|
+
declare function createFtpProviderFactory(options?: FtpProviderOptions): ProviderFactory;
|
|
2330
|
+
/**
|
|
2331
|
+
* Creates a provider factory for explicit or implicit FTPS connections.
|
|
2332
|
+
*
|
|
2333
|
+
* The factory resolves TLS material from each connection profile, upgrades explicit
|
|
2334
|
+
* sessions with `AUTH TLS`, and applies the configured `PROT` data-channel policy.
|
|
2335
|
+
*
|
|
2336
|
+
* @param options - Optional provider defaults.
|
|
2337
|
+
* @returns Provider factory suitable for `createTransferClient({ providers: [...] })`.
|
|
2338
|
+
*/
|
|
2339
|
+
declare function createFtpsProviderFactory(options?: FtpsProviderOptions): ProviderFactory;
|
|
2340
|
+
|
|
2341
|
+
/** FTP response status family derived from the first digit of the reply code. */
|
|
2342
|
+
type FtpResponseStatus = "preliminary" | "completion" | "intermediate" | "transientFailure" | "permanentFailure";
|
|
2343
|
+
/**
|
|
2344
|
+
* Complete parsed FTP response.
|
|
2345
|
+
*/
|
|
2346
|
+
interface FtpResponse {
|
|
2347
|
+
/** Numeric three-digit FTP reply code. */
|
|
2348
|
+
code: number;
|
|
2349
|
+
/** Response message with multi-line content joined by newlines. */
|
|
2350
|
+
message: string;
|
|
2351
|
+
/** Individual message lines without the reply-code prefix. */
|
|
2352
|
+
lines: string[];
|
|
2353
|
+
/** Raw response lines joined by newlines. */
|
|
2354
|
+
raw: string;
|
|
2355
|
+
/** Classified response status family. */
|
|
2356
|
+
status: FtpResponseStatus;
|
|
2357
|
+
/** Whether the response is a 1xx preliminary reply. */
|
|
2358
|
+
preliminary: boolean;
|
|
2359
|
+
/** Whether the response is a 2xx completion reply. */
|
|
2360
|
+
completion: boolean;
|
|
2361
|
+
/** Whether the response is a 3xx intermediate reply. */
|
|
2362
|
+
intermediate: boolean;
|
|
2363
|
+
/** Whether the response is a 4xx transient failure reply. */
|
|
2364
|
+
transientFailure: boolean;
|
|
2365
|
+
/** Whether the response is a 5xx permanent failure reply. */
|
|
2366
|
+
permanentFailure: boolean;
|
|
2367
|
+
}
|
|
2368
|
+
/**
|
|
2369
|
+
* Stateful parser for socket-delivered FTP response text.
|
|
2370
|
+
*/
|
|
2371
|
+
declare class FtpResponseParser {
|
|
2372
|
+
private buffer;
|
|
2373
|
+
private pendingResponse;
|
|
2374
|
+
/**
|
|
2375
|
+
* Adds incoming socket data and returns any complete responses.
|
|
2376
|
+
*
|
|
2377
|
+
* @param chunk - Buffer or string chunk from the FTP control connection.
|
|
2378
|
+
* @returns Zero or more complete parsed responses.
|
|
2379
|
+
* @throws {@link ParseError} When a malformed standalone response line is received.
|
|
2380
|
+
*/
|
|
2381
|
+
push(chunk: Buffer | string): FtpResponse[];
|
|
2382
|
+
/**
|
|
2383
|
+
* Clears buffered text and any incomplete multi-line response state.
|
|
2384
|
+
*
|
|
2385
|
+
* @returns Nothing.
|
|
2386
|
+
*/
|
|
2387
|
+
reset(): void;
|
|
2388
|
+
/**
|
|
2389
|
+
* Checks whether the parser is holding buffered or incomplete response data.
|
|
2390
|
+
*
|
|
2391
|
+
* @returns `true` when there is unconsumed text or an open multi-line response.
|
|
2392
|
+
*/
|
|
2393
|
+
hasPendingResponse(): boolean;
|
|
2394
|
+
/**
|
|
2395
|
+
* Consumes one line of FTP response text.
|
|
2396
|
+
*
|
|
2397
|
+
* @param rawLine - Line without a trailing CRLF delimiter.
|
|
2398
|
+
* @returns A complete response when the line finishes one, otherwise `undefined`.
|
|
2399
|
+
* @throws {@link ParseError} When a malformed standalone line is encountered.
|
|
2400
|
+
*/
|
|
2401
|
+
private consumeLine;
|
|
2402
|
+
}
|
|
2403
|
+
/**
|
|
2404
|
+
* Parses an exact set of response lines into one complete FTP response.
|
|
2405
|
+
*
|
|
2406
|
+
* @param lines - Raw response lines without trailing newline delimiters.
|
|
2407
|
+
* @returns A single complete parsed FTP response.
|
|
2408
|
+
* @throws {@link ParseError} When the lines do not contain exactly one complete response.
|
|
2409
|
+
*/
|
|
2410
|
+
declare function parseFtpResponseLines(lines: string[]): FtpResponse;
|
|
2411
|
+
|
|
2412
|
+
/**
|
|
2413
|
+
* FTP FEAT response parser.
|
|
2414
|
+
*
|
|
2415
|
+
* This module extracts advertised server capabilities and MLST facts from a parsed
|
|
2416
|
+
* FTP response, raw response string, or pre-split response lines.
|
|
2417
|
+
*
|
|
2418
|
+
* @module providers/classic/ftp/FtpFeatureParser
|
|
2419
|
+
*/
|
|
2420
|
+
|
|
2421
|
+
/**
|
|
2422
|
+
* Normalized server features returned by an FTP FEAT command.
|
|
2423
|
+
*/
|
|
2424
|
+
interface FtpFeatures {
|
|
2425
|
+
/** Raw normalized feature lines. */
|
|
2426
|
+
raw: string[];
|
|
2427
|
+
/** Uppercase feature names for fast lookup. */
|
|
2428
|
+
names: Set<string>;
|
|
2429
|
+
/** MLST facts advertised by the server, preserving required-fact markers. */
|
|
2430
|
+
mlstFacts: string[];
|
|
2431
|
+
/**
|
|
2432
|
+
* Checks whether a named feature is advertised.
|
|
2433
|
+
*
|
|
2434
|
+
* @param featureName - Feature name to search for, case-insensitively.
|
|
2435
|
+
* @returns `true` when the feature appears in the FEAT response.
|
|
2436
|
+
*/
|
|
2437
|
+
supports(featureName: string): boolean;
|
|
2438
|
+
}
|
|
2439
|
+
/**
|
|
2440
|
+
* Parses FTP FEAT output into a normalized feature set.
|
|
2441
|
+
*
|
|
2442
|
+
* @param input - Parsed FTP response, raw string, or individual response lines.
|
|
2443
|
+
* @returns Normalized feature names, raw feature lines, and MLST fact names.
|
|
2444
|
+
*/
|
|
2445
|
+
declare function parseFtpFeatures(input: FtpResponse | string | string[]): FtpFeatures;
|
|
2446
|
+
|
|
2447
|
+
/**
|
|
2448
|
+
* Parses an MLSD directory listing into normalized remote entries.
|
|
2449
|
+
*
|
|
2450
|
+
* @param input - Raw MLSD response body.
|
|
2451
|
+
* @param directory - Parent remote directory used to build entry paths.
|
|
2452
|
+
* @returns Remote entries excluding the `.` and `..` pseudo entries.
|
|
2453
|
+
* @throws {@link ParseError} When any listing line is malformed.
|
|
2454
|
+
*/
|
|
2455
|
+
declare function parseMlsdList(input: string, directory?: string): RemoteEntry[];
|
|
2456
|
+
/**
|
|
2457
|
+
* Parses a Unix-style FTP `LIST` response into normalized remote entries.
|
|
2458
|
+
*
|
|
2459
|
+
* This parser covers the common `ls -l` shape returned by classic FTP daemons and
|
|
2460
|
+
* is used as a compatibility fallback when a server does not support MLSD.
|
|
2461
|
+
*
|
|
2462
|
+
* @param input - Raw LIST response body.
|
|
2463
|
+
* @param directory - Parent remote directory used to build entry paths.
|
|
2464
|
+
* @param now - Reference date used when LIST entries include time but omit year.
|
|
2465
|
+
* @returns Remote entries excluding `.` and `..` pseudo entries.
|
|
2466
|
+
* @throws {@link ParseError} When any non-summary listing line is malformed.
|
|
2467
|
+
*/
|
|
2468
|
+
declare function parseUnixList(input: string, directory?: string, now?: Date): RemoteEntry[];
|
|
2469
|
+
/**
|
|
2470
|
+
* Parses one Unix-style FTP `LIST` line.
|
|
2471
|
+
*
|
|
2472
|
+
* @param line - Raw listing line in an `ls -l` compatible format.
|
|
2473
|
+
* @param directory - Parent remote directory used to build the entry path.
|
|
2474
|
+
* @param now - Reference date used when the line omits a year.
|
|
2475
|
+
* @returns Normalized remote entry with raw LIST metadata retained.
|
|
2476
|
+
* @throws {@link ParseError} When the line is not a supported Unix LIST entry.
|
|
2477
|
+
*/
|
|
2478
|
+
declare function parseUnixListLine(line: string, directory?: string, now?: Date): RemoteEntry;
|
|
2479
|
+
/**
|
|
2480
|
+
* Parses a single MLSD or MLST fact line.
|
|
2481
|
+
*
|
|
2482
|
+
* @param line - Raw fact line in `fact=value; name` format.
|
|
2483
|
+
* @param directory - Parent remote directory used to build the entry path.
|
|
2484
|
+
* @returns A normalized remote entry with parsed facts in `raw` metadata.
|
|
2485
|
+
* @throws {@link ParseError} When the line does not contain facts and a name.
|
|
2486
|
+
*/
|
|
2487
|
+
declare function parseMlsdLine(line: string, directory?: string): RemoteEntry;
|
|
2488
|
+
/**
|
|
2489
|
+
* Parses the UTC timestamp format used by MLST/MLSD `modify` facts.
|
|
2490
|
+
*
|
|
2491
|
+
* @param input - Timestamp text such as `20260427010203.123`.
|
|
2492
|
+
* @returns A UTC Date when the timestamp is valid, otherwise `undefined`.
|
|
2493
|
+
*/
|
|
2494
|
+
declare function parseMlstTimestamp(input: string | undefined): Date | undefined;
|
|
2495
|
+
|
|
2496
|
+
/** Options used to create an SFTP provider factory. */
|
|
2497
|
+
interface SftpProviderOptions {
|
|
2498
|
+
/** Hash algorithm used before calling ssh2's host verifier, such as `sha256`. */
|
|
2499
|
+
hostHash?: ConnectConfig["hostHash"];
|
|
2500
|
+
/** Host-key verifier passed directly to ssh2 for advanced callers. */
|
|
2501
|
+
hostVerifier?: ConnectConfig["hostVerifier"];
|
|
2502
|
+
/** Default SSH handshake timeout in milliseconds when the profile does not provide `timeoutMs`. */
|
|
2503
|
+
readyTimeoutMs?: number;
|
|
2504
|
+
}
|
|
2505
|
+
/** Raw SFTP session handles exposed for advanced diagnostics. */
|
|
2506
|
+
interface SftpRawSession {
|
|
2507
|
+
/** Underlying ssh2 client connection. */
|
|
2508
|
+
client: Client;
|
|
2509
|
+
/** Underlying ssh2 SFTP wrapper. */
|
|
2510
|
+
sftp: SFTPWrapper;
|
|
2511
|
+
}
|
|
2512
|
+
/**
|
|
2513
|
+
* Creates an SFTP provider factory backed by the mature `ssh2` implementation.
|
|
2514
|
+
*
|
|
2515
|
+
* @param options - Optional ssh2 host-key verifier and timeout defaults.
|
|
2516
|
+
* @returns Provider factory suitable for `createTransferClient({ providers: [...] })`.
|
|
2517
|
+
*/
|
|
2518
|
+
declare function createSftpProviderFactory(options?: SftpProviderOptions): ProviderFactory;
|
|
2519
|
+
|
|
2520
|
+
/** Options for {@link createSftpJumpHostSocketFactory}. */
|
|
2521
|
+
interface SftpJumpHostOptions {
|
|
2522
|
+
/** Static ssh2 connect configuration for the bastion. Mutually exclusive with {@link buildBastion}. */
|
|
2523
|
+
bastion?: ConnectConfig;
|
|
2524
|
+
/** Per-connection builder used to refresh credentials before each tunnel attempt. */
|
|
2525
|
+
buildBastion?: (context: SshSocketFactoryContext) => ConnectConfig | Promise<ConnectConfig>;
|
|
2526
|
+
/** Optional logger used for tunnel diagnostics. */
|
|
2527
|
+
logger?: ZeroTransferLogger;
|
|
2528
|
+
/** Optional ssh2 client factory override used in tests. */
|
|
2529
|
+
createClient?: () => Client;
|
|
2530
|
+
}
|
|
2531
|
+
/**
|
|
2532
|
+
* Builds an {@link SshSocketFactory} that tunnels SFTP connections through a bastion host.
|
|
2533
|
+
*
|
|
2534
|
+
* @param options - Bastion configuration and overrides.
|
|
2535
|
+
* @returns Factory that returns a forwarded ssh2 channel stream when invoked.
|
|
2536
|
+
* @throws {@link ConfigurationError} When neither {@link SftpJumpHostOptions.bastion} nor {@link SftpJumpHostOptions.buildBastion} is supplied.
|
|
2537
|
+
*/
|
|
2538
|
+
declare function createSftpJumpHostSocketFactory(options: SftpJumpHostOptions): SshSocketFactory;
|
|
2539
|
+
|
|
2540
|
+
/**
|
|
2541
|
+
* Transfer result and progress calculation helpers.
|
|
2542
|
+
*
|
|
2543
|
+
* These helpers are pure functions so future FTP, FTPS, and SFTP adapters can share
|
|
2544
|
+
* timing, throughput, and progress calculations without coupling to transport code.
|
|
2545
|
+
*
|
|
2546
|
+
* @module services/TransferService
|
|
2547
|
+
*/
|
|
2548
|
+
|
|
2549
|
+
/**
|
|
2550
|
+
* Input used to create a final transfer result.
|
|
2551
|
+
*/
|
|
2552
|
+
interface TransferResultInput {
|
|
2553
|
+
/** Local or remote source path when known. */
|
|
2554
|
+
sourcePath?: string;
|
|
2555
|
+
/** Local or remote destination path for the transfer. */
|
|
2556
|
+
destinationPath: string;
|
|
2557
|
+
/** Total bytes transferred. */
|
|
2558
|
+
bytesTransferred: number;
|
|
2559
|
+
/** Time the transfer began. */
|
|
2560
|
+
startedAt: Date;
|
|
2561
|
+
/** Time the transfer completed. */
|
|
2562
|
+
completedAt: Date;
|
|
2563
|
+
/** Whether the transfer resumed from an earlier partial state. */
|
|
2564
|
+
resumed?: boolean;
|
|
2565
|
+
/** Whether post-transfer verification succeeded. */
|
|
2566
|
+
verified?: boolean;
|
|
2567
|
+
/** Optional checksum value produced or verified by the transfer. */
|
|
2568
|
+
checksum?: string;
|
|
2569
|
+
}
|
|
2570
|
+
/**
|
|
2571
|
+
* Input used to create a transfer progress event.
|
|
2572
|
+
*/
|
|
2573
|
+
interface ProgressEventInput {
|
|
2574
|
+
/** Stable transfer identifier for correlation. */
|
|
2575
|
+
transferId: string;
|
|
2576
|
+
/** Bytes transferred so far. */
|
|
2577
|
+
bytesTransferred: number;
|
|
2578
|
+
/** Time the transfer began. */
|
|
2579
|
+
startedAt: Date;
|
|
2580
|
+
/** Time to use for the progress calculation; defaults to current time. */
|
|
2581
|
+
now?: Date;
|
|
2582
|
+
/** Total expected bytes when known. */
|
|
2583
|
+
totalBytes?: number;
|
|
2584
|
+
}
|
|
2585
|
+
/**
|
|
2586
|
+
* Creates a final transfer result with duration and average throughput.
|
|
2587
|
+
*
|
|
2588
|
+
* @param input - Transfer paths, byte count, timestamps, and optional verification metadata.
|
|
2589
|
+
* @returns A normalized transfer result.
|
|
2590
|
+
*/
|
|
2591
|
+
declare function createTransferResult(input: TransferResultInput): TransferResult;
|
|
2592
|
+
/**
|
|
2593
|
+
* Creates a progress event with elapsed time, rate, and optional percentage.
|
|
2594
|
+
*
|
|
2595
|
+
* @param input - Transfer id, byte count, start time, optional current time, and total bytes.
|
|
2596
|
+
* @returns A normalized transfer progress event.
|
|
2597
|
+
*/
|
|
2598
|
+
declare function createProgressEvent(input: ProgressEventInput): TransferProgressEvent;
|
|
2599
|
+
|
|
2600
|
+
/** Sleep helper signature used by {@link createBandwidthThrottle}. */
|
|
2601
|
+
type BandwidthSleep = (delayMs: number, signal?: AbortSignal) => Promise<void>;
|
|
2602
|
+
/** Construction overrides for deterministic tests. */
|
|
2603
|
+
interface BandwidthThrottleOptions {
|
|
2604
|
+
/** Monotonic clock returning milliseconds since an arbitrary epoch. Defaults to `Date.now`. */
|
|
2605
|
+
now?: () => number;
|
|
2606
|
+
/** Sleep implementation honoring an optional abort signal. Defaults to a `setTimeout` helper. */
|
|
2607
|
+
sleep?: BandwidthSleep;
|
|
2608
|
+
}
|
|
2609
|
+
/** Token-bucket throttle used to pace transfer chunks. */
|
|
2610
|
+
interface BandwidthThrottle {
|
|
2611
|
+
/** Maximum sustained transfer rate in bytes per second. */
|
|
2612
|
+
readonly bytesPerSecond: number;
|
|
2613
|
+
/** Burst capacity in bytes available before throttling kicks in. */
|
|
2614
|
+
readonly burstBytes: number;
|
|
2615
|
+
/**
|
|
2616
|
+
* Consumes `bytes` from the bucket, awaiting refill when not enough tokens are available.
|
|
2617
|
+
*
|
|
2618
|
+
* @param bytes - Non-negative byte count being released by the throttle.
|
|
2619
|
+
* @param signal - Optional abort signal that interrupts pending waits.
|
|
2620
|
+
* @throws {@link AbortError} When the signal is aborted while waiting.
|
|
2621
|
+
*/
|
|
2622
|
+
consume(bytes: number, signal?: AbortSignal): Promise<void>;
|
|
2623
|
+
}
|
|
2624
|
+
/**
|
|
2625
|
+
* Creates a token-bucket throttle that paces an asynchronous data pipeline to
|
|
2626
|
+
* a sustained {@link TransferBandwidthLimit}.
|
|
2627
|
+
*
|
|
2628
|
+
* Returns `undefined` when no limit is supplied so callers can omit throttling
|
|
2629
|
+
* without conditional branches at the call site.
|
|
2630
|
+
*
|
|
2631
|
+
* @param limit - Optional throughput limit. Returns `undefined` when omitted.
|
|
2632
|
+
* @param options - Optional clock/sleep overrides for deterministic tests.
|
|
2633
|
+
* @returns Throttle implementation when a limit is supplied, otherwise `undefined`.
|
|
2634
|
+
* @throws {@link ConfigurationError} When the supplied limit shape is invalid.
|
|
2635
|
+
*/
|
|
2636
|
+
declare function createBandwidthThrottle(limit: TransferBandwidthLimit | undefined, options?: BandwidthThrottleOptions): BandwidthThrottle | undefined;
|
|
2637
|
+
/**
|
|
2638
|
+
* Wraps an async iterable of byte chunks so each chunk is released only after
|
|
2639
|
+
* the throttle has admitted its byte count.
|
|
2640
|
+
*
|
|
2641
|
+
* When `throttle` is `undefined`, the source iterable is returned unchanged.
|
|
2642
|
+
*
|
|
2643
|
+
* @param source - Async iterable that produces byte chunks.
|
|
2644
|
+
* @param throttle - Optional throttle that paces chunk emission.
|
|
2645
|
+
* @param signal - Optional abort signal interrupting pending waits.
|
|
2646
|
+
* @returns Async generator emitting the original chunks at the throttled rate.
|
|
2647
|
+
*/
|
|
2648
|
+
declare function throttleByteIterable(source: AsyncIterable<Uint8Array>, throttle: BandwidthThrottle | undefined, signal?: AbortSignal): AsyncIterable<Uint8Array>;
|
|
2649
|
+
|
|
2650
|
+
/**
|
|
2651
|
+
* Transfer executor bridge for provider-backed read/write sessions.
|
|
2652
|
+
*
|
|
2653
|
+
* @module transfers/createProviderTransferExecutor
|
|
2654
|
+
*/
|
|
2655
|
+
|
|
2656
|
+
/** Endpoint role used while resolving provider sessions for a transfer job. */
|
|
2657
|
+
type ProviderTransferEndpointRole = "source" | "destination";
|
|
2658
|
+
/** Input passed to provider transfer session resolvers. */
|
|
2659
|
+
interface ProviderTransferSessionResolverInput {
|
|
2660
|
+
/** Endpoint being resolved. */
|
|
2661
|
+
endpoint: TransferEndpoint;
|
|
2662
|
+
/** Whether the endpoint is the source or destination side of the transfer. */
|
|
2663
|
+
role: ProviderTransferEndpointRole;
|
|
2664
|
+
/** Job currently being executed. */
|
|
2665
|
+
job: TransferJob;
|
|
2666
|
+
}
|
|
2667
|
+
/** Resolves the connected provider session that owns an endpoint. */
|
|
2668
|
+
type ProviderTransferSessionResolver = (input: ProviderTransferSessionResolverInput) => TransferSession | undefined;
|
|
2669
|
+
/** Options for {@link createProviderTransferExecutor}. */
|
|
2670
|
+
interface ProviderTransferExecutorOptions {
|
|
2671
|
+
/** Resolves connected provider sessions for source and destination endpoints. */
|
|
2672
|
+
resolveSession: ProviderTransferSessionResolver;
|
|
2673
|
+
/** Optional clock/sleep overrides for the bandwidth throttle. */
|
|
2674
|
+
throttle?: BandwidthThrottleOptions;
|
|
2675
|
+
}
|
|
2676
|
+
/**
|
|
2677
|
+
* Creates a {@link TransferExecutor} that reads from a source provider and writes to a destination provider.
|
|
2678
|
+
*
|
|
2679
|
+
* The returned executor supports single-object `upload`, `download`, and `copy` jobs. Provider sessions must
|
|
2680
|
+
* expose `session.transfers.read()` and `session.transfers.write()`; concrete providers remain responsible for
|
|
2681
|
+
* the actual streaming implementation.
|
|
2682
|
+
*
|
|
2683
|
+
* @param options - Session resolver used for source and destination endpoints.
|
|
2684
|
+
* @returns Transfer executor suitable for {@link TransferEngine.execute} or {@link TransferQueue}.
|
|
2685
|
+
*/
|
|
2686
|
+
declare function createProviderTransferExecutor(options: ProviderTransferExecutorOptions): TransferExecutor;
|
|
2687
|
+
|
|
2688
|
+
/**
|
|
2689
|
+
* Transfer plan and dry-run primitives.
|
|
2690
|
+
*
|
|
2691
|
+
* @module transfers/TransferPlan
|
|
2692
|
+
*/
|
|
2693
|
+
|
|
2694
|
+
/** Non-executing plan action used to explain an intentionally skipped step. */
|
|
2695
|
+
type TransferPlanAction = TransferOperation | "skip";
|
|
2696
|
+
/** Step inside a transfer plan. */
|
|
2697
|
+
interface TransferPlanStep {
|
|
2698
|
+
/** Stable step identifier within the plan. */
|
|
2699
|
+
id: string;
|
|
2700
|
+
/** Action the step would perform. */
|
|
2701
|
+
action: TransferPlanAction;
|
|
2702
|
+
/** Source endpoint when the action reads data. */
|
|
2703
|
+
source?: TransferEndpoint;
|
|
2704
|
+
/** Destination endpoint when the action writes data. */
|
|
2705
|
+
destination?: TransferEndpoint;
|
|
2706
|
+
/** Expected bytes affected by the step when known. */
|
|
2707
|
+
expectedBytes?: number;
|
|
2708
|
+
/** Whether this step may remove or replace data. */
|
|
2709
|
+
destructive?: boolean;
|
|
2710
|
+
/** Human-readable reason for planned or skipped work. */
|
|
2711
|
+
reason?: string;
|
|
2712
|
+
/** Caller-defined metadata retained for diagnostics. */
|
|
2713
|
+
metadata?: Record<string, unknown>;
|
|
2714
|
+
}
|
|
2715
|
+
/** Input used to create a transfer plan. */
|
|
2716
|
+
interface TransferPlanInput {
|
|
2717
|
+
/** Stable plan identifier. */
|
|
2718
|
+
id: string;
|
|
2719
|
+
/** Planned steps in execution order. */
|
|
2720
|
+
steps: TransferPlanStep[];
|
|
2721
|
+
/** Whether the plan is informational only. Defaults to `true`. */
|
|
2722
|
+
dryRun?: boolean;
|
|
2723
|
+
/** Clock used for deterministic tests. Defaults to `new Date()`. */
|
|
2724
|
+
now?: () => Date;
|
|
2725
|
+
/** Non-fatal plan warnings. */
|
|
2726
|
+
warnings?: string[];
|
|
2727
|
+
/** Caller-defined metadata retained for diagnostics. */
|
|
2728
|
+
metadata?: Record<string, unknown>;
|
|
2729
|
+
}
|
|
2730
|
+
/** Provider-neutral transfer plan. */
|
|
2731
|
+
interface TransferPlan {
|
|
2732
|
+
/** Stable plan identifier. */
|
|
2733
|
+
id: string;
|
|
2734
|
+
/** Whether this plan should be treated as a dry run. */
|
|
2735
|
+
dryRun: boolean;
|
|
2736
|
+
/** Time the plan was created. */
|
|
2737
|
+
createdAt: Date;
|
|
2738
|
+
/** Planned steps in execution order. */
|
|
2739
|
+
steps: TransferPlanStep[];
|
|
2740
|
+
/** Non-fatal plan warnings. */
|
|
2741
|
+
warnings: string[];
|
|
2742
|
+
/** Caller-defined metadata retained for diagnostics. */
|
|
2743
|
+
metadata?: Record<string, unknown>;
|
|
2744
|
+
}
|
|
2745
|
+
/** Summary of a transfer plan. */
|
|
2746
|
+
interface TransferPlanSummary {
|
|
2747
|
+
/** Total number of steps. */
|
|
2748
|
+
totalSteps: number;
|
|
2749
|
+
/** Number of executable steps. */
|
|
2750
|
+
executableSteps: number;
|
|
2751
|
+
/** Number of skipped steps. */
|
|
2752
|
+
skippedSteps: number;
|
|
2753
|
+
/** Number of destructive steps. */
|
|
2754
|
+
destructiveSteps: number;
|
|
2755
|
+
/** Sum of expected bytes for steps that provide sizes. */
|
|
2756
|
+
totalExpectedBytes: number;
|
|
2757
|
+
/** Counts grouped by action. */
|
|
2758
|
+
actions: Record<string, number>;
|
|
2759
|
+
}
|
|
2760
|
+
/** Creates a transfer plan from dry-run planning input. */
|
|
2761
|
+
declare function createTransferPlan(input: TransferPlanInput): TransferPlan;
|
|
2762
|
+
/** Summarizes a transfer plan for diagnostics, previews, and tests. */
|
|
2763
|
+
declare function summarizeTransferPlan(plan: TransferPlan): TransferPlanSummary;
|
|
2764
|
+
/** Converts executable plan steps into transfer jobs while preserving order. */
|
|
2765
|
+
declare function createTransferJobsFromPlan(plan: TransferPlan): TransferJob[];
|
|
2766
|
+
|
|
2767
|
+
/** Queue item lifecycle state. */
|
|
2768
|
+
type TransferQueueItemStatus = "queued" | "running" | "completed" | "failed" | "canceled";
|
|
2769
|
+
/** Resolver used when jobs do not provide an executor at enqueue time. */
|
|
2770
|
+
type TransferQueueExecutorResolver = (job: TransferJob) => TransferExecutor;
|
|
2771
|
+
/** Options used to create a transfer queue. */
|
|
2772
|
+
interface TransferQueueOptions {
|
|
2773
|
+
/** Transfer engine used to execute queued jobs. Defaults to a new engine. */
|
|
2774
|
+
engine?: TransferEngine;
|
|
2775
|
+
/** Maximum jobs to execute at the same time. Defaults to `1`. */
|
|
2776
|
+
concurrency?: number;
|
|
2777
|
+
/** Default executor used for jobs that do not provide one directly. */
|
|
2778
|
+
executor?: TransferExecutor;
|
|
2779
|
+
/** Dynamic executor resolver used when no per-job executor or default executor exists. */
|
|
2780
|
+
resolveExecutor?: TransferQueueExecutorResolver;
|
|
2781
|
+
/** Retry policy passed to engine executions. */
|
|
2782
|
+
retry?: TransferRetryPolicy;
|
|
2783
|
+
/** Timeout policy passed to engine executions. */
|
|
2784
|
+
timeout?: TransferTimeoutPolicy;
|
|
2785
|
+
/** Optional throughput limit shape passed to transfer executors. */
|
|
2786
|
+
bandwidthLimit?: TransferBandwidthLimit;
|
|
2787
|
+
/** Progress observer shared across queued jobs. */
|
|
2788
|
+
onProgress?: (event: TransferProgressEvent) => void;
|
|
2789
|
+
/** Completion observer for successful jobs. */
|
|
2790
|
+
onReceipt?: (receipt: TransferReceipt) => void;
|
|
2791
|
+
/** Failure observer for failed jobs. */
|
|
2792
|
+
onError?: (item: TransferQueueItem, error: unknown) => void;
|
|
2793
|
+
}
|
|
2794
|
+
/** Options used when draining a queue. */
|
|
2795
|
+
interface TransferQueueRunOptions {
|
|
2796
|
+
/** Abort signal used to cancel running jobs during this drain. */
|
|
2797
|
+
signal?: AbortSignal;
|
|
2798
|
+
/** Retry policy override for this drain. */
|
|
2799
|
+
retry?: TransferRetryPolicy;
|
|
2800
|
+
/** Timeout policy override for this drain. */
|
|
2801
|
+
timeout?: TransferTimeoutPolicy;
|
|
2802
|
+
/** Bandwidth limit override for this drain. */
|
|
2803
|
+
bandwidthLimit?: TransferBandwidthLimit;
|
|
2804
|
+
/** Progress observer override for this drain. */
|
|
2805
|
+
onProgress?: (event: TransferProgressEvent) => void;
|
|
2806
|
+
}
|
|
2807
|
+
/** Enqueued transfer job state. */
|
|
2808
|
+
interface TransferQueueItem {
|
|
2809
|
+
/** Queued job identifier. */
|
|
2810
|
+
id: string;
|
|
2811
|
+
/** Original transfer job. */
|
|
2812
|
+
job: TransferJob;
|
|
2813
|
+
/** Current queue status. */
|
|
2814
|
+
status: TransferQueueItemStatus;
|
|
2815
|
+
/** Successful transfer receipt when completed. */
|
|
2816
|
+
receipt?: TransferReceipt;
|
|
2817
|
+
/** Failure or cancellation reason when available. */
|
|
2818
|
+
error?: unknown;
|
|
2819
|
+
}
|
|
2820
|
+
/** Summary returned after a queue drain. */
|
|
2821
|
+
interface TransferQueueSummary {
|
|
2822
|
+
/** Number of items currently known to the queue. */
|
|
2823
|
+
total: number;
|
|
2824
|
+
/** Number of successfully completed jobs. */
|
|
2825
|
+
completed: number;
|
|
2826
|
+
/** Number of failed jobs. */
|
|
2827
|
+
failed: number;
|
|
2828
|
+
/** Number of canceled jobs. */
|
|
2829
|
+
canceled: number;
|
|
2830
|
+
/** Number of jobs still queued because the queue was paused. */
|
|
2831
|
+
queued: number;
|
|
2832
|
+
/** Number of jobs currently running. */
|
|
2833
|
+
running: number;
|
|
2834
|
+
/** Successful receipts in queue order. */
|
|
2835
|
+
receipts: TransferReceipt[];
|
|
2836
|
+
/** Failed queue items in queue order. */
|
|
2837
|
+
failures: TransferQueueItem[];
|
|
2838
|
+
}
|
|
2839
|
+
/** Minimal transfer queue with concurrency, pause/resume, cancellation, and drain summaries. */
|
|
2840
|
+
declare class TransferQueue {
|
|
2841
|
+
private readonly engine;
|
|
2842
|
+
private readonly items;
|
|
2843
|
+
private readonly defaultExecutor;
|
|
2844
|
+
private readonly resolveExecutor;
|
|
2845
|
+
private readonly retry;
|
|
2846
|
+
private readonly timeout;
|
|
2847
|
+
private readonly bandwidthLimit;
|
|
2848
|
+
private readonly onProgress;
|
|
2849
|
+
private readonly onReceipt;
|
|
2850
|
+
private readonly onError;
|
|
2851
|
+
private concurrency;
|
|
2852
|
+
private paused;
|
|
2853
|
+
/**
|
|
2854
|
+
* Creates a transfer queue.
|
|
2855
|
+
*
|
|
2856
|
+
* @param options - Queue engine, concurrency, executor, and observer options.
|
|
2857
|
+
*/
|
|
2858
|
+
constructor(options?: TransferQueueOptions);
|
|
2859
|
+
/** Adds a transfer job to the queue. */
|
|
2860
|
+
add(job: TransferJob, executor?: TransferExecutor): TransferQueueItem;
|
|
2861
|
+
/** Pauses dispatch of new queued jobs. Running jobs are allowed to finish. */
|
|
2862
|
+
pause(): void;
|
|
2863
|
+
/** Resumes dispatch of queued jobs on the next `run()` call. */
|
|
2864
|
+
resume(): void;
|
|
2865
|
+
/** Updates queue concurrency for subsequent drains. */
|
|
2866
|
+
setConcurrency(concurrency: number): void;
|
|
2867
|
+
/** Cancels a queued or running job. */
|
|
2868
|
+
cancel(jobId: string): boolean;
|
|
2869
|
+
/** Returns a queued item snapshot by id. */
|
|
2870
|
+
get(jobId: string): TransferQueueItem | undefined;
|
|
2871
|
+
/** Lists queue item snapshots in insertion order. */
|
|
2872
|
+
list(): TransferQueueItem[];
|
|
2873
|
+
/** Drains currently queued jobs until complete, failed, canceled, or paused. */
|
|
2874
|
+
run(options?: TransferQueueRunOptions): Promise<TransferQueueSummary>;
|
|
2875
|
+
/** Returns a queue summary without executing more work. */
|
|
2876
|
+
summarize(): TransferQueueSummary;
|
|
2877
|
+
private runWorker;
|
|
2878
|
+
private nextQueuedItem;
|
|
2879
|
+
private runItem;
|
|
2880
|
+
private requireExecutor;
|
|
2881
|
+
private countDispatchableItems;
|
|
2882
|
+
}
|
|
2883
|
+
|
|
2884
|
+
/**
|
|
2885
|
+
* Browser-friendly directory navigation helpers for file-manager UIs.
|
|
2886
|
+
*
|
|
2887
|
+
* Wraps a {@link RemoteFileSystem} with stateful current-directory tracking,
|
|
2888
|
+
* breadcrumb generation, and pure sort/filter utilities so consumers can render
|
|
2889
|
+
* directory views without re-implementing common navigation glue.
|
|
2890
|
+
*
|
|
2891
|
+
* @module sync/createRemoteBrowser
|
|
2892
|
+
*/
|
|
2893
|
+
|
|
2894
|
+
/** Sort key supported by {@link sortRemoteEntries}. */
|
|
2895
|
+
type RemoteEntrySortKey = "name" | "size" | "modifiedAt" | "type";
|
|
2896
|
+
/** Sort direction supported by {@link sortRemoteEntries}. */
|
|
2897
|
+
type RemoteEntrySortOrder = "asc" | "desc";
|
|
2898
|
+
/** Crumb describing one segment in the current path. */
|
|
2899
|
+
interface RemoteBreadcrumb {
|
|
2900
|
+
/** Display name. `""` is replaced with `"/"` for the root crumb. */
|
|
2901
|
+
name: string;
|
|
2902
|
+
/** Absolute path the crumb resolves to. */
|
|
2903
|
+
path: string;
|
|
2904
|
+
}
|
|
2905
|
+
/** Filter callback applied to a directory listing. */
|
|
2906
|
+
type RemoteBrowserFilter = (entry: RemoteEntry) => boolean;
|
|
2907
|
+
/** Options accepted by {@link createRemoteBrowser}. */
|
|
2908
|
+
interface CreateRemoteBrowserOptions {
|
|
2909
|
+
/** Remote file system to browse. */
|
|
2910
|
+
fs: RemoteFileSystem;
|
|
2911
|
+
/** Initial path. Defaults to `"/"`. */
|
|
2912
|
+
initialPath?: string;
|
|
2913
|
+
/** Sort key applied to listings. Defaults to `"name"`. */
|
|
2914
|
+
sortKey?: RemoteEntrySortKey;
|
|
2915
|
+
/** Sort order applied to listings. Defaults to `"asc"`. */
|
|
2916
|
+
sortOrder?: RemoteEntrySortOrder;
|
|
2917
|
+
/** Whether dotfile entries (names starting with `.`) are included. Defaults to `true`. */
|
|
2918
|
+
showHidden?: boolean;
|
|
2919
|
+
/** Optional filter applied after sort/hidden filtering. */
|
|
2920
|
+
filter?: RemoteBrowserFilter;
|
|
2921
|
+
}
|
|
2922
|
+
/** Snapshot returned by browser navigation methods. */
|
|
2923
|
+
interface RemoteBrowserSnapshot {
|
|
2924
|
+
/** Current absolute path. */
|
|
2925
|
+
path: string;
|
|
2926
|
+
/** Directory entries after sorting and filtering. */
|
|
2927
|
+
entries: RemoteEntry[];
|
|
2928
|
+
/** Breadcrumb trail leading from `/` to {@link path}. */
|
|
2929
|
+
breadcrumbs: RemoteBreadcrumb[];
|
|
2930
|
+
}
|
|
2931
|
+
/** Stateful directory browser returned by {@link createRemoteBrowser}. */
|
|
2932
|
+
interface RemoteBrowser {
|
|
2933
|
+
/** Current absolute path. */
|
|
2934
|
+
readonly path: string;
|
|
2935
|
+
/** Last loaded sorted/filtered entries. */
|
|
2936
|
+
readonly entries: readonly RemoteEntry[];
|
|
2937
|
+
/** Reload the current directory and return the latest snapshot. */
|
|
2938
|
+
refresh(): Promise<RemoteBrowserSnapshot>;
|
|
2939
|
+
/** Navigate to the supplied absolute or relative path. */
|
|
2940
|
+
navigate(target: string): Promise<RemoteBrowserSnapshot>;
|
|
2941
|
+
/** Descend into the supplied directory entry. Throws when the entry is not a directory. */
|
|
2942
|
+
open(entry: RemoteEntry): Promise<RemoteBrowserSnapshot>;
|
|
2943
|
+
/** Move to the parent directory; no-op when already at the root. */
|
|
2944
|
+
up(): Promise<RemoteBrowserSnapshot>;
|
|
2945
|
+
/** Compute breadcrumbs for the current path without re-listing. */
|
|
2946
|
+
breadcrumbs(): RemoteBreadcrumb[];
|
|
2947
|
+
/** Update the sort key. The next refresh re-sorts the cached entries. */
|
|
2948
|
+
setSort(key: RemoteEntrySortKey, order?: RemoteEntrySortOrder): void;
|
|
2949
|
+
/** Toggle hidden-entry visibility. The next refresh re-applies the filter. */
|
|
2950
|
+
setShowHidden(showHidden: boolean): void;
|
|
2951
|
+
}
|
|
2952
|
+
/**
|
|
2953
|
+
* Returns the parent directory of a remote path, or `"/"` for root inputs.
|
|
2954
|
+
*
|
|
2955
|
+
* @param input - Remote path to inspect.
|
|
2956
|
+
* @returns The parent path normalized to an absolute form.
|
|
2957
|
+
*/
|
|
2958
|
+
declare function parentRemotePath(input: string): string;
|
|
2959
|
+
/**
|
|
2960
|
+
* Builds breadcrumbs from `/` down to the supplied path.
|
|
2961
|
+
*
|
|
2962
|
+
* @param input - Absolute remote path.
|
|
2963
|
+
* @returns Ordered crumbs starting with the root.
|
|
2964
|
+
*/
|
|
2965
|
+
declare function buildRemoteBreadcrumbs(input: string): RemoteBreadcrumb[];
|
|
2966
|
+
/**
|
|
2967
|
+
* Returns a copy of the supplied entries sorted by the requested key. Directories
|
|
2968
|
+
* are grouped before files within ascending sorts, matching common file-manager UX.
|
|
2969
|
+
*
|
|
2970
|
+
* @param entries - Entries to sort.
|
|
2971
|
+
* @param key - Sort key.
|
|
2972
|
+
* @param order - Sort order.
|
|
2973
|
+
* @returns Sorted copy of the entries.
|
|
2974
|
+
*/
|
|
2975
|
+
declare function sortRemoteEntries(entries: readonly RemoteEntry[], key?: RemoteEntrySortKey, order?: RemoteEntrySortOrder): RemoteEntry[];
|
|
2976
|
+
/**
|
|
2977
|
+
* Filters entries using the optional predicate plus an optional hidden-file rule.
|
|
2978
|
+
*
|
|
2979
|
+
* @param entries - Entries to filter.
|
|
2980
|
+
* @param options - Filtering controls.
|
|
2981
|
+
* @returns Entries matching the supplied rules.
|
|
2982
|
+
*/
|
|
2983
|
+
declare function filterRemoteEntries(entries: readonly RemoteEntry[], options?: {
|
|
2984
|
+
filter?: RemoteBrowserFilter;
|
|
2985
|
+
showHidden?: boolean;
|
|
2986
|
+
}): RemoteEntry[];
|
|
2987
|
+
/**
|
|
2988
|
+
* Creates a stateful directory browser around a remote file system.
|
|
2989
|
+
*
|
|
2990
|
+
* The returned browser caches the most recent listing and applies sort/filter
|
|
2991
|
+
* settings on each refresh. Navigation methods return a snapshot so UI layers can
|
|
2992
|
+
* render synchronously without re-reading state.
|
|
2993
|
+
*
|
|
2994
|
+
* @param options - Browser configuration.
|
|
2995
|
+
* @returns Stateful browser bound to the supplied file system.
|
|
2996
|
+
*/
|
|
2997
|
+
declare function createRemoteBrowser(options: CreateRemoteBrowserOptions): RemoteBrowser;
|
|
2998
|
+
|
|
2999
|
+
/** Filter callback applied to each visited entry. Returning `false` skips the entry. */
|
|
3000
|
+
type RemoteTreeFilter = (entry: RemoteEntry) => boolean;
|
|
3001
|
+
/** Options accepted by {@link walkRemoteTree}. */
|
|
3002
|
+
interface WalkRemoteTreeOptions {
|
|
3003
|
+
/** Whether to descend into subdirectories. Defaults to `true`. */
|
|
3004
|
+
recursive?: boolean;
|
|
3005
|
+
/** Maximum traversal depth. `0` walks only the root listing. Unbounded by default. */
|
|
3006
|
+
maxDepth?: number;
|
|
3007
|
+
/** Whether to include directory entries in the output. Defaults to `true`. */
|
|
3008
|
+
includeDirectories?: boolean;
|
|
3009
|
+
/** Whether to include file entries in the output. Defaults to `true`. */
|
|
3010
|
+
includeFiles?: boolean;
|
|
3011
|
+
/** Whether to follow symlinks during traversal. Defaults to `false`. */
|
|
3012
|
+
followSymlinks?: boolean;
|
|
3013
|
+
/** Optional filter applied before yielding and before descending into directories. */
|
|
3014
|
+
filter?: RemoteTreeFilter;
|
|
3015
|
+
/** Optional abort signal that interrupts traversal between listings. */
|
|
3016
|
+
signal?: AbortSignal;
|
|
3017
|
+
}
|
|
3018
|
+
/** Walk record yielded by {@link walkRemoteTree}. */
|
|
3019
|
+
interface RemoteTreeEntry {
|
|
3020
|
+
/** Visited remote entry. */
|
|
3021
|
+
entry: RemoteEntry;
|
|
3022
|
+
/** Zero-based depth relative to the traversal root. */
|
|
3023
|
+
depth: number;
|
|
3024
|
+
/** Normalized parent directory path. */
|
|
3025
|
+
parentPath: string;
|
|
3026
|
+
}
|
|
3027
|
+
/**
|
|
3028
|
+
* Walks a remote file system depth-first, yielding entries in a stable order.
|
|
3029
|
+
*
|
|
3030
|
+
* Listings are sorted by entry path within each directory so output is deterministic
|
|
3031
|
+
* across providers. Errors thrown by `fs.list()` propagate; callers can supply a
|
|
3032
|
+
* filter to skip directories that should not be traversed.
|
|
3033
|
+
*
|
|
3034
|
+
* @param fs - Remote file system used for listings.
|
|
3035
|
+
* @param rootPath - Root directory to walk.
|
|
3036
|
+
* @param options - Optional traversal controls.
|
|
3037
|
+
* @returns Async generator emitting {@link RemoteTreeEntry} records.
|
|
3038
|
+
* @throws {@link AbortError} When the supplied abort signal is cancelled mid-walk.
|
|
3039
|
+
*/
|
|
3040
|
+
declare function walkRemoteTree(fs: RemoteFileSystem, rootPath: string, options?: WalkRemoteTreeOptions): AsyncGenerator<RemoteTreeEntry>;
|
|
3041
|
+
|
|
3042
|
+
/**
|
|
3043
|
+
* Directory diffing primitives that compare two remote trees.
|
|
3044
|
+
*
|
|
3045
|
+
* @module sync/diffRemoteTrees
|
|
3046
|
+
*/
|
|
3047
|
+
|
|
3048
|
+
/** Outcome category for an entry across the two compared trees. */
|
|
3049
|
+
type RemoteTreeDiffStatus = "added" | "removed" | "modified" | "unchanged";
|
|
3050
|
+
/** Reason an entry is considered modified. */
|
|
3051
|
+
type RemoteTreeDiffReason = "type" | "size" | "modifiedAt" | "checksum";
|
|
3052
|
+
/** Single diff record produced by {@link diffRemoteTrees}. */
|
|
3053
|
+
interface RemoteTreeDiffEntry {
|
|
3054
|
+
/** Path relative to the traversal root, beginning with `/`. */
|
|
3055
|
+
path: string;
|
|
3056
|
+
/** Outcome category for this entry. */
|
|
3057
|
+
status: RemoteTreeDiffStatus;
|
|
3058
|
+
/** Reasons the entry is considered modified. Empty for unchanged/added/removed records. */
|
|
3059
|
+
reasons: RemoteTreeDiffReason[];
|
|
3060
|
+
/** Source-side entry, when present. */
|
|
3061
|
+
source?: RemoteEntry;
|
|
3062
|
+
/** Destination-side entry, when present. */
|
|
3063
|
+
destination?: RemoteEntry;
|
|
3064
|
+
}
|
|
3065
|
+
/** Compact summary of a diff result. */
|
|
3066
|
+
interface RemoteTreeDiffSummary {
|
|
3067
|
+
/** Number of entries present only on the source side. */
|
|
3068
|
+
added: number;
|
|
3069
|
+
/** Number of entries present only on the destination side. */
|
|
3070
|
+
removed: number;
|
|
3071
|
+
/** Number of entries present on both sides whose contents differ. */
|
|
3072
|
+
modified: number;
|
|
3073
|
+
/** Number of entries present on both sides with identical contents. */
|
|
3074
|
+
unchanged: number;
|
|
3075
|
+
/** Total entries inspected across both sides. */
|
|
3076
|
+
total: number;
|
|
3077
|
+
}
|
|
3078
|
+
/** Result returned by {@link diffRemoteTrees}. */
|
|
3079
|
+
interface RemoteTreeDiff {
|
|
3080
|
+
/** Diff records sorted by path. */
|
|
3081
|
+
entries: RemoteTreeDiffEntry[];
|
|
3082
|
+
/** Compact counts for the diff. */
|
|
3083
|
+
summary: RemoteTreeDiffSummary;
|
|
3084
|
+
}
|
|
3085
|
+
/** Options accepted by {@link diffRemoteTrees}. */
|
|
3086
|
+
interface DiffRemoteTreesOptions {
|
|
3087
|
+
/** Optional traversal controls applied to both sides. */
|
|
3088
|
+
walk?: Pick<WalkRemoteTreeOptions, "filter" | "followSymlinks" | "includeDirectories" | "includeFiles" | "maxDepth" | "recursive">;
|
|
3089
|
+
/** Filter applied only to the source side. Overrides `walk.filter` when set. */
|
|
3090
|
+
sourceFilter?: RemoteTreeFilter;
|
|
3091
|
+
/** Filter applied only to the destination side. Overrides `walk.filter` when set. */
|
|
3092
|
+
destinationFilter?: RemoteTreeFilter;
|
|
3093
|
+
/** Whether unchanged entries are included in `entries`. Defaults to `false`. */
|
|
3094
|
+
includeUnchanged?: boolean;
|
|
3095
|
+
/** Tolerance in milliseconds when comparing modification timestamps. Defaults to `1000`. */
|
|
3096
|
+
modifiedAtToleranceMs?: number;
|
|
3097
|
+
/** Whether modification timestamps participate in the comparison. Defaults to `true`. */
|
|
3098
|
+
compareModifiedAt?: boolean;
|
|
3099
|
+
/** Whether sizes participate in the comparison. Defaults to `true`. */
|
|
3100
|
+
compareSize?: boolean;
|
|
3101
|
+
/** Whether to require matching `uniqueId` checksums when both entries expose one. Defaults to `false`. */
|
|
3102
|
+
compareUniqueId?: boolean;
|
|
3103
|
+
/** Optional abort signal threaded through both walks. */
|
|
3104
|
+
signal?: AbortSignal;
|
|
3105
|
+
}
|
|
3106
|
+
/**
|
|
3107
|
+
* Compares two remote subtrees and produces an entry-level diff.
|
|
3108
|
+
*
|
|
3109
|
+
* Source and destination paths are walked independently; entries are then aligned by
|
|
3110
|
+
* the relative path from each tree root. Directory equality is structural — directories
|
|
3111
|
+
* are equal when their relative paths match and the entry types agree.
|
|
3112
|
+
*
|
|
3113
|
+
* @param source - Source-side remote file system.
|
|
3114
|
+
* @param sourcePath - Source-side root path being compared.
|
|
3115
|
+
* @param destination - Destination-side remote file system.
|
|
3116
|
+
* @param destinationPath - Destination-side root path being compared.
|
|
3117
|
+
* @param options - Optional comparison controls.
|
|
3118
|
+
* @returns Diff result containing entries and a summary.
|
|
3119
|
+
*/
|
|
3120
|
+
declare function diffRemoteTrees(source: RemoteFileSystem, sourcePath: string, destination: RemoteFileSystem, destinationPath: string, options?: DiffRemoteTreesOptions): Promise<RemoteTreeDiff>;
|
|
3121
|
+
|
|
3122
|
+
/**
|
|
3123
|
+
* Sync planning primitives that build a {@link TransferPlan} from a remote-tree diff.
|
|
3124
|
+
*
|
|
3125
|
+
* @module sync/createSyncPlan
|
|
3126
|
+
*/
|
|
3127
|
+
|
|
3128
|
+
/** Sync direction used by {@link createSyncPlan}. */
|
|
3129
|
+
type SyncDirection = "source-to-destination" | "destination-to-source";
|
|
3130
|
+
/** How {@link createSyncPlan} reacts to entries that exist only on the destination. */
|
|
3131
|
+
type SyncDeletePolicy =
|
|
3132
|
+
/** Never delete destination entries that are missing on the source. */
|
|
3133
|
+
"never"
|
|
3134
|
+
/** Plan destination deletions when running source-to-destination sync. */
|
|
3135
|
+
| "mirror"
|
|
3136
|
+
/** Plan destination deletions only when paired with a same-path file on the source. */
|
|
3137
|
+
| "replace-only";
|
|
3138
|
+
/** How {@link createSyncPlan} reacts to entries flagged as modified on both sides. */
|
|
3139
|
+
type SyncConflictPolicy =
|
|
3140
|
+
/** Overwrite the destination with the source. */
|
|
3141
|
+
"overwrite"
|
|
3142
|
+
/** Overwrite the source with the destination. */
|
|
3143
|
+
| "prefer-destination"
|
|
3144
|
+
/** Skip conflicting entries with a `skip` step. */
|
|
3145
|
+
| "skip"
|
|
3146
|
+
/** Fail planning with a {@link ConfigurationError} when a conflict is encountered. */
|
|
3147
|
+
| "error";
|
|
3148
|
+
/** Endpoint shape supplied to {@link createSyncPlan}. */
|
|
3149
|
+
interface SyncEndpointInput {
|
|
3150
|
+
/** Provider that owns the endpoint when known. */
|
|
3151
|
+
provider?: ProviderId;
|
|
3152
|
+
/** Root path on the provider being synced. */
|
|
3153
|
+
rootPath: string;
|
|
3154
|
+
}
|
|
3155
|
+
/** Options accepted by {@link createSyncPlan}. */
|
|
3156
|
+
interface CreateSyncPlanOptions {
|
|
3157
|
+
/** Stable plan identifier. */
|
|
3158
|
+
id: string;
|
|
3159
|
+
/** Diff produced by {@link diffRemoteTrees} or an equivalent source. */
|
|
3160
|
+
diff: RemoteTreeDiff;
|
|
3161
|
+
/** Source-side endpoint that produced the diff. */
|
|
3162
|
+
source: SyncEndpointInput;
|
|
3163
|
+
/** Destination-side endpoint that produced the diff. */
|
|
3164
|
+
destination: SyncEndpointInput;
|
|
3165
|
+
/** Sync direction. Defaults to `"source-to-destination"`. */
|
|
3166
|
+
direction?: SyncDirection;
|
|
3167
|
+
/** Delete policy. Defaults to `"never"`. */
|
|
3168
|
+
deletePolicy?: SyncDeletePolicy;
|
|
3169
|
+
/** Conflict policy. Defaults to `"overwrite"`. */
|
|
3170
|
+
conflictPolicy?: SyncConflictPolicy;
|
|
3171
|
+
/** Whether to plan upload/download steps for directories. Defaults to `false`. */
|
|
3172
|
+
includeDirectoryActions?: boolean;
|
|
3173
|
+
/** Whether the plan is informational only. Defaults to `true`. */
|
|
3174
|
+
dryRun?: boolean;
|
|
3175
|
+
/** Clock used for deterministic tests. Defaults to `new Date()`. */
|
|
3176
|
+
now?: () => Date;
|
|
3177
|
+
/** Caller-defined metadata retained for diagnostics. */
|
|
3178
|
+
metadata?: Record<string, unknown>;
|
|
3179
|
+
}
|
|
3180
|
+
/**
|
|
3181
|
+
* Builds a {@link TransferPlan} that reconciles two remote subtrees.
|
|
3182
|
+
*
|
|
3183
|
+
* Plan steps are derived from a {@link RemoteTreeDiff}; the function does not perform
|
|
3184
|
+
* any I/O. Direction, delete policy, and conflict policy control which entries
|
|
3185
|
+
* become executable transfers and which become `skip` steps.
|
|
3186
|
+
*
|
|
3187
|
+
* @param options - Inputs and policies that shape the plan.
|
|
3188
|
+
* @returns Transfer plan ready for `createTransferJobsFromPlan` or queue execution.
|
|
3189
|
+
* @throws {@link ConfigurationError} When `conflictPolicy: "error"` encounters a conflict.
|
|
3190
|
+
*/
|
|
3191
|
+
declare function createSyncPlan(options: CreateSyncPlanOptions): TransferPlan;
|
|
3192
|
+
|
|
3193
|
+
/**
|
|
3194
|
+
* Atomic deploy planning helpers.
|
|
3195
|
+
*
|
|
3196
|
+
* Produces a structured plan that stages a release under `<liveRoot>/<releasesDir>/<releaseId>`,
|
|
3197
|
+
* activates it via rename or symlink swap, and prunes older releases beyond a retain count.
|
|
3198
|
+
*
|
|
3199
|
+
* The plan is provider-neutral and execution-free: callers wire the upload {@link TransferPlan}
|
|
3200
|
+
* through the transfer engine and execute the activate/prune steps using their provider's
|
|
3201
|
+
* filesystem mutation primitives (rename, symlink, delete).
|
|
3202
|
+
*
|
|
3203
|
+
* @module sync/createAtomicDeployPlan
|
|
3204
|
+
*/
|
|
3205
|
+
|
|
3206
|
+
/** Activation strategy used to swap a staged release into place. */
|
|
3207
|
+
type AtomicDeployStrategy =
|
|
3208
|
+
/** Rename `<liveRoot>` aside, then rename the staging path to `<liveRoot>`. */
|
|
3209
|
+
"rename"
|
|
3210
|
+
/** Update a symlink at `<liveRoot>` to point at the staging path. */
|
|
3211
|
+
| "symlink";
|
|
3212
|
+
/** Operation kind for an activation step. */
|
|
3213
|
+
type AtomicDeployActivateOperation = "rename" | "symlink" | "delete";
|
|
3214
|
+
/** Kind of activation step described by the plan. */
|
|
3215
|
+
interface AtomicDeployActivateStep {
|
|
3216
|
+
/** Stable identifier within the activation list. */
|
|
3217
|
+
id: string;
|
|
3218
|
+
/** Operation the step would perform. */
|
|
3219
|
+
operation: AtomicDeployActivateOperation;
|
|
3220
|
+
/** Source path the operation reads or moves from. */
|
|
3221
|
+
fromPath?: string;
|
|
3222
|
+
/** Destination path the operation writes to. */
|
|
3223
|
+
toPath: string;
|
|
3224
|
+
/** Provider identifier that owns the affected paths when known. */
|
|
3225
|
+
provider?: ProviderId;
|
|
3226
|
+
/** Whether the step replaces or removes data. */
|
|
3227
|
+
destructive?: boolean;
|
|
3228
|
+
/** Human-readable description for previews and logs. */
|
|
3229
|
+
reason: string;
|
|
3230
|
+
}
|
|
3231
|
+
/** Pruning step describing an old release directory marked for deletion. */
|
|
3232
|
+
interface AtomicDeployPruneStep {
|
|
3233
|
+
/** Stable identifier within the prune list. */
|
|
3234
|
+
id: string;
|
|
3235
|
+
/** Absolute release directory path to delete. */
|
|
3236
|
+
path: string;
|
|
3237
|
+
/** Provider identifier that owns the path when known. */
|
|
3238
|
+
provider?: ProviderId;
|
|
3239
|
+
/** Reason the release was selected for pruning. */
|
|
3240
|
+
reason: string;
|
|
3241
|
+
}
|
|
3242
|
+
/** Result returned by {@link createAtomicDeployPlan}. */
|
|
3243
|
+
interface AtomicDeployPlan {
|
|
3244
|
+
/** Stable plan identifier. */
|
|
3245
|
+
id: string;
|
|
3246
|
+
/** Release identifier embedded into the staging path. */
|
|
3247
|
+
releaseId: string;
|
|
3248
|
+
/** Activation strategy chosen for the swap. */
|
|
3249
|
+
strategy: AtomicDeployStrategy;
|
|
3250
|
+
/** Provider identifier for the live destination when known. */
|
|
3251
|
+
provider?: ProviderId;
|
|
3252
|
+
/** Live target path the release activates onto. */
|
|
3253
|
+
livePath: string;
|
|
3254
|
+
/** Staging directory the upload populates. */
|
|
3255
|
+
stagingPath: string;
|
|
3256
|
+
/** Releases root directory under which staging and prior releases live. */
|
|
3257
|
+
releasesRoot: string;
|
|
3258
|
+
/** Optional backup path used by the rename strategy. */
|
|
3259
|
+
backupPath?: string;
|
|
3260
|
+
/** Upload plan that populates the staging directory. */
|
|
3261
|
+
uploadPlan: TransferPlan;
|
|
3262
|
+
/** Activation steps that swap staging into the live path. */
|
|
3263
|
+
activate: AtomicDeployActivateStep[];
|
|
3264
|
+
/** Prune steps that remove older releases beyond {@link retain}. */
|
|
3265
|
+
prune: AtomicDeployPruneStep[];
|
|
3266
|
+
/** Number of releases to retain (including the new release). */
|
|
3267
|
+
retain: number;
|
|
3268
|
+
/** Time the plan was created. */
|
|
3269
|
+
createdAt: Date;
|
|
3270
|
+
/** Non-fatal plan warnings. */
|
|
3271
|
+
warnings: string[];
|
|
3272
|
+
/** Caller-defined metadata retained for diagnostics. */
|
|
3273
|
+
metadata?: Record<string, unknown>;
|
|
3274
|
+
}
|
|
3275
|
+
/** Options accepted by {@link createAtomicDeployPlan}. */
|
|
3276
|
+
interface CreateAtomicDeployPlanOptions {
|
|
3277
|
+
/** Stable plan identifier. */
|
|
3278
|
+
id: string;
|
|
3279
|
+
/** Diff describing source vs. staging contents (typically diffed against an empty staging directory). */
|
|
3280
|
+
diff: RemoteTreeDiff;
|
|
3281
|
+
/** Source-side endpoint feeding the release. */
|
|
3282
|
+
source: SyncEndpointInput;
|
|
3283
|
+
/** Live destination endpoint the release activates onto. */
|
|
3284
|
+
destination: SyncEndpointInput;
|
|
3285
|
+
/** Activation strategy. Defaults to `"rename"`. */
|
|
3286
|
+
strategy?: AtomicDeployStrategy;
|
|
3287
|
+
/** Release identifier. Defaults to a timestamp derived from {@link now}. */
|
|
3288
|
+
releaseId?: string;
|
|
3289
|
+
/** Releases directory name under the destination root. Defaults to `".releases"`. */
|
|
3290
|
+
releasesDirectory?: string;
|
|
3291
|
+
/** Number of releases to retain after the new release, including the new one. Defaults to `3`. */
|
|
3292
|
+
retain?: number;
|
|
3293
|
+
/** Existing release directory paths under the releases root that may be pruned. */
|
|
3294
|
+
existingReleases?: string[];
|
|
3295
|
+
/** Whether the plan is informational only. Defaults to `true`. */
|
|
3296
|
+
dryRun?: boolean;
|
|
3297
|
+
/** Clock used for deterministic tests. Defaults to `new Date()`. */
|
|
3298
|
+
now?: () => Date;
|
|
3299
|
+
/** Caller-defined metadata retained for diagnostics. */
|
|
3300
|
+
metadata?: Record<string, unknown>;
|
|
3301
|
+
}
|
|
3302
|
+
/**
|
|
3303
|
+
* Builds an {@link AtomicDeployPlan} that stages a release, swaps it live, and prunes old releases.
|
|
3304
|
+
*
|
|
3305
|
+
* @param options - Inputs and policies that shape the deploy.
|
|
3306
|
+
* @returns Structured deploy plan ready for execution by the calling host.
|
|
3307
|
+
* @throws {@link ConfigurationError} When `retain` is less than `1` or the destination root is empty.
|
|
3308
|
+
*/
|
|
3309
|
+
declare function createAtomicDeployPlan(options: CreateAtomicDeployPlanOptions): AtomicDeployPlan;
|
|
3310
|
+
|
|
3311
|
+
/** Schema version for the manifest payload. Bumped on incompatible format changes. */
|
|
3312
|
+
declare const REMOTE_MANIFEST_FORMAT_VERSION = 1;
|
|
3313
|
+
/** Manifest entry recorded for each visited remote node. */
|
|
3314
|
+
interface RemoteManifestEntry {
|
|
3315
|
+
/** Path relative to {@link RemoteManifest.root}, beginning with `/`. */
|
|
3316
|
+
path: string;
|
|
3317
|
+
/** Entry kind. */
|
|
3318
|
+
type: RemoteEntryType;
|
|
3319
|
+
/** Entry size in bytes when known. */
|
|
3320
|
+
size?: number;
|
|
3321
|
+
/** Last modification time as an ISO 8601 timestamp when known. */
|
|
3322
|
+
modifiedAt?: string;
|
|
3323
|
+
/** Protocol-specific stable identity when available. */
|
|
3324
|
+
uniqueId?: string;
|
|
3325
|
+
/** Target path for symbolic links when known. */
|
|
3326
|
+
symlinkTarget?: string;
|
|
3327
|
+
}
|
|
3328
|
+
/** Persisted snapshot of a remote subtree. */
|
|
3329
|
+
interface RemoteManifest {
|
|
3330
|
+
/** Schema version. Must equal {@link REMOTE_MANIFEST_FORMAT_VERSION}. */
|
|
3331
|
+
formatVersion: number;
|
|
3332
|
+
/** ISO 8601 timestamp recording when the manifest was generated. */
|
|
3333
|
+
generatedAt: string;
|
|
3334
|
+
/** Normalized absolute root path the manifest snapshot is anchored to. */
|
|
3335
|
+
root: string;
|
|
3336
|
+
/** Optional provider identifier the snapshot was captured from. */
|
|
3337
|
+
provider?: ProviderId;
|
|
3338
|
+
/** Manifest entries sorted by path. */
|
|
3339
|
+
entries: RemoteManifestEntry[];
|
|
3340
|
+
}
|
|
3341
|
+
/** Options accepted by {@link createRemoteManifest}. */
|
|
3342
|
+
interface CreateRemoteManifestOptions {
|
|
3343
|
+
/** Optional traversal controls forwarded to {@link walkRemoteTree}. */
|
|
3344
|
+
walk?: Pick<WalkRemoteTreeOptions, "filter" | "followSymlinks" | "includeDirectories" | "includeFiles" | "maxDepth" | "recursive">;
|
|
3345
|
+
/** Filter applied during traversal. Overrides `walk.filter` when provided. */
|
|
3346
|
+
filter?: RemoteTreeFilter;
|
|
3347
|
+
/** Provider identifier embedded into the manifest header. */
|
|
3348
|
+
provider?: ProviderId;
|
|
3349
|
+
/** Clock used to stamp `generatedAt`. Defaults to `Date.now`. */
|
|
3350
|
+
now?: () => Date;
|
|
3351
|
+
/** Optional abort signal threaded through the walk. */
|
|
3352
|
+
signal?: AbortSignal;
|
|
3353
|
+
}
|
|
3354
|
+
/** Options accepted by {@link compareRemoteManifests}. */
|
|
3355
|
+
interface CompareRemoteManifestsOptions {
|
|
3356
|
+
/** Whether unchanged entries are included in the result. Defaults to `false`. */
|
|
3357
|
+
includeUnchanged?: boolean;
|
|
3358
|
+
/** Tolerance in milliseconds applied to `modifiedAt` comparisons. Defaults to `1000`. */
|
|
3359
|
+
modifiedAtToleranceMs?: number;
|
|
3360
|
+
/** Whether modification timestamps participate in the comparison. Defaults to `true`. */
|
|
3361
|
+
compareModifiedAt?: boolean;
|
|
3362
|
+
/** Whether sizes participate in the comparison. Defaults to `true`. */
|
|
3363
|
+
compareSize?: boolean;
|
|
3364
|
+
/** Whether to require matching `uniqueId` checksums when both entries expose one. Defaults to `false`. */
|
|
3365
|
+
compareUniqueId?: boolean;
|
|
3366
|
+
}
|
|
3367
|
+
/**
|
|
3368
|
+
* Walks a remote subtree and produces a serializable manifest snapshot.
|
|
3369
|
+
*
|
|
3370
|
+
* @param fs - Remote file system to capture.
|
|
3371
|
+
* @param rootPath - Root path the manifest is anchored to.
|
|
3372
|
+
* @param options - Optional capture controls.
|
|
3373
|
+
* @returns Manifest snapshot suitable for serialization or comparison.
|
|
3374
|
+
*/
|
|
3375
|
+
declare function createRemoteManifest(fs: RemoteFileSystem, rootPath: string, options?: CreateRemoteManifestOptions): Promise<RemoteManifest>;
|
|
3376
|
+
/**
|
|
3377
|
+
* Serializes a manifest to a JSON string suitable for persistence.
|
|
3378
|
+
*
|
|
3379
|
+
* @param manifest - Manifest snapshot to serialize.
|
|
3380
|
+
* @param indent - Optional indentation passed to `JSON.stringify`. Defaults to `2`.
|
|
3381
|
+
* @returns Stable JSON representation of the manifest.
|
|
3382
|
+
*/
|
|
3383
|
+
declare function serializeRemoteManifest(manifest: RemoteManifest, indent?: number): string;
|
|
3384
|
+
/**
|
|
3385
|
+
* Parses a JSON-encoded manifest, validating the schema version and entry shape.
|
|
3386
|
+
*
|
|
3387
|
+
* @param text - JSON payload produced by {@link serializeRemoteManifest}.
|
|
3388
|
+
* @returns Parsed manifest snapshot.
|
|
3389
|
+
* @throws {@link ConfigurationError} When the payload is invalid or has an unsupported version.
|
|
3390
|
+
*/
|
|
3391
|
+
declare function parseRemoteManifest(text: string): RemoteManifest;
|
|
3392
|
+
/**
|
|
3393
|
+
* Compares two manifests and produces an entry-level diff.
|
|
3394
|
+
*
|
|
3395
|
+
* The comparison is performed on the relative-path keys recorded inside each manifest;
|
|
3396
|
+
* the absolute roots may differ between snapshots (e.g. captured against `/site` on the
|
|
3397
|
+
* source and `/var/www/site` on the destination).
|
|
3398
|
+
*
|
|
3399
|
+
* @param source - Source-side manifest snapshot.
|
|
3400
|
+
* @param destination - Destination-side manifest snapshot.
|
|
3401
|
+
* @param options - Optional comparison controls.
|
|
3402
|
+
* @returns Diff result mirroring {@link RemoteTreeDiff}.
|
|
3403
|
+
*/
|
|
3404
|
+
declare function compareRemoteManifests(source: RemoteManifest, destination: RemoteManifest, options?: CompareRemoteManifestsOptions): RemoteTreeDiff;
|
|
3405
|
+
|
|
3406
|
+
/** Mutable in-memory registry of MFT routes. */
|
|
3407
|
+
declare class RouteRegistry {
|
|
3408
|
+
private readonly routes;
|
|
3409
|
+
/**
|
|
3410
|
+
* Creates a registry and optionally seeds it with route definitions.
|
|
3411
|
+
*
|
|
3412
|
+
* @param routes - Routes to register immediately.
|
|
3413
|
+
*/
|
|
3414
|
+
constructor(routes?: Iterable<MftRoute>);
|
|
3415
|
+
/**
|
|
3416
|
+
* Registers a route definition.
|
|
3417
|
+
*
|
|
3418
|
+
* @param route - Route to add.
|
|
3419
|
+
* @returns This registry for fluent setup.
|
|
3420
|
+
* @throws {@link ConfigurationError} When the route id is already registered or empty.
|
|
3421
|
+
*/
|
|
3422
|
+
register(route: MftRoute): this;
|
|
3423
|
+
/**
|
|
3424
|
+
* Removes a route from the registry.
|
|
3425
|
+
*
|
|
3426
|
+
* @param routeId - Route id to remove.
|
|
3427
|
+
* @returns `true` when a route was removed.
|
|
3428
|
+
*/
|
|
3429
|
+
unregister(routeId: string): boolean;
|
|
3430
|
+
/**
|
|
3431
|
+
* Checks whether a route id is registered.
|
|
3432
|
+
*
|
|
3433
|
+
* @param routeId - Route id to inspect.
|
|
3434
|
+
* @returns `true` when a route exists.
|
|
3435
|
+
*/
|
|
3436
|
+
has(routeId: string): boolean;
|
|
3437
|
+
/**
|
|
3438
|
+
* Gets a route definition when registered.
|
|
3439
|
+
*
|
|
3440
|
+
* @param routeId - Route id to retrieve.
|
|
3441
|
+
* @returns The route, or `undefined` when missing.
|
|
3442
|
+
*/
|
|
3443
|
+
get(routeId: string): MftRoute | undefined;
|
|
3444
|
+
/**
|
|
3445
|
+
* Gets a route definition or throws a typed SDK error.
|
|
3446
|
+
*
|
|
3447
|
+
* @param routeId - Route id to retrieve.
|
|
3448
|
+
* @returns The registered route.
|
|
3449
|
+
* @throws {@link ConfigurationError} When no route is registered under the id.
|
|
3450
|
+
*/
|
|
3451
|
+
require(routeId: string): MftRoute;
|
|
3452
|
+
/**
|
|
3453
|
+
* Returns all registered routes in registration order.
|
|
3454
|
+
*
|
|
3455
|
+
* @returns Array of route definitions.
|
|
3456
|
+
*/
|
|
3457
|
+
list(): MftRoute[];
|
|
3458
|
+
/** Returns the number of routes currently registered. */
|
|
3459
|
+
get size(): number;
|
|
3460
|
+
}
|
|
3461
|
+
|
|
3462
|
+
/**
|
|
3463
|
+
* Inbox and outbox conventions for MFT routes.
|
|
3464
|
+
*
|
|
3465
|
+
* Conventions describe well-known directory layouts so callers can model
|
|
3466
|
+
* pickup/drop-off folders without reinventing path math. {@link createInboxRoute}
|
|
3467
|
+
* and {@link createOutboxRoute} produce {@link MftRoute} values that point at
|
|
3468
|
+
* the correct directories and surface helper paths (processed/failed subfolders)
|
|
3469
|
+
* via the route metadata. {@link inboxProcessedPath} / {@link inboxFailedPath}
|
|
3470
|
+
* expose those derived paths for callers that orchestrate post-transfer cleanup.
|
|
3471
|
+
*
|
|
3472
|
+
* @module mft/conventions
|
|
3473
|
+
*/
|
|
3474
|
+
|
|
3475
|
+
/** Default subdirectory used to archive successfully processed inbox files. */
|
|
3476
|
+
declare const DEFAULT_PROCESSED_SUBDIR = "processed";
|
|
3477
|
+
/** Default subdirectory used to quarantine files that failed processing. */
|
|
3478
|
+
declare const DEFAULT_FAILED_SUBDIR = "failed";
|
|
3479
|
+
/** Inbox layout convention. */
|
|
3480
|
+
interface MftInboxConvention {
|
|
3481
|
+
/** Profile used to connect to the inbox provider. */
|
|
3482
|
+
profile: ConnectionProfile;
|
|
3483
|
+
/** Base inbox directory where files arrive. */
|
|
3484
|
+
basePath: string;
|
|
3485
|
+
/** Subdirectory for processed files. Defaults to `"processed"`. */
|
|
3486
|
+
processedSubdir?: string;
|
|
3487
|
+
/** Subdirectory for failed files. Defaults to `"failed"`. */
|
|
3488
|
+
failedSubdir?: string;
|
|
3489
|
+
/** Filter applied to entries discovered under the base path. */
|
|
3490
|
+
filter?: MftRouteFilter;
|
|
3491
|
+
}
|
|
3492
|
+
/** Outbox layout convention. */
|
|
3493
|
+
interface MftOutboxConvention {
|
|
3494
|
+
/** Profile used to connect to the outbox provider. */
|
|
3495
|
+
profile: ConnectionProfile;
|
|
3496
|
+
/** Base outbox directory where files are dropped. */
|
|
3497
|
+
basePath: string;
|
|
3498
|
+
}
|
|
3499
|
+
/** Endpoint shape used by {@link createInboxRoute}/{@link createOutboxRoute}. */
|
|
3500
|
+
interface ConventionEndpoint {
|
|
3501
|
+
/** Profile used to connect to the endpoint provider. */
|
|
3502
|
+
profile: ConnectionProfile;
|
|
3503
|
+
/** Path on the endpoint side. */
|
|
3504
|
+
path: string;
|
|
3505
|
+
}
|
|
3506
|
+
/** Options accepted by {@link createInboxRoute}. */
|
|
3507
|
+
interface CreateInboxRouteOptions {
|
|
3508
|
+
/** Stable route id. */
|
|
3509
|
+
id: string;
|
|
3510
|
+
/** Optional human-friendly route name. */
|
|
3511
|
+
name?: string;
|
|
3512
|
+
/** Optional human-friendly description. */
|
|
3513
|
+
description?: string;
|
|
3514
|
+
/** Inbox convention. */
|
|
3515
|
+
inbox: MftInboxConvention;
|
|
3516
|
+
/** Destination endpoint that receives files from the inbox. */
|
|
3517
|
+
destination: ConventionEndpoint;
|
|
3518
|
+
/** Optional operation override. Defaults to `"copy"`. */
|
|
3519
|
+
operation?: MftRouteOperation;
|
|
3520
|
+
/** Whether the route is enabled. Defaults to `true`. */
|
|
3521
|
+
enabled?: boolean;
|
|
3522
|
+
/** Caller-defined metadata merged into the route. */
|
|
3523
|
+
metadata?: Record<string, unknown>;
|
|
3524
|
+
}
|
|
3525
|
+
/** Options accepted by {@link createOutboxRoute}. */
|
|
3526
|
+
interface CreateOutboxRouteOptions {
|
|
3527
|
+
/** Stable route id. */
|
|
3528
|
+
id: string;
|
|
3529
|
+
/** Optional human-friendly route name. */
|
|
3530
|
+
name?: string;
|
|
3531
|
+
/** Optional human-friendly description. */
|
|
3532
|
+
description?: string;
|
|
3533
|
+
/** Source endpoint that supplies files into the outbox. */
|
|
3534
|
+
source: ConventionEndpoint;
|
|
3535
|
+
/** Outbox convention. */
|
|
3536
|
+
outbox: MftOutboxConvention;
|
|
3537
|
+
/** Optional operation override. Defaults to `"copy"`. */
|
|
3538
|
+
operation?: MftRouteOperation;
|
|
3539
|
+
/** Whether the route is enabled. Defaults to `true`. */
|
|
3540
|
+
enabled?: boolean;
|
|
3541
|
+
/** Caller-defined metadata merged into the route. */
|
|
3542
|
+
metadata?: Record<string, unknown>;
|
|
3543
|
+
}
|
|
3544
|
+
/**
|
|
3545
|
+
* Computes the absolute path used to archive successfully processed files.
|
|
3546
|
+
*
|
|
3547
|
+
* @param inbox - Inbox convention.
|
|
3548
|
+
* @returns Absolute path to the processed subdirectory under {@link MftInboxConvention.basePath}.
|
|
3549
|
+
*/
|
|
3550
|
+
declare function inboxProcessedPath(inbox: MftInboxConvention): string;
|
|
3551
|
+
/**
|
|
3552
|
+
* Computes the absolute path used to quarantine failed files.
|
|
3553
|
+
*
|
|
3554
|
+
* @param inbox - Inbox convention.
|
|
3555
|
+
* @returns Absolute path to the failed subdirectory under {@link MftInboxConvention.basePath}.
|
|
3556
|
+
*/
|
|
3557
|
+
declare function inboxFailedPath(inbox: MftInboxConvention): string;
|
|
3558
|
+
/**
|
|
3559
|
+
* Creates a route that pulls files out of an inbox into a destination directory.
|
|
3560
|
+
*
|
|
3561
|
+
* @param options - Inbox layout, destination endpoint, and optional metadata.
|
|
3562
|
+
* @returns An {@link MftRoute} ready to register with {@link RouteRegistry}.
|
|
3563
|
+
*/
|
|
3564
|
+
declare function createInboxRoute(options: CreateInboxRouteOptions): MftRoute;
|
|
3565
|
+
/**
|
|
3566
|
+
* Creates a route that drops files from a source endpoint into an outbox directory.
|
|
3567
|
+
*
|
|
3568
|
+
* @param options - Source endpoint, outbox layout, and optional metadata.
|
|
3569
|
+
* @returns An {@link MftRoute} ready to register with {@link RouteRegistry}.
|
|
3570
|
+
*/
|
|
3571
|
+
declare function createOutboxRoute(options: CreateOutboxRouteOptions): MftRoute;
|
|
3572
|
+
|
|
3573
|
+
/** Retention policy that evicts entries older than `maxAgeMs`. */
|
|
3574
|
+
interface AgeRetentionPolicy {
|
|
3575
|
+
/** Discriminator. */
|
|
3576
|
+
kind: "age";
|
|
3577
|
+
/** Maximum age before an entry is considered evictable. */
|
|
3578
|
+
maxAgeMs: number;
|
|
3579
|
+
}
|
|
3580
|
+
/** Retention policy that retains the newest `maxCount` entries. */
|
|
3581
|
+
interface CountRetentionPolicy {
|
|
3582
|
+
/** Discriminator. */
|
|
3583
|
+
kind: "count";
|
|
3584
|
+
/** Maximum number of entries to retain. */
|
|
3585
|
+
maxCount: number;
|
|
3586
|
+
/**
|
|
3587
|
+
* Field used to rank entries from newest to oldest.
|
|
3588
|
+
* Defaults to `"modifiedAt"`. `"name"` sorts lexicographically (descending).
|
|
3589
|
+
*/
|
|
3590
|
+
sortBy?: "modifiedAt" | "name";
|
|
3591
|
+
}
|
|
3592
|
+
/** Combined retention policy union accepted by {@link evaluateRetention}. */
|
|
3593
|
+
type RetentionPolicy = AgeRetentionPolicy | CountRetentionPolicy;
|
|
3594
|
+
/** Result returned by {@link evaluateRetention}. */
|
|
3595
|
+
interface RetentionEvaluation {
|
|
3596
|
+
/** Entries that should be retained. */
|
|
3597
|
+
keep: RemoteEntry[];
|
|
3598
|
+
/** Entries selected for eviction. */
|
|
3599
|
+
evict: RemoteEntry[];
|
|
3600
|
+
}
|
|
3601
|
+
/** Options accepted by {@link evaluateRetention}. */
|
|
3602
|
+
interface EvaluateRetentionOptions {
|
|
3603
|
+
/** Listing to evaluate. Directories and symlinks are passed through unchanged. */
|
|
3604
|
+
entries: readonly RemoteEntry[];
|
|
3605
|
+
/** Policy to apply. */
|
|
3606
|
+
policy: RetentionPolicy;
|
|
3607
|
+
/** Reference time used by age policies. Defaults to `new Date()`. */
|
|
3608
|
+
now?: Date;
|
|
3609
|
+
}
|
|
3610
|
+
/**
|
|
3611
|
+
* Splits a listing into retained and evictable entries according to a policy.
|
|
3612
|
+
*
|
|
3613
|
+
* @param options - Listing, policy, and optional reference clock.
|
|
3614
|
+
* @returns The keep/evict split.
|
|
3615
|
+
* @throws {@link ConfigurationError} When the policy is malformed.
|
|
3616
|
+
*/
|
|
3617
|
+
declare function evaluateRetention(options: EvaluateRetentionOptions): RetentionEvaluation;
|
|
3618
|
+
|
|
3619
|
+
/**
|
|
3620
|
+
* MFT audit log primitives and immutable receipt wrapping.
|
|
3621
|
+
*
|
|
3622
|
+
* Audit entries are append-only records of route lifecycle events. They wrap a
|
|
3623
|
+
* frozen copy of the originating {@link TransferReceipt} (when present) so
|
|
3624
|
+
* downstream consumers can rely on the receipt being immutable. The
|
|
3625
|
+
* {@link InMemoryAuditLog} suits unit tests and short-lived processes;
|
|
3626
|
+
* {@link createJsonlAuditLog} streams entries as newline-delimited JSON to a
|
|
3627
|
+
* caller-provided writer for durable logs.
|
|
3628
|
+
*
|
|
3629
|
+
* @module mft/audit
|
|
3630
|
+
*/
|
|
3631
|
+
|
|
3632
|
+
/** Discriminator describing the lifecycle event being recorded. */
|
|
3633
|
+
type MftAuditEntryType = "fire" | "result" | "error";
|
|
3634
|
+
/** Audit record emitted by route execution. */
|
|
3635
|
+
interface MftAuditEntry {
|
|
3636
|
+
/** Stable record id. */
|
|
3637
|
+
id: string;
|
|
3638
|
+
/** Wall-clock time at which the entry was created. */
|
|
3639
|
+
recordedAt: Date;
|
|
3640
|
+
/** Event type discriminator. */
|
|
3641
|
+
type: MftAuditEntryType;
|
|
3642
|
+
/** Route id correlated with the entry. */
|
|
3643
|
+
routeId: string;
|
|
3644
|
+
/** Schedule id when the event originated from a scheduled fire. */
|
|
3645
|
+
scheduleId?: string;
|
|
3646
|
+
/** Frozen receipt for `result` entries. */
|
|
3647
|
+
receipt?: Readonly<TransferReceipt>;
|
|
3648
|
+
/** Serialized error details for `error` entries. */
|
|
3649
|
+
error?: {
|
|
3650
|
+
message: string;
|
|
3651
|
+
name?: string;
|
|
3652
|
+
code?: string;
|
|
3653
|
+
};
|
|
3654
|
+
/** Caller-defined metadata retained for diagnostics. */
|
|
3655
|
+
metadata?: Record<string, unknown>;
|
|
3656
|
+
}
|
|
3657
|
+
/** Append-only audit log surface. */
|
|
3658
|
+
interface MftAuditLog {
|
|
3659
|
+
/** Records a new audit entry. */
|
|
3660
|
+
record(entry: MftAuditEntry): Promise<void>;
|
|
3661
|
+
/** Returns recorded entries in insertion order. */
|
|
3662
|
+
list(): Promise<readonly MftAuditEntry[]>;
|
|
3663
|
+
}
|
|
3664
|
+
/** In-memory implementation of {@link MftAuditLog}. */
|
|
3665
|
+
declare class InMemoryAuditLog implements MftAuditLog {
|
|
3666
|
+
private readonly entries;
|
|
3667
|
+
/** Records a new audit entry. */
|
|
3668
|
+
record(entry: MftAuditEntry): Promise<void>;
|
|
3669
|
+
/** Returns recorded entries in insertion order. */
|
|
3670
|
+
list(): Promise<readonly MftAuditEntry[]>;
|
|
3671
|
+
/** Drops all recorded entries. */
|
|
3672
|
+
clear(): void;
|
|
3673
|
+
/** Number of currently recorded entries. */
|
|
3674
|
+
get size(): number;
|
|
3675
|
+
}
|
|
3676
|
+
/** Output sink consumed by {@link createJsonlAuditLog}. */
|
|
3677
|
+
interface JsonlWriter {
|
|
3678
|
+
/** Writes a UTF-8 line that already includes a trailing newline. */
|
|
3679
|
+
write(line: string): Promise<void>;
|
|
3680
|
+
}
|
|
3681
|
+
/**
|
|
3682
|
+
* Creates an audit log that streams records as newline-delimited JSON.
|
|
3683
|
+
*
|
|
3684
|
+
* `list()` is not supported by the JSONL writer because the durable form is
|
|
3685
|
+
* append-only on disk. Callers that need to read back entries should pair the
|
|
3686
|
+
* JSONL log with an {@link InMemoryAuditLog} via {@link composeAuditLogs}.
|
|
3687
|
+
*
|
|
3688
|
+
* @param writer - Sink that receives one JSON line per record.
|
|
3689
|
+
* @returns A log that writes JSONL on every `record` call.
|
|
3690
|
+
*/
|
|
3691
|
+
declare function createJsonlAuditLog(writer: JsonlWriter): MftAuditLog;
|
|
3692
|
+
/**
|
|
3693
|
+
* Combines multiple audit logs into a single fan-out log.
|
|
3694
|
+
*
|
|
3695
|
+
* @param logs - Logs that should each receive every recorded entry.
|
|
3696
|
+
* @returns A composite log whose `record` writes to all targets in order and
|
|
3697
|
+
* whose `list` returns the first non-empty result.
|
|
3698
|
+
*/
|
|
3699
|
+
declare function composeAuditLogs(...logs: readonly MftAuditLog[]): MftAuditLog;
|
|
3700
|
+
/**
|
|
3701
|
+
* Returns a deeply frozen copy of a transfer receipt.
|
|
3702
|
+
*
|
|
3703
|
+
* @param receipt - Receipt to freeze.
|
|
3704
|
+
* @returns Read-only copy safe to retain in audit records.
|
|
3705
|
+
*/
|
|
3706
|
+
declare function freezeReceipt(receipt: TransferReceipt): Readonly<TransferReceipt>;
|
|
3707
|
+
/**
|
|
3708
|
+
* Serializes an unknown error into the audit-friendly `{ message, name, code }` shape.
|
|
3709
|
+
*
|
|
3710
|
+
* @param error - Error value thrown by the route runner.
|
|
3711
|
+
* @returns A plain object suitable for {@link MftAuditEntry.error}.
|
|
3712
|
+
*/
|
|
3713
|
+
declare function summarizeError(error: unknown): {
|
|
3714
|
+
message: string;
|
|
3715
|
+
name?: string;
|
|
3716
|
+
code?: string;
|
|
3717
|
+
};
|
|
3718
|
+
|
|
3719
|
+
/** Webhook destination. */
|
|
3720
|
+
interface WebhookTarget {
|
|
3721
|
+
/** Absolute HTTP(S) URL that receives `POST` deliveries. */
|
|
3722
|
+
url: string;
|
|
3723
|
+
/** Additional headers merged into every request. */
|
|
3724
|
+
headers?: Record<string, string>;
|
|
3725
|
+
/** Shared secret used to compute the HMAC signature header. */
|
|
3726
|
+
secret?: string;
|
|
3727
|
+
/** Audit entry types to deliver. Defaults to all types. */
|
|
3728
|
+
types?: readonly MftAuditEntry["type"][];
|
|
3729
|
+
}
|
|
3730
|
+
/** Retry policy for webhook deliveries. */
|
|
3731
|
+
interface WebhookRetryPolicy {
|
|
3732
|
+
/** Maximum number of attempts including the initial request. Defaults to 3. */
|
|
3733
|
+
maxAttempts?: number;
|
|
3734
|
+
/** Base delay in milliseconds. Defaults to 250. */
|
|
3735
|
+
baseDelayMs?: number;
|
|
3736
|
+
/** Maximum delay in milliseconds. Defaults to 5000. */
|
|
3737
|
+
maxDelayMs?: number;
|
|
3738
|
+
}
|
|
3739
|
+
/** Options accepted by {@link dispatchWebhook}. */
|
|
3740
|
+
interface DispatchWebhookOptions {
|
|
3741
|
+
/** Webhook destination. */
|
|
3742
|
+
target: WebhookTarget;
|
|
3743
|
+
/** Audit entry payload to deliver. */
|
|
3744
|
+
payload: MftAuditEntry;
|
|
3745
|
+
/** Optional fetch implementation. Defaults to the global `fetch`. */
|
|
3746
|
+
fetch?: typeof globalThis.fetch;
|
|
3747
|
+
/** Retry policy override. */
|
|
3748
|
+
retry?: WebhookRetryPolicy;
|
|
3749
|
+
/** Abort signal forwarded to fetch. */
|
|
3750
|
+
signal?: AbortSignal;
|
|
3751
|
+
/** Sleep used between retries. Defaults to `setTimeout`. */
|
|
3752
|
+
sleep?: (delayMs: number) => Promise<void>;
|
|
3753
|
+
}
|
|
3754
|
+
/** Result returned by {@link dispatchWebhook}. */
|
|
3755
|
+
interface DispatchWebhookResult {
|
|
3756
|
+
/** Whether the delivery succeeded. */
|
|
3757
|
+
delivered: boolean;
|
|
3758
|
+
/** HTTP status of the final attempt. */
|
|
3759
|
+
status: number;
|
|
3760
|
+
/** Number of attempts performed. */
|
|
3761
|
+
attempts: number;
|
|
3762
|
+
}
|
|
3763
|
+
/** Signature payload produced by {@link signWebhookPayload}. */
|
|
3764
|
+
interface WebhookSignature {
|
|
3765
|
+
/** Hex-encoded HMAC-SHA256 digest. */
|
|
3766
|
+
digest: string;
|
|
3767
|
+
/** ISO-8601 timestamp included in the signed prefix. */
|
|
3768
|
+
timestamp: string;
|
|
3769
|
+
}
|
|
3770
|
+
/**
|
|
3771
|
+
* Computes the HMAC-SHA256 signature for a webhook payload.
|
|
3772
|
+
*
|
|
3773
|
+
* @param payload - Raw JSON string of the webhook body.
|
|
3774
|
+
* @param secret - Shared secret.
|
|
3775
|
+
* @param timestamp - Optional fixed timestamp. Defaults to `new Date().toISOString()`.
|
|
3776
|
+
* @returns The signature parts that should be included on the request.
|
|
3777
|
+
*/
|
|
3778
|
+
declare function signWebhookPayload(payload: string, secret: string, timestamp?: string): WebhookSignature;
|
|
3779
|
+
/**
|
|
3780
|
+
* Dispatches a single webhook payload with bounded retries.
|
|
3781
|
+
*
|
|
3782
|
+
* @param options - Target, payload, fetch impl, retry policy, abort signal.
|
|
3783
|
+
* @returns The delivery outcome.
|
|
3784
|
+
*/
|
|
3785
|
+
declare function dispatchWebhook(options: DispatchWebhookOptions): Promise<DispatchWebhookResult>;
|
|
3786
|
+
/** Options accepted by {@link createWebhookAuditLog}. */
|
|
3787
|
+
interface CreateWebhookAuditLogOptions {
|
|
3788
|
+
/** Webhook destination. */
|
|
3789
|
+
target: WebhookTarget;
|
|
3790
|
+
/** Optional fetch implementation. */
|
|
3791
|
+
fetch?: typeof globalThis.fetch;
|
|
3792
|
+
/** Retry policy override. */
|
|
3793
|
+
retry?: WebhookRetryPolicy;
|
|
3794
|
+
/** Sleep used between retries. */
|
|
3795
|
+
sleep?: (delayMs: number) => Promise<void>;
|
|
3796
|
+
/** Observer fired for every delivery attempt outcome. */
|
|
3797
|
+
onDelivery?: (input: {
|
|
3798
|
+
entry: MftAuditEntry;
|
|
3799
|
+
result: DispatchWebhookResult;
|
|
3800
|
+
}) => void;
|
|
3801
|
+
}
|
|
3802
|
+
/**
|
|
3803
|
+
* Wraps a webhook target as an {@link MftAuditLog}.
|
|
3804
|
+
*
|
|
3805
|
+
* Entries whose `type` is not in `target.types` are silently dropped. `list()`
|
|
3806
|
+
* always returns an empty array because webhook deliveries are not buffered.
|
|
3807
|
+
*
|
|
3808
|
+
* @param options - Webhook target plus optional retry/observer hooks.
|
|
3809
|
+
* @returns An audit log that delivers each `record` call to the webhook.
|
|
3810
|
+
*/
|
|
3811
|
+
declare function createWebhookAuditLog(options: CreateWebhookAuditLogOptions): MftAuditLog;
|
|
3812
|
+
|
|
3813
|
+
/** Repeats every `everyMs` milliseconds from a fixed reference point. */
|
|
3814
|
+
interface IntervalScheduleTrigger {
|
|
3815
|
+
/** Discriminator. */
|
|
3816
|
+
kind: "interval";
|
|
3817
|
+
/** Period between fires in milliseconds. Must be a positive finite number. */
|
|
3818
|
+
everyMs: number;
|
|
3819
|
+
/**
|
|
3820
|
+
* Reference time used to anchor the interval. Defaults to the scheduler start time.
|
|
3821
|
+
* Fires occur at `anchor + n * everyMs` for the smallest `n` strictly after `from`.
|
|
3822
|
+
*/
|
|
3823
|
+
anchor?: Date;
|
|
3824
|
+
}
|
|
3825
|
+
/** Fires at times matching a 5-field cron expression (minute hour dom month dow). */
|
|
3826
|
+
interface CronScheduleTrigger {
|
|
3827
|
+
/** Discriminator. */
|
|
3828
|
+
kind: "cron";
|
|
3829
|
+
/** 5-field cron expression: `minute hour day-of-month month day-of-week`. */
|
|
3830
|
+
expression: string;
|
|
3831
|
+
/** Timezone interpretation. Defaults to `"utc"`. */
|
|
3832
|
+
timezone?: "utc" | "local";
|
|
3833
|
+
}
|
|
3834
|
+
/** Combined trigger union accepted by {@link MftSchedule}. */
|
|
3835
|
+
type MftScheduleTrigger = IntervalScheduleTrigger | CronScheduleTrigger;
|
|
3836
|
+
/** Declarative schedule binding a route id to a trigger. */
|
|
3837
|
+
interface MftSchedule {
|
|
3838
|
+
/** Stable schedule identifier. */
|
|
3839
|
+
id: string;
|
|
3840
|
+
/** Route id the schedule fires through {@link runRoute}. */
|
|
3841
|
+
routeId: string;
|
|
3842
|
+
/** Trigger definition. */
|
|
3843
|
+
trigger: MftScheduleTrigger;
|
|
3844
|
+
/** Whether the schedule is enabled. Defaults to `true`. */
|
|
3845
|
+
enabled?: boolean;
|
|
3846
|
+
/** Caller-defined metadata retained for audit records and diagnostics. */
|
|
3847
|
+
metadata?: Record<string, unknown>;
|
|
3848
|
+
}
|
|
3849
|
+
/**
|
|
3850
|
+
* Validates a schedule and returns it for fluent setup.
|
|
3851
|
+
*
|
|
3852
|
+
* @param schedule - Schedule to validate.
|
|
3853
|
+
* @returns The same schedule instance.
|
|
3854
|
+
* @throws {@link ConfigurationError} When the schedule is malformed.
|
|
3855
|
+
*/
|
|
3856
|
+
declare function validateSchedule(schedule: MftSchedule): MftSchedule;
|
|
3857
|
+
/**
|
|
3858
|
+
* Computes the next fire time for a schedule strictly after `from`.
|
|
3859
|
+
*
|
|
3860
|
+
* @param schedule - Schedule whose next fire time should be computed.
|
|
3861
|
+
* @param from - Reference time. Defaults to the current wall clock.
|
|
3862
|
+
* @returns The next fire time, or `undefined` when no future fire exists.
|
|
3863
|
+
*/
|
|
3864
|
+
declare function nextScheduleFireAt(schedule: MftSchedule, from?: Date): Date | undefined;
|
|
3865
|
+
|
|
3866
|
+
/** Mutable in-memory registry of MFT schedules. */
|
|
3867
|
+
declare class ScheduleRegistry {
|
|
3868
|
+
private readonly schedules;
|
|
3869
|
+
/**
|
|
3870
|
+
* Creates a registry and optionally seeds it with schedules.
|
|
3871
|
+
*
|
|
3872
|
+
* @param schedules - Schedules to register immediately.
|
|
3873
|
+
*/
|
|
3874
|
+
constructor(schedules?: Iterable<MftSchedule>);
|
|
3875
|
+
/**
|
|
3876
|
+
* Registers a schedule.
|
|
3877
|
+
*
|
|
3878
|
+
* @param schedule - Schedule to add.
|
|
3879
|
+
* @returns This registry for fluent setup.
|
|
3880
|
+
* @throws {@link ConfigurationError} When the schedule is malformed or a duplicate.
|
|
3881
|
+
*/
|
|
3882
|
+
register(schedule: MftSchedule): this;
|
|
3883
|
+
/**
|
|
3884
|
+
* Removes a schedule.
|
|
3885
|
+
*
|
|
3886
|
+
* @param scheduleId - Schedule id to remove.
|
|
3887
|
+
* @returns `true` when a schedule was removed.
|
|
3888
|
+
*/
|
|
3889
|
+
unregister(scheduleId: string): boolean;
|
|
3890
|
+
/** Checks whether a schedule id is registered. */
|
|
3891
|
+
has(scheduleId: string): boolean;
|
|
3892
|
+
/** Gets a schedule when registered. */
|
|
3893
|
+
get(scheduleId: string): MftSchedule | undefined;
|
|
3894
|
+
/**
|
|
3895
|
+
* Gets a schedule or throws when missing.
|
|
3896
|
+
*
|
|
3897
|
+
* @param scheduleId - Schedule id to retrieve.
|
|
3898
|
+
* @returns The schedule.
|
|
3899
|
+
* @throws {@link ConfigurationError} When no schedule is registered under the id.
|
|
3900
|
+
*/
|
|
3901
|
+
require(scheduleId: string): MftSchedule;
|
|
3902
|
+
/** Returns all schedules in registration order. */
|
|
3903
|
+
list(): MftSchedule[];
|
|
3904
|
+
/** Number of schedules currently registered. */
|
|
3905
|
+
get size(): number;
|
|
3906
|
+
}
|
|
3907
|
+
|
|
3908
|
+
/**
|
|
3909
|
+
* Schedule runner that fires MFT routes through {@link runRoute} on a clock.
|
|
3910
|
+
*
|
|
3911
|
+
* The scheduler is timer-injectable so unit tests can drive it deterministically.
|
|
3912
|
+
* It watches the configured {@link ScheduleRegistry}, computes the next fire time
|
|
3913
|
+
* per schedule via {@link nextScheduleFireAt}, and dispatches matched routes
|
|
3914
|
+
* through the supplied runner. Failures from individual fires are surfaced via
|
|
3915
|
+
* `onError` and never abort the loop.
|
|
3916
|
+
*
|
|
3917
|
+
* @module mft/MftScheduler
|
|
3918
|
+
*/
|
|
3919
|
+
|
|
3920
|
+
/** Function shape used to fire a route. Defaults to {@link runRoute}. */
|
|
3921
|
+
type ScheduleRouteRunner = (input: {
|
|
3922
|
+
client: TransferClient;
|
|
3923
|
+
route: MftRoute;
|
|
3924
|
+
schedule: MftSchedule;
|
|
3925
|
+
signal: AbortSignal;
|
|
3926
|
+
}) => Promise<TransferReceipt>;
|
|
3927
|
+
/** Timer hooks injected by tests so fake clocks stay deterministic. */
|
|
3928
|
+
interface ScheduleTimerHooks {
|
|
3929
|
+
/** Returns the current wall-clock time. Defaults to `() => new Date()`. */
|
|
3930
|
+
now?: () => Date;
|
|
3931
|
+
/** Schedules a one-shot callback after `delayMs`. Defaults to `setTimeout`. */
|
|
3932
|
+
setTimer?: (callback: () => void, delayMs: number) => unknown;
|
|
3933
|
+
/** Cancels a pending timer handle returned by `setTimer`. Defaults to `clearTimeout`. */
|
|
3934
|
+
clearTimer?: (handle: unknown) => void;
|
|
3935
|
+
}
|
|
3936
|
+
/** Construction options for {@link MftScheduler}. */
|
|
3937
|
+
interface MftSchedulerOptions {
|
|
3938
|
+
/** Transfer client passed to each fired route. */
|
|
3939
|
+
client: TransferClient;
|
|
3940
|
+
/** Routes registry resolved by `route id`. */
|
|
3941
|
+
routes: RouteRegistry;
|
|
3942
|
+
/** Schedules registry watched by the scheduler. */
|
|
3943
|
+
schedules: ScheduleRegistry;
|
|
3944
|
+
/** Optional runner override. Defaults to invoking {@link runRoute}. */
|
|
3945
|
+
runner?: ScheduleRouteRunner;
|
|
3946
|
+
/** Observer fired before each route is dispatched. */
|
|
3947
|
+
onFire?: (input: {
|
|
3948
|
+
schedule: MftSchedule;
|
|
3949
|
+
firedAt: Date;
|
|
3950
|
+
}) => void;
|
|
3951
|
+
/** Observer fired after a successful route execution. */
|
|
3952
|
+
onResult?: (input: {
|
|
3953
|
+
schedule: MftSchedule;
|
|
3954
|
+
receipt: TransferReceipt;
|
|
3955
|
+
}) => void;
|
|
3956
|
+
/** Observer fired when a single route fire fails. */
|
|
3957
|
+
onError?: (input: {
|
|
3958
|
+
schedule: MftSchedule;
|
|
3959
|
+
error: unknown;
|
|
3960
|
+
}) => void;
|
|
3961
|
+
/** Timer/clock injection used by tests. */
|
|
3962
|
+
timer?: ScheduleTimerHooks;
|
|
3963
|
+
}
|
|
3964
|
+
/** Runs routes on configured schedules. */
|
|
3965
|
+
declare class MftScheduler {
|
|
3966
|
+
private readonly options;
|
|
3967
|
+
private readonly now;
|
|
3968
|
+
private readonly setTimer;
|
|
3969
|
+
private readonly clearTimer;
|
|
3970
|
+
private readonly timers;
|
|
3971
|
+
private readonly inflight;
|
|
3972
|
+
private running;
|
|
3973
|
+
private startedAt;
|
|
3974
|
+
/**
|
|
3975
|
+
* Creates a scheduler bound to a transfer client and registries.
|
|
3976
|
+
*
|
|
3977
|
+
* @param options - Client, registries, optional runner, observers, and timer hooks.
|
|
3978
|
+
*/
|
|
3979
|
+
constructor(options: MftSchedulerOptions);
|
|
3980
|
+
/** Whether the scheduler is currently running. */
|
|
3981
|
+
get isRunning(): boolean;
|
|
3982
|
+
/** Starts the scheduler. No-op when already running. */
|
|
3983
|
+
start(): void;
|
|
3984
|
+
/**
|
|
3985
|
+
* Stops the scheduler and aborts in-flight route executions.
|
|
3986
|
+
*
|
|
3987
|
+
* @returns A promise that resolves once all in-flight fires have settled.
|
|
3988
|
+
*/
|
|
3989
|
+
stop(): Promise<void>;
|
|
3990
|
+
private scheduleNextFire;
|
|
3991
|
+
private fire;
|
|
3992
|
+
}
|
|
3993
|
+
|
|
3994
|
+
/**
|
|
3995
|
+
* Approval gates that pause routes until an out-of-band reviewer signs off.
|
|
3996
|
+
*
|
|
3997
|
+
* Approval requests are pure data records held by an in-memory registry. The
|
|
3998
|
+
* {@link ApprovalGate} executor wraps a route runner so dispatch is deferred
|
|
3999
|
+
* until {@link ApprovalRegistry.approve} is called. Rejection short-circuits
|
|
4000
|
+
* the run with an {@link ApprovalRejectedError}.
|
|
4001
|
+
*
|
|
4002
|
+
* @module mft/approvals
|
|
4003
|
+
*/
|
|
4004
|
+
|
|
4005
|
+
/** Lifecycle status of an approval request. */
|
|
4006
|
+
type ApprovalStatus = "pending" | "approved" | "rejected";
|
|
4007
|
+
/** Approval request record. */
|
|
4008
|
+
interface ApprovalRequest {
|
|
4009
|
+
/** Stable approval id. */
|
|
4010
|
+
id: string;
|
|
4011
|
+
/** Route id awaiting approval. */
|
|
4012
|
+
routeId: string;
|
|
4013
|
+
/** Wall-clock time at which the request was created. */
|
|
4014
|
+
requestedAt: Date;
|
|
4015
|
+
/** Current status. */
|
|
4016
|
+
status: ApprovalStatus;
|
|
4017
|
+
/** Wall-clock time at which the status changed. */
|
|
4018
|
+
resolvedAt?: Date;
|
|
4019
|
+
/** Identifier of the principal that resolved the request. */
|
|
4020
|
+
resolvedBy?: string;
|
|
4021
|
+
/** Caller-defined reason recorded with the resolution. */
|
|
4022
|
+
reason?: string;
|
|
4023
|
+
/** Caller-defined metadata retained for diagnostics. */
|
|
4024
|
+
metadata?: Record<string, unknown>;
|
|
4025
|
+
}
|
|
4026
|
+
/** Error raised when an approval request is rejected. */
|
|
4027
|
+
declare class ApprovalRejectedError extends ZeroTransferError {
|
|
4028
|
+
readonly request: ApprovalRequest;
|
|
4029
|
+
/**
|
|
4030
|
+
* Creates a rejection error.
|
|
4031
|
+
*
|
|
4032
|
+
* @param request - The rejected approval request.
|
|
4033
|
+
*/
|
|
4034
|
+
constructor(request: ApprovalRequest);
|
|
4035
|
+
}
|
|
4036
|
+
/** In-memory approval registry. */
|
|
4037
|
+
declare class ApprovalRegistry {
|
|
4038
|
+
private readonly requests;
|
|
4039
|
+
private readonly pending;
|
|
4040
|
+
/**
|
|
4041
|
+
* Creates a new request and returns a promise that resolves when the request
|
|
4042
|
+
* transitions out of `"pending"` state.
|
|
4043
|
+
*
|
|
4044
|
+
* @param input - Request seed (id, routeId, optional metadata).
|
|
4045
|
+
* @param now - Reference clock used to stamp `requestedAt`.
|
|
4046
|
+
* @returns The created request and a promise tracking its resolution.
|
|
4047
|
+
*/
|
|
4048
|
+
create(input: {
|
|
4049
|
+
id: string;
|
|
4050
|
+
routeId: string;
|
|
4051
|
+
metadata?: Record<string, unknown>;
|
|
4052
|
+
}, now?: Date): {
|
|
4053
|
+
request: ApprovalRequest;
|
|
4054
|
+
settled: Promise<ApprovalRequest>;
|
|
4055
|
+
};
|
|
4056
|
+
/**
|
|
4057
|
+
* Approves a pending request.
|
|
4058
|
+
*
|
|
4059
|
+
* @param id - Approval id to resolve.
|
|
4060
|
+
* @param input - Optional reviewer identifier and reason.
|
|
4061
|
+
* @param now - Reference clock used to stamp `resolvedAt`.
|
|
4062
|
+
* @returns The updated approval record.
|
|
4063
|
+
*/
|
|
4064
|
+
approve(id: string, input?: {
|
|
4065
|
+
resolvedBy?: string;
|
|
4066
|
+
reason?: string;
|
|
4067
|
+
}, now?: Date): ApprovalRequest;
|
|
4068
|
+
/**
|
|
4069
|
+
* Rejects a pending request.
|
|
4070
|
+
*
|
|
4071
|
+
* @param id - Approval id to resolve.
|
|
4072
|
+
* @param input - Optional reviewer identifier and reason.
|
|
4073
|
+
* @param now - Reference clock used to stamp `resolvedAt`.
|
|
4074
|
+
* @returns The updated approval record.
|
|
4075
|
+
*/
|
|
4076
|
+
reject(id: string, input?: {
|
|
4077
|
+
resolvedBy?: string;
|
|
4078
|
+
reason?: string;
|
|
4079
|
+
}, now?: Date): ApprovalRequest;
|
|
4080
|
+
/** Looks up a request by id. */
|
|
4081
|
+
get(id: string): ApprovalRequest | undefined;
|
|
4082
|
+
/** Lists pending requests in insertion order. */
|
|
4083
|
+
listPending(): ApprovalRequest[];
|
|
4084
|
+
/** Lists every request ever created. */
|
|
4085
|
+
list(): ApprovalRequest[];
|
|
4086
|
+
private resolve;
|
|
4087
|
+
}
|
|
4088
|
+
/** Options accepted by {@link createApprovalGate}. */
|
|
4089
|
+
interface CreateApprovalGateOptions {
|
|
4090
|
+
/** Registry that holds approval requests. */
|
|
4091
|
+
registry: ApprovalRegistry;
|
|
4092
|
+
/** Underlying runner that executes the route once approval is granted. */
|
|
4093
|
+
runner: ScheduleRouteRunner;
|
|
4094
|
+
/** Function that derives an approval id from each route invocation. */
|
|
4095
|
+
approvalId: (input: {
|
|
4096
|
+
route: MftRoute;
|
|
4097
|
+
}) => string;
|
|
4098
|
+
/** Optional clock used for `requestedAt`/`resolvedAt`. */
|
|
4099
|
+
now?: () => Date;
|
|
4100
|
+
/** Observer fired when a new approval request is created. */
|
|
4101
|
+
onRequested?: (request: ApprovalRequest) => void;
|
|
4102
|
+
}
|
|
4103
|
+
/**
|
|
4104
|
+
* Wraps a route runner with an approval gate.
|
|
4105
|
+
*
|
|
4106
|
+
* The returned runner creates an approval request, waits for resolution, and
|
|
4107
|
+
* dispatches the underlying runner only when the request is approved. Rejection
|
|
4108
|
+
* surfaces an {@link ApprovalRejectedError}.
|
|
4109
|
+
*
|
|
4110
|
+
* @param options - Registry, downstream runner, approval-id derivation, hooks.
|
|
4111
|
+
* @returns A {@link ScheduleRouteRunner} that gates execution behind approval.
|
|
4112
|
+
*/
|
|
4113
|
+
declare function createApprovalGate(options: CreateApprovalGateOptions): ScheduleRouteRunner;
|
|
4114
|
+
|
|
4115
|
+
/** Compiled cron field as a sorted set of allowed integer values. */
|
|
4116
|
+
type CronField = readonly number[];
|
|
4117
|
+
/** Compiled cron expression. */
|
|
4118
|
+
interface CronExpression {
|
|
4119
|
+
/** Minutes 0-59. */
|
|
4120
|
+
minute: CronField;
|
|
4121
|
+
/** Hours 0-23. */
|
|
4122
|
+
hour: CronField;
|
|
4123
|
+
/** Days of month 1-31. */
|
|
4124
|
+
dayOfMonth: CronField;
|
|
4125
|
+
/** Months 1-12. */
|
|
4126
|
+
month: CronField;
|
|
4127
|
+
/** Days of week 0-6 (Sunday = 0). */
|
|
4128
|
+
dayOfWeek: CronField;
|
|
4129
|
+
/** Whether day-of-month was specified explicitly. */
|
|
4130
|
+
hasDomConstraint: boolean;
|
|
4131
|
+
/** Whether day-of-week was specified explicitly. */
|
|
4132
|
+
hasDowConstraint: boolean;
|
|
4133
|
+
}
|
|
4134
|
+
/**
|
|
4135
|
+
* Parses a 5-field cron expression.
|
|
4136
|
+
*
|
|
4137
|
+
* @param expression - Whitespace-separated 5-field cron expression.
|
|
4138
|
+
* @returns Compiled representation usable by {@link nextCronFireAt}.
|
|
4139
|
+
* @throws {@link ConfigurationError} When the expression is malformed.
|
|
4140
|
+
*/
|
|
4141
|
+
declare function parseCronExpression(expression: string): CronExpression;
|
|
4142
|
+
/**
|
|
4143
|
+
* Computes the next time at which a cron expression fires strictly after `from`.
|
|
4144
|
+
*
|
|
4145
|
+
* @param expression - Compiled cron expression.
|
|
4146
|
+
* @param from - Reference time.
|
|
4147
|
+
* @param timezone - Either `"utc"` or `"local"`. Defaults to `"utc"`.
|
|
4148
|
+
* @returns The next fire time, or `undefined` when no fire occurs within five years.
|
|
4149
|
+
*/
|
|
4150
|
+
declare function nextCronFireAt(expression: CronExpression, from: Date, timezone?: "utc" | "local"): Date | undefined;
|
|
4151
|
+
|
|
4152
|
+
/**
|
|
4153
|
+
* Validates that an FTP command argument cannot inject additional command lines.
|
|
4154
|
+
*
|
|
4155
|
+
* @param value - Argument value to validate.
|
|
4156
|
+
* @param label - Human-readable argument label used in error messages.
|
|
4157
|
+
* @returns The original value when it is safe.
|
|
4158
|
+
* @throws {@link ConfigurationError} When the value contains CR or LF characters.
|
|
4159
|
+
*/
|
|
4160
|
+
declare function assertSafeFtpArgument(value: string, label?: string): string;
|
|
4161
|
+
/**
|
|
4162
|
+
* Normalizes a remote path using POSIX-style separators without escaping absolute roots.
|
|
4163
|
+
*
|
|
4164
|
+
* @param input - Remote path that may contain duplicate separators or dot segments.
|
|
4165
|
+
* @returns A normalized remote path, `/` for absolute root, or `.` for an empty relative path.
|
|
4166
|
+
* @throws {@link ConfigurationError} When the input contains unsafe CR or LF characters.
|
|
4167
|
+
*/
|
|
4168
|
+
declare function normalizeRemotePath(input: string): string;
|
|
4169
|
+
/**
|
|
4170
|
+
* Joins remote path segments and normalizes the result.
|
|
4171
|
+
*
|
|
4172
|
+
* @param segments - Remote path segments to concatenate.
|
|
4173
|
+
* @returns A normalized remote path.
|
|
4174
|
+
* @throws {@link ConfigurationError} When any joined segment contains unsafe characters.
|
|
4175
|
+
*/
|
|
4176
|
+
declare function joinRemotePath(...segments: string[]): string;
|
|
4177
|
+
/**
|
|
4178
|
+
* Extracts the final name segment from a normalized remote path.
|
|
4179
|
+
*
|
|
4180
|
+
* @param input - Remote path to inspect.
|
|
4181
|
+
* @returns The final path segment, or `/` when the input is the absolute root.
|
|
4182
|
+
* @throws {@link ConfigurationError} When the input contains unsafe characters.
|
|
4183
|
+
*/
|
|
4184
|
+
declare function basenameRemotePath(input: string): string;
|
|
4185
|
+
|
|
4186
|
+
export { AbortError, type AgeRetentionPolicy, ApprovalRegistry, ApprovalRejectedError, type ApprovalRequest, type ApprovalStatus, type AtomicDeployActivateOperation, type AtomicDeployActivateStep, type AtomicDeployPlan, type AtomicDeployPruneStep, type AtomicDeployStrategy, type AuthenticationCapability, AuthenticationError, AuthorizationError, type AzureBlobProviderOptions, type BandwidthSleep, type BandwidthThrottle, type BandwidthThrottleOptions, type Base64EnvSecretSource, type BuiltInProviderId, type BuiltinCapabilityMatrixEntry, type BuiltinProviderMatrixId, CLASSIC_PROVIDER_IDS, type CapabilitySet, type ChecksumCapability, type ClassicProviderId, type ClientDiagnostics, type CompareRemoteManifestsOptions, ConfigurationError, type ConnectionDiagnosticTimings, type ConnectionDiagnosticsResult, ConnectionError, type ConnectionProfile, type ConventionEndpoint, type CopyBetweenOptions, type CountRetentionPolicy, type CreateApprovalGateOptions, type CreateAtomicDeployPlanOptions, type CreateInboxRouteOptions, type CreateOutboxRouteOptions, type CreateRemoteBrowserOptions, type CreateRemoteManifestOptions, type CreateSyncPlanOptions, type CreateWebhookAuditLogOptions, type CronExpression, type CronField, type CronScheduleTrigger, DEFAULT_FAILED_SUBDIR, DEFAULT_PROCESSED_SUBDIR, type DiffRemoteTreesOptions, type DispatchWebhookOptions, type DispatchWebhookResult, type DownloadFileOptions, type DropboxProviderOptions, type EnvSecretSource, type EvaluateRetentionOptions, type FileSecretSource, type FileZillaSite, type FriendlyTransferOptions, type FtpFeatures, type FtpPassiveHostStrategy, type FtpProviderOptions, type FtpReplyErrorInput, type FtpResponse, FtpResponseParser, type FtpResponseStatus, type FtpsDataProtection, type FtpsMode, type FtpsProviderOptions, type GcsProviderOptions, type GoogleDriveProviderOptions, type HttpFetch, type HttpProviderOptions, type ImportFileZillaSitesResult, type ImportOpenSshConfigOptions, type ImportOpenSshConfigResult, type ImportWinScpSessionsResult, InMemoryAuditLog, type IntervalScheduleTrigger, type JsonlWriter, type KnownHostsEntry, type KnownHostsMarker, type ListOptions, type LocalProviderOptions, type LogLevel, type LogRecord, type LogRecordInput, type LoggerMethod, type MemoryProviderEntry, type MemoryProviderOptions, type MetadataCapability, type MftAuditEntry, type MftAuditEntryType, type MftAuditLog, type MftInboxConvention, type MftOutboxConvention, type MftRoute, type MftRouteEndpoint, type MftRouteFilter, type MftRouteOperation, type MftSchedule, type MftScheduleTrigger, MftScheduler, type MftSchedulerOptions, type OAuthAccessToken, type OAuthRefreshCallback, type OAuthTokenSecretSourceOptions, type OneDriveProviderOptions, type OpenSshConfigEntry, ParseError, PathAlreadyExistsError, PathNotFoundError, PermissionDeniedError, type ProgressEventInput, ProtocolError, type AuthenticationCapability as ProviderAuthenticationCapability, type CapabilitySet as ProviderCapabilities, type ChecksumCapability as ProviderChecksumCapability, type ProviderFactory, type ProviderId, type MetadataCapability as ProviderMetadataCapability, ProviderRegistry, type ProviderSelection, type ProviderTransferEndpointRole, type ProviderTransferExecutorOptions, type ProviderTransferOperations, type ProviderTransferReadRequest, type ProviderTransferReadResult, type ProviderTransferRequest, type ProviderTransferSessionResolver, type ProviderTransferSessionResolverInput, type ProviderTransferWriteRequest, type ProviderTransferWriteResult, REDACTED, REMOTE_MANIFEST_FORMAT_VERSION, type RemoteBreadcrumb, type RemoteBrowser, type RemoteBrowserFilter, type RemoteBrowserSnapshot, type RemoteEntry, type RemoteEntrySortKey, type RemoteEntrySortOrder, type RemoteEntryType, type RemoteFileAdapter, type RemoteFileEndpoint, type RemoteFileSystem, type RemoteManifest, type RemoteManifestEntry, type RemotePermissions, type RemoteProtocol, type RemoteStat, type RemoteTreeDiff, type RemoteTreeDiffEntry, type RemoteTreeDiffReason, type RemoteTreeDiffStatus, type RemoteTreeDiffSummary, type RemoteTreeEntry, type RemoteTreeFilter, type ResolveSecretOptions, type ResolvedConnectionProfile, type ResolvedOpenSshHost, type ResolvedSshProfile, type ResolvedTlsProfile, type RetentionEvaluation, type RetentionPolicy, RouteRegistry, type RunConnectionDiagnosticsOptions, type RunRouteOptions, type S3MultipartCheckpoint, type S3MultipartOptions, type S3MultipartPart, type S3MultipartResumeKey, type S3MultipartResumeStore, type S3ProviderOptions, ScheduleRegistry, type ScheduleRouteRunner, type ScheduleTimerHooks, type SecretProvider, type SecretSource, type SecretValue, type SftpJumpHostOptions, type SftpProviderOptions, type SftpRawSession, type SpecializedErrorDetails, type SshAgentSource, type SshAlgorithms, type SshKeyboardInteractiveChallenge, type SshKeyboardInteractiveHandler, type SshKeyboardInteractivePrompt, type SshKnownHostsSource, type SshProfile, type SshSocketFactory, type SshSocketFactoryContext, type StatOptions, type SyncConflictPolicy, type SyncDeletePolicy, type SyncDirection, type SyncEndpointInput, TimeoutError, type TlsProfile, type TlsSecretSource, type TransferAttempt, type TransferAttemptError, type TransferBandwidthLimit, type TransferByteRange, TransferClient, type TransferClientOptions, type TransferDataChunk, type TransferDataSource, type TransferEndpoint, TransferEngine, type TransferEngineExecuteOptions, type TransferEngineOptions, TransferError, type TransferExecutionContext, type TransferExecutionResult, type TransferExecutor, type TransferJob, type TransferOperation, type TransferPlan, type TransferPlanAction, type TransferPlanInput, type TransferPlanStep, type TransferPlanSummary, type TransferProgressEvent, type TransferProvider, TransferQueue, type TransferQueueExecutorResolver, type TransferQueueItem, type TransferQueueItemStatus, type TransferQueueOptions, type TransferQueueRunOptions, type TransferQueueSummary, type TransferReceipt, type TransferResult, type TransferResultInput, type TransferRetryDecisionInput, type TransferRetryPolicy, type TransferSession, type TransferTimeoutPolicy, type TransferVerificationResult, UnsupportedFeatureError, type UploadFileOptions, type ValueSecretSource, VerificationError, type WalkRemoteTreeOptions, type WebDavProviderOptions, type WebhookRetryPolicy, type WebhookSignature, type WebhookTarget, type WinScpSession, ZeroTransfer, type ZeroTransferCapabilities, ZeroTransferError, type ZeroTransferErrorDetails, type ZeroTransferLogger, type ZeroTransferOptions, assertSafeFtpArgument, basenameRemotePath, buildRemoteBreadcrumbs, compareRemoteManifests, composeAuditLogs, copyBetween, createApprovalGate, createAtomicDeployPlan, createAzureBlobProviderFactory, createBandwidthThrottle, createDropboxProviderFactory, createFtpProviderFactory, createFtpsProviderFactory, createGcsProviderFactory, createGoogleDriveProviderFactory, createHttpProviderFactory, createInboxRoute, createJsonlAuditLog, createLocalProviderFactory, createMemoryProviderFactory, createMemoryS3MultipartResumeStore, createOAuthTokenSecretSource, createOneDriveProviderFactory, createOutboxRoute, createProgressEvent, createProviderTransferExecutor, createRemoteBrowser, createRemoteManifest, createS3ProviderFactory, createSftpJumpHostSocketFactory, createSftpProviderFactory, createSyncPlan, createTransferClient, createTransferJobsFromPlan, createTransferPlan, createTransferResult, createWebDavProviderFactory, createWebhookAuditLog, diffRemoteTrees, dispatchWebhook, downloadFile, emitLog, errorFromFtpReply, evaluateRetention, filterRemoteEntries, formatCapabilityMatrixMarkdown, freezeReceipt, getBuiltinCapabilityMatrix, importFileZillaSites, importOpenSshConfig, importWinScpSessions, inboxFailedPath, inboxProcessedPath, isClassicProviderId, isSensitiveKey, joinRemotePath, matchKnownHosts, matchKnownHostsEntry, nextCronFireAt, nextScheduleFireAt, noopLogger, normalizeRemotePath, parentRemotePath, parseCronExpression, parseFtpFeatures, parseFtpResponseLines, parseKnownHosts, parseMlsdLine, parseMlsdList, parseMlstTimestamp, parseOpenSshConfig, parseRemoteManifest, parseUnixList, parseUnixListLine, redactCommand, redactConnectionProfile, redactObject, redactSecretSource, redactValue, resolveConnectionProfileSecrets, resolveOpenSshHost, resolveProviderId, resolveSecret, runConnectionDiagnostics, runRoute, serializeRemoteManifest, signWebhookPayload, sortRemoteEntries, summarizeClientDiagnostics, summarizeError, summarizeTransferPlan, throttleByteIterable, uploadFile, validateConnectionProfile, validateSchedule, walkRemoteTree };
|