fffleet 2.5.1 → 2.7.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/index.d.ts CHANGED
@@ -38,6 +38,8 @@ export interface JobSpecInput {
38
38
  class?: string;
39
39
  /** -1000..1000, higher runs first. */
40
40
  priority?: number;
41
+ /** Ordered worker IDs. The first eligible worker wins; unlisted workers are excluded. */
42
+ workerPreference?: string[];
41
43
  owner?: string;
42
44
  /** Capabilities a worker must have, e.g. 'filter:ass', 'encoder:libx264', 'font:DejaVu Sans'. */
43
45
  requires?: string[];
@@ -47,6 +49,8 @@ export interface JobSpecInput {
47
49
  stdin?: boolean;
48
50
  /** Stream jobs only: ffmpeg's `pipe:1` is readable through `job.stdout()`. No `-progress` is reported. */
49
51
  stdout?: boolean;
52
+ /** Secret values replaced by *** in stderr tails and job events (4-512 characters, at most 10). The spec itself keeps them. */
53
+ redact?: string[];
50
54
  inputs?: Endpoint[];
51
55
  outputs?: Endpoint[];
52
56
  ffmpeg?: { args: string[]; durationMs?: number | null };
@@ -63,6 +67,8 @@ export interface JobSpec {
63
67
  type: string;
64
68
  class: string;
65
69
  priority: number;
70
+ /** Ordered worker IDs; when set, only listed workers may run the job. */
71
+ workerPreference?: string[];
66
72
  owner: string;
67
73
  requires: string[];
68
74
  labels: Record<string, string>;
@@ -117,6 +123,7 @@ export interface JobSnapshot {
117
123
  class: string;
118
124
  owner: string;
119
125
  priority: number;
126
+ workerPreference?: string[];
120
127
  labels: Record<string, string>;
121
128
  state: JobState;
122
129
  workerId: string | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fffleet",
3
- "version": "2.5.1",
3
+ "version": "2.7.0",
4
4
  "description": "Run ffmpeg jobs locally, on one worker or across a pool, through one client and one job contract",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
package/src/contract.js CHANGED
@@ -79,6 +79,15 @@ export function validateSpec(input) {
79
79
  const priority = s.priority ?? 0;
80
80
  if (!Number.isInteger(priority) || priority < -1000 || priority > 1000) err('priority', 'must be an integer from -1000 to 1000');
81
81
 
82
+ // Ordered worker IDs; when set, this list is also a placement allowlist.
83
+ const workerPreference = s.workerPreference;
84
+ if (workerPreference !== undefined && (!Array.isArray(workerPreference)
85
+ || workerPreference.length === 0
86
+ || workerPreference.some(id => typeof id !== 'string' || !id.trim() || id.length > 128)
87
+ || new Set(workerPreference).size !== workerPreference.length)) {
88
+ err('workerPreference', 'must be a non-empty array of unique worker IDs (1-128 characters each)');
89
+ }
90
+
82
91
  const owner = s.owner ?? '';
83
92
  if (typeof owner !== 'string' || owner.length > 256) err('owner', 'must be a string of at most 256 characters');
84
93
 
@@ -92,6 +101,11 @@ export function validateSpec(input) {
92
101
  if (typeof stdout !== 'boolean') err('stdout', 'must be a boolean');
93
102
  else if (stdout && s.kind !== 'stream') err('stdout', 'is only allowed for stream jobs');
94
103
 
104
+ const redact = s.redact ?? [];
105
+ if (!Array.isArray(redact) || redact.length > 10 || redact.some(r => typeof r !== 'string' || r.length < 4 || r.length > 512)) {
106
+ err('redact', 'must be an array of at most 10 strings of 4-512 characters');
107
+ }
108
+
95
109
  const requires = s.requires ?? [];
96
110
  if (!Array.isArray(requires) || requires.some(r => typeof r !== 'string' || !r)) err('requires', 'must be an array of capability strings');
97
111
 
@@ -127,6 +141,7 @@ export function validateSpec(input) {
127
141
  type,
128
142
  class: cls,
129
143
  priority,
144
+ ...(workerPreference !== undefined ? { workerPreference: [...workerPreference] } : {}),
130
145
  owner,
131
146
  requires: [...new Set(requires)].sort(),
132
147
  labels: { ...labels },
@@ -136,6 +151,7 @@ export function validateSpec(input) {
136
151
  inputs,
137
152
  outputs,
138
153
  };
154
+ if (redact.length) spec.redact = [...new Set(redact)];
139
155
  if (ffmpeg) spec.ffmpeg = ffmpeg;
140
156
  else if (s[type] !== undefined) spec[type] = s[type];
141
157
  return { ok: true, spec };
package/src/executor.js CHANGED
@@ -245,9 +245,11 @@ function runProcess(cmd, args, spec, rt) {
245
245
  child.stdout.setEncoding('utf8');
246
246
  child.stdout.on('data', parse);
247
247
  }
248
+ const secrets = spec.redact ?? [];
248
249
  child.stderr.setEncoding('utf8');
249
250
  child.stderr.on('data', d => {
250
- tail = (tail + d).slice(-STDERR_TAIL_BYTES);
251
+ // Redact the whole buffer before trimming, so a secret split across two chunks is still caught.
252
+ tail = redactSecrets(tail + d, secrets).slice(-STDERR_TAIL_BYTES);
251
253
  rt.stderr?.(tail.trim());
252
254
  });
253
255
  if (child.stdin) {
@@ -289,6 +291,13 @@ function runProcess(cmd, args, spec, rt) {
289
291
  });
290
292
  }
291
293
 
294
+ /** Replaces every occurrence of a caller-supplied secret with "***" (spec.redact). */
295
+ export function redactSecrets(text, secrets) {
296
+ let out = text;
297
+ for (const secret of secrets) out = out.split(secret).join('***');
298
+ return out;
299
+ }
300
+
292
301
  /** Windows: ends a process and everything it started. Falls back to killing just the child. */
293
302
  function killTree(child) {
294
303
  try {
package/src/job-record.js CHANGED
@@ -129,6 +129,7 @@ export class JobRecord {
129
129
  class: this.spec.class,
130
130
  owner: this.spec.owner,
131
131
  priority: this.spec.priority,
132
+ ...(this.spec.workerPreference ? { workerPreference: this.spec.workerPreference } : {}),
132
133
  labels: this.spec.labels,
133
134
  state: this.state,
134
135
  workerId: this.workerId,
package/src/types.js CHANGED
@@ -16,12 +16,14 @@
16
16
  * @property {string} type Executor, 'ffmpeg' by default.
17
17
  * @property {string} class Slot pool on the worker, 'default' by default.
18
18
  * @property {number} priority Higher runs first.
19
+ * @property {string[]} [workerPreference] Ordered worker IDs; also restricts placement to listed workers.
19
20
  * @property {string} owner Opaque label of whoever submitted the job.
20
21
  * @property {string[]} requires Capabilities a worker must have, e.g. 'filter:ass'.
21
22
  * @property {Record<string, string>} labels
22
23
  * @property {number | null} timeoutMs
23
24
  * @property {boolean} stdin Keep ffmpeg's stdin open for POST /v1/jobs/:id/stdin.
24
25
  * @property {boolean} stdout Hand ffmpeg's stdout (`pipe:1`) to GET /v1/jobs/:id/stdout. Stream jobs only; no `-progress` is reported then.
26
+ * @property {string[]} [redact] Secret values (4-512 characters, at most 10) replaced by *** in stderr tails and job events.
25
27
  * @property {Endpoint[]} inputs
26
28
  * @property {Endpoint[]} outputs
27
29
  * @property {{ args: string[], durationMs: number | null }} [ffmpeg]