trigger.dev
Version:
A Command-Line Interface for Trigger.dev projects
29 lines • 947 B
JavaScript
/**
* Holds an attempt's env values in Buffers that can be zeroed, so the controller keeps no long-lived
* strings of them. Strings made by `toRecord()` stay in the heap until garbage collected.
*/
export class SecretEnv {
entries;
constructor(entries) {
this.entries = entries;
}
/** Moves the values out of `env`, deleting its keys so it no longer references them. */
static takeFrom(env) {
const entries = [];
for (const key of Object.keys(env)) {
entries.push([key, Buffer.from(env[key] ?? "", "utf8")]);
delete env[key];
}
return new SecretEnv(entries);
}
toRecord() {
return Object.fromEntries(this.entries.map(([key, value]) => [key, value.toString("utf8")]));
}
zero() {
for (const [, value] of this.entries) {
value.fill(0);
}
this.entries = [];
}
}
//# sourceMappingURL=secretEnv.js.map