@dsegovia90/redacted
Version:
Explicit access to sensitive data. Wraps values in a Redacted class to protect them from being leaked into loggers (ie: console.log) and serializers. Works with zod.
64 lines • 2.37 kB
TypeScript
export interface Properties {
/**
* [redactedOnJsonStringify = true] - Whether the data should be
* safe to stringify with JSON.stringify(), use with care since a lot of loggers
* use this JSON.stringify().
*/
redactedOnJsonStringify?: boolean;
}
/**
* MutableRedacted is a class that wraps a value and provides methods to mutate and expose the value.
* It can be used to safely expose sensitive data without exposing the entire object.
*
* @param data - The data to be redacted.
* @param properties - Optional properties to configure the behavior of the redacted object.
*
* @example
* const mutableRedacted = new MutableRedacted("secret");
* console.log(mutableRedacted.exposeSecret()); // "secret"
* mutableRedacted.mutateSecret("newSecret");
* console.log(mutableRedacted.exposeSecret()); // "newSecret"
*
* @example
* const mutableRedacted = new MutableRedacted("secret", { redactedOnJsonStringify: false });
* console.log(JSON.stringify(mutableRedacted)); // "secret"
*
* @example
* const mutableRedacted = new MutableRedacted("secret"); // <-- secure by default!
* console.log(JSON.stringify(mutableRedacted)); // "{}"
*/
export declare class MutableRedacted<T> {
#private;
constructor(data: T, properties?: Properties);
exposeSecret(): T;
mutateSecret(newData: T): void;
toJSON(): T | typeof this;
}
/**
* Redacted is a class that wraps a value and provides methods to expose the value.
* It can be used to safely expose sensitive data without exposing the entire object.
*
* @param data - The data to be redacted.
* @param properties - Optional properties to configure the behavior of the redacted object.
*
* @example
* const redactedValue = new Redacted("secret");
* console.log(redactedValue)
* console.log(redactedValue.exposeSecret()); // "secret"
*
* @example
* const redactedValue = new Redacted("secret", { redactedOnJsonStringify: false });
* console.log(JSON.stringify(redactedValue)); // "secret"
*
* @example
* const redactedValue = new Redacted("secret"); // <-- secure by default!
* console.log(JSON.stringify(redactedValue)); // "{}"
*/
export declare class Redacted<T> {
#private;
constructor(data: T, properties?: Properties);
exposeSecret(): T;
toJSON(): T | typeof this;
}
export * from "./zod-v3.js";
//# sourceMappingURL=mod.d.ts.map