@open-norantec/herbal 1.0.2-alpha.6 → 1.0.2-alpha.7

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.
@@ -77,8 +77,8 @@ 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");
@@ -154,62 +154,64 @@ function HerbalGuard(options) {
154
154
  }
155
155
  HerbalGuardMixin.prototype.canActivate = function (context) {
156
156
  var _a, e_1, _b, _c;
157
- var _d, _e, _f, _g, _h;
157
+ var _d, _e, _f, _g, _h, _j, _k;
158
158
  return __awaiter(this, void 0, void 0, function () {
159
- var sequelizeInstance, transaction, request, response, traceId, chunks, _j, request_1, request_1_1, chunk, e_1_1, _k, parsedBody, authAdapters, _i, authAdapters_1, AuthAdapterClass, adapter, authenticateResult, error_1, _l;
159
+ var sequelizeInstance, transaction, request, response, traceId, chunks, _l, request_1, request_1_1, chunk, e_1_1, _m, parsedBody, handlerName, authAdapters, _i, authAdapters_1, AuthAdapterClass, adapter, authenticateResult, error_1, _o;
160
160
  var _this = this;
161
- return __generator(this, function (_m) {
162
- switch (_m.label) {
161
+ return __generator(this, function (_p) {
162
+ switch (_p.label) {
163
163
  case 0:
164
164
  sequelizeInstance = _.attempt(function () { return _this.ref.get(sequelize_typescript_1.Sequelize, { strict: false }); });
165
165
  transaction = undefined;
166
166
  if (!!(sequelizeInstance instanceof Error)) return [3, 2];
167
167
  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); }))];
168
168
  case 1:
169
- transaction = _m.sent();
170
- _m.label = 2;
169
+ transaction = _p.sent();
170
+ _p.label = 2;
171
171
  case 2:
172
172
  request = context.switchToHttp().getRequest();
173
173
  response = context.switchToHttp().getResponse();
174
- traceId = typeof (options === null || options === void 0 ? void 0 : options.getTraceId) === 'function' ? _.attempt(function () { return options.getTraceId(request); }) : (0, uuid_1.v4)();
175
- if (traceId instanceof Error)
176
- traceId = (0, uuid_1.v4)();
174
+ traceId = typeof (options === null || options === void 0 ? void 0 : options.getTraceId) === 'function'
175
+ ? _.attempt(function () { return options.getTraceId(request); })
176
+ : uuid_util_class_1.UUIDUtil.generateV4();
177
+ if (traceId instanceof Error || string_util_class_1.StringUtil.isFalsyString(traceId))
178
+ traceId = uuid_util_class_1.UUIDUtil.generateV4();
177
179
  request.traceId = traceId;
178
180
  request.methodName = request.url.split('/').pop();
179
181
  request.transaction = transaction;
180
182
  response.setHeader(headers_constant_1.HEADERS.TRACE_ID, traceId);
181
183
  chunks = [];
182
- _m.label = 3;
184
+ _p.label = 3;
183
185
  case 3:
184
- _m.trys.push([3, 16, , 17]);
185
- _m.label = 4;
186
+ _p.trys.push([3, 16, , 17]);
187
+ _p.label = 4;
186
188
  case 4:
187
- _m.trys.push([4, 9, 10, 15]);
188
- _j = true, request_1 = __asyncValues(request);
189
- _m.label = 5;
189
+ _p.trys.push([4, 9, 10, 15]);
190
+ _l = true, request_1 = __asyncValues(request);
191
+ _p.label = 5;
190
192
  case 5: return [4, request_1.next()];
191
193
  case 6:
192
- if (!(request_1_1 = _m.sent(), _a = request_1_1.done, !_a)) return [3, 8];
194
+ if (!(request_1_1 = _p.sent(), _a = request_1_1.done, !_a)) return [3, 8];
193
195
  _c = request_1_1.value;
194
- _j = false;
196
+ _l = false;
195
197
  chunk = _c;
196
198
  chunks.push(chunk);
197
- _m.label = 7;
199
+ _p.label = 7;
198
200
  case 7:
199
- _j = true;
201
+ _l = true;
200
202
  return [3, 5];
201
203
  case 8: return [3, 15];
202
204
  case 9:
203
- e_1_1 = _m.sent();
205
+ e_1_1 = _p.sent();
204
206
  e_1 = { error: e_1_1 };
205
207
  return [3, 15];
206
208
  case 10:
207
- _m.trys.push([10, , 13, 14]);
208
- if (!(!_j && !_a && (_b = request_1.return))) return [3, 12];
209
+ _p.trys.push([10, , 13, 14]);
210
+ if (!(!_l && !_a && (_b = request_1.return))) return [3, 12];
209
211
  return [4, _b.call(request_1)];
210
212
  case 11:
211
- _m.sent();
212
- _m.label = 12;
213
+ _p.sent();
214
+ _p.label = 12;
213
215
  case 12: return [3, 14];
214
216
  case 13:
215
217
  if (e_1) throw e_1.error;
@@ -217,7 +219,7 @@ function HerbalGuard(options) {
217
219
  case 14: return [7];
218
220
  case 15: return [3, 17];
219
221
  case 16:
220
- _k = _m.sent();
222
+ _m = _p.sent();
221
223
  return [3, 17];
222
224
  case 17:
223
225
  parsedBody = _.attempt(function () { return Buffer.concat(chunks).toString('utf8'); });
@@ -228,13 +230,14 @@ function HerbalGuard(options) {
228
230
  request.rawBody = null;
229
231
  }
230
232
  _.attempt(function () { return _this.getLogger().log("[trace:".concat(request === null || request === void 0 ? void 0 : request.traceId, ":request:body] ").concat(request.rawBody)); });
231
- authAdapters = auth_adapter_decorator_1.AuthAdapters.getAdapters((_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, request.methodName);
232
- _m.label = 18;
233
+ handlerName = (_g = (_f = context === null || context === void 0 ? void 0 : context.getHandler) === null || _f === void 0 ? void 0 : _f.call(context)) === null || _g === void 0 ? void 0 : _g.name;
234
+ authAdapters = auth_adapter_decorator_1.AuthAdapters.getAdapters((_j = (_h = context === null || context === void 0 ? void 0 : context.getClass) === null || _h === void 0 ? void 0 : _h.call(context)) === null || _j === void 0 ? void 0 : _j.prototype, string_util_class_1.StringUtil.isFalsyString(handlerName) ? request.methodName : handlerName);
235
+ _p.label = 18;
233
236
  case 18:
234
- _m.trys.push([18, 24, , 29]);
237
+ _p.trys.push([18, 24, , 29]);
235
238
  if (!(Array.isArray(authAdapters) && authAdapters.length > 0)) return [3, 23];
236
239
  _i = 0, authAdapters_1 = authAdapters;
237
- _m.label = 19;
240
+ _p.label = 19;
238
241
  case 19:
239
242
  if (!(_i < authAdapters_1.length)) return [3, 22];
240
243
  AuthAdapterClass = authAdapters_1[_i];
@@ -243,7 +246,7 @@ function HerbalGuard(options) {
243
246
  return [3, 21];
244
247
  return [4, adapter.authenticate(transaction)];
245
248
  case 20:
246
- authenticateResult = _m.sent();
249
+ authenticateResult = _p.sent();
247
250
  if (!authenticateResult)
248
251
  return [3, 22];
249
252
  request.authenticateResult = __assign({ AuthenticatorClass: AuthAdapterClass }, authenticateResult);
@@ -254,17 +257,17 @@ function HerbalGuard(options) {
254
257
  case 22: throw new common_2.UnauthorizedException();
255
258
  case 23: return [3, 29];
256
259
  case 24:
257
- error_1 = _m.sent();
258
- _m.label = 25;
260
+ error_1 = _p.sent();
261
+ _p.label = 25;
259
262
  case 25:
260
- _m.trys.push([25, 27, , 28]);
263
+ _p.trys.push([25, 27, , 28]);
261
264
  this.getLogger().error("Got error when handling route: ".concat(error_1 === null || error_1 === void 0 ? void 0 : error_1.message, " ").concat(error_1 === null || error_1 === void 0 ? void 0 : error_1.stack));
262
- return [4, ((_h = transaction === null || transaction === void 0 ? void 0 : transaction.rollback) === null || _h === void 0 ? void 0 : _h.call(transaction))];
265
+ return [4, ((_k = transaction === null || transaction === void 0 ? void 0 : transaction.rollback) === null || _k === void 0 ? void 0 : _k.call(transaction))];
263
266
  case 26:
264
- _m.sent();
267
+ _p.sent();
265
268
  return [3, 28];
266
269
  case 27:
267
- _l = _m.sent();
270
+ _o = _p.sent();
268
271
  return [3, 28];
269
272
  case 28: throw error_1;
270
273
  case 29: return [2, true];
@@ -296,12 +299,13 @@ var ControllerUtil = (function () {
296
299
  ControllerUtil.create = function (createOptions) {
297
300
  function Controller(options) {
298
301
  return function (target) {
302
+ var _a;
299
303
  var finalPrefix = string_util_class_1.StringUtil.isFalsyString(options === null || options === void 0 ? void 0 : options.prefix)
300
304
  ? string_util_class_1.StringUtil.isFalsyString(createOptions === null || createOptions === void 0 ? void 0 : createOptions.prefix)
301
305
  ? ''
302
306
  : createOptions.prefix
303
307
  : options.prefix;
304
- finalPrefix += "/".concat(_.camelCase(target.name.replace(/Controller$/g, '')));
308
+ finalPrefix += "".concat(((_a = finalPrefix === null || finalPrefix === void 0 ? void 0 : finalPrefix.endsWith) === null || _a === void 0 ? void 0 : _a.call(finalPrefix, '/')) ? '' : '/').concat(_.camelCase(target.name.replace(/Controller$/g, '')));
305
309
  if (!finalPrefix.startsWith('/'))
306
310
  finalPrefix = "/".concat(finalPrefix);
307
311
  Reflect.defineMetadata(IS_CONTROLLER, true, target.prototype);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-norantec/herbal",
3
- "version": "1.0.2-alpha.6",
3
+ "version": "1.0.2-alpha.7",
4
4
  "description": "Herbal is a builder and toolchain for Nest.js applications",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {