@open-norantec/herbal 1.0.2-alpha.3 → 1.0.2-alpha.30
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/abstracts/client.abstract.class.d.ts +13 -0
- package/dist/abstracts/client.abstract.class.js +39 -0
- package/dist/abstracts/index.d.ts +1 -0
- package/dist/abstracts/index.js +1 -0
- package/dist/cli/herbal.js +167 -71
- package/dist/clients/index.d.ts +1 -0
- package/dist/clients/index.js +17 -0
- package/dist/clients/typescript-client.class.d.ts +7 -0
- package/dist/clients/typescript-client.class.js +239 -0
- package/dist/core.d.ts +2 -7
- package/dist/core.js +58 -71
- package/dist/{create.d.ts → create/create-application.d.ts} +8 -8
- package/dist/create/create-application.js +18 -0
- package/dist/create/create-client.d.ts +9 -0
- package/dist/create/create-client.js +17 -0
- package/dist/create/index.d.ts +2 -0
- package/dist/create/index.js +18 -0
- package/dist/decorators/index.d.ts +1 -0
- package/dist/decorators/index.js +1 -0
- package/dist/decorators/no-transaction.decorator.d.ts +5 -0
- package/dist/decorators/no-transaction.decorator.js +16 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/sequelize-di.js +4 -6
- package/dist/types/request.type.d.ts +3 -2
- package/dist/utilities/controller-util.class.d.ts +43 -2
- package/dist/utilities/controller-util.class.js +260 -82
- package/package.json +9 -12
- package/dist/create.js +0 -154
- package/dist/transformers/reflect-declaration.d.ts +0 -3
- package/dist/transformers/reflect-declaration.js +0 -63
|
@@ -72,13 +72,13 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
72
72
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
73
73
|
};
|
|
74
74
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
75
|
-
exports.ControllerUtil = exports.isHerbalController = void 0;
|
|
75
|
+
exports.ControllerUtil = exports.getControllerName = exports.isHerbalController = void 0;
|
|
76
76
|
require("reflect-metadata");
|
|
77
77
|
var common_1 = require("@nestjs/common");
|
|
78
78
|
var _ = require("lodash");
|
|
79
79
|
var string_util_class_1 = require("@open-norantec/utilities/dist/string-util.class");
|
|
80
|
+
var uuid_util_class_1 = require("@open-norantec/utilities/dist/uuid-util.class");
|
|
80
81
|
var common_2 = require("@nestjs/common");
|
|
81
|
-
var uuid_1 = require("uuid");
|
|
82
82
|
var headers_constant_1 = require("../constants/headers.constant");
|
|
83
83
|
var core_1 = require("@nestjs/core");
|
|
84
84
|
var auth_adapter_decorator_1 = require("../decorators/auth-adapter.decorator");
|
|
@@ -86,11 +86,137 @@ var rxjs_1 = require("rxjs");
|
|
|
86
86
|
var operators_1 = require("rxjs/operators");
|
|
87
87
|
var logger_service_1 = require("../modules/logger/logger.service");
|
|
88
88
|
var sequelize_typescript_1 = require("sequelize-typescript");
|
|
89
|
-
var
|
|
89
|
+
var decorators_1 = require("../decorators");
|
|
90
|
+
var zod_1 = require("zod");
|
|
91
|
+
var zod_openapi_1 = require("zod-openapi");
|
|
92
|
+
var METHOD_POOL = Symbol();
|
|
93
|
+
var MethodConfig = (function () {
|
|
94
|
+
function MethodConfig(name, options, callback) {
|
|
95
|
+
this.name = name;
|
|
96
|
+
this.options = options;
|
|
97
|
+
this.callback = callback;
|
|
98
|
+
}
|
|
99
|
+
MethodConfig.prototype.call = function (controller, callContext) {
|
|
100
|
+
var _a, _b, _c, _d, _e, _f;
|
|
101
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
102
|
+
var inputSchema, outputSchema, parsedBody_1, input, rawResponse_1, response, error_1;
|
|
103
|
+
return __generator(this, function (_g) {
|
|
104
|
+
switch (_g.label) {
|
|
105
|
+
case 0:
|
|
106
|
+
inputSchema = this.options.inputSchema;
|
|
107
|
+
outputSchema = this.options.outputSchema;
|
|
108
|
+
_g.label = 1;
|
|
109
|
+
case 1:
|
|
110
|
+
_g.trys.push([1, 3, , 4]);
|
|
111
|
+
parsedBody_1 = _.attempt(function () { return JSON.parse((callContext === null || callContext === void 0 ? void 0 : callContext.rawBody) || ''); });
|
|
112
|
+
input = _.attempt(function () { return (parsedBody_1 instanceof Error ? undefined : inputSchema.parse(parsedBody_1)); });
|
|
113
|
+
if (input instanceof zod_1.ZodError) {
|
|
114
|
+
throw new common_1.BadRequestException({
|
|
115
|
+
from: 'request',
|
|
116
|
+
invalidParams: (_c = (_b = (_a = input === null || input === void 0 ? void 0 : input.issues) === null || _a === void 0 ? void 0 : _a.map) === null || _b === void 0 ? void 0 : _b.call(_a, function (item) { var _a, _b; return (_b = (_a = item === null || item === void 0 ? void 0 : item.path) === null || _a === void 0 ? void 0 : _a.join) === null || _b === void 0 ? void 0 : _b.call(_a, '.'); })) !== null && _c !== void 0 ? _c : [],
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
else if (input instanceof Error)
|
|
120
|
+
throw input;
|
|
121
|
+
return [4, this.callback.call(controller, __assign(__assign({}, callContext), { input: input }))];
|
|
122
|
+
case 2:
|
|
123
|
+
rawResponse_1 = _g.sent();
|
|
124
|
+
response = _.attempt(function () { return outputSchema.parse(rawResponse_1); });
|
|
125
|
+
if (response instanceof zod_1.ZodError) {
|
|
126
|
+
throw new common_1.BadRequestException({
|
|
127
|
+
from: 'response',
|
|
128
|
+
invalidParams: (_f = (_e = (_d = response === null || response === void 0 ? void 0 : response.issues) === null || _d === void 0 ? void 0 : _d.map) === null || _e === void 0 ? void 0 : _e.call(_d, function (item) { var _a, _b; return (_b = (_a = item === null || item === void 0 ? void 0 : item.path) === null || _a === void 0 ? void 0 : _a.join) === null || _b === void 0 ? void 0 : _b.call(_a, '.'); })) !== null && _f !== void 0 ? _f : [],
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
else if (response instanceof Error)
|
|
132
|
+
throw response;
|
|
133
|
+
return [2, response];
|
|
134
|
+
case 3:
|
|
135
|
+
error_1 = _g.sent();
|
|
136
|
+
throw error_1;
|
|
137
|
+
case 4: return [2];
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
};
|
|
142
|
+
return MethodConfig;
|
|
143
|
+
}());
|
|
144
|
+
var MethodPool = (function () {
|
|
145
|
+
function MethodPool() {
|
|
146
|
+
this.methods = new Map();
|
|
147
|
+
}
|
|
148
|
+
MethodPool.prototype.registerMethod = function (name, options, callback) {
|
|
149
|
+
if (string_util_class_1.StringUtil.isFalsyString(name))
|
|
150
|
+
return;
|
|
151
|
+
if (name.includes('/'))
|
|
152
|
+
throw new Error("Method name cannot contain slashes: ".concat(name));
|
|
153
|
+
this.methods.set(name, new MethodConfig(name, options, callback));
|
|
154
|
+
};
|
|
155
|
+
MethodPool.prototype.getCallFn = function (name) {
|
|
156
|
+
var config = this.methods.get(name);
|
|
157
|
+
if (!(config instanceof MethodConfig))
|
|
158
|
+
return null;
|
|
159
|
+
return config.call.bind(config);
|
|
160
|
+
};
|
|
161
|
+
MethodPool.prototype.getAuthAdapters = function (name) {
|
|
162
|
+
var config = this.methods.get(name);
|
|
163
|
+
if (!(config instanceof MethodConfig))
|
|
164
|
+
return null;
|
|
165
|
+
return config.options.authAdapters;
|
|
166
|
+
};
|
|
167
|
+
MethodPool.prototype.getOpenAPIPathsObject = function (group) {
|
|
168
|
+
var result = {};
|
|
169
|
+
Array.from(this.methods.entries()).forEach(function (_a) {
|
|
170
|
+
var _b;
|
|
171
|
+
var name = _a[0], config = _a[1];
|
|
172
|
+
var defaultGroupName = "".concat(Date.now(), "_").concat(Math.random().toString(16).slice(2));
|
|
173
|
+
var currentGroupName = string_util_class_1.StringUtil.isFalsyString(group) ? defaultGroupName : group;
|
|
174
|
+
var clientGroups = typeof config.options.clientGroups === 'function'
|
|
175
|
+
? config.options.clientGroups(defaultGroupName)
|
|
176
|
+
: (_b = config === null || config === void 0 ? void 0 : config.options) === null || _b === void 0 ? void 0 : _b.clientGroups;
|
|
177
|
+
if (!Array.isArray(clientGroups) && !string_util_class_1.StringUtil.isFalsyString(group) && defaultGroupName !== group)
|
|
178
|
+
return;
|
|
179
|
+
if (Array.isArray(clientGroups) && !clientGroups.includes(currentGroupName))
|
|
180
|
+
return;
|
|
181
|
+
result["/".concat(name)] = {
|
|
182
|
+
post: {
|
|
183
|
+
requestBody: {
|
|
184
|
+
description: 'Request body for method ' + name,
|
|
185
|
+
required: true,
|
|
186
|
+
content: {
|
|
187
|
+
'application/json': {
|
|
188
|
+
schema: (0, zod_openapi_1.createSchema)(config.options.inputSchema).schema,
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
responses: {
|
|
193
|
+
'200': {
|
|
194
|
+
description: 'Response for method ' + name,
|
|
195
|
+
content: {
|
|
196
|
+
'application/json': (0, zod_openapi_1.createSchema)(zod_1.z.object({
|
|
197
|
+
data: config.options.outputSchema,
|
|
198
|
+
token: zod_1.z.string().nullable(),
|
|
199
|
+
})),
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
},
|
|
204
|
+
};
|
|
205
|
+
});
|
|
206
|
+
return result;
|
|
207
|
+
};
|
|
208
|
+
return MethodPool;
|
|
209
|
+
}());
|
|
210
|
+
var IS_HERBAL_CONTROLLER = Symbol();
|
|
211
|
+
var CONTROLLER_NAME = Symbol();
|
|
90
212
|
function isHerbalController(target) {
|
|
91
|
-
return _.attempt(function () { return Reflect.getMetadata(
|
|
213
|
+
return _.attempt(function () { return Reflect.getMetadata(IS_HERBAL_CONTROLLER, target.prototype); }) === true;
|
|
92
214
|
}
|
|
93
215
|
exports.isHerbalController = isHerbalController;
|
|
216
|
+
function getControllerName(target) {
|
|
217
|
+
return Reflect.getMetadata(CONTROLLER_NAME, target.prototype);
|
|
218
|
+
}
|
|
219
|
+
exports.getControllerName = getControllerName;
|
|
94
220
|
var ControllerInterceptor = (function () {
|
|
95
221
|
function ControllerInterceptor(ref) {
|
|
96
222
|
this.ref = ref;
|
|
@@ -102,9 +228,6 @@ var ControllerInterceptor = (function () {
|
|
|
102
228
|
_.attempt(function () {
|
|
103
229
|
_this.getLogger().log("[trace:".concat(request === null || request === void 0 ? void 0 : request.traceId, ":response:url] ").concat(request === null || request === void 0 ? void 0 : request.originalUrl));
|
|
104
230
|
});
|
|
105
|
-
_.attempt(function () {
|
|
106
|
-
return _this.getLogger().log("[trace:".concat(request === null || request === void 0 ? void 0 : request.traceId, ":request:body] ").concat(JSON.stringify(request === null || request === void 0 ? void 0 : request.body)));
|
|
107
|
-
});
|
|
108
231
|
_.attempt(function () {
|
|
109
232
|
return _this.getLogger().log("[trace:".concat(request === null || request === void 0 ? void 0 : request.traceId, ":request:headers] ").concat(JSON.stringify(request === null || request === void 0 ? void 0 : request.headers)));
|
|
110
233
|
});
|
|
@@ -139,6 +262,7 @@ var ControllerInterceptor = (function () {
|
|
|
139
262
|
_.attempt(function () {
|
|
140
263
|
_this.getLogger().error("[trace:".concat(request === null || request === void 0 ? void 0 : request.traceId, ":response:error:stack] ").concat(error === null || error === void 0 ? void 0 : error.stack));
|
|
141
264
|
});
|
|
265
|
+
_this.getLogger().error("Got error when handling route in interceptor: ".concat(error === null || error === void 0 ? void 0 : error.message, " ").concat(error === null || error === void 0 ? void 0 : error.stack));
|
|
142
266
|
_.attempt(function () { var _a, _b, _c, _d; return (_d = (_c = (_b = (_a = request === null || request === void 0 ? void 0 : request.transaction) === null || _a === void 0 ? void 0 : _a.rollback) === null || _b === void 0 ? void 0 : _b.call(_a)) === null || _c === void 0 ? void 0 : _c.catch) === null || _d === void 0 ? void 0 : _d.call(_c, function () { }); });
|
|
143
267
|
return (0, rxjs_1.throwError)(function () { return error; });
|
|
144
268
|
}));
|
|
@@ -156,72 +280,67 @@ function HerbalGuard(options) {
|
|
|
156
280
|
}
|
|
157
281
|
HerbalGuardMixin.prototype.canActivate = function (context) {
|
|
158
282
|
var _a, e_1, _b, _c;
|
|
159
|
-
var _d, _e, _f, _g, _h;
|
|
283
|
+
var _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
160
284
|
return __awaiter(this, void 0, void 0, function () {
|
|
161
|
-
var sequelizeInstance, transaction, request, response, traceId, chunks,
|
|
285
|
+
var sequelizeInstance, transaction, request, response, traceId, chunks, _o, request_1, request_1_1, chunk, e_1_1, _p, parsedBody, rawHandlerName, handlerPropertype, handlerName, authAdapters, error_2, _i, authAdapters_1, AuthAdapterClass, adapter, authenticateResult, error_3, _q;
|
|
162
286
|
var _this = this;
|
|
163
|
-
return __generator(this, function (
|
|
164
|
-
switch (
|
|
287
|
+
return __generator(this, function (_r) {
|
|
288
|
+
switch (_r.label) {
|
|
165
289
|
case 0:
|
|
166
290
|
sequelizeInstance = _.attempt(function () { return _this.ref.get(sequelize_typescript_1.Sequelize, { strict: false }); });
|
|
167
291
|
transaction = undefined;
|
|
168
|
-
if (!!(sequelizeInstance instanceof Error)) return [3, 2];
|
|
169
|
-
return [4, ((_e = (_d = sequelizeInstance === null || sequelizeInstance === void 0 ? void 0 : sequelizeInstance.transaction) === null || _d === void 0 ? void 0 : _d.call(sequelizeInstance)) === null || _e === void 0 ? void 0 : _e.catch(function () { return Promise.resolve(undefined); }))];
|
|
170
|
-
case 1:
|
|
171
|
-
transaction = _m.sent();
|
|
172
|
-
_m.label = 2;
|
|
173
|
-
case 2:
|
|
174
292
|
request = context.switchToHttp().getRequest();
|
|
175
293
|
response = context.switchToHttp().getResponse();
|
|
176
|
-
traceId = typeof (options === null || options === void 0 ? void 0 : options.getTraceId) === 'function'
|
|
177
|
-
|
|
178
|
-
|
|
294
|
+
traceId = typeof (options === null || options === void 0 ? void 0 : options.getTraceId) === 'function'
|
|
295
|
+
? _.attempt(function () { return options.getTraceId(request); })
|
|
296
|
+
: uuid_util_class_1.UUIDUtil.generateV4();
|
|
297
|
+
if (traceId instanceof Error || string_util_class_1.StringUtil.isFalsyString(traceId))
|
|
298
|
+
traceId = uuid_util_class_1.UUIDUtil.generateV4();
|
|
179
299
|
request.traceId = traceId;
|
|
180
300
|
request.methodName = request.url.split('/').pop();
|
|
181
|
-
request.transaction = transaction;
|
|
182
301
|
response.setHeader(headers_constant_1.HEADERS.TRACE_ID, traceId);
|
|
183
302
|
chunks = [];
|
|
184
|
-
|
|
185
|
-
case
|
|
186
|
-
|
|
187
|
-
|
|
303
|
+
_r.label = 1;
|
|
304
|
+
case 1:
|
|
305
|
+
_r.trys.push([1, 14, , 15]);
|
|
306
|
+
_r.label = 2;
|
|
307
|
+
case 2:
|
|
308
|
+
_r.trys.push([2, 7, 8, 13]);
|
|
309
|
+
_o = true, request_1 = __asyncValues(request);
|
|
310
|
+
_r.label = 3;
|
|
311
|
+
case 3: return [4, request_1.next()];
|
|
188
312
|
case 4:
|
|
189
|
-
|
|
190
|
-
_j = true, request_1 = __asyncValues(request);
|
|
191
|
-
_m.label = 5;
|
|
192
|
-
case 5: return [4, request_1.next()];
|
|
193
|
-
case 6:
|
|
194
|
-
if (!(request_1_1 = _m.sent(), _a = request_1_1.done, !_a)) return [3, 8];
|
|
313
|
+
if (!(request_1_1 = _r.sent(), _a = request_1_1.done, !_a)) return [3, 6];
|
|
195
314
|
_c = request_1_1.value;
|
|
196
|
-
|
|
315
|
+
_o = false;
|
|
197
316
|
chunk = _c;
|
|
198
317
|
chunks.push(chunk);
|
|
199
|
-
|
|
318
|
+
_r.label = 5;
|
|
319
|
+
case 5:
|
|
320
|
+
_o = true;
|
|
321
|
+
return [3, 3];
|
|
322
|
+
case 6: return [3, 13];
|
|
200
323
|
case 7:
|
|
201
|
-
|
|
202
|
-
return [3, 5];
|
|
203
|
-
case 8: return [3, 15];
|
|
204
|
-
case 9:
|
|
205
|
-
e_1_1 = _m.sent();
|
|
324
|
+
e_1_1 = _r.sent();
|
|
206
325
|
e_1 = { error: e_1_1 };
|
|
207
|
-
return [3,
|
|
208
|
-
case
|
|
209
|
-
|
|
210
|
-
if (!(!
|
|
326
|
+
return [3, 13];
|
|
327
|
+
case 8:
|
|
328
|
+
_r.trys.push([8, , 11, 12]);
|
|
329
|
+
if (!(!_o && !_a && (_b = request_1.return))) return [3, 10];
|
|
211
330
|
return [4, _b.call(request_1)];
|
|
331
|
+
case 9:
|
|
332
|
+
_r.sent();
|
|
333
|
+
_r.label = 10;
|
|
334
|
+
case 10: return [3, 12];
|
|
212
335
|
case 11:
|
|
213
|
-
_m.sent();
|
|
214
|
-
_m.label = 12;
|
|
215
|
-
case 12: return [3, 14];
|
|
216
|
-
case 13:
|
|
217
336
|
if (e_1) throw e_1.error;
|
|
218
337
|
return [7];
|
|
219
|
-
case
|
|
220
|
-
case
|
|
221
|
-
case
|
|
222
|
-
|
|
223
|
-
return [3,
|
|
224
|
-
case
|
|
338
|
+
case 12: return [7];
|
|
339
|
+
case 13: return [3, 15];
|
|
340
|
+
case 14:
|
|
341
|
+
_p = _r.sent();
|
|
342
|
+
return [3, 15];
|
|
343
|
+
case 15:
|
|
225
344
|
parsedBody = _.attempt(function () { return Buffer.concat(chunks).toString('utf8'); });
|
|
226
345
|
if (!(parsedBody instanceof Error)) {
|
|
227
346
|
request.rawBody = parsedBody;
|
|
@@ -229,49 +348,89 @@ function HerbalGuard(options) {
|
|
|
229
348
|
else {
|
|
230
349
|
request.rawBody = null;
|
|
231
350
|
}
|
|
232
|
-
|
|
233
|
-
|
|
351
|
+
_.attempt(function () { return _this.getLogger().log("[trace:".concat(request === null || request === void 0 ? void 0 : request.traceId, ":request:body] ").concat(request.rawBody)); });
|
|
352
|
+
rawHandlerName = (_e = (_d = context === null || context === void 0 ? void 0 : context.getHandler) === null || _d === void 0 ? void 0 : _d.call(context)) === null || _e === void 0 ? void 0 : _e.name;
|
|
353
|
+
handlerPropertype = (_g = (_f = context === null || context === void 0 ? void 0 : context.getClass) === null || _f === void 0 ? void 0 : _f.call(context)) === null || _g === void 0 ? void 0 : _g.prototype;
|
|
354
|
+
handlerName = string_util_class_1.StringUtil.isFalsyString(rawHandlerName) ? request.methodName : rawHandlerName;
|
|
355
|
+
authAdapters = (_j = (_h = ControllerUtil.getPool(handlerPropertype)) === null || _h === void 0 ? void 0 : _h.getAuthAdapters) === null || _j === void 0 ? void 0 : _j.call(_h, handlerName);
|
|
356
|
+
if (authAdapters === null)
|
|
357
|
+
authAdapters = auth_adapter_decorator_1.AuthAdapters.getAdapters(handlerPropertype, handlerName);
|
|
358
|
+
if (!(!(sequelizeInstance instanceof Error) && !decorators_1.NoTransaction.isDisabled(handlerPropertype, handlerName))) return [3, 20];
|
|
359
|
+
_r.label = 16;
|
|
360
|
+
case 16:
|
|
361
|
+
_r.trys.push([16, 18, , 19]);
|
|
362
|
+
return [4, ((_l = (_k = sequelizeInstance === null || sequelizeInstance === void 0 ? void 0 : sequelizeInstance.transaction) === null || _k === void 0 ? void 0 : _k.call(sequelizeInstance)) === null || _l === void 0 ? void 0 : _l.catch(function () { return Promise.resolve(undefined); }))];
|
|
363
|
+
case 17:
|
|
364
|
+
transaction = _r.sent();
|
|
365
|
+
request.transaction = transaction;
|
|
366
|
+
this.getLogger().log("[trace:".concat(request === null || request === void 0 ? void 0 : request.traceId, ":transaction] Started transaction for route: ").concat(handlerName));
|
|
367
|
+
return [3, 19];
|
|
234
368
|
case 18:
|
|
235
|
-
|
|
236
|
-
if (
|
|
369
|
+
error_2 = _r.sent();
|
|
370
|
+
if (error_2 instanceof Error) {
|
|
371
|
+
this.getLogger().error("[trace:".concat(request === null || request === void 0 ? void 0 : request.traceId, ":transaction] Failed to start transaction: ").concat(error_2 === null || error_2 === void 0 ? void 0 : error_2.message, "\n").concat(error_2 === null || error_2 === void 0 ? void 0 : error_2.stack));
|
|
372
|
+
}
|
|
373
|
+
return [3, 19];
|
|
374
|
+
case 19: return [3, 21];
|
|
375
|
+
case 20:
|
|
376
|
+
if (decorators_1.NoTransaction.isDisabled(handlerPropertype, handlerName)) {
|
|
377
|
+
this.getLogger().log("[trace:".concat(request === null || request === void 0 ? void 0 : request.traceId, ":transaction] Transaction is disabled for this route: ").concat(handlerName));
|
|
378
|
+
}
|
|
379
|
+
_r.label = 21;
|
|
380
|
+
case 21:
|
|
381
|
+
_r.trys.push([21, 27, , 32]);
|
|
382
|
+
if (!(Array.isArray(authAdapters) && authAdapters.length > 0)) return [3, 26];
|
|
237
383
|
_i = 0, authAdapters_1 = authAdapters;
|
|
238
|
-
|
|
239
|
-
case
|
|
240
|
-
if (!(_i < authAdapters_1.length)) return [3,
|
|
384
|
+
_r.label = 22;
|
|
385
|
+
case 22:
|
|
386
|
+
if (!(_i < authAdapters_1.length)) return [3, 25];
|
|
241
387
|
AuthAdapterClass = authAdapters_1[_i];
|
|
242
388
|
adapter = new AuthAdapterClass(request, this.ref);
|
|
243
389
|
if (!adapter.match())
|
|
244
|
-
return [3,
|
|
390
|
+
return [3, 24];
|
|
245
391
|
return [4, adapter.authenticate(transaction)];
|
|
246
|
-
case
|
|
247
|
-
authenticateResult =
|
|
392
|
+
case 23:
|
|
393
|
+
authenticateResult = _r.sent();
|
|
248
394
|
if (!authenticateResult)
|
|
249
|
-
return [3,
|
|
395
|
+
return [3, 25];
|
|
250
396
|
request.authenticateResult = __assign({ AuthenticatorClass: AuthAdapterClass }, authenticateResult);
|
|
251
397
|
return [2, true];
|
|
252
|
-
case 21:
|
|
253
|
-
_i++;
|
|
254
|
-
return [3, 19];
|
|
255
|
-
case 22: throw new common_2.UnauthorizedException();
|
|
256
|
-
case 23: return [3, 29];
|
|
257
398
|
case 24:
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
case 25:
|
|
261
|
-
|
|
262
|
-
return [4, ((_h = transaction === null || transaction === void 0 ? void 0 : transaction.rollback) === null || _h === void 0 ? void 0 : _h.call(transaction))];
|
|
263
|
-
case 26:
|
|
264
|
-
_m.sent();
|
|
265
|
-
return [3, 28];
|
|
399
|
+
_i++;
|
|
400
|
+
return [3, 22];
|
|
401
|
+
case 25: throw new common_2.UnauthorizedException();
|
|
402
|
+
case 26: return [3, 32];
|
|
266
403
|
case 27:
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
case 28:
|
|
270
|
-
|
|
404
|
+
error_3 = _r.sent();
|
|
405
|
+
_r.label = 28;
|
|
406
|
+
case 28:
|
|
407
|
+
_r.trys.push([28, 30, , 31]);
|
|
408
|
+
if (error_3 instanceof Error) {
|
|
409
|
+
this.getLogger().error("Got error when handling route: ".concat(error_3 === null || error_3 === void 0 ? void 0 : error_3.message, " ").concat(error_3 === null || error_3 === void 0 ? void 0 : error_3.stack));
|
|
410
|
+
}
|
|
411
|
+
return [4, ((_m = transaction === null || transaction === void 0 ? void 0 : transaction.rollback) === null || _m === void 0 ? void 0 : _m.call(transaction))];
|
|
412
|
+
case 29:
|
|
413
|
+
_r.sent();
|
|
414
|
+
return [3, 31];
|
|
415
|
+
case 30:
|
|
416
|
+
_q = _r.sent();
|
|
417
|
+
return [3, 31];
|
|
418
|
+
case 31: throw error_3;
|
|
419
|
+
case 32: return [2, true];
|
|
271
420
|
}
|
|
272
421
|
});
|
|
273
422
|
});
|
|
274
423
|
};
|
|
424
|
+
HerbalGuardMixin.prototype.getLogger = function () {
|
|
425
|
+
var loggerService = this.ref.get(logger_service_1.LoggerService, { strict: false });
|
|
426
|
+
if (!(loggerService instanceof logger_service_1.LoggerService)) {
|
|
427
|
+
return {
|
|
428
|
+
log: function () { },
|
|
429
|
+
error: function () { },
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
return loggerService;
|
|
433
|
+
};
|
|
275
434
|
HerbalGuardMixin = __decorate([
|
|
276
435
|
(0, common_2.Injectable)(),
|
|
277
436
|
__metadata("design:paramtypes", [core_1.ModuleRef])
|
|
@@ -283,24 +442,43 @@ function HerbalGuard(options) {
|
|
|
283
442
|
var ControllerUtil = (function () {
|
|
284
443
|
function ControllerUtil() {
|
|
285
444
|
}
|
|
445
|
+
ControllerUtil.getPool = function (targetPrototype) {
|
|
446
|
+
var pool = Reflect.getMetadata(METHOD_POOL, targetPrototype);
|
|
447
|
+
if (!(pool instanceof MethodPool))
|
|
448
|
+
return null;
|
|
449
|
+
return pool;
|
|
450
|
+
};
|
|
286
451
|
ControllerUtil.create = function (createOptions) {
|
|
287
452
|
function Controller(options) {
|
|
288
453
|
return function (target) {
|
|
454
|
+
var _a;
|
|
455
|
+
var methodPool = new MethodPool();
|
|
289
456
|
var finalPrefix = string_util_class_1.StringUtil.isFalsyString(options === null || options === void 0 ? void 0 : options.prefix)
|
|
290
457
|
? string_util_class_1.StringUtil.isFalsyString(createOptions === null || createOptions === void 0 ? void 0 : createOptions.prefix)
|
|
291
458
|
? ''
|
|
292
459
|
: createOptions.prefix
|
|
293
460
|
: options.prefix;
|
|
294
|
-
|
|
461
|
+
var controllerName = _.camelCase(target.name.replace(/Controller$/g, ''));
|
|
462
|
+
finalPrefix += "".concat(((_a = finalPrefix === null || finalPrefix === void 0 ? void 0 : finalPrefix.endsWith) === null || _a === void 0 ? void 0 : _a.call(finalPrefix, '/')) ? '' : '/').concat(controllerName);
|
|
463
|
+
var register = function (name, options, callback) {
|
|
464
|
+
if (string_util_class_1.StringUtil.isFalsyString(name) || typeof callback !== 'function')
|
|
465
|
+
return;
|
|
466
|
+
methodPool.registerMethod(name, options, callback);
|
|
467
|
+
};
|
|
295
468
|
if (!finalPrefix.startsWith('/'))
|
|
296
469
|
finalPrefix = "/".concat(finalPrefix);
|
|
297
|
-
Reflect.defineMetadata(
|
|
470
|
+
Reflect.defineMetadata(IS_HERBAL_CONTROLLER, true, target.prototype);
|
|
471
|
+
Reflect.defineMetadata(CONTROLLER_NAME, controllerName, target.prototype);
|
|
472
|
+
Reflect.defineMetadata(METHOD_POOL, methodPool, target.prototype);
|
|
473
|
+
if (typeof (options === null || options === void 0 ? void 0 : options.methods) === 'function')
|
|
474
|
+
options.methods(register);
|
|
298
475
|
(0, common_1.Controller)(finalPrefix)(target);
|
|
299
476
|
(0, common_1.UseInterceptors)(ControllerInterceptor)(target);
|
|
300
477
|
common_1.UseGuards.apply(void 0, __spreadArray(__spreadArray(__spreadArray([HerbalGuard(_.pick(createOptions, ['getTraceId']))], (Array.isArray(options === null || options === void 0 ? void 0 : options.useHeadGuards) ? options.useHeadGuards : []), false), (Array.isArray(createOptions === null || createOptions === void 0 ? void 0 : createOptions.useGuards) ? createOptions.useGuards : []), false), (Array.isArray(options === null || options === void 0 ? void 0 : options.useTailGuards) ? options.useTailGuards : []), false))(target);
|
|
301
478
|
};
|
|
302
479
|
}
|
|
303
480
|
Controller.isHerbalController = isHerbalController;
|
|
481
|
+
Controller.getControllerName = getControllerName;
|
|
304
482
|
return Controller;
|
|
305
483
|
};
|
|
306
484
|
return ControllerUtil;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-norantec/herbal",
|
|
3
|
-
"version": "1.0.2-alpha.
|
|
3
|
+
"version": "1.0.2-alpha.30",
|
|
4
4
|
"description": "Herbal is a builder and toolchain for Nest.js applications",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -38,9 +38,11 @@
|
|
|
38
38
|
"@nestjs/common": "^10.0.0",
|
|
39
39
|
"@nestjs/core": "^10.4.19",
|
|
40
40
|
"@nestjs/sequelize": "^10.0.1",
|
|
41
|
-
"@open-norantec/forge": "
|
|
41
|
+
"@open-norantec/forge": "^2.0.0-alpha.9",
|
|
42
42
|
"@open-norantec/utilities": "latest",
|
|
43
43
|
"commander": "^12.1.0",
|
|
44
|
+
"fs-extra": "^11.3.4",
|
|
45
|
+
"json-schema-to-typescript": "^15.0.4",
|
|
44
46
|
"lodash": "^4.17.21",
|
|
45
47
|
"nest-winston": "^1.10.2",
|
|
46
48
|
"nj-request-scope": "^1.0.10",
|
|
@@ -49,26 +51,21 @@
|
|
|
49
51
|
"rxjs": "^7.8.2",
|
|
50
52
|
"sequelize": "6.37.7",
|
|
51
53
|
"sequelize-typescript": "^2.1.5",
|
|
52
|
-
"ts-patch": "^3.3.0",
|
|
53
54
|
"type-fest": "^4.41.0",
|
|
55
|
+
"typescript": ">=5.1.0 <5.2.0",
|
|
54
56
|
"uuid": "^11.1.0",
|
|
55
|
-
"zod": "^3.25.67"
|
|
57
|
+
"zod": "^3.25.67",
|
|
58
|
+
"zod-openapi": "4.2.4"
|
|
56
59
|
},
|
|
57
60
|
"devDependencies": {
|
|
58
|
-
"@stylistic/eslint-plugin": "^2.12.1",
|
|
59
61
|
"@types/express": "^5.0.3",
|
|
62
|
+
"@types/fs-extra": "^11.0.4",
|
|
60
63
|
"@types/lodash": "^4.17.16",
|
|
61
64
|
"@types/node": "18.11.18",
|
|
62
|
-
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
|
63
|
-
"@typescript-eslint/parser": "^8.0.0",
|
|
64
65
|
"cross-env": "^7.0.3",
|
|
65
66
|
"eslint": "^8.0.0",
|
|
66
|
-
"eslint-config-prettier": "^9.0.0",
|
|
67
|
-
"eslint-plugin-prettier": "^5.0.0",
|
|
68
67
|
"express": "^4.21.2",
|
|
69
|
-
"prettier": "^3.0.0",
|
|
70
68
|
"rimraf": "^6.0.1",
|
|
71
|
-
"ts-node": "^10.0.0"
|
|
72
|
-
"typescript": "~5.1.3"
|
|
69
|
+
"ts-node": "^10.0.0"
|
|
73
70
|
}
|
|
74
71
|
}
|