kaven-utils
Version:
Utils for Node.js.
247 lines (246 loc) • 6.72 kB
TypeScript
/********************************************************************
* @author: Kaven
* @email: kaven@wuwenkai.com
* @website: http://blog.kaven.xyz
* @file: [Kaven-Utils] /src/base/Interfaces.ts
* @create: 2018-11-06 15:20:27.145
* @modify: 2024-11-01 10:48:07.335
* @version: 5.4.5
* @times: 129
* @lines: 303
* @copyright: Copyright © 2018-2024 Kaven. All Rights Reserved.
* @description: [description]
* @license: [license]
********************************************************************/
import { IHostPort, ITimeSpan, ITraceableOptions, LogLevel, TIpAddressType } from "kaven-basic";
import { ExecOptions, SpawnOptionsWithoutStdio } from "node:child_process";
import { HttpOrHttpsServer } from "./Types.js";
export interface IExternalIpRule {
url: string;
type?: TIpAddressType;
rule?: (data: string) => string;
regex?: {
pattern: string;
flags?: string;
resultIndex?: number;
};
}
export interface IDigestAuthenticationResponse {
username?: string;
realm?: string;
nonce?: string;
uri?: string;
algorithm?: string;
response?: string;
opaque?: string;
qop?: string;
nc?: string;
cnonce?: string;
[index: string]: string | undefined;
}
export interface IStartServerOptions {
beforeListen?: (s: HttpOrHttpsServer) => Promise<void>;
hostname?: string;
enableHttps?: boolean;
sslCertFile?: string;
sslKeyFile?: string;
handleSignals?: boolean;
disposeBeforeShutdown?: () => Promise<void>;
mode?: string;
}
export interface ICopyEntry {
src: string | string[];
dest: string;
override?: boolean;
}
export interface ICopyConfig {
entries: ICopyEntry[];
override?: boolean;
}
export interface IArchiveOptions extends ITraceableOptions {
password?: string;
notRecurseSubdirectories?: boolean;
overwriteFile?: boolean;
/**
* Sets level of compression. Default: `5`
*/
compressionLevel?: 0 | 1 | 3 | 5 | 7 | 9;
parameters?: NodeJS.Dict<string>;
}
export interface IHttpHeader {
name: string;
value: string;
}
export interface IHttpAuthorizationInfo {
authorization?: string;
method?: string;
ip?: string;
}
export interface IGeneratedFile {
Path: string;
GetContent(force?: boolean): Promise<string>;
Delete(): Promise<boolean>;
CopyTo(dest: string): Promise<boolean>;
MoveTo(dest: string): Promise<boolean>;
}
export interface IGeneratedCertificateFiles {
CaKey?: IGeneratedFile;
CaCert?: IGeneratedFile;
ServerKey?: IGeneratedFile;
ServerReq?: IGeneratedFile;
ServerCert?: IGeneratedFile;
ClientKey?: IGeneratedFile;
ClientReq?: IGeneratedFile;
ClientCert?: IGeneratedFile;
Delete(): Promise<void>;
Save(file: string): Promise<void>;
}
export interface ICertificateSubject {
C?: string;
ST?: string;
L?: string;
O?: string;
OU?: string;
CN?: string;
}
export interface ICertificate {
caKey?: string;
caCert?: string;
serverKey?: string;
serverReq?: string;
serverCert?: string;
clientKey?: string;
clientReq?: string;
clientCert?: string;
}
export interface ICertificateCreationOptions extends ICertificate {
/**
* the size of the private key to generate in bits. This must be the last option specified. The default is 2048.
*/
size?: number;
days?: number;
certGenerateDir?: string;
caSubj?: ICertificateSubject;
serverSubj?: ICertificateSubject;
clientSubj?: ICertificateSubject;
openssl?: string;
}
export interface IStartTlsProxyServerOptions extends ICertificateCreationOptions, IHostPort {
certJsonFile?: string;
validClients?: string[];
}
export interface IStartTlsProxyClientOptions {
cert?: IGeneratedCertificateFiles;
tlsServer?: IHostPort;
httpListen?: IHostPort;
checkCertCn?: boolean;
validServers?: string[];
}
export interface IKavenLoggerFileOptions {
file: string;
levels?: LogLevel[];
saveWithAnsiColor?: boolean;
}
export interface IKavenLoggerOptions {
resetSizeInBytes?: number;
resetInterval?: number | ITimeSpan;
files?: IKavenLoggerFileOptions[];
}
export interface IHttpServerLoggerOptions {
dateTime?: boolean;
useRemoteAddr?: boolean;
}
export interface IProxyConfig {
SERVER: boolean;
SERVER_HOST: string;
SERVER_PORT: number;
SERVER_CERT_GENERATE_DIR: string;
SERVER_CERT_JSON_FILE: string;
SERVER_VALID_CLIENTS: string[];
CLIENT: boolean;
CLIENT_CONNECT_HOST: string;
CLIENT_CONNECT_PORT: number;
CLIENT_HTTP_HOST: string;
CLIENT_HTTP_PORT: number;
CLIENT_CERT_JSON_FILE: string;
CLIENT_CHECK_CERT_CN: boolean;
CLIENT_VALID_SERVERS: string[];
}
/**
* @since 5.0.4
* @version 2023-11-24
*/
export interface IExecuteSoapActionOptions extends ITraceableOptions {
url: string;
serviceType: string;
/**
* eg: GetExternalIPAddress
*/
action: string;
/**
* eg: NewExternalIPAddress
*/
actionResultName?: string;
}
/**
* @since 5.0.4
* @version 2023-11-24
*/
export interface IGetExternalIpOptions extends ITraceableOptions {
rules?: IExternalIpRule[];
ipv6?: boolean;
ignoreCache?: boolean;
ignoreBuiltInRules?: boolean;
}
/**
* @since 5.2.0
* @version 2023-12-02
*/
export interface ICommand {
command: string;
options?: IExecuteOptions;
}
/**
* @since 5.0.5
* @version 2023-12-02
*/
export interface IContinuousIntegrationForDocumentsOptions {
sourceDocumentFileOrDirectory: string;
sourceVersionFile: string;
targetRootDirectory: string;
targetDirectoryName: string;
updateReadmeFile?: boolean;
readmeFileName?: string;
readmeFileTableLine?: string;
gitCommit?: boolean;
targetRepositoryDirectory?: string;
variables?: NodeJS.Dict<string>;
commands?: ICommand[];
}
/**
* @since 5.0.7
* @version 2023-11-25
*/
export interface IExecuteOptions extends ITraceableOptions {
execOptions?: ExecOptions;
spawn?: boolean;
spawnArgs?: string[];
spawnOptions?: SpawnOptionsWithoutStdio;
/**
* cp936
* @see https://www.npmjs.com/package/iconv-lite#supported-encodings
*/
decoderEncoding?: string;
console?: boolean;
stdout?: NodeJS.WritableStream;
stderr?: NodeJS.WritableStream;
resolveNonZeroExitCodes?: boolean;
}
export interface IMinifyFileOptions extends ITraceableOptions {
src: string | string[];
deleteSourceMap?: boolean;
setSourceMappingURL?: boolean;
deleteTypeScriptDeclarationFile?: boolean;
includeNodeModules?: boolean;
terserOptions?: object;
}