@vritti/api-sdk 0.3.3 → 0.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. package/dist/auth.cjs +942 -0
  2. package/dist/auth.cjs.map +1 -0
  3. package/dist/auth.d.cts +95 -0
  4. package/dist/auth.d.ts +95 -0
  5. package/dist/auth.js +884 -0
  6. package/dist/auth.js.map +1 -0
  7. package/dist/cache.cjs +182 -14
  8. package/dist/cache.cjs.map +1 -1
  9. package/dist/cache.d.cts +48 -4
  10. package/dist/cache.d.ts +48 -4
  11. package/dist/cache.js +177 -12
  12. package/dist/cache.js.map +1 -1
  13. package/dist/catalog-resolver.cjs +226 -51
  14. package/dist/catalog-resolver.cjs.map +1 -1
  15. package/dist/catalog-resolver.d.cts +41 -19
  16. package/dist/catalog-resolver.d.ts +41 -19
  17. package/dist/catalog-resolver.js +212 -46
  18. package/dist/catalog-resolver.js.map +1 -1
  19. package/dist/code-pattern-BP4zkNtT.d.cts +12 -0
  20. package/dist/code-pattern-BP4zkNtT.d.ts +12 -0
  21. package/dist/context.cjs +93 -0
  22. package/dist/context.cjs.map +1 -0
  23. package/dist/context.d.cts +19 -0
  24. package/dist/context.d.ts +19 -0
  25. package/dist/context.js +64 -0
  26. package/dist/context.js.map +1 -0
  27. package/dist/countries.cjs +1559 -0
  28. package/dist/countries.cjs.map +1 -0
  29. package/dist/countries.d.cts +13 -0
  30. package/dist/countries.d.ts +13 -0
  31. package/dist/countries.js +1532 -0
  32. package/dist/countries.js.map +1 -0
  33. package/dist/data-table.cjs +1280 -0
  34. package/dist/data-table.cjs.map +1 -0
  35. package/dist/data-table.d.cts +123 -0
  36. package/dist/data-table.d.ts +123 -0
  37. package/dist/data-table.js +1260 -0
  38. package/dist/data-table.js.map +1 -0
  39. package/dist/database.cjs +1510 -0
  40. package/dist/database.cjs.map +1 -0
  41. package/dist/database.d.cts +287 -0
  42. package/dist/database.d.ts +287 -0
  43. package/dist/database.js +1469 -0
  44. package/dist/database.js.map +1 -0
  45. package/dist/decimal.d.cts +0 -1
  46. package/dist/decimal.d.ts +0 -1
  47. package/dist/decorators.cjs +1817 -0
  48. package/dist/decorators.cjs.map +1 -0
  49. package/dist/decorators.d.cts +24 -0
  50. package/dist/decorators.d.ts +24 -0
  51. package/dist/decorators.js +1780 -0
  52. package/dist/decorators.js.map +1 -0
  53. package/dist/drizzle-pg-core.cjs +25 -0
  54. package/dist/drizzle-pg-core.cjs.map +1 -1
  55. package/dist/drizzle-pg-core.d.cts +7 -0
  56. package/dist/drizzle-pg-core.d.ts +7 -0
  57. package/dist/drizzle-pg-core.js +22 -0
  58. package/dist/drizzle-pg-core.js.map +1 -1
  59. package/dist/exceptions.cjs +301 -0
  60. package/dist/exceptions.cjs.map +1 -0
  61. package/dist/exceptions.d.cts +90 -0
  62. package/dist/exceptions.d.ts +90 -0
  63. package/dist/exceptions.js +257 -0
  64. package/dist/exceptions.js.map +1 -0
  65. package/dist/filter.types-PuARU9XD.d.cts +50 -0
  66. package/dist/filter.types-PuARU9XD.d.ts +50 -0
  67. package/dist/filters.cjs +407 -0
  68. package/dist/filters.cjs.map +1 -0
  69. package/dist/filters.d.cts +55 -0
  70. package/dist/filters.d.ts +55 -0
  71. package/dist/filters.js +377 -0
  72. package/dist/filters.js.map +1 -0
  73. package/dist/index.cjs +0 -5423
  74. package/dist/index.cjs.map +1 -1
  75. package/dist/index.d.cts +93 -854
  76. package/dist/index.d.ts +93 -854
  77. package/dist/index.js +0 -5301
  78. package/dist/index.js.map +1 -1
  79. package/dist/is-country.decorator-CcNwSSr5.d.cts +5 -0
  80. package/dist/is-country.decorator-CcNwSSr5.d.ts +5 -0
  81. package/dist/license.d.cts +1 -1
  82. package/dist/license.d.ts +1 -1
  83. package/dist/lodash.cjs.map +1 -1
  84. package/dist/lodash.js.map +1 -1
  85. package/dist/logger.cjs +862 -0
  86. package/dist/logger.cjs.map +1 -0
  87. package/dist/logger.d.cts +118 -0
  88. package/dist/logger.d.ts +118 -0
  89. package/dist/logger.js +816 -0
  90. package/dist/logger.js.map +1 -0
  91. package/dist/migrate.cjs +2 -2
  92. package/dist/migrate.cjs.map +1 -1
  93. package/dist/migrate.d.cts +2 -0
  94. package/dist/migrate.d.ts +2 -0
  95. package/dist/migrate.js +2 -2
  96. package/dist/migrate.js.map +1 -1
  97. package/dist/money.cjs +18 -3
  98. package/dist/money.cjs.map +1 -1
  99. package/dist/money.d.cts +13 -13
  100. package/dist/money.d.ts +13 -13
  101. package/dist/money.js +18 -3
  102. package/dist/money.js.map +1 -1
  103. package/dist/nats.cjs +34 -35
  104. package/dist/nats.cjs.map +1 -1
  105. package/dist/nats.d.cts +14 -14
  106. package/dist/nats.d.ts +14 -14
  107. package/dist/nats.js +32 -33
  108. package/dist/nats.js.map +1 -1
  109. package/dist/root.cjs +225 -0
  110. package/dist/root.cjs.map +1 -0
  111. package/dist/root.d.cts +4 -0
  112. package/dist/root.d.ts +4 -0
  113. package/dist/root.js +200 -0
  114. package/dist/root.js.map +1 -0
  115. package/dist/{types-DQRwj5rr.d.cts → types-C9jPdQqH.d.cts} +32 -6
  116. package/dist/{types-DQRwj5rr.d.ts → types-C9jPdQqH.d.ts} +32 -6
  117. package/dist/types.cjs +19 -0
  118. package/dist/types.cjs.map +1 -0
  119. package/dist/types.d.cts +17 -0
  120. package/dist/types.d.ts +17 -0
  121. package/dist/types.js +1 -0
  122. package/dist/types.js.map +1 -0
  123. package/dist/utils.cjs +273 -0
  124. package/dist/utils.cjs.map +1 -0
  125. package/dist/utils.d.cts +8 -0
  126. package/dist/utils.d.ts +8 -0
  127. package/dist/utils.js +245 -0
  128. package/dist/utils.js.map +1 -0
  129. package/package.json +122 -1
  130. package/dist/cache.service-_SuJIcNA.d.cts +0 -20
  131. package/dist/cache.service-_SuJIcNA.d.ts +0 -20
  132. package/dist/fastify-augmentation-CQPBNS5a.d.cts +0 -105
  133. package/dist/fastify-augmentation-CQPBNS5a.d.ts +0 -105
@@ -0,0 +1,407 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/filters/index.ts
22
+ var filters_exports = {};
23
+ __export(filters_exports, {
24
+ ErrorCode: () => ErrorCode,
25
+ HttpExceptionFilter: () => HttpExceptionFilter,
26
+ TransportAwareExceptionFilter: () => TransportAwareExceptionFilter,
27
+ createGraphqlFormatError: () => createGraphqlFormatError,
28
+ errorCodeFromStatus: () => errorCodeFromStatus,
29
+ getHttpStatusTitle: () => getHttpStatusTitle
30
+ });
31
+ module.exports = __toCommonJS(filters_exports);
32
+
33
+ // src/filters/error-code.ts
34
+ var import_common = require("@nestjs/common");
35
+ var ErrorCode = /* @__PURE__ */ (function(ErrorCode2) {
36
+ ErrorCode2["UNAUTHENTICATED"] = "UNAUTHENTICATED";
37
+ ErrorCode2["FORBIDDEN"] = "FORBIDDEN";
38
+ ErrorCode2["NOT_FOUND"] = "NOT_FOUND";
39
+ ErrorCode2["VALIDATION_FAILED"] = "VALIDATION_FAILED";
40
+ ErrorCode2["CONFLICT"] = "CONFLICT";
41
+ ErrorCode2["RATE_LIMITED"] = "RATE_LIMITED";
42
+ ErrorCode2["BAD_REQUEST"] = "BAD_REQUEST";
43
+ ErrorCode2["INTERNAL"] = "INTERNAL";
44
+ return ErrorCode2;
45
+ })({});
46
+ function errorCodeFromStatus(status) {
47
+ switch (status) {
48
+ case import_common.HttpStatus.UNAUTHORIZED:
49
+ return "UNAUTHENTICATED";
50
+ case import_common.HttpStatus.FORBIDDEN:
51
+ return "FORBIDDEN";
52
+ case import_common.HttpStatus.NOT_FOUND:
53
+ return "NOT_FOUND";
54
+ case import_common.HttpStatus.BAD_REQUEST:
55
+ case import_common.HttpStatus.UNPROCESSABLE_ENTITY:
56
+ return "VALIDATION_FAILED";
57
+ case import_common.HttpStatus.CONFLICT:
58
+ return "CONFLICT";
59
+ case import_common.HttpStatus.TOO_MANY_REQUESTS:
60
+ return "RATE_LIMITED";
61
+ default:
62
+ if (status >= 400 && status < 500) {
63
+ return "BAD_REQUEST";
64
+ }
65
+ return "INTERNAL";
66
+ }
67
+ }
68
+ __name(errorCodeFromStatus, "errorCodeFromStatus");
69
+
70
+ // src/filters/problem-extraction.ts
71
+ var import_common2 = require("@nestjs/common");
72
+ function getHttpStatusTitle(status) {
73
+ const enumKey = Object.entries(import_common2.HttpStatus).find(([key, value]) => value === status && Number.isNaN(Number(key)))?.[0];
74
+ if (!enumKey) {
75
+ return "Error";
76
+ }
77
+ return enumKey.split("_").map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join(" ");
78
+ }
79
+ __name(getHttpStatusTitle, "getHttpStatusTitle");
80
+ function extractValidationFieldErrors(message) {
81
+ return message.map((msg) => {
82
+ if (typeof msg === "object" && "property" in msg && "constraints" in msg) {
83
+ const constraintValues = Object.values(msg.constraints);
84
+ return {
85
+ field: msg.property,
86
+ message: constraintValues[0] ?? "Validation failed"
87
+ };
88
+ }
89
+ return null;
90
+ }).filter((error) => error !== null);
91
+ }
92
+ __name(extractValidationFieldErrors, "extractValidationFieldErrors");
93
+ function extractProblemFromResponse(exceptionResponse, problemFallbackDetail) {
94
+ let type = "about:blank";
95
+ let label;
96
+ let detail;
97
+ let errors = [];
98
+ if (typeof exceptionResponse === "string") {
99
+ detail = exceptionResponse;
100
+ return {
101
+ type,
102
+ label,
103
+ detail,
104
+ errors
105
+ };
106
+ }
107
+ if (exceptionResponse !== null && typeof exceptionResponse === "object") {
108
+ const responseObj = exceptionResponse;
109
+ if ("type" in responseObj || "label" in responseObj || "errors" in responseObj) {
110
+ const problemResponse = responseObj;
111
+ type = problemResponse.type ?? "about:blank";
112
+ label = problemResponse.label;
113
+ detail = problemResponse.detail ?? problemFallbackDetail;
114
+ errors = problemResponse.errors ?? [];
115
+ } else if ("message" in responseObj && Array.isArray(responseObj.message)) {
116
+ errors = extractValidationFieldErrors(responseObj.message);
117
+ detail = "Validation failed";
118
+ } else if ("message" in responseObj) {
119
+ const message = responseObj.message;
120
+ detail = Array.isArray(message) ? message.join(", ") : message;
121
+ }
122
+ }
123
+ return {
124
+ type,
125
+ label,
126
+ detail,
127
+ errors
128
+ };
129
+ }
130
+ __name(extractProblemFromResponse, "extractProblemFromResponse");
131
+
132
+ // src/filters/graphql-format-error.ts
133
+ function isHttpExceptionLike(error) {
134
+ return error instanceof Error && typeof error.getStatus === "function" && typeof error.getResponse === "function";
135
+ }
136
+ __name(isHttpExceptionLike, "isHttpExceptionLike");
137
+ function isProblemLike(error) {
138
+ if (error == null || typeof error !== "object") {
139
+ return false;
140
+ }
141
+ const o = error;
142
+ return typeof o.status === "number" || typeof o.statusCode === "number";
143
+ }
144
+ __name(isProblemLike, "isProblemLike");
145
+ function findProblemSource(error) {
146
+ let current = error;
147
+ for (let depth = 0; current && depth < 10; depth++) {
148
+ if (isHttpExceptionLike(current)) {
149
+ const status = current.getStatus();
150
+ return {
151
+ status,
152
+ response: current.getResponse(),
153
+ fallback: current.message ?? getHttpStatusTitle(status)
154
+ };
155
+ }
156
+ if (isProblemLike(current)) {
157
+ const status = current.status ?? current.statusCode ?? 500;
158
+ return {
159
+ status,
160
+ response: current,
161
+ fallback: current.detail ?? current.message ?? getHttpStatusTitle(status)
162
+ };
163
+ }
164
+ const next = current;
165
+ current = next.originalError ?? next.thrownValue;
166
+ }
167
+ return void 0;
168
+ }
169
+ __name(findProblemSource, "findProblemSource");
170
+ var GENERIC_INTERNAL_MESSAGE = "Internal server error";
171
+ function createGraphqlFormatError(opts) {
172
+ const { isProduction, getTraceId } = opts;
173
+ return (formattedError, error) => {
174
+ const gqlError = error ?? void 0;
175
+ const source = findProblemSource(gqlError);
176
+ let status = 500;
177
+ let detail;
178
+ let label;
179
+ let fieldErrors = [];
180
+ if (source) {
181
+ status = source.status;
182
+ const extracted = extractProblemFromResponse(source.response, source.fallback);
183
+ detail = extracted.detail;
184
+ label = extracted.label;
185
+ fieldErrors = extracted.errors;
186
+ }
187
+ const code = errorCodeFromStatus(status);
188
+ let message = detail ?? formattedError.message;
189
+ if (code === "INTERNAL" && isProduction) {
190
+ message = GENERIC_INTERNAL_MESSAGE;
191
+ }
192
+ const incoming = {
193
+ ...formattedError.extensions ?? {}
194
+ };
195
+ const traceId = getTraceId?.();
196
+ const timestamp = (/* @__PURE__ */ new Date()).toISOString();
197
+ const extensions = {
198
+ ...incoming,
199
+ // Always our canonical code — overrides Apollo's default INTERNAL_SERVER_ERROR.
200
+ code,
201
+ ...traceId !== void 0 ? {
202
+ traceId
203
+ } : {},
204
+ timestamp,
205
+ ...label !== void 0 ? {
206
+ label
207
+ } : {},
208
+ ...fieldErrors.length > 0 ? {
209
+ fieldErrors
210
+ } : {}
211
+ };
212
+ if (isProduction) {
213
+ delete extensions.stacktrace;
214
+ delete extensions.exception;
215
+ delete extensions.originalError;
216
+ }
217
+ const result = {
218
+ message,
219
+ extensions
220
+ };
221
+ if (formattedError.locations) result.locations = formattedError.locations;
222
+ if (formattedError.path) result.path = formattedError.path;
223
+ return result;
224
+ };
225
+ }
226
+ __name(createGraphqlFormatError, "createGraphqlFormatError");
227
+
228
+ // src/filters/http-exception.filter.ts
229
+ var import_common5 = require("@nestjs/common");
230
+
231
+ // src/exceptions/conflict.exception.ts
232
+ var import_common4 = require("@nestjs/common");
233
+
234
+ // src/exceptions/base-field.exception.ts
235
+ var import_common3 = require("@nestjs/common");
236
+ var HttpProblemException = class extends import_common3.HttpException {
237
+ static {
238
+ __name(this, "HttpProblemException");
239
+ }
240
+ constructor(detailOrOptions, httpStatus) {
241
+ const options = typeof detailOrOptions === "string" ? {
242
+ detail: detailOrOptions
243
+ } : detailOrOptions;
244
+ super({
245
+ type: options.type ?? "about:blank",
246
+ label: options.label,
247
+ detail: options.detail,
248
+ errors: options.errors ?? []
249
+ }, httpStatus);
250
+ }
251
+ };
252
+
253
+ // src/exceptions/conflict.exception.ts
254
+ var ConflictException = class extends HttpProblemException {
255
+ static {
256
+ __name(this, "ConflictException");
257
+ }
258
+ constructor(detailOrOptions) {
259
+ super(detailOrOptions ?? "Conflict", import_common4.HttpStatus.CONFLICT);
260
+ }
261
+ };
262
+
263
+ // src/filters/pg-error.translator.ts
264
+ var PG_UNIQUE_VIOLATION = "23505";
265
+ function tryTranslatePgError(error) {
266
+ const pgError = findPgError(error);
267
+ if (!pgError) return void 0;
268
+ const { code, constraint, table, detail } = pgError;
269
+ if (code !== PG_UNIQUE_VIOLATION) return void 0;
270
+ return new ConflictException({
271
+ label: "Duplicate Entry",
272
+ detail: detail?.trim() || "A record with these values already exists.",
273
+ errors: [],
274
+ ...constraint || table ? {
275
+ meta: {
276
+ constraint,
277
+ table
278
+ }
279
+ } : {}
280
+ });
281
+ }
282
+ __name(tryTranslatePgError, "tryTranslatePgError");
283
+ function findPgError(error, depth = 0) {
284
+ if (!error || typeof error !== "object" || depth > 5) return void 0;
285
+ const candidate = error;
286
+ if (typeof candidate.code === "string") return candidate;
287
+ return findPgError(candidate.cause, depth + 1);
288
+ }
289
+ __name(findPgError, "findPgError");
290
+
291
+ // src/filters/http-exception.filter.ts
292
+ function _ts_decorate(decorators, target, key, desc) {
293
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
294
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
295
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
296
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
297
+ }
298
+ __name(_ts_decorate, "_ts_decorate");
299
+ var HttpExceptionFilter = class _HttpExceptionFilter {
300
+ static {
301
+ __name(this, "HttpExceptionFilter");
302
+ }
303
+ logger = new import_common5.Logger(_HttpExceptionFilter.name);
304
+ catch(exception, host) {
305
+ const ctx = host.switchToHttp();
306
+ const response = ctx.getResponse();
307
+ const request = ctx.getRequest();
308
+ const translatedPgError = tryTranslatePgError(exception);
309
+ if (translatedPgError) exception = translatedPgError;
310
+ let status = import_common5.HttpStatus.INTERNAL_SERVER_ERROR;
311
+ let type = "about:blank";
312
+ let label;
313
+ let detail = "Internal server error";
314
+ let errors = [];
315
+ if (this.isHttpException(exception)) {
316
+ status = exception.getStatus();
317
+ const exceptionResponse = exception.getResponse();
318
+ const extracted = extractProblemFromResponse(exceptionResponse, exception.message ?? getHttpStatusTitle(status));
319
+ type = extracted.type;
320
+ label = extracted.label;
321
+ detail = extracted.detail ?? detail;
322
+ errors = extracted.errors;
323
+ } else if (this.isProblemLikeObject(exception)) {
324
+ const problemObj = exception;
325
+ const statusCandidate = problemObj.status ?? problemObj.statusCode;
326
+ if (typeof statusCandidate === "number" && statusCandidate >= 400 && statusCandidate <= 599) {
327
+ status = statusCandidate;
328
+ }
329
+ type = typeof problemObj.type === "string" ? problemObj.type : "about:blank";
330
+ label = typeof problemObj.label === "string" ? problemObj.label : void 0;
331
+ detail = typeof problemObj.detail === "string" ? problemObj.detail : typeof problemObj.message === "string" ? problemObj.message : getHttpStatusTitle(status);
332
+ errors = Array.isArray(problemObj.errors) ? problemObj.errors : [];
333
+ } else if (this.isAxiosError(exception)) {
334
+ const axiosStatus = exception.response?.status;
335
+ const axiosDetail = exception.response?.data?.message || exception.response?.data?.detail || exception.message;
336
+ const url = exception.config?.url;
337
+ status = import_common5.HttpStatus.BAD_GATEWAY;
338
+ detail = `Upstream service error${axiosStatus ? ` (${axiosStatus})` : ""}: ${axiosDetail}`;
339
+ this.logger.error(`Upstream API error [${axiosStatus}]: ${axiosDetail} \u2014 URL: ${url}`, exception.stack);
340
+ } else {
341
+ detail = "An unexpected error occurred";
342
+ }
343
+ const problemDetails = {
344
+ type,
345
+ title: getHttpStatusTitle(status),
346
+ status,
347
+ ...label && {
348
+ label
349
+ },
350
+ detail,
351
+ instance: request.url,
352
+ errors
353
+ };
354
+ response.header("Content-Type", "application/problem+json").status(status).send(problemDetails);
355
+ }
356
+ // Duck-type check for HttpException — avoids instanceof failing across pnpm package instances
357
+ isHttpException(error) {
358
+ return error instanceof Error && typeof error.getStatus === "function" && typeof error.getResponse === "function";
359
+ }
360
+ // Duck-type check for AxiosError without importing axios
361
+ isAxiosError(error) {
362
+ return error instanceof Error && error.isAxiosError === true;
363
+ }
364
+ isProblemLikeObject(error) {
365
+ if (!error || typeof error !== "object") return false;
366
+ const obj = error;
367
+ return typeof obj.status === "number" || typeof obj.statusCode === "number" || typeof obj.detail === "string" || Array.isArray(obj.errors);
368
+ }
369
+ };
370
+ HttpExceptionFilter = _ts_decorate([
371
+ (0, import_common5.Catch)()
372
+ ], HttpExceptionFilter);
373
+
374
+ // src/filters/transport-aware-exception.filter.ts
375
+ var import_common6 = require("@nestjs/common");
376
+ function _ts_decorate2(decorators, target, key, desc) {
377
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
378
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
379
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
380
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
381
+ }
382
+ __name(_ts_decorate2, "_ts_decorate");
383
+ var TransportAwareExceptionFilter = class {
384
+ static {
385
+ __name(this, "TransportAwareExceptionFilter");
386
+ }
387
+ httpFilter = new HttpExceptionFilter();
388
+ catch(exception, host) {
389
+ if (host.getType() !== "http") {
390
+ throw exception;
391
+ }
392
+ this.httpFilter.catch(exception, host);
393
+ }
394
+ };
395
+ TransportAwareExceptionFilter = _ts_decorate2([
396
+ (0, import_common6.Catch)()
397
+ ], TransportAwareExceptionFilter);
398
+ // Annotate the CommonJS export names for ESM import in node:
399
+ 0 && (module.exports = {
400
+ ErrorCode,
401
+ HttpExceptionFilter,
402
+ TransportAwareExceptionFilter,
403
+ createGraphqlFormatError,
404
+ errorCodeFromStatus,
405
+ getHttpStatusTitle
406
+ });
407
+ //# sourceMappingURL=filters.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/filters/index.ts","../src/filters/error-code.ts","../src/filters/problem-extraction.ts","../src/filters/graphql-format-error.ts","../src/filters/http-exception.filter.ts","../src/exceptions/conflict.exception.ts","../src/exceptions/base-field.exception.ts","../src/filters/pg-error.translator.ts","../src/filters/transport-aware-exception.filter.ts"],"sourcesContent":["// Machine-readable error contract + status mapper (shared across HTTP and GraphQL transports).\n\nexport { ErrorCode, errorCodeFromStatus } from './error-code';\n// GraphQL error shaping (Apollo formatError factory) — composes with TransportAwareExceptionFilter.\nexport {\n createGraphqlFormatError,\n type FormattedErrorExtensions,\n type GraphqlFormatErrorOptions,\n} from './graphql-format-error';\nexport { getHttpStatusTitle, HttpExceptionFilter } from './http-exception.filter';\nexport { TransportAwareExceptionFilter } from './transport-aware-exception.filter';\n// RpcProblemExceptionFilter is exported from '@vritti/api-sdk/nats' (it needs @nestjs/microservices).\n","import { HttpStatus } from '@nestjs/common';\n\nexport enum ErrorCode {\n UNAUTHENTICATED = 'UNAUTHENTICATED',\n FORBIDDEN = 'FORBIDDEN',\n NOT_FOUND = 'NOT_FOUND',\n VALIDATION_FAILED = 'VALIDATION_FAILED',\n CONFLICT = 'CONFLICT',\n RATE_LIMITED = 'RATE_LIMITED',\n BAD_REQUEST = 'BAD_REQUEST',\n INTERNAL = 'INTERNAL',\n}\n\n// Maps an HTTP status code to the canonical ErrorCode so HTTP and GraphQL classify identically.\nexport function errorCodeFromStatus(status: number): ErrorCode {\n switch (status) {\n case HttpStatus.UNAUTHORIZED: // 401\n return ErrorCode.UNAUTHENTICATED;\n case HttpStatus.FORBIDDEN: // 403\n return ErrorCode.FORBIDDEN;\n case HttpStatus.NOT_FOUND: // 404\n return ErrorCode.NOT_FOUND;\n case HttpStatus.BAD_REQUEST: // 400\n case HttpStatus.UNPROCESSABLE_ENTITY: // 422\n return ErrorCode.VALIDATION_FAILED;\n case HttpStatus.CONFLICT: // 409\n return ErrorCode.CONFLICT;\n case HttpStatus.TOO_MANY_REQUESTS: // 429\n return ErrorCode.RATE_LIMITED;\n default:\n // Any other 4xx is a generic bad request; 5xx and unknown collapse to INTERNAL.\n if (status >= 400 && status < 500) {\n return ErrorCode.BAD_REQUEST;\n }\n return ErrorCode.INTERNAL;\n }\n}\n","import { HttpStatus } from '@nestjs/common';\nimport type { FieldError } from '../types/error-response.types';\n\ninterface ProblemExceptionResponse {\n type?: string;\n label?: string;\n detail?: string;\n errors?: FieldError[];\n}\n\ninterface ValidationExceptionResponse {\n message: Array<string | { property: string; constraints: Record<string, string> }>;\n error?: string;\n}\n\ninterface StandardExceptionResponse {\n message: string | string[];\n error?: string;\n}\n\ntype ExceptionResponseObject = ProblemExceptionResponse | ValidationExceptionResponse | StandardExceptionResponse;\n\nexport interface ExtractedProblem {\n type: string;\n label?: string;\n detail?: string;\n errors: FieldError[];\n}\n\n// Converts an HTTP status code to its title string (e.g., 400 → \"Bad Request\")\nexport function getHttpStatusTitle(status: number): string {\n // Find the enum key for the given status code\n const enumKey = Object.entries(HttpStatus).find(([key, value]) => value === status && Number.isNaN(Number(key)))?.[0];\n\n if (!enumKey) {\n return 'Error';\n }\n\n // Convert enum key to title case (e.g., BAD_REQUEST -> Bad Request)\n return enumKey\n .split('_')\n .map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())\n .join(' ');\n}\n\n// Extracts field-specific errors from a class-validator ValidationPipe message array, mirroring the RFC 9457 errors[].\nfunction extractValidationFieldErrors(\n message: Array<string | { property: string; constraints: Record<string, string> }>,\n): FieldError[] {\n return message\n .map((msg) => {\n if (typeof msg === 'object' && 'property' in msg && 'constraints' in msg) {\n const constraintValues = Object.values(msg.constraints);\n return {\n field: msg.property,\n message: constraintValues[0] ?? 'Validation failed',\n };\n }\n // Non-field-specific validation messages are ignored here; they belong at the detail level.\n return null;\n })\n .filter((error): error is FieldError => error !== null);\n}\n\n// Parses a NestJS HttpException response body into normalized problem fields across the SDK's three body shapes.\nexport function extractProblemFromResponse(\n exceptionResponse: string | object,\n problemFallbackDetail: string,\n): ExtractedProblem {\n let type = 'about:blank';\n let label: string | undefined;\n let detail: string | undefined;\n let errors: FieldError[] = [];\n\n if (typeof exceptionResponse === 'string') {\n detail = exceptionResponse;\n return { type, label, detail, errors };\n }\n\n if (exceptionResponse !== null && typeof exceptionResponse === 'object') {\n const responseObj = exceptionResponse as ExceptionResponseObject;\n\n // Custom HttpProblemException from @vritti/api-sdk\n if ('type' in responseObj || 'label' in responseObj || 'errors' in responseObj) {\n const problemResponse = responseObj as ProblemExceptionResponse;\n type = problemResponse.type ?? 'about:blank';\n label = problemResponse.label;\n detail = problemResponse.detail ?? problemFallbackDetail;\n errors = problemResponse.errors ?? [];\n }\n // class-validator DTO validation errors\n else if ('message' in responseObj && Array.isArray(responseObj.message)) {\n errors = extractValidationFieldErrors(responseObj.message);\n detail = 'Validation failed';\n }\n // Standard NestJS exceptions\n else if ('message' in responseObj) {\n const message = (responseObj as StandardExceptionResponse).message;\n detail = Array.isArray(message) ? message.join(', ') : message;\n }\n }\n\n return { type, label, detail, errors };\n}\n","import { type ErrorCode, errorCodeFromStatus } from './error-code';\nimport { extractProblemFromResponse, getHttpStatusTitle } from './problem-extraction';\n\n// graphql and @nestjs/graphql are optional peers not installed here, so we declare minimal structural shapes locally.\n\ninterface GraphqlFormattedErrorShape {\n message: string;\n locations?: ReadonlyArray<{ line: number; column: number }>;\n path?: ReadonlyArray<string | number>;\n extensions?: Record<string, unknown>;\n}\n\ninterface GraphqlErrorShape {\n message: string;\n originalError?: unknown;\n extensions?: Record<string, unknown>;\n}\n\ninterface HttpExceptionLike {\n getStatus(): number;\n getResponse(): string | object;\n message: string;\n}\n\nexport interface GraphqlFormatErrorOptions {\n isProduction: boolean;\n getTraceId?: () => string | undefined;\n}\n\nexport interface FormattedErrorExtensions {\n code: ErrorCode;\n traceId?: string;\n timestamp: string;\n fieldErrors?: Array<{ field: string; message: string }>;\n [key: string]: unknown;\n}\n\n// Duck-types a NestJS HttpException without importing @nestjs/common (cross-package-instance safe).\nfunction isHttpExceptionLike(error: unknown): error is HttpExceptionLike {\n return (\n error instanceof Error &&\n typeof (error as { getStatus?: unknown }).getStatus === 'function' &&\n typeof (error as { getResponse?: unknown }).getResponse === 'function'\n );\n}\n\ninterface ProblemLike {\n status?: number;\n statusCode?: number;\n detail?: string;\n message?: string;\n}\n\nfunction isProblemLike(error: unknown): error is ProblemLike {\n if (error == null || typeof error !== 'object') {\n return false;\n }\n const o = error as Record<string, unknown>;\n return typeof o.status === 'number' || typeof o.statusCode === 'number';\n}\n\ninterface ProblemSource {\n status: number;\n response: string | object;\n fallback: string;\n}\n\n// Walks the error chain to find the underlying HttpException or plain RFC 9457 problem via originalError/thrownValue.\nfunction findProblemSource(error: GraphqlErrorShape | undefined): ProblemSource | undefined {\n let current: unknown = error;\n // Bounded walk — guard against cyclic chains.\n for (let depth = 0; current && depth < 10; depth++) {\n if (isHttpExceptionLike(current)) {\n const status = current.getStatus();\n return { status, response: current.getResponse(), fallback: current.message ?? getHttpStatusTitle(status) };\n }\n if (isProblemLike(current)) {\n const status = current.status ?? current.statusCode ?? 500;\n return { status, response: current, fallback: current.detail ?? current.message ?? getHttpStatusTitle(status) };\n }\n const next = current as { originalError?: unknown; thrownValue?: unknown };\n current = next.originalError ?? next.thrownValue;\n }\n return undefined;\n}\n\nconst GENERIC_INTERNAL_MESSAGE = 'Internal server error';\n\n// Builds an Apollo formatError that normalizes every GraphQL error into a stable, transport-consistent shape.\nexport function createGraphqlFormatError(\n opts: GraphqlFormatErrorOptions,\n): (formattedError: GraphqlFormattedErrorShape, error: unknown) => GraphqlFormattedErrorShape {\n const { isProduction, getTraceId } = opts;\n\n return (formattedError, error) => {\n const gqlError = (error ?? undefined) as GraphqlErrorShape | undefined;\n const source = findProblemSource(gqlError);\n\n // Derive status + problem body from the underlying source since Apollo only copies .message and defaults code to INTERNAL.\n let status = 500;\n let detail: string | undefined;\n let label: string | undefined;\n let fieldErrors: Array<{ field: string; message: string }> = [];\n\n if (source) {\n status = source.status;\n const extracted = extractProblemFromResponse(source.response, source.fallback);\n detail = extracted.detail;\n label = extracted.label;\n fieldErrors = extracted.errors;\n }\n\n const code = errorCodeFromStatus(status);\n\n // Prefer the problem detail, then the formatted message; never surface internals for INTERNAL in production.\n let message = detail ?? formattedError.message;\n if (code === 'INTERNAL' && isProduction) {\n message = GENERIC_INTERNAL_MESSAGE;\n }\n\n // Start from Apollo's extensions so any framework-set keys survive, then normalize ours on top.\n const incoming: Record<string, unknown> = { ...(formattedError.extensions ?? {}) };\n\n const traceId = getTraceId?.();\n const timestamp = new Date().toISOString();\n\n const extensions: FormattedErrorExtensions = {\n ...incoming,\n // Always our canonical code — overrides Apollo's default INTERNAL_SERVER_ERROR.\n code,\n ...(traceId !== undefined ? { traceId } : {}),\n timestamp,\n ...(label !== undefined ? { label } : {}),\n ...(fieldErrors.length > 0 ? { fieldErrors } : {}),\n };\n\n if (isProduction) {\n // Strip anything that could leak server internals to clients.\n delete extensions.stacktrace;\n delete extensions.exception;\n delete extensions.originalError;\n }\n\n const result: GraphqlFormattedErrorShape = {\n message,\n extensions,\n };\n // Preserve location/path metadata GraphQL attaches (useful to clients, leaks nothing).\n if (formattedError.locations) result.locations = formattedError.locations;\n if (formattedError.path) result.path = formattedError.path;\n\n return result;\n };\n}\n","import {\n type ArgumentsHost,\n Catch,\n type ExceptionFilter,\n type HttpException,\n HttpStatus,\n Logger,\n} from '@nestjs/common';\nimport type { FastifyReply, FastifyRequest } from 'fastify';\nimport type { ApiErrorResponse, FieldError } from '../types/error-response.types';\nimport { tryTranslatePgError } from './pg-error.translator';\nimport { extractProblemFromResponse, getHttpStatusTitle } from './problem-extraction';\n\nexport { getHttpStatusTitle };\n\n@Catch()\nexport class HttpExceptionFilter implements ExceptionFilter {\n private readonly logger = new Logger(HttpExceptionFilter.name);\n\n catch(exception: unknown, host: ArgumentsHost) {\n const ctx = host.switchToHttp();\n const response = ctx.getResponse<FastifyReply>();\n const request = ctx.getRequest<FastifyRequest>();\n\n // Translate raw Postgres errors (e.g. 23505 unique_violation) into a ConflictException before classifying as 500.\n const translatedPgError = tryTranslatePgError(exception);\n if (translatedPgError) exception = translatedPgError;\n\n let status = HttpStatus.INTERNAL_SERVER_ERROR;\n let type = 'about:blank';\n let label: string | undefined;\n let detail = 'Internal server error';\n let errors: FieldError[] = [];\n\n if (this.isHttpException(exception)) {\n status = exception.getStatus();\n const exceptionResponse = exception.getResponse();\n\n // Reuse the shared extractor so HTTP and GraphQL surface identical problem details.\n const extracted = extractProblemFromResponse(exceptionResponse, exception.message ?? getHttpStatusTitle(status));\n type = extracted.type;\n label = extracted.label;\n // Keep the initial 'Internal server error' when the body matched no known shape (byte-identical HTTP output).\n detail = extracted.detail ?? detail;\n errors = extracted.errors;\n } else if (this.isProblemLikeObject(exception)) {\n const problemObj = exception as Record<string, unknown>;\n const statusCandidate = problemObj.status ?? problemObj.statusCode;\n if (typeof statusCandidate === 'number' && statusCandidate >= 400 && statusCandidate <= 599) {\n status = statusCandidate;\n }\n type = typeof problemObj.type === 'string' ? problemObj.type : 'about:blank';\n label = typeof problemObj.label === 'string' ? problemObj.label : undefined;\n detail =\n typeof problemObj.detail === 'string'\n ? problemObj.detail\n : typeof problemObj.message === 'string'\n ? problemObj.message\n : getHttpStatusTitle(status);\n errors = Array.isArray(problemObj.errors) ? (problemObj.errors as FieldError[]) : [];\n } else if (this.isAxiosError(exception)) {\n // Outgoing HTTP call failures (e.g., service-to-service calls)\n const axiosStatus = exception.response?.status;\n const axiosDetail = exception.response?.data?.message || exception.response?.data?.detail || exception.message;\n const url = exception.config?.url;\n status = HttpStatus.BAD_GATEWAY;\n detail = `Upstream service error${axiosStatus ? ` (${axiosStatus})` : ''}: ${axiosDetail}`;\n this.logger.error(`Upstream API error [${axiosStatus}]: ${axiosDetail} — URL: ${url}`, exception.stack);\n } else {\n // Unknown errors — logged by HttpLoggerInterceptor, no need to log again here\n detail = 'An unexpected error occurred';\n }\n\n const problemDetails: ApiErrorResponse = {\n type,\n title: getHttpStatusTitle(status),\n status,\n ...(label && { label }),\n detail,\n instance: request.url,\n errors,\n };\n\n response.header('Content-Type', 'application/problem+json').status(status).send(problemDetails);\n }\n\n // Duck-type check for HttpException — avoids instanceof failing across pnpm package instances\n private isHttpException(error: unknown): error is HttpException {\n return (\n error instanceof Error &&\n typeof (error as { getStatus?: unknown }).getStatus === 'function' &&\n typeof (error as { getResponse?: unknown }).getResponse === 'function'\n );\n }\n\n // Duck-type check for AxiosError without importing axios\n private isAxiosError(error: unknown): error is Error & {\n isAxiosError: true;\n response?: { status?: number; data?: Record<string, unknown> };\n config?: { url?: string };\n } {\n return error instanceof Error && (error as { isAxiosError?: boolean }).isAxiosError === true;\n }\n\n private isProblemLikeObject(error: unknown): error is Record<string, unknown> {\n if (!error || typeof error !== 'object') return false;\n const obj = error as Record<string, unknown>;\n return (\n typeof obj.status === 'number' ||\n typeof obj.statusCode === 'number' ||\n typeof obj.detail === 'string' ||\n Array.isArray(obj.errors)\n );\n }\n}\n","import { HttpStatus } from '@nestjs/common';\nimport { HttpProblemException, type ProblemOptions } from './base-field.exception';\n\nexport class ConflictException extends HttpProblemException {\n constructor(detailOrOptions?: string | ProblemOptions) {\n super(detailOrOptions ?? 'Conflict', HttpStatus.CONFLICT);\n }\n}\n","import { HttpException, HttpStatus } from '@nestjs/common';\nimport type { FieldError } from '../types/error-response.types';\n\n// Re-export FieldError for backwards compatibility\nexport type { FieldError } from '../types/error-response.types';\n\nexport interface ProblemOptions {\n type?: string;\n label?: string;\n detail?: string;\n errors?: FieldError[];\n}\n\nexport abstract class HttpProblemException extends HttpException {\n constructor(detailOrOptions: string | ProblemOptions, httpStatus: HttpStatus) {\n const options = typeof detailOrOptions === 'string' ? { detail: detailOrOptions } : detailOrOptions;\n\n super(\n {\n type: options.type ?? 'about:blank',\n label: options.label,\n detail: options.detail,\n errors: options.errors ?? [],\n },\n httpStatus,\n );\n }\n}\n","import { ConflictException } from '../exceptions/conflict.exception';\n\nconst PG_UNIQUE_VIOLATION = '23505';\n\nexport type PgErrorShape = {\n code?: string;\n message?: string;\n constraint?: string;\n table?: string;\n schema?: string;\n column?: string;\n detail?: string;\n hint?: string;\n};\n\n// Returns a ConflictException for a Postgres unique-violation error, otherwise undefined.\nexport function tryTranslatePgError(error: unknown): ConflictException | undefined {\n const pgError = findPgError(error);\n if (!pgError) return undefined;\n const { code, constraint, table, detail } = pgError;\n if (code !== PG_UNIQUE_VIOLATION) return undefined;\n return new ConflictException({\n label: 'Duplicate Entry',\n detail: detail?.trim() || 'A record with these values already exists.',\n errors: [],\n ...(constraint || table ? { meta: { constraint, table } } : {}),\n });\n}\n\n// Walks up to N levels of `.cause` looking for a pg-shaped error (has SQLSTATE `code`), capping depth.\nexport function findPgError(error: unknown, depth = 0): PgErrorShape | undefined {\n if (!error || typeof error !== 'object' || depth > 5) return undefined;\n const candidate = error as PgErrorShape & { cause?: unknown };\n if (typeof candidate.code === 'string') return candidate;\n return findPgError(candidate.cause, depth + 1);\n}\n","import { type ArgumentsHost, Catch, type ExceptionFilter } from '@nestjs/common';\nimport { HttpExceptionFilter } from './http-exception.filter';\n\n@Catch()\nexport class TransportAwareExceptionFilter implements ExceptionFilter {\n private readonly httpFilter = new HttpExceptionFilter();\n\n catch(exception: unknown, host: ArgumentsHost): void {\n if (host.getType() !== 'http') {\n throw exception;\n }\n this.httpFilter.catch(exception, host);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;ACAA,oBAA2B;AAEpB,IAAKA,YAAAA,0BAAAA,YAAAA;;;;;;;;;SAAAA;;AAYL,SAASC,oBAAoBC,QAAc;AAChD,UAAQA,QAAAA;IACN,KAAKC,yBAAWC;AACd,aAAA;IACF,KAAKD,yBAAWE;AACd,aAAA;IACF,KAAKF,yBAAWG;AACd,aAAA;IACF,KAAKH,yBAAWI;IAChB,KAAKJ,yBAAWK;AACd,aAAA;IACF,KAAKL,yBAAWM;AACd,aAAA;IACF,KAAKN,yBAAWO;AACd,aAAA;IACF;AAEE,UAAIR,UAAU,OAAOA,SAAS,KAAK;AACjC,eAAA;MACF;AACA,aAAA;EACJ;AACF;AAtBgBD;;;ACdhB,IAAAU,iBAA2B;AA8BpB,SAASC,mBAAmBC,QAAc;AAE/C,QAAMC,UAAUC,OAAOC,QAAQC,yBAAAA,EAAYC,KAAK,CAAC,CAACC,KAAKC,KAAAA,MAAWA,UAAUP,UAAUQ,OAAOC,MAAMD,OAAOF,GAAAA,CAAAA,CAAAA,IAAS,CAAA;AAEnH,MAAI,CAACL,SAAS;AACZ,WAAO;EACT;AAGA,SAAOA,QACJS,MAAM,GAAA,EACNC,IAAI,CAACC,SAASA,KAAKC,OAAO,CAAA,EAAGC,YAAW,IAAKF,KAAKG,MAAM,CAAA,EAAGC,YAAW,CAAA,EACtEC,KAAK,GAAA;AACV;AAbgBlB;AAgBhB,SAASmB,6BACPC,SAAkF;AAElF,SAAOA,QACJR,IAAI,CAACS,QAAAA;AACJ,QAAI,OAAOA,QAAQ,YAAY,cAAcA,OAAO,iBAAiBA,KAAK;AACxE,YAAMC,mBAAmBnB,OAAOoB,OAAOF,IAAIG,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AQoB,MAAoCjC,gBAAgB;EAEhE;;EAGQ0B,aAAaO,OAInB;AACA,WAAOA,iBAAiBO,SAAUP,MAAqCP,iBAAiB;EAC1F;EAEQP,oBAAoBc,OAAkD;AAC5E,QAAI,CAACA,SAAS,OAAOA,UAAU,SAAU,QAAO;AAChD,UAAMQ,MAAMR;AACZ,WACE,OAAOQ,IAAIpC,WAAW,YACtB,OAAOoC,IAAInB,eAAe,YAC1B,OAAOmB,IAAI/B,WAAW,YACtBc,MAAMC,QAAQgB,IAAI9B,MAAM;EAE5B;AACF;;;;;;AIlHA,IAAA+B,iBAAgE;;;;;;;;AAIzD,IAAMC,gCAAN,MAAMA;SAAAA;;;EACMC,aAAa,IAAIC,oBAAAA;EAElCC,MAAMC,WAAoBC,MAA2B;AACnD,QAAIA,KAAKC,QAAO,MAAO,QAAQ;AAC7B,YAAMF;IACR;AACA,SAAKH,WAAWE,MAAMC,WAAWC,IAAAA;EACnC;AACF;;;;","names":["ErrorCode","errorCodeFromStatus","status","HttpStatus","UNAUTHORIZED","FORBIDDEN","NOT_FOUND","BAD_REQUEST","UNPROCESSABLE_ENTITY","CONFLICT","TOO_MANY_REQUESTS","import_common","getHttpStatusTitle","status","enumKey","Object","entries","HttpStatus","find","key","value","Number","isNaN","split","map","word","charAt","toUpperCase","slice","toLowerCase","join","extractValidationFieldErrors","message","msg","constraintValues","values","constraints","field","property","filter","error","extractProblemFromResponse","exceptionResponse","problemFallbackDetail","type","label","detail","errors","responseObj","problemResponse","Array","isArray","isHttpExceptionLike","error","Error","getStatus","getResponse","isProblemLike","o","status","statusCode","findProblemSource","current","depth","response","fallback","message","getHttpStatusTitle","detail","next","originalError","thrownValue","undefined","GENERIC_INTERNAL_MESSAGE","createGraphqlFormatError","opts","isProduction","getTraceId","formattedError","gqlError","source","label","fieldErrors","extracted","extractProblemFromResponse","errors","code","errorCodeFromStatus","incoming","extensions","traceId","timestamp","Date","toISOString","length","stacktrace","exception","result","locations","path","import_common","import_common","import_common","HttpProblemException","HttpException","detailOrOptions","httpStatus","options","detail","type","label","errors","ConflictException","HttpProblemException","detailOrOptions","HttpStatus","CONFLICT","PG_UNIQUE_VIOLATION","tryTranslatePgError","error","pgError","findPgError","undefined","code","constraint","table","detail","ConflictException","label","trim","errors","meta","depth","candidate","cause","HttpExceptionFilter","logger","Logger","name","catch","exception","host","ctx","switchToHttp","response","getResponse","request","getRequest","translatedPgError","tryTranslatePgError","status","HttpStatus","INTERNAL_SERVER_ERROR","type","label","detail","errors","isHttpException","getStatus","exceptionResponse","extracted","extractProblemFromResponse","message","getHttpStatusTitle","isProblemLikeObject","problemObj","statusCandidate","statusCode","undefined","Array","isArray","isAxiosError","axiosStatus","axiosDetail","data","url","config","BAD_GATEWAY","error","stack","problemDetails","title","instance","header","send","Error","obj","import_common","TransportAwareExceptionFilter","httpFilter","HttpExceptionFilter","catch","exception","host","getType"]}
@@ -0,0 +1,55 @@
1
+ import { ExceptionFilter, ArgumentsHost } from '@nestjs/common';
2
+
3
+ declare enum ErrorCode {
4
+ UNAUTHENTICATED = "UNAUTHENTICATED",
5
+ FORBIDDEN = "FORBIDDEN",
6
+ NOT_FOUND = "NOT_FOUND",
7
+ VALIDATION_FAILED = "VALIDATION_FAILED",
8
+ CONFLICT = "CONFLICT",
9
+ RATE_LIMITED = "RATE_LIMITED",
10
+ BAD_REQUEST = "BAD_REQUEST",
11
+ INTERNAL = "INTERNAL"
12
+ }
13
+ declare function errorCodeFromStatus(status: number): ErrorCode;
14
+
15
+ interface GraphqlFormattedErrorShape {
16
+ message: string;
17
+ locations?: ReadonlyArray<{
18
+ line: number;
19
+ column: number;
20
+ }>;
21
+ path?: ReadonlyArray<string | number>;
22
+ extensions?: Record<string, unknown>;
23
+ }
24
+ interface GraphqlFormatErrorOptions {
25
+ isProduction: boolean;
26
+ getTraceId?: () => string | undefined;
27
+ }
28
+ interface FormattedErrorExtensions {
29
+ code: ErrorCode;
30
+ traceId?: string;
31
+ timestamp: string;
32
+ fieldErrors?: Array<{
33
+ field: string;
34
+ message: string;
35
+ }>;
36
+ [key: string]: unknown;
37
+ }
38
+ declare function createGraphqlFormatError(opts: GraphqlFormatErrorOptions): (formattedError: GraphqlFormattedErrorShape, error: unknown) => GraphqlFormattedErrorShape;
39
+
40
+ declare function getHttpStatusTitle(status: number): string;
41
+
42
+ declare class HttpExceptionFilter implements ExceptionFilter {
43
+ private readonly logger;
44
+ catch(exception: unknown, host: ArgumentsHost): void;
45
+ private isHttpException;
46
+ private isAxiosError;
47
+ private isProblemLikeObject;
48
+ }
49
+
50
+ declare class TransportAwareExceptionFilter implements ExceptionFilter {
51
+ private readonly httpFilter;
52
+ catch(exception: unknown, host: ArgumentsHost): void;
53
+ }
54
+
55
+ export { ErrorCode, type FormattedErrorExtensions, type GraphqlFormatErrorOptions, HttpExceptionFilter, TransportAwareExceptionFilter, createGraphqlFormatError, errorCodeFromStatus, getHttpStatusTitle };
@@ -0,0 +1,55 @@
1
+ import { ExceptionFilter, ArgumentsHost } from '@nestjs/common';
2
+
3
+ declare enum ErrorCode {
4
+ UNAUTHENTICATED = "UNAUTHENTICATED",
5
+ FORBIDDEN = "FORBIDDEN",
6
+ NOT_FOUND = "NOT_FOUND",
7
+ VALIDATION_FAILED = "VALIDATION_FAILED",
8
+ CONFLICT = "CONFLICT",
9
+ RATE_LIMITED = "RATE_LIMITED",
10
+ BAD_REQUEST = "BAD_REQUEST",
11
+ INTERNAL = "INTERNAL"
12
+ }
13
+ declare function errorCodeFromStatus(status: number): ErrorCode;
14
+
15
+ interface GraphqlFormattedErrorShape {
16
+ message: string;
17
+ locations?: ReadonlyArray<{
18
+ line: number;
19
+ column: number;
20
+ }>;
21
+ path?: ReadonlyArray<string | number>;
22
+ extensions?: Record<string, unknown>;
23
+ }
24
+ interface GraphqlFormatErrorOptions {
25
+ isProduction: boolean;
26
+ getTraceId?: () => string | undefined;
27
+ }
28
+ interface FormattedErrorExtensions {
29
+ code: ErrorCode;
30
+ traceId?: string;
31
+ timestamp: string;
32
+ fieldErrors?: Array<{
33
+ field: string;
34
+ message: string;
35
+ }>;
36
+ [key: string]: unknown;
37
+ }
38
+ declare function createGraphqlFormatError(opts: GraphqlFormatErrorOptions): (formattedError: GraphqlFormattedErrorShape, error: unknown) => GraphqlFormattedErrorShape;
39
+
40
+ declare function getHttpStatusTitle(status: number): string;
41
+
42
+ declare class HttpExceptionFilter implements ExceptionFilter {
43
+ private readonly logger;
44
+ catch(exception: unknown, host: ArgumentsHost): void;
45
+ private isHttpException;
46
+ private isAxiosError;
47
+ private isProblemLikeObject;
48
+ }
49
+
50
+ declare class TransportAwareExceptionFilter implements ExceptionFilter {
51
+ private readonly httpFilter;
52
+ catch(exception: unknown, host: ArgumentsHost): void;
53
+ }
54
+
55
+ export { ErrorCode, type FormattedErrorExtensions, type GraphqlFormatErrorOptions, HttpExceptionFilter, TransportAwareExceptionFilter, createGraphqlFormatError, errorCodeFromStatus, getHttpStatusTitle };