@open-norantec/herbal 1.0.1-alpha.1 → 1.0.1-alpha.3

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.
@@ -37,7 +37,7 @@ command.action(async () => {
37
37
  await new Promise((resolve) => {
38
38
  const childProcess = spawn(
39
39
  'npx',
40
- ['patch-package', `--patch-dir=${path.relative(process.cwd(), path.resolve(__dirname, '../patches'))}`],
40
+ ['patch-package', `--patch-dir=${path.relative(cwd, path.resolve(__dirname, '../patches'))}`],
41
41
  {
42
42
  stdio: 'inherit',
43
43
  cwd,
@@ -148,14 +148,21 @@ function HerbalGuard(options) {
148
148
  this.ref = ref;
149
149
  }
150
150
  HerbalGuardMixin.prototype.canActivate = function (context) {
151
- var _a, _b, _c, _d, _e, _f, _g, _h;
151
+ var _a, _b, _c, _d, _e;
152
152
  return __awaiter(this, void 0, void 0, function () {
153
- var transaction, request, response, traceId, authAdapters, _i, authAdapters_1, AuthAdapterClass, adapter, authenticateResult, error_1, _j;
154
- return __generator(this, function (_k) {
155
- switch (_k.label) {
156
- case 0: return [4, ((_e = (_d = (_c = (_b = (_a = this.ref) === null || _a === void 0 ? void 0 : _a.get) === null || _b === void 0 ? void 0 : _b.call(_a, sequelize_typescript_1.Sequelize, { strict: false })) === null || _c === void 0 ? void 0 : _c.transaction) === null || _d === void 0 ? void 0 : _d.call(_c)) === null || _e === void 0 ? void 0 : _e.catch(function () { return Promise.resolve(undefined); }))];
153
+ var sequelizeInstance, transaction, request, response, traceId, authAdapters, _i, authAdapters_1, AuthAdapterClass, adapter, authenticateResult, error_1, _f;
154
+ var _this = this;
155
+ return __generator(this, function (_g) {
156
+ switch (_g.label) {
157
+ case 0:
158
+ sequelizeInstance = _.attempt(function () { return _this.ref.get(sequelize_typescript_1.Sequelize, { strict: false }); });
159
+ transaction = undefined;
160
+ if (!!(sequelizeInstance instanceof Error)) return [3, 2];
161
+ return [4, ((_b = (_a = sequelizeInstance === null || sequelizeInstance === void 0 ? void 0 : sequelizeInstance.transaction) === null || _a === void 0 ? void 0 : _a.call(sequelizeInstance)) === null || _b === void 0 ? void 0 : _b.catch(function () { return Promise.resolve(undefined); }))];
157
162
  case 1:
158
- transaction = _k.sent();
163
+ transaction = _g.sent();
164
+ _g.label = 2;
165
+ case 2:
159
166
  request = context.switchToHttp().getRequest();
160
167
  response = context.switchToHttp().getResponse();
161
168
  traceId = typeof (options === null || options === void 0 ? void 0 : options.getTraceId) === 'function' ? _.attempt(function () { return options.getTraceId(request); }) : (0, uuid_1.v4)();
@@ -165,45 +172,45 @@ function HerbalGuard(options) {
165
172
  request.methodName = request.url.split('/').pop();
166
173
  request.transaction = transaction;
167
174
  response.setHeader(headers_constant_1.HEADERS.TRACE_ID, traceId);
168
- 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);
169
- _k.label = 2;
170
- case 2:
171
- _k.trys.push([2, 8, , 13]);
172
- if (!(Array.isArray(authAdapters) && authAdapters.length > 0)) return [3, 7];
173
- _i = 0, authAdapters_1 = authAdapters;
174
- _k.label = 3;
175
+ authAdapters = auth_adapter_decorator_1.AuthAdapters.getAdapters((_d = (_c = context === null || context === void 0 ? void 0 : context.getClass) === null || _c === void 0 ? void 0 : _c.call(context)) === null || _d === void 0 ? void 0 : _d.prototype, request.methodName);
176
+ _g.label = 3;
175
177
  case 3:
176
- if (!(_i < authAdapters_1.length)) return [3, 6];
178
+ _g.trys.push([3, 9, , 14]);
179
+ if (!(Array.isArray(authAdapters) && authAdapters.length > 0)) return [3, 8];
180
+ _i = 0, authAdapters_1 = authAdapters;
181
+ _g.label = 4;
182
+ case 4:
183
+ if (!(_i < authAdapters_1.length)) return [3, 7];
177
184
  AuthAdapterClass = authAdapters_1[_i];
178
185
  adapter = new AuthAdapterClass(request, this.ref);
179
186
  if (!adapter.match())
180
- return [3, 5];
187
+ return [3, 6];
181
188
  return [4, adapter.authenticate(transaction)];
182
- case 4:
183
- authenticateResult = _k.sent();
189
+ case 5:
190
+ authenticateResult = _g.sent();
184
191
  if (!authenticateResult)
185
- return [3, 6];
192
+ return [3, 7];
186
193
  request.authenticateResult = __assign({ AuthenticatorClass: AuthAdapterClass }, authenticateResult);
187
194
  return [2, true];
188
- case 5:
195
+ case 6:
189
196
  _i++;
190
- return [3, 3];
191
- case 6: throw new common_2.UnauthorizedException();
192
- case 7: return [3, 13];
193
- case 8:
194
- error_1 = _k.sent();
195
- _k.label = 9;
197
+ return [3, 4];
198
+ case 7: throw new common_2.UnauthorizedException();
199
+ case 8: return [3, 14];
196
200
  case 9:
197
- _k.trys.push([9, 11, , 12]);
198
- return [4, ((_h = transaction === null || transaction === void 0 ? void 0 : transaction.rollback) === null || _h === void 0 ? void 0 : _h.call(transaction))];
201
+ error_1 = _g.sent();
202
+ _g.label = 10;
199
203
  case 10:
200
- _k.sent();
201
- return [3, 12];
204
+ _g.trys.push([10, 12, , 13]);
205
+ return [4, ((_e = transaction === null || transaction === void 0 ? void 0 : transaction.rollback) === null || _e === void 0 ? void 0 : _e.call(transaction))];
202
206
  case 11:
203
- _j = _k.sent();
204
- return [3, 12];
205
- case 12: throw error_1;
206
- case 13: return [2, true];
207
+ _g.sent();
208
+ return [3, 13];
209
+ case 12:
210
+ _f = _g.sent();
211
+ return [3, 13];
212
+ case 13: throw error_1;
213
+ case 14: return [2, true];
207
214
  }
208
215
  });
209
216
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-norantec/herbal",
3
- "version": "1.0.1-alpha.1",
3
+ "version": "1.0.1-alpha.3",
4
4
  "description": "Herbal is a builder and toolchain for Nest.js applications",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {