@freakyfelt/secrets-js
Version:
Client library to make secrets fetching easy and safe
129 lines (123 loc) • 4.3 kB
TypeScript
import { SecretsManager as SecretsManager$1, GetSecretValueResponse, GetSecretValueRequest } from '@aws-sdk/client-secrets-manager';
declare class SecretsError extends Error {
readonly details: object;
constructor(msg: string, details: object);
}
/**
* A class of errors around a specific SecretValue
*/
declare class InvalidSecretError extends SecretsError {
constructor(msg: string, arn: string | null);
}
/**
* Thrown when a parser exception was thrown while parsing the secret
*/
declare class SecretParseError extends InvalidSecretError {
}
/**
* Thrown when the requested operation is not supported
*/
declare class UnsupportedOperationError extends InvalidSecretError {
}
type GetSecretValueMetadata = Omit<GetSecretValueResponse, "SecretString" | "SecretBinary">;
type SecretsManager = Pick<SecretsManager$1, "getSecretValue">;
type SecretPayloadType = "string" | "binary";
declare class SecretValue {
#private;
constructor(input: GetSecretValueResponse);
/**
* The ARN of the secret
*/
get ARN(): string;
/**
* The user-specified friendly name of the secret
*/
get Name(): string;
/**
* The AWS-specified VersionId of the secret
*/
get VersionId(): string;
/**
* The array of version stages associated with the secret
*
* See also {@link isAWSCurrentVersion} and {@link hasVersionStage}
*/
get VersionStages(): string[];
get CreatedDate(): Date;
/**
* True if the secret is the current version per AWS (via the AWSCURRENT version stage)
*/
isAWSCurrentVersion(): boolean;
/**
* True if the secret is the upcoming/pending version per AWS (via the AWSPENDING version stage)
*/
isAWSPendingVersion(): boolean;
/**
* True if the secret is the previous/outgoing version per AWS (via the AWSPREVIOUS version stage)
*/
isAWSPreviousVersion(): boolean;
/**
* Checks if the secret has the specified version stage
*
* @param stage The stage name to search for
* @returns True if the secret has the specified version stage
*/
hasVersionStage(stage: string): boolean;
/**
* Whether the secret payload was created a string (present as SecretString) or binary (present as SecretBinary)
*/
get payloadType(): SecretPayloadType;
/**
* Returns non-sensitive metadata about the secret
*
* Current fields:
*
* - ARN
* - Name
* - VersionId
* - VersionStages
* - CreatedDate
*/
metadata(): GetSecretValueMetadata;
/**
* Converts the SecretString or SecretBinary content into a Buffer
*/
bytes(): Promise<Uint8Array>;
/**
* Parses the contents of SecretString as JSON, throwing a SecretParseError on failure to do so
*
* NOTE: The JSON string is always re-parsed on each request
*
* @throws {UnsupportedOperationError} the SecretString field is not populated
* @throws {SecretParseError} the contents of SecretString is not valid JSON
*/
json(): Promise<unknown>;
/**
* Returns the raw response body from the GetSecretValue API call
*
* NOTE: The API response will usually be a {@link GetSecretCommandOutput} that implements GetSecretValueResponse
*/
raw(): Promise<GetSecretValueResponse>;
/**
* Returns a string with the contents of `SecretString`
*/
text(): Promise<string>;
}
type FetchOptions = Omit<GetSecretValueRequest, "SecretId">;
declare class SecretsFetcher {
private client;
constructor(client: SecretsManager);
/**
* Shorthand method for fetching the string representation of the SecretString
*
* @param input
* @returns the resolved secret
*/
fetchString(SecretId: string, opts?: FetchOptions): Promise<string>;
/**
* Shorthand method for fetching the JSON representation of the SecretString
*/
fetchJson(SecretId: string, opts?: FetchOptions): Promise<unknown>;
fetch(SecretId: string, opts?: FetchOptions): Promise<SecretValue>;
}
export { type FetchOptions, type GetSecretValueMetadata, InvalidSecretError, SecretParseError, type SecretPayloadType, SecretValue, SecretsError, SecretsFetcher, type SecretsManager, UnsupportedOperationError };