@vritti/api-sdk 0.2.10 → 0.3.1
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.
- package/dist/cache.cjs +252 -0
- package/dist/cache.cjs.map +1 -0
- package/dist/cache.d.cts +25 -0
- package/dist/cache.d.ts +25 -0
- package/dist/cache.js +214 -0
- package/dist/cache.js.map +1 -0
- package/dist/cache.service-_SuJIcNA.d.cts +20 -0
- package/dist/cache.service-_SuJIcNA.d.ts +20 -0
- package/dist/catalog-resolver.cjs +364 -0
- package/dist/catalog-resolver.cjs.map +1 -0
- package/dist/catalog-resolver.d.cts +109 -0
- package/dist/catalog-resolver.d.ts +109 -0
- package/dist/catalog-resolver.js +330 -0
- package/dist/catalog-resolver.js.map +1 -0
- package/dist/email.cjs +691 -0
- package/dist/email.cjs.map +1 -0
- package/dist/email.d.cts +35 -0
- package/dist/email.d.ts +35 -0
- package/dist/email.js +665 -0
- package/dist/email.js.map +1 -0
- package/dist/fastify-augmentation-CQPBNS5a.d.cts +105 -0
- package/dist/fastify-augmentation-CQPBNS5a.d.ts +105 -0
- package/dist/icons.cjs +13803 -0
- package/dist/icons.cjs.map +1 -0
- package/dist/icons.d.cts +8 -0
- package/dist/icons.d.ts +8 -0
- package/dist/icons.js +13778 -0
- package/dist/icons.js.map +1 -0
- package/dist/index.cjs +742 -1367
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +103 -181
- package/dist/index.d.ts +103 -181
- package/dist/index.js +601 -1233
- package/dist/index.js.map +1 -1
- package/dist/license.cjs +104 -0
- package/dist/license.cjs.map +1 -0
- package/dist/license.d.cts +32 -0
- package/dist/license.d.ts +32 -0
- package/dist/license.js +75 -0
- package/dist/license.js.map +1 -0
- package/dist/money.cjs +93 -6
- package/dist/money.cjs.map +1 -1
- package/dist/money.d.cts +13 -1
- package/dist/money.d.ts +13 -1
- package/dist/money.js +115 -3
- package/dist/money.js.map +1 -1
- package/dist/nats.cjs +196 -179
- package/dist/nats.cjs.map +1 -1
- package/dist/nats.d.cts +13 -11
- package/dist/nats.d.ts +13 -11
- package/dist/nats.js +172 -155
- package/dist/nats.js.map +1 -1
- package/dist/types-DQRwj5rr.d.cts +113 -0
- package/dist/types-DQRwj5rr.d.ts +113 -0
- package/package.json +55 -1
package/dist/nats.cjs
CHANGED
|
@@ -33,8 +33,149 @@ __export(nats_exports, {
|
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(nats_exports);
|
|
35
35
|
|
|
36
|
-
// src/
|
|
36
|
+
// src/filters/rpc-problem-exception.filter.ts
|
|
37
|
+
var import_common3 = require("@nestjs/common");
|
|
38
|
+
var import_microservices = require("@nestjs/microservices");
|
|
39
|
+
var import_rxjs = require("rxjs");
|
|
40
|
+
|
|
41
|
+
// src/exceptions/conflict.exception.ts
|
|
42
|
+
var import_common2 = require("@nestjs/common");
|
|
43
|
+
|
|
44
|
+
// src/exceptions/base-field.exception.ts
|
|
37
45
|
var import_common = require("@nestjs/common");
|
|
46
|
+
var HttpProblemException = class extends import_common.HttpException {
|
|
47
|
+
static {
|
|
48
|
+
__name(this, "HttpProblemException");
|
|
49
|
+
}
|
|
50
|
+
constructor(detailOrOptions, httpStatus) {
|
|
51
|
+
const options = typeof detailOrOptions === "string" ? {
|
|
52
|
+
detail: detailOrOptions
|
|
53
|
+
} : detailOrOptions;
|
|
54
|
+
super({
|
|
55
|
+
type: options.type ?? "about:blank",
|
|
56
|
+
label: options.label,
|
|
57
|
+
detail: options.detail,
|
|
58
|
+
errors: options.errors ?? []
|
|
59
|
+
}, httpStatus);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
// src/exceptions/conflict.exception.ts
|
|
64
|
+
var ConflictException = class extends HttpProblemException {
|
|
65
|
+
static {
|
|
66
|
+
__name(this, "ConflictException");
|
|
67
|
+
}
|
|
68
|
+
constructor(detailOrOptions) {
|
|
69
|
+
super(detailOrOptions ?? "Conflict", import_common2.HttpStatus.CONFLICT);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// src/filters/pg-error.translator.ts
|
|
74
|
+
var PG_UNIQUE_VIOLATION = "23505";
|
|
75
|
+
function tryTranslatePgError(error) {
|
|
76
|
+
const pgError = findPgError(error);
|
|
77
|
+
if (!pgError) return void 0;
|
|
78
|
+
const { code, constraint, table, detail } = pgError;
|
|
79
|
+
if (code !== PG_UNIQUE_VIOLATION) return void 0;
|
|
80
|
+
return new ConflictException({
|
|
81
|
+
label: "Duplicate Entry",
|
|
82
|
+
detail: detail?.trim() || "A record with these values already exists.",
|
|
83
|
+
errors: [],
|
|
84
|
+
...constraint || table ? {
|
|
85
|
+
meta: {
|
|
86
|
+
constraint,
|
|
87
|
+
table
|
|
88
|
+
}
|
|
89
|
+
} : {}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
__name(tryTranslatePgError, "tryTranslatePgError");
|
|
93
|
+
function findPgError(error, depth = 0) {
|
|
94
|
+
if (!error || typeof error !== "object" || depth > 5) return void 0;
|
|
95
|
+
const candidate = error;
|
|
96
|
+
if (typeof candidate.code === "string") return candidate;
|
|
97
|
+
return findPgError(candidate.cause, depth + 1);
|
|
98
|
+
}
|
|
99
|
+
__name(findPgError, "findPgError");
|
|
100
|
+
|
|
101
|
+
// src/filters/rpc-problem-exception.filter.ts
|
|
102
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
103
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
104
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
105
|
+
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;
|
|
106
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
107
|
+
}
|
|
108
|
+
__name(_ts_decorate, "_ts_decorate");
|
|
109
|
+
var RpcProblemExceptionFilter = class _RpcProblemExceptionFilter {
|
|
110
|
+
static {
|
|
111
|
+
__name(this, "RpcProblemExceptionFilter");
|
|
112
|
+
}
|
|
113
|
+
logger = new import_common3.Logger(_RpcProblemExceptionFilter.name);
|
|
114
|
+
catch(exception, _host) {
|
|
115
|
+
const translatedPgError = tryTranslatePgError(exception);
|
|
116
|
+
if (translatedPgError) exception = translatedPgError;
|
|
117
|
+
if (exception instanceof import_microservices.RpcException) {
|
|
118
|
+
return (0, import_rxjs.throwError)(() => exception.getError());
|
|
119
|
+
}
|
|
120
|
+
if (this.isHttpException(exception)) {
|
|
121
|
+
const status = exception.getStatus();
|
|
122
|
+
const response = exception.getResponse();
|
|
123
|
+
return (0, import_rxjs.throwError)(() => this.toProblemPayload(response, status));
|
|
124
|
+
}
|
|
125
|
+
if (exception instanceof Error) {
|
|
126
|
+
const cause = exception.cause;
|
|
127
|
+
const causeMessage = cause instanceof Error ? cause.message : void 0;
|
|
128
|
+
const causeStack = cause instanceof Error ? cause.stack : void 0;
|
|
129
|
+
this.logger.error(causeMessage ?? exception.message, causeStack ?? exception.stack);
|
|
130
|
+
if (cause && cause !== exception) {
|
|
131
|
+
this.logger.error(`Wrapped by: ${exception.message}`);
|
|
132
|
+
}
|
|
133
|
+
return (0, import_rxjs.throwError)(() => this.toProblemPayload({
|
|
134
|
+
type: "about:blank",
|
|
135
|
+
detail: causeMessage ?? exception.message,
|
|
136
|
+
errors: []
|
|
137
|
+
}, import_common3.HttpStatus.INTERNAL_SERVER_ERROR));
|
|
138
|
+
}
|
|
139
|
+
this.logger.error(`Unhandled non-error exception: ${JSON.stringify(exception)}`);
|
|
140
|
+
return (0, import_rxjs.throwError)(() => this.toProblemPayload({
|
|
141
|
+
type: "about:blank",
|
|
142
|
+
detail: "An unexpected error occurred",
|
|
143
|
+
errors: []
|
|
144
|
+
}, import_common3.HttpStatus.INTERNAL_SERVER_ERROR));
|
|
145
|
+
}
|
|
146
|
+
toProblemPayload(response, status) {
|
|
147
|
+
if (typeof response === "string") {
|
|
148
|
+
return {
|
|
149
|
+
type: "about:blank",
|
|
150
|
+
detail: response,
|
|
151
|
+
message: response,
|
|
152
|
+
errors: [],
|
|
153
|
+
status,
|
|
154
|
+
statusCode: status
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
const obj = response ?? {};
|
|
158
|
+
const detail = typeof obj.detail === "string" ? obj.detail : "Request failed";
|
|
159
|
+
return {
|
|
160
|
+
type: typeof obj.type === "string" ? obj.type : "about:blank",
|
|
161
|
+
label: typeof obj.label === "string" ? obj.label : void 0,
|
|
162
|
+
detail,
|
|
163
|
+
message: detail,
|
|
164
|
+
errors: Array.isArray(obj.errors) ? obj.errors : [],
|
|
165
|
+
status,
|
|
166
|
+
statusCode: status
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
isHttpException(error) {
|
|
170
|
+
return error instanceof Error && typeof error.getStatus === "function" && typeof error.getResponse === "function";
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
RpcProblemExceptionFilter = _ts_decorate([
|
|
174
|
+
(0, import_common3.Catch)()
|
|
175
|
+
], RpcProblemExceptionFilter);
|
|
176
|
+
|
|
177
|
+
// src/nats/decorators/nats-headers.decorator.ts
|
|
178
|
+
var import_common4 = require("@nestjs/common");
|
|
38
179
|
|
|
39
180
|
// src/nats/nats-context.ts
|
|
40
181
|
var NATS_HEADER_KEYS = {
|
|
@@ -74,44 +215,56 @@ function parseNatsHeaders(headers) {
|
|
|
74
215
|
__name(parseNatsHeaders, "parseNatsHeaders");
|
|
75
216
|
|
|
76
217
|
// src/nats/decorators/nats-headers.decorator.ts
|
|
77
|
-
var RpcNatsHeaders = (0,
|
|
218
|
+
var RpcNatsHeaders = (0, import_common4.createParamDecorator)((_data, ctx) => {
|
|
78
219
|
const rpcCtx = ctx.switchToRpc().getContext();
|
|
79
220
|
return parseNatsHeaders(rpcCtx.getHeaders());
|
|
80
221
|
});
|
|
81
|
-
var RpcBuId = (0,
|
|
222
|
+
var RpcBuId = (0, import_common4.createParamDecorator)((_data, ctx) => {
|
|
82
223
|
const rpcCtx = ctx.switchToRpc().getContext();
|
|
83
224
|
const headers = parseNatsHeaders(rpcCtx.getHeaders());
|
|
84
|
-
if (!headers?.buId) throw new
|
|
225
|
+
if (!headers?.buId) throw new import_common4.InternalServerErrorException("Missing buId in NATS headers.");
|
|
85
226
|
return headers.buId;
|
|
86
227
|
});
|
|
87
|
-
var RpcBuCurrencyCode = (0,
|
|
228
|
+
var RpcBuCurrencyCode = (0, import_common4.createParamDecorator)((_data, ctx) => {
|
|
88
229
|
const rpcCtx = ctx.switchToRpc().getContext();
|
|
89
230
|
const headers = parseNatsHeaders(rpcCtx.getHeaders());
|
|
90
|
-
if (!headers?.buCurrencyCode) throw new
|
|
231
|
+
if (!headers?.buCurrencyCode) throw new import_common4.InternalServerErrorException("Missing buCurrencyCode in NATS headers.");
|
|
91
232
|
return headers.buCurrencyCode;
|
|
92
233
|
});
|
|
93
234
|
|
|
94
235
|
// src/nats/nats-client.module.ts
|
|
95
|
-
var
|
|
236
|
+
var import_common7 = require("@nestjs/common");
|
|
96
237
|
var import_config = require("@nestjs/config");
|
|
97
|
-
var
|
|
238
|
+
var import_microservices4 = require("@nestjs/microservices");
|
|
98
239
|
|
|
99
240
|
// src/nats/constants.ts
|
|
100
241
|
var NATS_MODULE_OPTIONS = Symbol("NATS_MODULE_OPTIONS");
|
|
101
242
|
var NATS_CONTEXT_RESOLVER = Symbol("NATS_CONTEXT_RESOLVER");
|
|
102
243
|
|
|
103
244
|
// src/nats/nats-client.service.ts
|
|
104
|
-
var
|
|
245
|
+
var import_common5 = require("@nestjs/common");
|
|
105
246
|
var import_core = require("@nestjs/core");
|
|
106
|
-
var
|
|
247
|
+
var import_microservices2 = require("@nestjs/microservices");
|
|
107
248
|
var import_nats = require("nats");
|
|
108
|
-
|
|
249
|
+
|
|
250
|
+
// src/context/resolve-request.ts
|
|
251
|
+
function resolveInjectedRequest(injected) {
|
|
252
|
+
const candidate = injected;
|
|
253
|
+
if (candidate && candidate.headers === void 0 && candidate.req) {
|
|
254
|
+
return candidate.req;
|
|
255
|
+
}
|
|
256
|
+
return injected;
|
|
257
|
+
}
|
|
258
|
+
__name(resolveInjectedRequest, "resolveInjectedRequest");
|
|
259
|
+
|
|
260
|
+
// src/nats/nats-client.service.ts
|
|
261
|
+
function _ts_decorate2(decorators, target, key, desc) {
|
|
109
262
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
110
263
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
111
264
|
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;
|
|
112
265
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
113
266
|
}
|
|
114
|
-
__name(
|
|
267
|
+
__name(_ts_decorate2, "_ts_decorate");
|
|
115
268
|
function _ts_metadata(k, v) {
|
|
116
269
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
117
270
|
}
|
|
@@ -127,15 +280,20 @@ var NatsClientService = class {
|
|
|
127
280
|
static {
|
|
128
281
|
__name(this, "NatsClientService");
|
|
129
282
|
}
|
|
130
|
-
|
|
283
|
+
injectedRequest;
|
|
131
284
|
contextResolver;
|
|
132
285
|
clients;
|
|
133
286
|
cachedContext = null;
|
|
134
|
-
constructor(
|
|
135
|
-
this.
|
|
287
|
+
constructor(injectedRequest, contextResolver, clients) {
|
|
288
|
+
this.injectedRequest = injectedRequest;
|
|
136
289
|
this.contextResolver = contextResolver;
|
|
137
290
|
this.clients = clients;
|
|
138
291
|
}
|
|
292
|
+
// For GraphQL, @Inject(REQUEST) is the { req, reply } context wrapper, not the Fastify request;
|
|
293
|
+
// unwrap so `sessionInfo` (set by the auth guard on the request) is visible across both transports.
|
|
294
|
+
get request() {
|
|
295
|
+
return resolveInjectedRequest(this.injectedRequest);
|
|
296
|
+
}
|
|
139
297
|
// Sends a message to a named microservice with NatsHeaders as NATS headers
|
|
140
298
|
async send(service, cmd, data) {
|
|
141
299
|
const client = this.clients.get(service);
|
|
@@ -152,19 +310,19 @@ var NatsClientService = class {
|
|
|
152
310
|
this.cachedContext = await this.contextResolver(sessionInfo);
|
|
153
311
|
}
|
|
154
312
|
const headers = contextToHeaders(this.cachedContext);
|
|
155
|
-
const record = new
|
|
313
|
+
const record = new import_microservices2.NatsRecordBuilder(data ?? {}).setHeaders(headers).build();
|
|
156
314
|
return client.send({
|
|
157
315
|
cmd
|
|
158
316
|
}, record).toPromise();
|
|
159
317
|
}
|
|
160
318
|
};
|
|
161
|
-
NatsClientService =
|
|
162
|
-
(0,
|
|
163
|
-
scope:
|
|
319
|
+
NatsClientService = _ts_decorate2([
|
|
320
|
+
(0, import_common5.Injectable)({
|
|
321
|
+
scope: import_common5.Scope.REQUEST
|
|
164
322
|
}),
|
|
165
|
-
_ts_param(0, (0,
|
|
166
|
-
_ts_param(1, (0,
|
|
167
|
-
_ts_param(2, (0,
|
|
323
|
+
_ts_param(0, (0, import_common5.Inject)(import_core.REQUEST)),
|
|
324
|
+
_ts_param(1, (0, import_common5.Inject)(NATS_CONTEXT_RESOLVER)),
|
|
325
|
+
_ts_param(2, (0, import_common5.Inject)(NATS_CLIENTS)),
|
|
168
326
|
_ts_metadata("design:type", Function),
|
|
169
327
|
_ts_metadata("design:paramtypes", [
|
|
170
328
|
typeof FastifyRequest === "undefined" ? Object : FastifyRequest,
|
|
@@ -186,15 +344,15 @@ function contextToHeaders(ctx) {
|
|
|
186
344
|
__name(contextToHeaders, "contextToHeaders");
|
|
187
345
|
|
|
188
346
|
// src/nats/nats-microservice-client.service.ts
|
|
189
|
-
var
|
|
190
|
-
var
|
|
191
|
-
function
|
|
347
|
+
var import_common6 = require("@nestjs/common");
|
|
348
|
+
var import_microservices3 = require("@nestjs/microservices");
|
|
349
|
+
function _ts_decorate3(decorators, target, key, desc) {
|
|
192
350
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
193
351
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
194
352
|
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;
|
|
195
353
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
196
354
|
}
|
|
197
|
-
__name(
|
|
355
|
+
__name(_ts_decorate3, "_ts_decorate");
|
|
198
356
|
function _ts_metadata2(k, v) {
|
|
199
357
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
200
358
|
}
|
|
@@ -230,15 +388,15 @@ var NatsMicroserviceClientService = class {
|
|
|
230
388
|
[NATS_HEADER_KEYS.BU_ANCESTOR_IDS]: JSON.stringify(natsHeaders2.buAncestorIds),
|
|
231
389
|
[NATS_HEADER_KEYS.BU_DESCENDANT_IDS]: JSON.stringify(natsHeaders2.buDescendantIds)
|
|
232
390
|
};
|
|
233
|
-
const record = new
|
|
391
|
+
const record = new import_microservices3.NatsRecordBuilder(data ?? {}).setHeaders(headers).build();
|
|
234
392
|
return client.send({
|
|
235
393
|
cmd
|
|
236
394
|
}, record).toPromise();
|
|
237
395
|
}
|
|
238
396
|
};
|
|
239
|
-
NatsMicroserviceClientService =
|
|
240
|
-
(0,
|
|
241
|
-
_ts_param2(0, (0,
|
|
397
|
+
NatsMicroserviceClientService = _ts_decorate3([
|
|
398
|
+
(0, import_common6.Injectable)(),
|
|
399
|
+
_ts_param2(0, (0, import_common6.Inject)(NATS_MS_CLIENTS)),
|
|
242
400
|
_ts_metadata2("design:type", Function),
|
|
243
401
|
_ts_metadata2("design:paramtypes", [
|
|
244
402
|
typeof Map === "undefined" ? Object : Map
|
|
@@ -246,19 +404,19 @@ NatsMicroserviceClientService = _ts_decorate2([
|
|
|
246
404
|
], NatsMicroserviceClientService);
|
|
247
405
|
|
|
248
406
|
// src/nats/nats-client.module.ts
|
|
249
|
-
function
|
|
407
|
+
function _ts_decorate4(decorators, target, key, desc) {
|
|
250
408
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
251
409
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
252
410
|
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;
|
|
253
411
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
254
412
|
}
|
|
255
|
-
__name(
|
|
413
|
+
__name(_ts_decorate4, "_ts_decorate");
|
|
256
414
|
var NATS_MS_OPTIONS = Symbol("NATS_MS_OPTIONS");
|
|
257
415
|
var NatsClientModule = class _NatsClientModule {
|
|
258
416
|
static {
|
|
259
417
|
__name(this, "NatsClientModule");
|
|
260
418
|
}
|
|
261
|
-
static logger = new
|
|
419
|
+
static logger = new import_common7.Logger(_NatsClientModule.name);
|
|
262
420
|
static allClients = [];
|
|
263
421
|
async onModuleDestroy() {
|
|
264
422
|
await Promise.all(_NatsClientModule.allClients.map((c) => c.close()));
|
|
@@ -268,8 +426,8 @@ var NatsClientModule = class _NatsClientModule {
|
|
|
268
426
|
static buildClients(options, natsUrl) {
|
|
269
427
|
const clients = /* @__PURE__ */ new Map();
|
|
270
428
|
for (const svc of options.services) {
|
|
271
|
-
const proxy =
|
|
272
|
-
transport:
|
|
429
|
+
const proxy = import_microservices4.ClientProxyFactory.create({
|
|
430
|
+
transport: import_microservices4.Transport.NATS,
|
|
273
431
|
options: {
|
|
274
432
|
servers: [
|
|
275
433
|
natsUrl
|
|
@@ -359,151 +517,10 @@ var NatsClientModule = class _NatsClientModule {
|
|
|
359
517
|
};
|
|
360
518
|
}
|
|
361
519
|
};
|
|
362
|
-
NatsClientModule =
|
|
363
|
-
(0,
|
|
364
|
-
(0,
|
|
520
|
+
NatsClientModule = _ts_decorate4([
|
|
521
|
+
(0, import_common7.Global)(),
|
|
522
|
+
(0, import_common7.Module)({})
|
|
365
523
|
], NatsClientModule);
|
|
366
|
-
|
|
367
|
-
// src/filters/rpc-problem-exception.filter.ts
|
|
368
|
-
var import_common7 = require("@nestjs/common");
|
|
369
|
-
var import_microservices4 = require("@nestjs/microservices");
|
|
370
|
-
var import_rxjs = require("rxjs");
|
|
371
|
-
|
|
372
|
-
// src/exceptions/conflict.exception.ts
|
|
373
|
-
var import_common6 = require("@nestjs/common");
|
|
374
|
-
|
|
375
|
-
// src/exceptions/base-field.exception.ts
|
|
376
|
-
var import_common5 = require("@nestjs/common");
|
|
377
|
-
var HttpProblemException = class extends import_common5.HttpException {
|
|
378
|
-
static {
|
|
379
|
-
__name(this, "HttpProblemException");
|
|
380
|
-
}
|
|
381
|
-
constructor(detailOrOptions, httpStatus) {
|
|
382
|
-
const options = typeof detailOrOptions === "string" ? {
|
|
383
|
-
detail: detailOrOptions
|
|
384
|
-
} : detailOrOptions;
|
|
385
|
-
super({
|
|
386
|
-
type: options.type ?? "about:blank",
|
|
387
|
-
label: options.label,
|
|
388
|
-
detail: options.detail,
|
|
389
|
-
errors: options.errors ?? []
|
|
390
|
-
}, httpStatus);
|
|
391
|
-
}
|
|
392
|
-
};
|
|
393
|
-
|
|
394
|
-
// src/exceptions/conflict.exception.ts
|
|
395
|
-
var ConflictException = class extends HttpProblemException {
|
|
396
|
-
static {
|
|
397
|
-
__name(this, "ConflictException");
|
|
398
|
-
}
|
|
399
|
-
constructor(detailOrOptions) {
|
|
400
|
-
super(detailOrOptions ?? "Conflict", import_common6.HttpStatus.CONFLICT);
|
|
401
|
-
}
|
|
402
|
-
};
|
|
403
|
-
|
|
404
|
-
// src/filters/pg-error.translator.ts
|
|
405
|
-
var PG_UNIQUE_VIOLATION = "23505";
|
|
406
|
-
function tryTranslatePgError(error) {
|
|
407
|
-
const pgError = findPgError(error);
|
|
408
|
-
if (!pgError) return void 0;
|
|
409
|
-
const { code, constraint, table, detail } = pgError;
|
|
410
|
-
if (code !== PG_UNIQUE_VIOLATION) return void 0;
|
|
411
|
-
return new ConflictException({
|
|
412
|
-
label: "Duplicate Entry",
|
|
413
|
-
detail: detail?.trim() || "A record with these values already exists.",
|
|
414
|
-
errors: [],
|
|
415
|
-
...constraint || table ? {
|
|
416
|
-
meta: {
|
|
417
|
-
constraint,
|
|
418
|
-
table
|
|
419
|
-
}
|
|
420
|
-
} : {}
|
|
421
|
-
});
|
|
422
|
-
}
|
|
423
|
-
__name(tryTranslatePgError, "tryTranslatePgError");
|
|
424
|
-
function findPgError(error, depth = 0) {
|
|
425
|
-
if (!error || typeof error !== "object" || depth > 5) return void 0;
|
|
426
|
-
const candidate = error;
|
|
427
|
-
if (typeof candidate.code === "string") return candidate;
|
|
428
|
-
return findPgError(candidate.cause, depth + 1);
|
|
429
|
-
}
|
|
430
|
-
__name(findPgError, "findPgError");
|
|
431
|
-
|
|
432
|
-
// src/filters/rpc-problem-exception.filter.ts
|
|
433
|
-
function _ts_decorate4(decorators, target, key, desc) {
|
|
434
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
435
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
436
|
-
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;
|
|
437
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
438
|
-
}
|
|
439
|
-
__name(_ts_decorate4, "_ts_decorate");
|
|
440
|
-
var RpcProblemExceptionFilter = class _RpcProblemExceptionFilter {
|
|
441
|
-
static {
|
|
442
|
-
__name(this, "RpcProblemExceptionFilter");
|
|
443
|
-
}
|
|
444
|
-
logger = new import_common7.Logger(_RpcProblemExceptionFilter.name);
|
|
445
|
-
catch(exception, _host) {
|
|
446
|
-
const translatedPgError = tryTranslatePgError(exception);
|
|
447
|
-
if (translatedPgError) exception = translatedPgError;
|
|
448
|
-
if (exception instanceof import_microservices4.RpcException) {
|
|
449
|
-
return (0, import_rxjs.throwError)(() => exception.getError());
|
|
450
|
-
}
|
|
451
|
-
if (this.isHttpException(exception)) {
|
|
452
|
-
const status = exception.getStatus();
|
|
453
|
-
const response = exception.getResponse();
|
|
454
|
-
return (0, import_rxjs.throwError)(() => this.toProblemPayload(response, status));
|
|
455
|
-
}
|
|
456
|
-
if (exception instanceof Error) {
|
|
457
|
-
const cause = exception.cause;
|
|
458
|
-
const causeMessage = cause instanceof Error ? cause.message : void 0;
|
|
459
|
-
const causeStack = cause instanceof Error ? cause.stack : void 0;
|
|
460
|
-
this.logger.error(causeMessage ?? exception.message, causeStack ?? exception.stack);
|
|
461
|
-
if (cause && cause !== exception) {
|
|
462
|
-
this.logger.error(`Wrapped by: ${exception.message}`);
|
|
463
|
-
}
|
|
464
|
-
return (0, import_rxjs.throwError)(() => this.toProblemPayload({
|
|
465
|
-
type: "about:blank",
|
|
466
|
-
detail: causeMessage ?? exception.message,
|
|
467
|
-
errors: []
|
|
468
|
-
}, import_common7.HttpStatus.INTERNAL_SERVER_ERROR));
|
|
469
|
-
}
|
|
470
|
-
this.logger.error(`Unhandled non-error exception: ${JSON.stringify(exception)}`);
|
|
471
|
-
return (0, import_rxjs.throwError)(() => this.toProblemPayload({
|
|
472
|
-
type: "about:blank",
|
|
473
|
-
detail: "An unexpected error occurred",
|
|
474
|
-
errors: []
|
|
475
|
-
}, import_common7.HttpStatus.INTERNAL_SERVER_ERROR));
|
|
476
|
-
}
|
|
477
|
-
toProblemPayload(response, status) {
|
|
478
|
-
if (typeof response === "string") {
|
|
479
|
-
return {
|
|
480
|
-
type: "about:blank",
|
|
481
|
-
detail: response,
|
|
482
|
-
message: response,
|
|
483
|
-
errors: [],
|
|
484
|
-
status,
|
|
485
|
-
statusCode: status
|
|
486
|
-
};
|
|
487
|
-
}
|
|
488
|
-
const obj = response ?? {};
|
|
489
|
-
const detail = typeof obj.detail === "string" ? obj.detail : "Request failed";
|
|
490
|
-
return {
|
|
491
|
-
type: typeof obj.type === "string" ? obj.type : "about:blank",
|
|
492
|
-
label: typeof obj.label === "string" ? obj.label : void 0,
|
|
493
|
-
detail,
|
|
494
|
-
message: detail,
|
|
495
|
-
errors: Array.isArray(obj.errors) ? obj.errors : [],
|
|
496
|
-
status,
|
|
497
|
-
statusCode: status
|
|
498
|
-
};
|
|
499
|
-
}
|
|
500
|
-
isHttpException(error) {
|
|
501
|
-
return error instanceof Error && typeof error.getStatus === "function" && typeof error.getResponse === "function";
|
|
502
|
-
}
|
|
503
|
-
};
|
|
504
|
-
RpcProblemExceptionFilter = _ts_decorate4([
|
|
505
|
-
(0, import_common7.Catch)()
|
|
506
|
-
], RpcProblemExceptionFilter);
|
|
507
524
|
// Annotate the CommonJS export names for ESM import in node:
|
|
508
525
|
0 && (module.exports = {
|
|
509
526
|
NATS_HEADER_KEYS,
|