@snyxex/pipex 0.0.0-stage → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +30 -0
- package/LICENSE +21 -0
- package/README.md +220 -2
- package/SECURITY.md +41 -0
- package/dist/index.d.mts +765 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +3 -0
- package/dist/index.mjs.map +1 -0
- package/docs/architecture.md +124 -0
- package/docs/encryption-v4-migration.md +45 -0
- package/docs/enterprise.md +280 -0
- package/package.json +91 -4
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# PipeX architecture
|
|
2
|
+
|
|
3
|
+
## Components
|
|
4
|
+
|
|
5
|
+
`DataEngine` owns configuration, plugin order, limits, schema validation, observability hooks, and request lifecycle state. Its `binary`, `file`, and `stream` controllers expose APIs suited to each I/O model.
|
|
6
|
+
|
|
7
|
+
The configured plugin list is exposed only as an immutable snapshot. Pipeline mutation is rejected while operations are active, so execution and audit metadata cannot diverge during concurrent work.
|
|
8
|
+
|
|
9
|
+
Core helpers in `src/core/core.ts` implement serialization, retry behavior, manifests, byte/frame limits, path containment, and stream composition. Plugins implement transformations and optional reverse operations.
|
|
10
|
+
|
|
11
|
+
The local worker plugin owns one bounded, lazily created Piscina pool. It
|
|
12
|
+
performs admission control across running and queued tasks, combines task and
|
|
13
|
+
request cancellation, and has explicit draining and forced shutdown states.
|
|
14
|
+
|
|
15
|
+
## Data paths
|
|
16
|
+
|
|
17
|
+
### Binary transformations
|
|
18
|
+
|
|
19
|
+
`binary.run(value)` converts the value to a buffer, applies plugins in registration order, and returns an `EngineResult`. `binary.undo(result, options)` applies reversible plugins in reverse order, honors cancellation and deadlines, and restores the trusted expected JavaScript type. Transported results require
|
|
20
|
+
an application-owned expectedType; received type metadata is never authoritative.
|
|
21
|
+
|
|
22
|
+
The `EngineResult.pipeline` field records the plugin identifiers used by the operation. It is metadata, not a cryptographic signature.
|
|
23
|
+
|
|
24
|
+
### File and raw-stream transformations
|
|
25
|
+
|
|
26
|
+
`file.process()` and `stream.pipe()` apply plugins in registration order. Reverse operations apply them in reverse order. File writes use a private temporary output followed by an atomic rename so a failed operation does not expose a partial destination.
|
|
27
|
+
|
|
28
|
+
Native plugin streams participate in Node.js backpressure. A plugin without `createStream()` is adapted per chunk; this fallback is only correct for transformations whose chunks can be processed independently.
|
|
29
|
+
|
|
30
|
+
`stream.into()` and `stream.reverseInto()` expose writable endpoints whose
|
|
31
|
+
`finish` event is delayed until the destination, internal pipeline, and audit
|
|
32
|
+
hook have completed. Source, transform, destination, and cancellation errors
|
|
33
|
+
therefore reach the calling `pipeline()` instead of becoming late background
|
|
34
|
+
failures.
|
|
35
|
+
|
|
36
|
+
### MessagePack framing
|
|
37
|
+
|
|
38
|
+
`binary.pack()`, `file.pack()`, and `stream.pack()` are serialization APIs. They do not apply the plugin chain.
|
|
39
|
+
|
|
40
|
+
File and stream packages begin with a versioned MessagePack manifest:
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
interface PipeXManifest {
|
|
44
|
+
readonly __pipex_v: 1;
|
|
45
|
+
readonly plugins: readonly string[];
|
|
46
|
+
readonly ts: number;
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
The serialization-only format currently requires an empty `plugins` list.
|
|
51
|
+
Before decoding, a structural scanner enforces the configured byte limit at each
|
|
52
|
+
top-level MessagePack frame, including across fragmented length headers. It also
|
|
53
|
+
rejects declared lengths and container counts that cannot fit in the remaining
|
|
54
|
+
frame budget. Aggregate input/output limits and application-frame counts are
|
|
55
|
+
enforced separately.
|
|
56
|
+
|
|
57
|
+
## Security boundaries
|
|
58
|
+
|
|
59
|
+
- Input, output, frame, retry, timeout, and concurrency limits are enforced by the engine.
|
|
60
|
+
- File paths are resolved against an allowed root, then opened through native
|
|
61
|
+
directory capabilities with no-follow/reparse checks. Commit and cleanup use
|
|
62
|
+
the acquired directory or file handles; no path-only fallback is used.
|
|
63
|
+
- AES-GCM and ChaCha20-Poly1305 use versioned, independently authenticated
|
|
64
|
+
frames. A frame is never released before its tag verifies. Sequence numbers
|
|
65
|
+
and an authenticated final frame reject reordering, duplication, and
|
|
66
|
+
truncation.
|
|
67
|
+
- Encryption memory is bounded by the configured authenticated frame size.
|
|
68
|
+
Previously authenticated frames may already have been consumed if a later
|
|
69
|
+
frame or the final marker fails; callers must treat terminal success as the
|
|
70
|
+
commit point for the complete message.
|
|
71
|
+
- HMAC verification buffers plaintext up to the configured aggregate bound and
|
|
72
|
+
releases it only after the appended digest verifies.
|
|
73
|
+
- KMS envelopes carry a version, algorithm, explicit lengths, and authenticated
|
|
74
|
+
metadata. Envelope keys are validated and plaintext data keys are zeroed
|
|
75
|
+
after use.
|
|
76
|
+
- Generic KMS operations expose runtime-validated capabilities. Provider calls
|
|
77
|
+
inherit the central operation deadline and cancellation signal; provider
|
|
78
|
+
authentication, availability, timeout, cancellation, and unknown failures
|
|
79
|
+
use distinct sanitized error types.
|
|
80
|
+
- Event-listener failures are isolated; audit logger failures remain visible to the caller.
|
|
81
|
+
|
|
82
|
+
PipeX does not provide HTTP authentication, authorization, tenant isolation, secret storage, or network policy. The embedding application owns those boundaries.
|
|
83
|
+
|
|
84
|
+
## Performance model
|
|
85
|
+
|
|
86
|
+
- MessagePack serialization uses `msgpackr`.
|
|
87
|
+
- File and raw-stream paths use Node.js pipeline backpressure.
|
|
88
|
+
- Buffer slicing uses `subarray()` where ownership permits it.
|
|
89
|
+
- HMAC verification performs one bounded aggregate allocation instead of repeated growing concatenations.
|
|
90
|
+
- Framed encryption and decryption use a fixed-size plaintext/ciphertext buffer
|
|
91
|
+
per frame rather than buffering the complete stream.
|
|
92
|
+
- Binary compression uses asynchronous native Zlib/Brotli work so CPU-heavy compression does not block the event loop. Stream APIs remain preferable for payloads that should not be held entirely in memory.
|
|
93
|
+
|
|
94
|
+
## Plugin contract
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
interface ProcessorPlugin {
|
|
98
|
+
readonly name: string;
|
|
99
|
+
readonly version: string;
|
|
100
|
+
readonly reversible?: boolean;
|
|
101
|
+
readonly streaming?: boolean;
|
|
102
|
+
retryOptions?: RetryOptions;
|
|
103
|
+
process(data: Buffer, context: ProcessorContext): Promise<Buffer> | Buffer;
|
|
104
|
+
reverse?(data: Buffer, context: ProcessorContext): Promise<Buffer> | Buffer;
|
|
105
|
+
createStream?(mode: 'compress' | 'decompress', context?: StreamPluginContext): Duplex;
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Capabilities are normalized and validated by `getPluginCapabilities(plugin)` and
|
|
110
|
+
can be queried with `supportsOperation(plugin, 'process' | 'reverse' | 'stream')`.
|
|
111
|
+
For registered pipelines, `engine.pluginCapabilities` returns an immutable view
|
|
112
|
+
in execution order. `streamMode` distinguishes native plugin streams from the
|
|
113
|
+
per-chunk fallback adapter and plugins that reject streaming entirely.
|
|
114
|
+
|
|
115
|
+
`reversible: true` requires a real `reverse()` implementation. Omitting
|
|
116
|
+
`reversible` derives support from the implementation; setting it to `false`
|
|
117
|
+
allows configuration-dependent plugins to disable an otherwise present method.
|
|
118
|
+
Likewise, `streaming: false` must not be combined with `createStream()`. Invalid
|
|
119
|
+
declarations fail during `engine.use()` with `InvalidPluginCapabilityError`.
|
|
120
|
+
|
|
121
|
+
A reversible pipeline requires every plugin to support `reverse()`. Unsupported
|
|
122
|
+
operations fail before any reverse plugin is executed with
|
|
123
|
+
`UnsupportedReverseError`; the default `BasePlugin.reverse()` also throws that
|
|
124
|
+
typed error and never returns the input as a successful result.
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Encryption v4 migration
|
|
2
|
+
|
|
3
|
+
`EncryptionPlugin` v4 introduces the versioned `PXAE` authenticated-frame
|
|
4
|
+
format. `KmsEncryptionPlugin` v2 similarly introduces the versioned `PXKM`
|
|
5
|
+
envelope. Both changes alter newly written ciphertext and are semver-major at
|
|
6
|
+
the plugin/data-format boundary.
|
|
7
|
+
|
|
8
|
+
## Why the format changed
|
|
9
|
+
|
|
10
|
+
The old encryption packet stored one algorithm byte, IV, authentication tag,
|
|
11
|
+
and ciphertext. A stream therefore had to buffer the complete input or output,
|
|
12
|
+
and its header was not authenticated. The old KMS envelope likewise lacked a
|
|
13
|
+
version and did not authenticate its length and key-envelope metadata.
|
|
14
|
+
|
|
15
|
+
The new formats provide:
|
|
16
|
+
|
|
17
|
+
- explicit magic, format version, algorithm, and bounded lengths;
|
|
18
|
+
- authenticated headers and metadata;
|
|
19
|
+
- a random 128-bit salt and HKDF-SHA256-derived key per `PXAE` stream;
|
|
20
|
+
- a deterministic nonce derived from the frame sequence under that per-stream
|
|
21
|
+
key;
|
|
22
|
+
- independently authenticated data frames and an authenticated final frame;
|
|
23
|
+
- rejection of reordered, duplicated, trailing, and truncated frames.
|
|
24
|
+
|
|
25
|
+
`maxFrameBytes` includes the 13-byte frame header and 16-byte authentication
|
|
26
|
+
tag. The default plaintext frame size is 64 KiB and is automatically reduced
|
|
27
|
+
when the configured frame limit is smaller. `maxFrames`, aggregate input, and
|
|
28
|
+
aggregate output limits are checked before frame allocation and cryptography.
|
|
29
|
+
|
|
30
|
+
## Rolling migration
|
|
31
|
+
|
|
32
|
+
1. Deploy v4 readers while leaving `allowLegacyDecrypt` at its default `true`.
|
|
33
|
+
2. New writes immediately use `PXAE` or `PXKM`; no legacy ciphertext is emitted.
|
|
34
|
+
3. Re-encrypt retained legacy records by decrypting them with the migration
|
|
35
|
+
reader and writing them again with the current plugin.
|
|
36
|
+
4. After all retained ciphertext has been migrated, set
|
|
37
|
+
`allowLegacyDecrypt: false` on both encryption plugin types.
|
|
38
|
+
|
|
39
|
+
Legacy stream decryption is compatibility-only and still buffers the complete
|
|
40
|
+
legacy packet up to the configured aggregate limit. Disable it after migration
|
|
41
|
+
to guarantee framed, bounded-memory decryption for every accepted stream.
|
|
42
|
+
|
|
43
|
+
Do not infer whole-message success from receiving the first plaintext frame.
|
|
44
|
+
Every emitted frame has passed its own authentication, but the operation is
|
|
45
|
+
complete only when the authenticated final frame and stream completion succeed.
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
# Production operations
|
|
2
|
+
|
|
3
|
+
## Resource limits
|
|
4
|
+
|
|
5
|
+
Every engine has conservative defaults. Tune them for the workload instead of disabling them:
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
const engine = new DataEngine({
|
|
9
|
+
maxInputBytes: 64 * 1024 * 1024,
|
|
10
|
+
maxOutputBytes: 256 * 1024 * 1024,
|
|
11
|
+
maxFrameBytes: 8 * 1024 * 1024,
|
|
12
|
+
maxFrames: 100_000,
|
|
13
|
+
maxConcurrentOperations: 32,
|
|
14
|
+
operationTimeoutMs: 5 * 60_000,
|
|
15
|
+
maxRetryAttempts: 5,
|
|
16
|
+
maxRetryDelayMs: 30_000,
|
|
17
|
+
maxKmsEncryptedKeyBytes: 64 * 1024,
|
|
18
|
+
maxKmsKeyIdBytes: 512,
|
|
19
|
+
});
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
The same values can be passed as `limits` to `DataEngine.fromConfig()`. That factory also wires supplied `logger`, `tracer`, `auditLogger`, `dlq`, `schema`, and `schemaRegistry` instances; it does not construct integrations from names or file paths.
|
|
23
|
+
|
|
24
|
+
All defaults are finite. `maxFrameBytes` applies to each top-level MessagePack
|
|
25
|
+
value, while `maxFrames` counts application values (the PipeX manifest is not an
|
|
26
|
+
application value). Incoming frame structure and declared string, binary, array,
|
|
27
|
+
map, and extension lengths are checked before decoding. PipeX's bounded wire
|
|
28
|
+
writers preserve Set, Error and RegExp using msgpackr moreTypes. The bounded
|
|
29
|
+
format includes their extension prefixes and their subsequent
|
|
30
|
+
value in the same logical frame. It permits payload-contained undefined, BigInt,
|
|
31
|
+
typed-array and timestamp extensions. C1, records, bundled strings, structured
|
|
32
|
+
references and unknown extensions are rejected; PipeX's encoders disable records,
|
|
33
|
+
bundles and structured cloning. Custom msgpackr extension registration is outside
|
|
34
|
+
this wire profile.
|
|
35
|
+
|
|
36
|
+
Native and buffer-based standard plugins receive the same immutable request
|
|
37
|
+
limits. Their temporary buffers and predictable output sizes are checked before
|
|
38
|
+
copying, cryptographic work, validation parsing, or worker transfer;
|
|
39
|
+
decompression uses the configured output bound. KMS encryption rejects outputs
|
|
40
|
+
that cannot fit even the smallest valid envelope before contacting the provider,
|
|
41
|
+
then rechecks the provider-supplied envelope size. The encrypted KMS data-key
|
|
42
|
+
field is bounded by the central `maxKmsEncryptedKeyBytes` limit (64 KiB by
|
|
43
|
+
default). Provider key identifiers are independently bounded as UTF-8 by
|
|
44
|
+
`maxKmsKeyIdBytes` (512 bytes by default).
|
|
45
|
+
|
|
46
|
+
`engine.limits` is frozen. Use `setLimits()` between operations; changing limits
|
|
47
|
+
while a request is active is rejected so a pipeline cannot observe mixed limits.
|
|
48
|
+
|
|
49
|
+
Callers can supply `{ signal, timeoutMs }` to binary, file, and stream operations. A timeout of `0` disables only the per-operation deadline; input and output limits remain active.
|
|
50
|
+
|
|
51
|
+
Deadlines stop waiting for plugin promises, including plugins that ignore their
|
|
52
|
+
signal. Non-cooperative work still occupies concurrency capacity until its
|
|
53
|
+
promise settles. Late results are discarded. This prevents repeated timeouts
|
|
54
|
+
from starting unbounded background tasks; use workers for terminable CPU work.
|
|
55
|
+
Synchronous work cannot be preempted, but cannot report success after its deadline.
|
|
56
|
+
|
|
57
|
+
## File-system boundary
|
|
58
|
+
|
|
59
|
+
Keep the allowed root, its configuration, and input/output directories private
|
|
60
|
+
and controlled by the service account. Path containment is a directory-entry
|
|
61
|
+
boundary, not a sandbox against application code, the same OS identity,
|
|
62
|
+
administrators, mount-namespace changes, or modification of file contents by
|
|
63
|
+
principals already authorized to write them.
|
|
64
|
+
|
|
65
|
+
File sessions bind directories and input/output objects before plugin callbacks:
|
|
66
|
+
|
|
67
|
+
- Windows opens the root with CreateFileW, verifies its final handle path, and
|
|
68
|
+
opens each child relative to a directory handle with NtCreateFile and
|
|
69
|
+
FILE_OPEN_REPARSE_POINT. Reparse points and non-disk/non-regular files are
|
|
70
|
+
rejected. Directory handles exclude delete sharing; input and temporary
|
|
71
|
+
output handles also exclude write sharing. The temporary output is renamed
|
|
72
|
+
relative to the pinned destination directory with NtSetInformationFile, and
|
|
73
|
+
failure cleanup deletes that exact opened object by handle.
|
|
74
|
+
- POSIX opens directory components with O_DIRECTORY/O_NOFOLLOW and opens files
|
|
75
|
+
using openat. A mode-0700 temporary directory with verified ownership and
|
|
76
|
+
permissions protects its mode-0600 output file. renameat and unlinkat operate
|
|
77
|
+
relative to the acquired directory descriptors. Renaming a directory after
|
|
78
|
+
admission does not redirect work through a replacement symlink; the session
|
|
79
|
+
continues using the original directory capability.
|
|
80
|
+
|
|
81
|
+
Native reads/writes run asynchronously with backpressure. Disposal waits for
|
|
82
|
+
pending native I/O before closing handles, including error/cancellation paths.
|
|
83
|
+
Native-binding or filesystem failures reject the file operation; there is no
|
|
84
|
+
fallback to a path-only open. Binary and stream APIs do not load native bindings.
|
|
85
|
+
Koffi 3.3.2 is pinned and its platform package must be included in installation.
|
|
86
|
+
|
|
87
|
+
The implementation follows the documented [NtCreateFile RootDirectory contract](https://learn.microsoft.com/en-us/windows/win32/api/winternl/nf-winternl-ntcreatefile),
|
|
88
|
+
[Windows rename information](https://learn.microsoft.com/en-us/windows/win32/api/winbase/ns-winbase-file_rename_info),
|
|
89
|
+
and [POSIX directory-relative opens](https://man7.org/linux/man-pages/man2/openat.2.html).
|
|
90
|
+
|
|
91
|
+
## Logging and events
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
engine.setLogger({
|
|
95
|
+
info: (message, context) => logger.info(context, message),
|
|
96
|
+
warn: (message, context) => logger.warn(context, message),
|
|
97
|
+
error: (message, context) => logger.error(context, message),
|
|
98
|
+
debug: (message, context) => logger.debug(context, message),
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
engine.on('progress', (bytes, requestId) => metrics.bytes.add(bytes, { requestId }));
|
|
102
|
+
engine.on('error', (error, requestId) => logger.error({ requestId, error }, 'PipeX operation failed'));
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Logger and event-listener exceptions are isolated from transformation work. Audit logging is awaited and may fail the caller after transformation completion; operate the audit sink accordingly.
|
|
106
|
+
|
|
107
|
+
## Retries and caller-provided failure sink
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
class RemotePlugin extends BasePlugin {
|
|
111
|
+
readonly name = 'remote';
|
|
112
|
+
readonly version = '1.0.0';
|
|
113
|
+
retryOptions = { attempts: 3, backoff: 'exponential' as const, delayMs: 100 };
|
|
114
|
+
// process() implementation
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
engine.setDlq(createWriteStream('./var/pipex.dlq', { flags: 'a', mode: 0o600 }));
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Retries are capped by engine limits and honor cancellation. `dlq` and
|
|
121
|
+
`setDlq()` are retained compatibility names for an optional failure sink; the
|
|
122
|
+
value is always a `Writable` created and owned by the caller. PipeX does not
|
|
123
|
+
create storage, serialize records, end the stream, retain failed chunks for
|
|
124
|
+
later delivery, replay failures, manage jobs, or schedule delivery attempts.
|
|
125
|
+
|
|
126
|
+
For chunk-independent fallback transforms, PipeX writes the original failed
|
|
127
|
+
chunk once after plugin retries are exhausted and then rejects the operation
|
|
128
|
+
with the plugin error. A `false` result from `write()` pauses completion until
|
|
129
|
+
`drain`. Sink errors and premature closure fail the operation, and cancellation
|
|
130
|
+
removes the temporary `drain`, `error`, and abort listeners. Native plugin
|
|
131
|
+
streams manage their own failure semantics and do not use this fallback hook.
|
|
132
|
+
|
|
133
|
+
The sink receives raw input bytes, not a redacted error envelope. Those bytes
|
|
134
|
+
may contain plaintext, credentials, personal data, or other secrets. The caller
|
|
135
|
+
is responsible for access control, encryption, retention, redaction, monitoring,
|
|
136
|
+
stream lifecycle, and any persistence or replay policy. Structured failure
|
|
137
|
+
context remains available separately through PipeX logging and error handling;
|
|
138
|
+
PipeX never logs the failed chunk itself.
|
|
139
|
+
|
|
140
|
+
`failureSink` may be considered later as a clearer additive alias. No rename or
|
|
141
|
+
removal of `dlq`/`setDlq()` is made in the Standard Core.
|
|
142
|
+
|
|
143
|
+
## Local worker pools
|
|
144
|
+
|
|
145
|
+
`WorkerPoolPlugin` runs only caller-owned module exports in local Piscina worker
|
|
146
|
+
threads. It is not a scheduler or durable job system. No demo encryption or
|
|
147
|
+
built-in XOR transform is exported by the package.
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
const workers = new WorkerPoolPlugin({
|
|
151
|
+
filename: new URL('./worker.mjs', import.meta.url),
|
|
152
|
+
processName: 'transform',
|
|
153
|
+
reverseName: 'restore',
|
|
154
|
+
maxThreads: 4,
|
|
155
|
+
maxQueue: 64,
|
|
156
|
+
taskTimeoutMs: 30_000,
|
|
157
|
+
closeTimeoutMs: 10_000,
|
|
158
|
+
});
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
The default worker count is the smaller of four and the host's available CPU
|
|
162
|
+
parallelism; workers are created lazily. The default queue holds 64 waiting
|
|
163
|
+
tasks. The implementation caps configuration at 128 workers and 100,000 queued
|
|
164
|
+
tasks. Admission is rejected before copying or transferring input once all
|
|
165
|
+
worker and queue slots are occupied. The rejection is a typed
|
|
166
|
+
`WorkerQueueFullError` with code `WORKER_QUEUE_FULL`; callers should apply
|
|
167
|
+
upstream backpressure or retry outside the pool.
|
|
168
|
+
|
|
169
|
+
Each task combines its caller `AbortSignal` with `taskTimeoutMs`. When
|
|
170
|
+
`taskTimeoutMs` is omitted, the central `operationTimeoutMs` applies; an
|
|
171
|
+
explicit zero disables only the plugin-level timer. Cancellation and timeout
|
|
172
|
+
reject as `OperationAbortedError` and `OperationTimeoutError`. Worker handler
|
|
173
|
+
errors and unexpected worker exits reject as `WorkerTaskError`, so submitted
|
|
174
|
+
promises do not remain pending.
|
|
175
|
+
|
|
176
|
+
`close()` atomically stops admission, drains every accepted running or queued
|
|
177
|
+
task, and is bounded by `closeTimeoutMs`. Concurrent calls await the same
|
|
178
|
+
shutdown. `close({ force: true })` terminates running and queued work immediately;
|
|
179
|
+
those task promises reject as `WorkerTaskError`. A graceful-close timeout rejects
|
|
180
|
+
as `WorkerPoolCloseError` after terminating the pool. New work rejects as
|
|
181
|
+
`WorkerPoolClosedError` as soon as shutdown begins.
|
|
182
|
+
|
|
183
|
+
### Worker stream format migration
|
|
184
|
+
|
|
185
|
+
WorkerPoolPlugin 5 writes PXWK v1 streams: a five-byte magic/version header,
|
|
186
|
+
length-prefixed transformed task records, and an explicit end marker. Each
|
|
187
|
+
reverse task receives exactly one forward task result, independent of transport
|
|
188
|
+
chunk boundaries. Frame size/count and aggregate byte limits apply. The format
|
|
189
|
+
provides framing, not authentication; use an outer encryption or HMAC plugin
|
|
190
|
+
when required.
|
|
191
|
+
|
|
192
|
+
Binary worker processing retains the caller's raw transform format. Worker
|
|
193
|
+
streams from 4.x had no recoverable task boundaries and are rejected by 5.x.
|
|
194
|
+
Before upgrading, decode existing streams with the old application and its
|
|
195
|
+
original chunk-boundary contract, then re-encode them. Do not guess boundaries
|
|
196
|
+
or silently reinterpret raw bytes as framed records.
|
|
197
|
+
|
|
198
|
+
## Encryption and key management
|
|
199
|
+
|
|
200
|
+
`KmsEncryptionPlugin` 2.1 adds provider capability discovery, sanitized error
|
|
201
|
+
classification, and provider-call deadlines without changing the `PXKM` v1
|
|
202
|
+
ciphertext format introduced by plugin version 2.0.
|
|
203
|
+
|
|
204
|
+
Use a unique 32-byte key for AES-256-GCM or ChaCha20-Poly1305 and obtain it from a secret manager. Never embed production keys in configuration files or source code.
|
|
205
|
+
|
|
206
|
+
```ts
|
|
207
|
+
import {
|
|
208
|
+
DataEngine,
|
|
209
|
+
KmsEncryptionPlugin,
|
|
210
|
+
KmsProviderAuthenticationError,
|
|
211
|
+
KmsProviderUnavailableError,
|
|
212
|
+
getKmsProviderCapabilities,
|
|
213
|
+
type KmsProvider,
|
|
214
|
+
} from '@snyxex/pipex';
|
|
215
|
+
|
|
216
|
+
const kms: KmsProvider = createKmsProvider();
|
|
217
|
+
console.log(getKmsProviderCapabilities(kms));
|
|
218
|
+
// { encrypt: false, decrypt: true, generateDataKey: true }
|
|
219
|
+
|
|
220
|
+
const engine = new DataEngine().use(new KmsEncryptionPlugin({
|
|
221
|
+
kms,
|
|
222
|
+
keyId: 'production/data-pipeline',
|
|
223
|
+
}));
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
The KMS plugin is binary-only. Use `binary.run()` and `binary.undo()` or provide an application-level framed transport for large streams.
|
|
227
|
+
|
|
228
|
+
Provider methods receive a request-local `AbortSignal`. The engine operation
|
|
229
|
+
deadline applies to every provider call; direct plugin calls use the same
|
|
230
|
+
central `operationTimeoutMs` default. A provider that cannot physically cancel
|
|
231
|
+
an in-flight SDK request may finish in the background, but PipeX stops waiting
|
|
232
|
+
at the deadline and clears any plaintext data key returned later.
|
|
233
|
+
|
|
234
|
+
Provider methods are optional. Declare a compatibility stub as unsupported so
|
|
235
|
+
PipeX never calls it:
|
|
236
|
+
|
|
237
|
+
```ts
|
|
238
|
+
const provider: KmsProvider = {
|
|
239
|
+
capabilities: { encrypt: false, decrypt: true, generateDataKey: true },
|
|
240
|
+
async encrypt() { throw new Error('legacy stub'); }, // never called by PipeX
|
|
241
|
+
async decrypt(envelope, keyId, { signal } = {}) { /* adapter */ },
|
|
242
|
+
async generateDataKey(keyId, { signal } = {}) { /* adapter */ },
|
|
243
|
+
};
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
Omitted capability flags are derived from method presence. A capability marked
|
|
247
|
+
`true` without an implementation is rejected. `KmsEncryptionPlugin` requires
|
|
248
|
+
`generateDataKey`; a provider without `decrypt` remains usable for forward-only
|
|
249
|
+
encryption and the plugin advertises `reverse: false`.
|
|
250
|
+
|
|
251
|
+
Provider adapters should translate credential rejection to
|
|
252
|
+
`KmsProviderAuthenticationError` and transient service/network unavailability
|
|
253
|
+
to `KmsProviderUnavailableError`. PipeX preserves those classifications as
|
|
254
|
+
sanitized errors. Unknown provider exceptions become `KmsProviderError`.
|
|
255
|
+
Provider exception messages, key IDs, envelopes, tokens, and payloads are not
|
|
256
|
+
copied into PipeX error messages or log contexts.
|
|
257
|
+
|
|
258
|
+
## Audit logging
|
|
259
|
+
|
|
260
|
+
```ts
|
|
261
|
+
engine.setAuditLogger({
|
|
262
|
+
async log(record) {
|
|
263
|
+
await auditStore.append(record);
|
|
264
|
+
},
|
|
265
|
+
});
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
Audit records include request ID, operation, plugin chain, timestamp, and operation metadata. They do not contain payload bytes.
|
|
269
|
+
|
|
270
|
+
Binary, file, and stream controllers emit the same audit record shape. Awaitable APIs propagate audit-sink failures to the caller. The writable adapters `into` and `reverseInto` delay `finish` and propagate audit failures to the calling stream pipeline. The duplex serialization adapters `pack` and `unpack` report late audit failures through the engine's `error` event because their readable side may already be complete.
|
|
271
|
+
|
|
272
|
+
## Deployment checklist
|
|
273
|
+
|
|
274
|
+
- Use `npm ci` with the committed lockfile.
|
|
275
|
+
- Run `npm test`, `npm run build`, and `npm pack --dry-run` in CI.
|
|
276
|
+
- Store encryption and HMAC secrets outside the package and application image.
|
|
277
|
+
- Configure explicit resource limits and deadlines for the workload.
|
|
278
|
+
- Keep output roots private and owned by the service account.
|
|
279
|
+
- Monitor error events, dead-letter growth, timeouts, and worker-pool saturation.
|
|
280
|
+
- Exercise round-trip and tamper tests with production-equivalent KMS, storage, and filesystem permissions before rollout.
|
package/package.json
CHANGED
|
@@ -1,6 +1,93 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@snyxex/pipex",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"description": "PipeX — A lightweight, modular data transformation engine. Effortlessly chain compression, encryption, and hashing through a unified stream-based architecture.",
|
|
5
|
+
"main": "./dist/index.mjs",
|
|
6
|
+
"types": "./dist/index.d.mts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"sideEffects": false,
|
|
9
|
+
"scripts": {
|
|
10
|
+
"test": "npm run typecheck && npm run build && npm run test:tooling && npm run test:unit && npm run test:integration && npm run test:security && npm run test:package:built && npm run test:consumer:built",
|
|
11
|
+
"test:tooling": "node scripts/run-test-suite.mjs --timeout=10000 test/tooling",
|
|
12
|
+
"test:unit": "node scripts/run-test-suite.mjs --timeout=15000 test/unit",
|
|
13
|
+
"test:integration": "node scripts/run-test-suite.mjs --timeout=20000 test/integration",
|
|
14
|
+
"test:security": "node scripts/run-test-suite.mjs --timeout=30000 test/security",
|
|
15
|
+
"test:package": "npm run build && npm run test:package:built",
|
|
16
|
+
"test:package:built": "node scripts/run-test-suite.mjs --timeout=30000 test/package",
|
|
17
|
+
"test:consumer": "npm run build && npm run test:consumer:built",
|
|
18
|
+
"test:consumer:built": "node scripts/run-test-suite.mjs --timeout=120000 test/consumer",
|
|
19
|
+
"test:consumer:github": "node scripts/verify-github-consumer.mjs",
|
|
20
|
+
"test:hardening": "npm run test:security",
|
|
21
|
+
"test:performance": "npm run build && npm run test:performance:built",
|
|
22
|
+
"test:performance:built": "node scripts/run-test-suite.mjs --timeout=15000 test/performance",
|
|
23
|
+
"quality:ci": "npm run typecheck && npm run build && npm run test:tooling && npm run test:unit && npm run test:integration && npm run test:security && npm run test:package:built && npm run test:consumer:built && npm run test:performance:built",
|
|
24
|
+
"benchmark:large": "npm run build && node scripts/run-test-suite.mjs --suffix=.benchmark.mjs --timeout=600000 benchmarks",
|
|
25
|
+
"typecheck": "npm run typecheck:prod",
|
|
26
|
+
"typecheck:prod": "tsc -p tsconfig.prod.json --noEmit",
|
|
27
|
+
"build": "tsdown --minify",
|
|
28
|
+
"prepare": "npm run build",
|
|
29
|
+
"prepublishOnly": "npm test",
|
|
30
|
+
"release:preflight": "node scripts/release-preflight.mjs"
|
|
31
|
+
},
|
|
32
|
+
"keywords": [
|
|
33
|
+
"data",
|
|
34
|
+
"engine",
|
|
35
|
+
"hashing",
|
|
36
|
+
"compression",
|
|
37
|
+
"encryption",
|
|
38
|
+
"binary",
|
|
39
|
+
"transformation"
|
|
40
|
+
],
|
|
41
|
+
"author": "Snyxex",
|
|
42
|
+
"license": "MIT",
|
|
43
|
+
"packageManager": "npm@11.16.0",
|
|
44
|
+
"engines": {
|
|
45
|
+
"node": ">=22"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@types/node": "^25.6.0",
|
|
49
|
+
"tsdown": "^0.21.10",
|
|
50
|
+
"typescript": "^6.0.2"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"koffi": "3.3.2",
|
|
54
|
+
"msgpackr": "^1.11.9",
|
|
55
|
+
"piscina": "^5.2.0",
|
|
56
|
+
"zod": "^4.6.7"
|
|
57
|
+
},
|
|
58
|
+
"exports": {
|
|
59
|
+
".": {
|
|
60
|
+
"types": "./dist/index.d.mts",
|
|
61
|
+
"import": "./dist/index.mjs"
|
|
62
|
+
},
|
|
63
|
+
"./plugins/kms": {
|
|
64
|
+
"types": "./dist/index.d.mts",
|
|
65
|
+
"import": "./dist/index.mjs"
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
"files": [
|
|
69
|
+
"dist",
|
|
70
|
+
"LICENSE",
|
|
71
|
+
"README.md",
|
|
72
|
+
"CHANGELOG.md",
|
|
73
|
+
"SECURITY.md",
|
|
74
|
+
"docs/architecture.md",
|
|
75
|
+
"docs/encryption-v4-migration.md",
|
|
76
|
+
"docs/enterprise.md"
|
|
77
|
+
],
|
|
78
|
+
"allowScripts": {
|
|
79
|
+
"msgpackr-extract@3.0.4": true
|
|
80
|
+
},
|
|
81
|
+
"repository": {
|
|
82
|
+
"type": "git",
|
|
83
|
+
"url": "git+https://github.com/Snyxex/PipeX.git"
|
|
84
|
+
},
|
|
85
|
+
"homepage": "https://github.com/Snyxex/PipeX#readme",
|
|
86
|
+
"bugs": {
|
|
87
|
+
"url": "https://github.com/Snyxex/PipeX/issues"
|
|
88
|
+
},
|
|
89
|
+
"publishConfig": {
|
|
90
|
+
"access": "public",
|
|
91
|
+
"registry": "https://registry.npmjs.org/"
|
|
92
|
+
}
|
|
93
|
+
}
|