Skip to content

index

Classes

CursorPaginationMetaDto

Defined in: src/dto/response.dto.ts:46

Constructors

Constructor
ts
new CursorPaginationMetaDto(): CursorPaginationMetaDto;
Returns

CursorPaginationMetaDto

Properties

hasMore
ts
hasMore: boolean;

Defined in: src/dto/response.dto.ts:57

limit
ts
limit: number;

Defined in: src/dto/response.dto.ts:60

ts
optional links?: PaginationLinksDto;

Defined in: src/dto/response.dto.ts:66

nextCursor
ts
nextCursor: string | null;

Defined in: src/dto/response.dto.ts:51

previousCursor
ts
previousCursor: string | null;

Defined in: src/dto/response.dto.ts:54

totalCount?
ts
optional totalCount?: number;

Defined in: src/dto/response.dto.ts:63

type
ts
type: "cursor";

Defined in: src/dto/response.dto.ts:48


DeprecationMetaDto

Defined in: src/dto/response.dto.ts:87

Constructors

Constructor
ts
new DeprecationMetaDto(): DeprecationMetaDto;
Returns

DeprecationMetaDto

Properties

deprecated
ts
deprecated: true;

Defined in: src/dto/response.dto.ts:89

ts
optional link?: string;

Defined in: src/dto/response.dto.ts:101

message?
ts
optional message?: string;

Defined in: src/dto/response.dto.ts:98

since?
ts
optional since?: string;

Defined in: src/dto/response.dto.ts:92

sunset?
ts
optional sunset?: string;

Defined in: src/dto/response.dto.ts:95


ErrorDetailDto

Defined in: src/dto/response.dto.ts:173

Constructors

Constructor
ts
new ErrorDetailDto(): ErrorDetailDto;
Returns

ErrorDetailDto

Properties

code
ts
code: string;

Defined in: src/dto/response.dto.ts:175

details?
ts
optional details?: unknown;

Defined in: src/dto/response.dto.ts:183

message
ts
message: string;

Defined in: src/dto/response.dto.ts:178


ErrorResponseMetaDto

Defined in: src/dto/response.dto.ts:186

Indexable

ts
[key: string]: unknown

Additional context fields (e.g., traceId, correlationId) injected via CLS

Constructors

Constructor
ts
new ErrorResponseMetaDto(): ErrorResponseMetaDto;
Returns

ErrorResponseMetaDto

Properties

deprecation?
ts
optional deprecation?: DeprecationMetaDto;

Defined in: src/dto/response.dto.ts:191

rateLimit?
ts
optional rateLimit?: RateLimitMetaDto;

Defined in: src/dto/response.dto.ts:194

responseTime?
ts
optional responseTime?: number;

Defined in: src/dto/response.dto.ts:188


FilterMetaDto

Defined in: src/dto/response.dto.ts:77

Constructors

Constructor
ts
new FilterMetaDto(): FilterMetaDto;
Returns

FilterMetaDto

Properties

filters
ts
filters: Record<string, unknown>;

Defined in: src/dto/response.dto.ts:84


NestI18nAdapter

Defined in: src/adapters/i18n.adapter.ts:25

Built-in adapter for nestjs-i18n. Wraps I18nService from the nestjs-i18n package.

Implements

Constructors

Constructor
ts
new NestI18nAdapter(i18nService): NestI18nAdapter;

Defined in: src/adapters/i18n.adapter.ts:26

Parameters
ParameterType
i18nServiceI18nServiceLike
Returns

NestI18nAdapter

Methods

resolveLanguage()
ts
resolveLanguage(request): string;

Defined in: src/adapters/i18n.adapter.ts:41

Resolve the preferred language from the request

Parameters
ParameterType
requestunknown
Returns

string

Implementation of

I18nAdapter.resolveLanguage

translate()
ts
translate(key, options?): string;

Defined in: src/adapters/i18n.adapter.ts:28

Translate a message key to the target language

Parameters
ParameterType
keystring
options?{ args?: Record<string, unknown>; lang?: string; }
options.args?Record<string, unknown>
options.lang?string
Returns

string

Implementation of

I18nAdapter.translate


PaginationLinksDto

Defined in: src/dto/response.dto.ts:3

Constructors

Constructor
ts
new PaginationLinksDto(): PaginationLinksDto;
Returns

PaginationLinksDto

Properties

first
ts
first: string;

Defined in: src/dto/response.dto.ts:8

last
ts
last: string | null;

Defined in: src/dto/response.dto.ts:17

next
ts
next: string | null;

Defined in: src/dto/response.dto.ts:14

prev
ts
prev: string | null;

Defined in: src/dto/response.dto.ts:11

self
ts
self: string;

Defined in: src/dto/response.dto.ts:5


PaginationMetaDto

Defined in: src/dto/response.dto.ts:20

Constructors

Constructor
ts
new PaginationMetaDto(): PaginationMetaDto;
Returns

PaginationMetaDto

Properties

hasNext
ts
hasNext: boolean;

Defined in: src/dto/response.dto.ts:37

hasPrev
ts
hasPrev: boolean;

Defined in: src/dto/response.dto.ts:40

limit
ts
limit: number;

Defined in: src/dto/response.dto.ts:28

ts
optional links?: PaginationLinksDto;

Defined in: src/dto/response.dto.ts:43

page
ts
page: number;

Defined in: src/dto/response.dto.ts:25

total
ts
total: number;

Defined in: src/dto/response.dto.ts:31

totalPages
ts
totalPages: number;

Defined in: src/dto/response.dto.ts:34

type?
ts
optional type?: "offset";

Defined in: src/dto/response.dto.ts:22


ProblemDetailsDto

Defined in: src/dto/response.dto.ts:223

Constructors

Constructor
ts
new ProblemDetailsDto(): ProblemDetailsDto;
Returns

ProblemDetailsDto

Properties

code?
ts
optional code?: string;

Defined in: src/dto/response.dto.ts:240

detail
ts
detail: string;

Defined in: src/dto/response.dto.ts:234

details?
ts
optional details?: unknown;

Defined in: src/dto/response.dto.ts:246

instance
ts
instance: string;

Defined in: src/dto/response.dto.ts:237

meta?
ts
optional meta?: ErrorResponseMetaDto;

Defined in: src/dto/response.dto.ts:249

requestId?
ts
optional requestId?: string;

Defined in: src/dto/response.dto.ts:243

status
ts
status: number;

Defined in: src/dto/response.dto.ts:231

title
ts
title: string;

Defined in: src/dto/response.dto.ts:228

type
ts
type: string;

Defined in: src/dto/response.dto.ts:225


RateLimitMetaDto

Defined in: src/dto/response.dto.ts:104

Constructors

Constructor
ts
new RateLimitMetaDto(): RateLimitMetaDto;
Returns

RateLimitMetaDto

Properties

limit
ts
limit: number;

Defined in: src/dto/response.dto.ts:106

remaining
ts
remaining: number;

Defined in: src/dto/response.dto.ts:109

reset
ts
reset: number;

Defined in: src/dto/response.dto.ts:112

retryAfter?
ts
optional retryAfter?: number;

Defined in: src/dto/response.dto.ts:115


ResponseMetaDto

Defined in: src/dto/response.dto.ts:119

Constructors

Constructor
ts
new ResponseMetaDto(): ResponseMetaDto;
Returns

ResponseMetaDto

Properties

deprecation?
ts
optional deprecation?: DeprecationMetaDto;

Defined in: src/dto/response.dto.ts:141

filters?
ts
optional filters?: Record<string, unknown>;

Defined in: src/dto/response.dto.ts:138

message?
ts
optional message?: string;

Defined in: src/dto/response.dto.ts:129

pagination?
ts
optional pagination?: 
  | PaginationMetaDto
  | CursorPaginationMetaDto;

Defined in: src/dto/response.dto.ts:126

rateLimit?
ts
optional rateLimit?: RateLimitMetaDto;

Defined in: src/dto/response.dto.ts:144

responseTime?
ts
optional responseTime?: number;

Defined in: src/dto/response.dto.ts:132

sort?
ts
optional sort?: SortMetaDto;

Defined in: src/dto/response.dto.ts:135


SafeErrorResponseDto

Defined in: src/dto/response.dto.ts:200

Constructors

Constructor
ts
new SafeErrorResponseDto(): SafeErrorResponseDto;
Returns

SafeErrorResponseDto

Properties

error
ts
error: ErrorDetailDto;

Defined in: src/dto/response.dto.ts:211

meta?
ts
optional meta?: ErrorResponseMetaDto;

Defined in: src/dto/response.dto.ts:214

path?
ts
optional path?: string;

Defined in: src/dto/response.dto.ts:220

requestId?
ts
optional requestId?: string;

Defined in: src/dto/response.dto.ts:208

statusCode
ts
statusCode: number;

Defined in: src/dto/response.dto.ts:205

success
ts
success: false;

Defined in: src/dto/response.dto.ts:202

timestamp?
ts
optional timestamp?: string;

Defined in: src/dto/response.dto.ts:217


SafeExceptionFilter

Defined in: src/filters/safe-exception.filter.ts:63

Global exception filter that wraps errors in the SafeErrorResponse or RFC 9457 Problem Details envelope.

Known Limitation — Guard-phase exceptions

NestJS lifecycle: Middleware → Guards → Interceptors → Pipes → Handler. Metadata set by the interceptor (@Deprecated(), @ProblemType(), responseTime) is stored on the request object. When a guard throws before the interceptor runs, these values are unavailable to this filter:

  • meta.responseTime — start time was never captured
  • meta.deprecation / Deprecation headers — @Deprecated() options not forwarded
  • Problem Details type URI — @ProblemType() value not forwarded (falls back to config.baseUrl-derived URI or about:blank)

This is an architectural constraint of NestJS's ArgumentsHost, which does not expose getHandler() for reflector-based metadata reads.

Implements

  • ExceptionFilter

Constructors

Constructor
ts
new SafeExceptionFilter(
   httpAdapterHost, 
   options?, 
   moduleRef?): SafeExceptionFilter;

Defined in: src/filters/safe-exception.filter.ts:68

Parameters
ParameterType
httpAdapterHostHttpAdapterHost
optionsSafeResponseModuleOptions
moduleRef?ModuleRef
Returns

SafeExceptionFilter

Methods

catch()
ts
catch(exception, host): void;

Defined in: src/filters/safe-exception.filter.ts:92

Method to implement a custom exception filter.

Parameters
ParameterTypeDescription
exceptionunknownthe class of the exception being handled
hostArgumentsHostused to access an array of arguments for the in-flight request
Returns

void

Implementation of
ts
ExceptionFilter.catch

SafeResponseInterceptor

Defined in: src/interceptors/safe-response.interceptor.ts:60

Implements

  • NestInterceptor

Constructors

Constructor
ts
new SafeResponseInterceptor(
   reflector, 
   options?, 
   moduleRef?): SafeResponseInterceptor;

Defined in: src/interceptors/safe-response.interceptor.ts:65

Parameters
ParameterType
reflectorReflector
optionsSafeResponseModuleOptions
moduleRef?ModuleRef
Returns

SafeResponseInterceptor

Methods

intercept()
ts
intercept(context, next): Observable<any>;

Defined in: src/interceptors/safe-response.interceptor.ts:80

Method to implement a custom interceptor.

Parameters
ParameterTypeDescription
contextExecutionContextan ExecutionContext object providing methods to access the route handler and class about to be invoked.
nextCallHandlera reference to the CallHandler, which provides access to an Observable representing the response stream from the route handler.
Returns

Observable<any>

Implementation of
ts
NestInterceptor.intercept

SafeResponseModule

Defined in: src/safe-response.module.ts:12

Implements

  • OnModuleInit

Constructors

Constructor
ts
new SafeResponseModule(): SafeResponseModule;
Returns

SafeResponseModule

Methods

onModuleInit()
ts
onModuleInit(): void;

Defined in: src/safe-response.module.ts:16

Returns

void

Implementation of
ts
OnModuleInit.onModuleInit
register()
ts
static register(options?): DynamicModule;

Defined in: src/safe-response.module.ts:27

Parameters
ParameterType
optionsSafeResponseModuleOptions
Returns

DynamicModule

registerAsync()
ts
static registerAsync(options): DynamicModule;

Defined in: src/safe-response.module.ts:48

Parameters
ParameterType
optionsSafeResponseModuleAsyncOptions
Returns

DynamicModule


SafeSuccessResponseDto

Defined in: src/dto/response.dto.ts:147

Constructors

Constructor
ts
new SafeSuccessResponseDto(): SafeSuccessResponseDto;
Returns

SafeSuccessResponseDto

Properties

code?
ts
optional code?: string;

Defined in: src/dto/response.dto.ts:155

data
ts
data: unknown;

Defined in: src/dto/response.dto.ts:161

meta?
ts
optional meta?: ResponseMetaDto;

Defined in: src/dto/response.dto.ts:164

path?
ts
optional path?: string;

Defined in: src/dto/response.dto.ts:170

requestId?
ts
optional requestId?: string;

Defined in: src/dto/response.dto.ts:158

statusCode
ts
statusCode: number;

Defined in: src/dto/response.dto.ts:152

success
ts
success: true;

Defined in: src/dto/response.dto.ts:149

timestamp?
ts
optional timestamp?: string;

Defined in: src/dto/response.dto.ts:167


SortMetaDto

Defined in: src/dto/response.dto.ts:69

Constructors

Constructor
ts
new SortMetaDto(): SortMetaDto;
Returns

SortMetaDto

Properties

field
ts
field: string;

Defined in: src/dto/response.dto.ts:71

order
ts
order: "asc" | "desc";

Defined in: src/dto/response.dto.ts:74

Interfaces

ApiSafeErrorResponseOptions

Defined in: src/interfaces/index.ts:237

Properties

code?
ts
optional code?: string;

Defined in: src/interfaces/index.ts:241

Override the auto-resolved error code from DEFAULT_ERROR_CODE_MAP

description?
ts
optional description?: string;

Defined in: src/interfaces/index.ts:239

Description shown in Swagger UI

details?
ts
optional details?: unknown;

Defined in: src/interfaces/index.ts:245

Example details value (type is inferred: array → array schema, object → object schema)

message?
ts
optional message?: string;

Defined in: src/interfaces/index.ts:243

Example error message


ContextOptions

Defined in: src/interfaces/index.ts:10

Properties

fields?
ts
optional fields?: Record<string, string>;

Defined in: src/interfaces/index.ts:12

Map CLS store keys to response meta fields. Key = meta field name, Value = CLS store key.

resolver?
ts
optional resolver?: (store) => Record<string, unknown>;

Defined in: src/interfaces/index.ts:14

Custom resolver function. Receives the CLS service instance and returns fields to inject.

Parameters
ParameterType
storeunknown
Returns

Record<string, unknown>


CursorPaginatedOptions

Defined in: src/interfaces/index.ts:222

Properties

ts
optional links?: boolean;

Defined in: src/interfaces/index.ts:225

Generate HATEOAS navigation links in pagination meta. Default: false

maxLimit?
ts
optional maxLimit?: number;

Defined in: src/interfaces/index.ts:223


CursorPaginatedResult

Defined in: src/interfaces/index.ts:228

Type Parameters

Type ParameterDefault type
Tunknown

Properties

data
ts
data: T[];

Defined in: src/interfaces/index.ts:229

hasMore
ts
hasMore: boolean;

Defined in: src/interfaces/index.ts:232

limit
ts
limit: number;

Defined in: src/interfaces/index.ts:233

nextCursor
ts
nextCursor: string | null;

Defined in: src/interfaces/index.ts:230

previousCursor?
ts
optional previousCursor?: string | null;

Defined in: src/interfaces/index.ts:231

totalCount?
ts
optional totalCount?: number;

Defined in: src/interfaces/index.ts:234


CursorPaginationMeta

Defined in: src/interfaces/index.ts:143

Properties

hasMore
ts
hasMore: boolean;

Defined in: src/interfaces/index.ts:147

limit
ts
limit: number;

Defined in: src/interfaces/index.ts:148

ts
optional links?: PaginationLinks;

Defined in: src/interfaces/index.ts:150

nextCursor
ts
nextCursor: string | null;

Defined in: src/interfaces/index.ts:145

previousCursor
ts
previousCursor: string | null;

Defined in: src/interfaces/index.ts:146

totalCount?
ts
optional totalCount?: number;

Defined in: src/interfaces/index.ts:149

type
ts
type: "cursor";

Defined in: src/interfaces/index.ts:144


DeprecatedOptions

Defined in: src/interfaces/index.ts:19

Properties

ts
optional link?: string;

Defined in: src/interfaces/index.ts:27

URL of the successor endpoint or migration guide

message?
ts
optional message?: string;

Defined in: src/interfaces/index.ts:25

Human-readable deprecation message for API consumers

since?
ts
optional since?: string | Date;

Defined in: src/interfaces/index.ts:21

Date when the endpoint was deprecated (ISO string or Date object)

sunset?
ts
optional sunset?: string | Date;

Defined in: src/interfaces/index.ts:23

Date when the endpoint will be removed (ISO string or Date object)


DeprecationMeta

Defined in: src/interfaces/index.ts:30

Properties

deprecated
ts
deprecated: true;

Defined in: src/interfaces/index.ts:31

ts
optional link?: string;

Defined in: src/interfaces/index.ts:35

message?
ts
optional message?: string;

Defined in: src/interfaces/index.ts:34

since?
ts
optional since?: string;

Defined in: src/interfaces/index.ts:32

sunset?
ts
optional sunset?: string;

Defined in: src/interfaces/index.ts:33


ErrorCodeMapperContext

Defined in: src/interfaces/index.ts:50

Properties

defaultCode
ts
defaultCode: string;

Defined in: src/interfaces/index.ts:54

Default code from errorCodes option or DEFAULT_ERROR_CODE_MAP

statusCode
ts
statusCode: number;

Defined in: src/interfaces/index.ts:52

Resolved HTTP status code


I18nAdapter

Defined in: src/adapters/i18n.adapter.ts:5

Interface for i18n adapters. Implementations bridge the gap between @nestarc/safe-response and i18n libraries.

Methods

resolveLanguage()
ts
resolveLanguage(request): string;

Defined in: src/adapters/i18n.adapter.ts:9

Resolve the preferred language from the request

Parameters
ParameterType
requestunknown
Returns

string

translate()
ts
translate(key, options?): string;

Defined in: src/adapters/i18n.adapter.ts:7

Translate a message key to the target language

Parameters
ParameterType
keystring
options?{ args?: Record<string, unknown>; lang?: string; }
options.args?Record<string, unknown>
options.lang?string
Returns

string


I18nServiceLike

Defined in: src/adapters/i18n.adapter.ts:17

Minimal interface for nestjs-i18n's I18nService. Requires only the translate() method, making it structurally compatible with nestjs-i18n v10+ without importing the package at compile time.

Methods

translate()
ts
translate(key, options?): unknown;

Defined in: src/adapters/i18n.adapter.ts:18

Parameters
ParameterType
keystring
options?{ args?: Record<string, unknown>; lang?: string; }
options.args?Record<string, unknown>
options.lang?string
Returns

unknown


PaginatedOptions

Defined in: src/interfaces/index.ts:209

Properties

ts
optional links?: boolean;

Defined in: src/interfaces/index.ts:212

Generate HATEOAS navigation links in pagination meta. Default: false

maxLimit?
ts
optional maxLimit?: number;

Defined in: src/interfaces/index.ts:210


PaginatedResult

Defined in: src/interfaces/index.ts:215

Type Parameters

Type ParameterDefault type
Tunknown

Properties

data
ts
data: T[];

Defined in: src/interfaces/index.ts:216

limit
ts
limit: number;

Defined in: src/interfaces/index.ts:219

page
ts
page: number;

Defined in: src/interfaces/index.ts:218

total
ts
total: number;

Defined in: src/interfaces/index.ts:217


Defined in: src/interfaces/index.ts:201

Properties

first
ts
first: string;

Defined in: src/interfaces/index.ts:203

last
ts
last: string | null;

Defined in: src/interfaces/index.ts:206

next
ts
next: string | null;

Defined in: src/interfaces/index.ts:205

prev
ts
prev: string | null;

Defined in: src/interfaces/index.ts:204

self
ts
self: string;

Defined in: src/interfaces/index.ts:202


PaginationMeta

Defined in: src/interfaces/index.ts:132

Properties

hasNext
ts
hasNext: boolean;

Defined in: src/interfaces/index.ts:138

hasPrev
ts
hasPrev: boolean;

Defined in: src/interfaces/index.ts:139

limit
ts
limit: number;

Defined in: src/interfaces/index.ts:135

ts
optional links?: PaginationLinks;

Defined in: src/interfaces/index.ts:140

page
ts
page: number;

Defined in: src/interfaces/index.ts:134

total
ts
total: number;

Defined in: src/interfaces/index.ts:136

totalPages
ts
totalPages: number;

Defined in: src/interfaces/index.ts:137

type?
ts
optional type?: "offset";

Defined in: src/interfaces/index.ts:133


ProblemDetailsOptions

Defined in: src/interfaces/index.ts:95

Properties

baseUrl?
ts
optional baseUrl?: string;

Defined in: src/interfaces/index.ts:97

Base URL for problem type URIs (e.g., 'https://api.example.com/problems')


RateLimitMeta

Defined in: src/interfaces/index.ts:43

Properties

limit
ts
limit: number;

Defined in: src/interfaces/index.ts:44

remaining
ts
remaining: number;

Defined in: src/interfaces/index.ts:45

reset
ts
reset: number;

Defined in: src/interfaces/index.ts:46

retryAfter?
ts
optional retryAfter?: number;

Defined in: src/interfaces/index.ts:47


RateLimitOptions

Defined in: src/interfaces/index.ts:38

Properties

headerPrefix?
ts
optional headerPrefix?: string;

Defined in: src/interfaces/index.ts:40

Header name prefix (default: 'X-RateLimit'). Headers read: {prefix}-Limit, {prefix}-Remaining, {prefix}-Reset


RequestIdOptions

Defined in: src/interfaces/index.ts:3

Properties

generator?
ts
optional generator?: () => string;

Defined in: src/interfaces/index.ts:7

Custom ID generator (default: crypto.randomUUID())

Returns

string

headerName?
ts
optional headerName?: string;

Defined in: src/interfaces/index.ts:5

Custom header name (default: 'X-Request-Id')


ResponseMeta

Defined in: src/interfaces/index.ts:158

Indexable

ts
[key: string]: unknown

Additional context fields (e.g., traceId, correlationId)

Properties

deprecation?
ts
optional deprecation?: DeprecationMeta;

Defined in: src/interfaces/index.ts:164

filters?
ts
optional filters?: Record<string, unknown>;

Defined in: src/interfaces/index.ts:163

message?
ts
optional message?: string;

Defined in: src/interfaces/index.ts:160

pagination?
ts
optional pagination?: 
  | PaginationMeta
  | CursorPaginationMeta;

Defined in: src/interfaces/index.ts:159

rateLimit?
ts
optional rateLimit?: RateLimitMeta;

Defined in: src/interfaces/index.ts:165

responseTime?
ts
optional responseTime?: number;

Defined in: src/interfaces/index.ts:161

sort?
ts
optional sort?: SortInfo;

Defined in: src/interfaces/index.ts:162


SafeCursorPaginatedEndpointOptions

Defined in: src/interfaces/index.ts:306

Properties

code?
ts
optional code?: string;

Defined in: src/interfaces/index.ts:320

Custom success code

deprecated?
ts
optional deprecated?: DeprecatedOptions;

Defined in: src/interfaces/index.ts:324

Mark endpoint as deprecated with RFC headers

description?
ts
optional description?: string;

Defined in: src/interfaces/index.ts:316

Swagger response description

errors?
ts
optional errors?: ApiSafeErrorResponseConfig[];

Defined in: src/interfaces/index.ts:322

Error responses to document in Swagger

filter?
ts
optional filter?: boolean;

Defined in: src/interfaces/index.ts:314

Include filter metadata (default: false)

ts
optional links?: boolean;

Defined in: src/interfaces/index.ts:310

Generate HATEOAS navigation links (default: false)

maxLimit?
ts
optional maxLimit?: number;

Defined in: src/interfaces/index.ts:308

Maximum items per page

message?
ts
optional message?: string;

Defined in: src/interfaces/index.ts:318

Custom response message in meta

problemDetails?
ts
optional problemDetails?: boolean;

Defined in: src/interfaces/index.ts:330

Use RFC 9457 Problem Details schema for error responses in Swagger (default: false). Note: This only controls Swagger documentation schema. The actual runtime error format is determined by the module-level problemDetails option. Keep both in sync.

sort?
ts
optional sort?: boolean;

Defined in: src/interfaces/index.ts:312

Include sort metadata (default: false)


SafeEndpointOptions

Defined in: src/interfaces/index.ts:252

Properties

code?
ts
optional code?: string;

Defined in: src/interfaces/index.ts:266

Custom success code

deprecated?
ts
optional deprecated?: DeprecatedOptions;

Defined in: src/interfaces/index.ts:270

Mark endpoint as deprecated with RFC headers

description?
ts
optional description?: string;

Defined in: src/interfaces/index.ts:258

Swagger response description

errors?
ts
optional errors?: ApiSafeErrorResponseConfig[];

Defined in: src/interfaces/index.ts:268

Error responses to document in Swagger

filter?
ts
optional filter?: boolean;

Defined in: src/interfaces/index.ts:262

Include filter metadata from handler return value (default: false)

isArray?
ts
optional isArray?: boolean;

Defined in: src/interfaces/index.ts:256

Whether data is an array (default: false)

message?
ts
optional message?: string;

Defined in: src/interfaces/index.ts:264

Custom response message in meta

problemDetails?
ts
optional problemDetails?: boolean;

Defined in: src/interfaces/index.ts:276

Use RFC 9457 Problem Details schema for error responses in Swagger (default: false). Note: This only controls Swagger documentation schema. The actual runtime error format is determined by the module-level problemDetails option. Keep both in sync.

sort?
ts
optional sort?: boolean;

Defined in: src/interfaces/index.ts:260

Include sort metadata from handler return value (default: false)

statusCode?
ts
optional statusCode?: number;

Defined in: src/interfaces/index.ts:254

HTTP status code for Swagger response (default: 200)


SafeErrorResponse

Defined in: src/interfaces/index.ts:181

Properties

error
ts
error: {
  code: string;
  details?: unknown;
  message: string;
};

Defined in: src/interfaces/index.ts:185

code
ts
code: string;
details?
ts
optional details?: unknown;
message
ts
message: string;
meta?
ts
optional meta?: {
[key: string]: unknown;
  deprecation?: DeprecationMeta;
  rateLimit?: RateLimitMeta;
  responseTime?: number;
};

Defined in: src/interfaces/index.ts:190

Index Signature
ts
[key: string]: unknown

Additional context fields (e.g., traceId, correlationId)

deprecation?
ts
optional deprecation?: DeprecationMeta;
rateLimit?
ts
optional rateLimit?: RateLimitMeta;
responseTime?
ts
optional responseTime?: number;
path?
ts
optional path?: string;

Defined in: src/interfaces/index.ts:198

requestId?
ts
optional requestId?: string;

Defined in: src/interfaces/index.ts:184

statusCode
ts
statusCode: number;

Defined in: src/interfaces/index.ts:183

success
ts
success: false;

Defined in: src/interfaces/index.ts:182

timestamp?
ts
optional timestamp?: string;

Defined in: src/interfaces/index.ts:197


SafePaginatedEndpointOptions

Defined in: src/interfaces/index.ts:279

Properties

code?
ts
optional code?: string;

Defined in: src/interfaces/index.ts:293

Custom success code

deprecated?
ts
optional deprecated?: DeprecatedOptions;

Defined in: src/interfaces/index.ts:297

Mark endpoint as deprecated with RFC headers

description?
ts
optional description?: string;

Defined in: src/interfaces/index.ts:289

Swagger response description

errors?
ts
optional errors?: ApiSafeErrorResponseConfig[];

Defined in: src/interfaces/index.ts:295

Error responses to document in Swagger

filter?
ts
optional filter?: boolean;

Defined in: src/interfaces/index.ts:287

Include filter metadata from handler return value (default: false)

ts
optional links?: boolean;

Defined in: src/interfaces/index.ts:283

Generate HATEOAS navigation links (default: false)

maxLimit?
ts
optional maxLimit?: number;

Defined in: src/interfaces/index.ts:281

Maximum items per page (clamped via PaginatedOptions.maxLimit)

message?
ts
optional message?: string;

Defined in: src/interfaces/index.ts:291

Custom response message in meta

problemDetails?
ts
optional problemDetails?: boolean;

Defined in: src/interfaces/index.ts:303

Use RFC 9457 Problem Details schema for error responses in Swagger (default: false). Note: This only controls Swagger documentation schema. The actual runtime error format is determined by the module-level problemDetails option. Keep both in sync.

sort?
ts
optional sort?: boolean;

Defined in: src/interfaces/index.ts:285

Include sort metadata from handler return value (default: false)


SafeProblemDetailsResponse

Defined in: src/interfaces/index.ts:100

Properties

code?
ts
optional code?: string;

Defined in: src/interfaces/index.ts:107

Extension member: machine-readable error code

detail
ts
detail: string;

Defined in: src/interfaces/index.ts:104

details?
ts
optional details?: unknown;

Defined in: src/interfaces/index.ts:111

Extension member: validation error details

instance
ts
instance: string;

Defined in: src/interfaces/index.ts:105

meta?
ts
optional meta?: {
[key: string]: unknown;
  deprecation?: DeprecationMeta;
  rateLimit?: RateLimitMeta;
  responseTime?: number;
};

Defined in: src/interfaces/index.ts:113

Extension member: response time and context

Index Signature
ts
[key: string]: unknown

Additional context fields (e.g., traceId, correlationId)

deprecation?
ts
optional deprecation?: DeprecationMeta;
rateLimit?
ts
optional rateLimit?: RateLimitMeta;
responseTime?
ts
optional responseTime?: number;
requestId?
ts
optional requestId?: string;

Defined in: src/interfaces/index.ts:109

Extension member: request tracking ID

status
ts
status: number;

Defined in: src/interfaces/index.ts:103

title
ts
title: string;

Defined in: src/interfaces/index.ts:102

type
ts
type: string;

Defined in: src/interfaces/index.ts:101


SafeResponseModuleAsyncOptions

Defined in: src/interfaces/index.ts:122

Extends

  • Pick<ModuleMetadata, "imports">

Properties

imports?
ts
optional imports?: (
  | DynamicModule
  | Type<any>
  | Promise<DynamicModule>
  | ForwardReference<any>)[];

Defined in: node_modules/@nestjs/common/interfaces/modules/module-metadata.interface.d.ts:18

Optional list of imported modules that export the providers which are required in this module.

Inherited from
ts
Pick.imports
inject?
ts
optional inject?: any[];

Defined in: src/interfaces/index.ts:129

useFactory
ts
useFactory: (...args) => 
  | SafeResponseModuleOptions
| Promise<SafeResponseModuleOptions>;

Defined in: src/interfaces/index.ts:124

Parameters
ParameterType
...argsany[]
Returns

| SafeResponseModuleOptions | Promise<SafeResponseModuleOptions>


SafeResponseModuleOptions

Defined in: src/interfaces/index.ts:62

Properties

context?
ts
optional context?: ContextOptions;

Defined in: src/interfaces/index.ts:84

Inject request context values (e.g., traceId) into response meta. Requires nestjs-cls.

dateFormatter?
ts
optional dateFormatter?: () => string;

Defined in: src/interfaces/index.ts:70

Custom date formatter function (default: ISO 8601)

Returns

string

errorCodeMapper?
ts
optional errorCodeMapper?: (exception, context?) => string | undefined;

Defined in: src/interfaces/index.ts:68

Custom error code mapper function. Optional second arg provides statusCode and defaultCode context.

Parameters
ParameterType
exceptionunknown
context?ErrorCodeMapperContext
Returns

string | undefined

errorCodes?
ts
optional errorCodes?: Record<number, string>;

Defined in: src/interfaces/index.ts:92

Declarative error code map. Merged on top of DEFAULT_ERROR_CODE_MAP. Use for simple status-to-code mappings.

i18n?
ts
optional i18n?: boolean | I18nAdapter;

Defined in: src/interfaces/index.ts:86

Enable i18n for error/success messages. true = auto-detect nestjs-i18n, or pass a custom I18nAdapter.

path?
ts
optional path?: boolean;

Defined in: src/interfaces/index.ts:66

Include path field in responses (default: true)

problemDetails?
ts
optional problemDetails?: boolean | ProblemDetailsOptions;

Defined in: src/interfaces/index.ts:80

Enable RFC 9457 Problem Details format for error responses. Default: false

rateLimit?
ts
optional rateLimit?: boolean | RateLimitOptions;

Defined in: src/interfaces/index.ts:88

Mirror rate limit response headers into meta.rateLimit. true uses defaults, or pass options object.

requestId?
ts
optional requestId?: boolean | RequestIdOptions;

Defined in: src/interfaces/index.ts:76

Enable request ID tracking. true uses defaults, or pass options object.

responseTime?
ts
optional responseTime?: boolean;

Defined in: src/interfaces/index.ts:78

Include response time in meta (milliseconds). Default: false

successCodeMapper?
ts
optional successCodeMapper?: (statusCode) => string | undefined;

Defined in: src/interfaces/index.ts:72

Custom success code mapper function (statusCode → code string)

Parameters
ParameterType
statusCodenumber
Returns

string | undefined

suppressWarnings?
ts
optional suppressWarnings?: boolean;

Defined in: src/interfaces/index.ts:90

Suppress shape-mismatch warnings for @Paginated, @CursorPaginated, @SortMeta, @FilterMeta. Default: false

swagger?
ts
optional swagger?: SwaggerOptions;

Defined in: src/interfaces/index.ts:82

Swagger documentation options

timestamp?
ts
optional timestamp?: boolean;

Defined in: src/interfaces/index.ts:64

Include timestamp field in responses (default: true)

transformResponse?
ts
optional transformResponse?: (data) => unknown;

Defined in: src/interfaces/index.ts:74

Transform data before wrapping (sync only, runs before pagination check)

Parameters
ParameterType
dataunknown
Returns

unknown


SafeSuccessResponse

Defined in: src/interfaces/index.ts:170

Type Parameters

Type ParameterDefault type
Tunknown

Properties

code?
ts
optional code?: string;

Defined in: src/interfaces/index.ts:173

data
ts
data: T;

Defined in: src/interfaces/index.ts:175

meta?
ts
optional meta?: ResponseMeta;

Defined in: src/interfaces/index.ts:176

path?
ts
optional path?: string;

Defined in: src/interfaces/index.ts:178

requestId?
ts
optional requestId?: string;

Defined in: src/interfaces/index.ts:174

statusCode
ts
statusCode: number;

Defined in: src/interfaces/index.ts:172

success
ts
success: true;

Defined in: src/interfaces/index.ts:171

timestamp?
ts
optional timestamp?: string;

Defined in: src/interfaces/index.ts:177


SortInfo

Defined in: src/interfaces/index.ts:153

Properties

field
ts
field: string;

Defined in: src/interfaces/index.ts:154

order
ts
order: "asc" | "desc";

Defined in: src/interfaces/index.ts:155


SwaggerOptions

Defined in: src/interfaces/index.ts:57

Properties

globalErrors?
ts
optional globalErrors?: ApiSafeErrorResponseConfig[];

Defined in: src/interfaces/index.ts:59

Error responses to add to all routes (e.g., [401, 403, 500])

Type Aliases

ApiSafeErrorResponseConfig

ts
type ApiSafeErrorResponseConfig = 
  | number
  | {
  status: number;
} & ApiSafeErrorResponseOptions;

Defined in: src/interfaces/index.ts:248

Variables

DEFAULT_ERROR_CODE_MAP

ts
const DEFAULT_ERROR_CODE_MAP: {
  400: "BAD_REQUEST";
  401: "UNAUTHORIZED";
  403: "FORBIDDEN";
  404: "NOT_FOUND";
  405: "METHOD_NOT_ALLOWED";
  409: "CONFLICT";
  422: "UNPROCESSABLE_ENTITY";
  429: "TOO_MANY_REQUESTS";
  500: "INTERNAL_SERVER_ERROR";
  502: "BAD_GATEWAY";
  503: "SERVICE_UNAVAILABLE";
};

Defined in: src/constants.ts:39

Type Declaration

NameTypeDefault valueDefined in
400"BAD_REQUEST"'BAD_REQUEST'src/constants.ts:40
401"UNAUTHORIZED"'UNAUTHORIZED'src/constants.ts:41
403"FORBIDDEN"'FORBIDDEN'src/constants.ts:42
404"NOT_FOUND"'NOT_FOUND'src/constants.ts:43
405"METHOD_NOT_ALLOWED"'METHOD_NOT_ALLOWED'src/constants.ts:44
409"CONFLICT"'CONFLICT'src/constants.ts:45
422"UNPROCESSABLE_ENTITY"'UNPROCESSABLE_ENTITY'src/constants.ts:46
429"TOO_MANY_REQUESTS"'TOO_MANY_REQUESTS'src/constants.ts:47
500"INTERNAL_SERVER_ERROR"'INTERNAL_SERVER_ERROR'src/constants.ts:48
502"BAD_GATEWAY"'BAD_GATEWAY'src/constants.ts:49
503"SERVICE_UNAVAILABLE"'SERVICE_UNAVAILABLE'src/constants.ts:50

DEFAULT_PROBLEM_TITLE_MAP

ts
const DEFAULT_PROBLEM_TITLE_MAP: {
  400: "Bad Request";
  401: "Unauthorized";
  403: "Forbidden";
  404: "Not Found";
  405: "Method Not Allowed";
  409: "Conflict";
  422: "Unprocessable Entity";
  429: "Too Many Requests";
  500: "Internal Server Error";
  502: "Bad Gateway";
  503: "Service Unavailable";
};

Defined in: src/constants.ts:25

Type Declaration

NameTypeDefault valueDefined in
400"Bad Request"'Bad Request'src/constants.ts:26
401"Unauthorized"'Unauthorized'src/constants.ts:27
403"Forbidden"'Forbidden'src/constants.ts:28
404"Not Found"'Not Found'src/constants.ts:29
405"Method Not Allowed"'Method Not Allowed'src/constants.ts:30
409"Conflict"'Conflict'src/constants.ts:31
422"Unprocessable Entity"'Unprocessable Entity'src/constants.ts:32
429"Too Many Requests"'Too Many Requests'src/constants.ts:33
500"Internal Server Error"'Internal Server Error'src/constants.ts:34
502"Bad Gateway"'Bad Gateway'src/constants.ts:35
503"Service Unavailable"'Service Unavailable'src/constants.ts:36

Functions

ApiCursorPaginatedSafeResponse()

ts
function ApiCursorPaginatedSafeResponse<T>(model, options?): MethodDecorator;

Defined in: src/decorators/index.ts:218

Document a cursor-paginated response with Swagger schema.

Type Parameters

Type Parameter
T extends Type<any>

Parameters

ParameterType
modelT
options?{ description?: string; }
options.description?string

Returns

MethodDecorator


ApiPaginatedSafeResponse()

ts
function ApiPaginatedSafeResponse<T>(model, options?): MethodDecorator;

Defined in: src/decorators/index.ts:80

Document a paginated response with Swagger schema.

Type Parameters

Type Parameter
T extends Type<any>

Parameters

ParameterType
modelT
options?{ description?: string; }
options.description?string

Returns

MethodDecorator


ApiSafeErrorResponse()

ts
function ApiSafeErrorResponse(status, options?): MethodDecorator;

Defined in: src/decorators/index.ts:149

Document a single error response in Swagger with the SafeErrorResponseDto envelope. Error code auto-resolves from DEFAULT_ERROR_CODE_MAP if not provided.

Parameters

ParameterType
statusnumber
options?ApiSafeErrorResponseOptions

Returns

MethodDecorator

Example

typescript
@ApiSafeErrorResponse(404)
@ApiSafeErrorResponse(400, { code: 'VALIDATION_ERROR', details: ['email must be an email'] })

ApiSafeErrorResponses()

ts
function ApiSafeErrorResponses(configs): MethodDecorator;

Defined in: src/decorators/index.ts:204

Document multiple error responses in Swagger at once. Accepts an array of status codes (number) or config objects.

Parameters

ParameterType
configsApiSafeErrorResponseConfig[]

Returns

MethodDecorator

Example

typescript
@ApiSafeErrorResponses([400, 401, 404])
@ApiSafeErrorResponses([
  400,
  { status: 401, description: 'Token expired' },
  { status: 404, code: 'USER_NOT_FOUND' },
])

ApiSafeProblemResponse()

ts
function ApiSafeProblemResponse(status, options?): MethodDecorator;

Defined in: src/decorators/index.ts:338

Document an RFC 9457 Problem Details error response in Swagger.

Always generates status-specific examples (status, title, code) via allOf composition with ProblemDetailsDto. When code, message, or details are provided, those override the auto-resolved defaults.

Parameters

ParameterType
statusnumber
options?{ code?: string; description?: string; details?: unknown; message?: string; }
options.code?string
options.description?string
options.details?unknown
options.message?string

Returns

MethodDecorator


ApiSafeResponse()

ts
function ApiSafeResponse<T>(model, options?): MethodDecorator;

Defined in: src/decorators/index.ts:45

Document the Swagger data field with a specific DTO type.

Type Parameters

Type Parameter
T extends Type<any>

Parameters

ParameterType
modelT
options?{ description?: string; isArray?: boolean; statusCode?: number; }
options.description?string
options.isArray?boolean
options.statusCode?number

Returns

MethodDecorator


applyGlobalErrors()

ts
function applyGlobalErrors<T>(document, options): T;

Defined in: src/swagger/global-errors.ts:44

Apply global error response schemas to all operations in an OpenAPI document.

Call this after SwaggerModule.createDocument() and before SwaggerModule.setup():

typescript
const document = SwaggerModule.createDocument(app, config);
applyGlobalErrors(document, options);
SwaggerModule.setup('api', app, document);

The generic preserves the caller's document type — if you pass OpenAPIObject, you get OpenAPIObject back, so chaining with SwaggerModule.setup() works without manual casts.

Routes decorated with @SkipGlobalErrors() are excluded. Route-level error responses take priority over global ones (no overwriting).

Type Parameters

Type Parameter
T extends object

Parameters

ParameterType
documentT
optionsSafeResponseModuleOptions

Returns

T


CursorPaginated()

ts
function CursorPaginated(options?): CustomDecorator<string>;

Defined in: src/decorators/index.ts:268

Enable cursor-based pagination metadata auto-calculation.

Parameters

ParameterType
options?CursorPaginatedOptions

Returns

CustomDecorator<string>


Deprecated()

ts
function Deprecated(options?): <TFunction, Y>(target, propertyKey?, descriptor?) => void;

Defined in: src/decorators/index.ts:325

Mark a route as deprecated with RFC 9745 Deprecation and RFC 8594 Sunset headers. Also sets deprecated: true in the Swagger operation documentation.

Parameters

ParameterTypeDescription
options?DeprecatedOptionsOptional deprecation configuration

Returns

<TFunction, Y>(target, propertyKey?, descriptor?) => void

Example

typescript
@Get('v1/users')
@Deprecated({ sunset: '2026-12-31', link: '/v2/users' })
findAll() { ... }

FilterMeta()

ts
function FilterMeta(): CustomDecorator<string>;

Defined in: src/decorators/index.ts:300

Include filter metadata in the response meta. The handler must return a filters field in the paginated result.

Returns

CustomDecorator<string>


lookupErrorCode()

ts
function lookupErrorCode(statusCode): string | undefined;

Defined in: src/constants.ts:54

Look up an error code by HTTP status. Returns undefined for unmapped status codes.

Parameters

ParameterType
statusCodenumber

Returns

string | undefined


lookupProblemTitle()

ts
function lookupProblemTitle(statusCode): string | undefined;

Defined in: src/constants.ts:59

Look up a problem title by HTTP status. Returns undefined for unmapped status codes.

Parameters

ParameterType
statusCodenumber

Returns

string | undefined


Paginated()

ts
function Paginated(options?): CustomDecorator<string>;

Defined in: src/decorators/index.ts:262

Enable offset pagination metadata auto-calculation.

Parameters

ParameterType
options?PaginatedOptions

Returns

CustomDecorator<string>


ProblemType()

ts
function ProblemType(typeUri): CustomDecorator<string>;

Defined in: src/decorators/index.ts:287

Set the RFC 9457 problem type URI for this route. Used when problemDetails is enabled in module options.

Parameters

ParameterType
typeUristring

Returns

CustomDecorator<string>


RawResponse()

ts
function RawResponse(): CustomDecorator<string>;

Defined in: src/decorators/index.ts:257

Skip response wrapping for this route.

Returns

CustomDecorator<string>


ResponseMessage()

ts
function ResponseMessage(message): CustomDecorator<string>;

Defined in: src/decorators/index.ts:274

Set a custom message in the response meta.

Parameters

ParameterType
messagestring

Returns

CustomDecorator<string>


SafeCursorPaginatedEndpoint()

ts
function SafeCursorPaginatedEndpoint<T>(model, options?): MethodDecorator;

Defined in: src/decorators/index.ts:436

Composite decorator for cursor-paginated endpoints. Combines Swagger cursor-paginated response, @CursorPaginated(), sort/filter meta, and more.

Type Parameters

Type Parameter
T extends Type<any>

Parameters

ParameterType
modelT
optionsSafeCursorPaginatedEndpointOptions

Returns

MethodDecorator


SafeEndpoint()

ts
function SafeEndpoint<T>(model, options?): MethodDecorator;

Defined in: src/decorators/index.ts:379

Composite decorator for standard (non-paginated) endpoints. Combines Swagger response, success code, message, error responses, and deprecation.

Type Parameters

Type Parameter
T extends Type<any>

Parameters

ParameterType
modelT
optionsSafeEndpointOptions

Returns

MethodDecorator


SafePaginatedEndpoint()

ts
function SafePaginatedEndpoint<T>(model, options?): MethodDecorator;

Defined in: src/decorators/index.ts:407

Composite decorator for offset-paginated endpoints. Combines Swagger paginated response, @Paginated(), sort/filter meta, and more.

Type Parameters

Type Parameter
T extends Type<any>

Parameters

ParameterType
modelT
optionsSafePaginatedEndpointOptions

Returns

MethodDecorator


SafeResponse()

ts
function SafeResponse(options?): MethodDecorator;

Defined in: src/decorators/index.ts:23

Apply standard safe response wrapping + basic Swagger schema.

Parameters

ParameterType
options?{ description?: string; statusCode?: number; }
options.description?string
options.statusCode?number

Returns

MethodDecorator


SkipGlobalErrors()

ts
function SkipGlobalErrors(): <TFunction, Y>(target, propertyKey?, descriptor?) => void;

Defined in: src/decorators/index.ts:306

Skip global error responses for this route. Use on health checks, public endpoints, etc. that should not inherit global error documentation.

Returns

<TFunction, Y>(target, propertyKey?, descriptor?) => void


SortMeta()

ts
function SortMeta(): CustomDecorator<string>;

Defined in: src/decorators/index.ts:294

Include sort metadata in the response meta. The handler must return a sort field in the paginated result.

Returns

CustomDecorator<string>


SuccessCode()

ts
function SuccessCode(code): CustomDecorator<string>;

Defined in: src/decorators/index.ts:281

Set a custom success code for this route (method-level only). Takes priority over successCodeMapper module option.

Parameters

ParameterType
codestring

Returns

CustomDecorator<string>

Released under the MIT License.