unnbound-logger-sdk
Version:
A structured logging library with TypeScript support using Pino. Provides consistent, well-typed logging with automatic logId, workflowId, traceId, and deploymentId tracking across operational contexts.
75 lines (74 loc) • 2.29 kB
TypeScript
export type LogLevel = 'info' | 'debug' | 'error' | 'warn';
export type LogType = 'general' | 'http' | 'sftp' | 'edi';
export type HttpMethod = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head';
export type EventSource = 'http' | 'queue';
export type Maybe<T> = {
error: unknown;
result?: never;
} | {
error?: never;
result: T;
};
export interface Log<T extends LogType = 'general'> {
logId: string;
level: LogLevel;
message: string;
type: T;
traceId?: string;
spanId?: string;
serviceId?: string;
deploymentId?: string;
workflowId?: string;
http: T extends 'http' ? HttpPayload : never;
sftp: T extends 'sftp' ? SftpPayload : never;
edi: T extends 'edi' ? EdiPayload : never;
duration?: number;
err?: unknown;
}
export interface HttpPayload {
url: string;
method: HttpMethod;
source?: EventSource;
ip?: string;
request: {
headers: Record<string, string | string[]>;
body?: unknown;
};
response?: {
headers: Record<string, string | string[]>;
status: number;
body?: unknown;
};
}
export type SftpOperation = 'connect' | 'upload' | 'download' | 'list' | 'delete' | 'rename' | 'stat' | 'exists' | 'realPath' | 'get' | 'put' | 'cwd' | 'mkdir' | 'rmdir' | 'chmod' | 'append' | 'uploadDir' | 'downloadDir' | 'close';
export interface SftpPayload {
host: string;
operation: SftpOperation;
path?: string;
bytes?: number;
destinationPath?: string;
files?: string[];
content?: string;
exists?: string | false;
}
export type EdiX12Operation = 'fromX12' | 'toX12' | 'validateX12' | 'acknowledgeX12';
export type EdiOperation = EdiX12Operation;
export type EdiFormat = 'x12';
export interface EdiX12Payload {
input: unknown;
output: unknown;
}
export interface EdiPayload {
operation: EdiOperation;
type: EdiFormat;
x12?: EdiX12Payload;
}
export interface HttpOptions<G extends Function> {
ignoreTraceRoutes?: string[];
traceHeaderKey?: string;
messageHeaderKey?: string;
getPayload?: G;
}
export declare const defaultIgnoreTraceRoutes: string[];
export declare const defaultTraceHeaderKey = "x-unnbound-trace-id";
export declare const defaultMessageHeaderKey = "x-message-id";