@nestjs-kitchen/authz 2.0.2 → 2.0.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.
@@ -4,8 +4,6 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __getProtoOf = Object.getPrototypeOf;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
7
  var __export = (target, all) => {
10
8
  for (var name in all)
11
9
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -27,7 +25,15 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
25
  mod
28
26
  ));
29
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
28
+ var __decorateClass = (decorators, target, key, kind) => {
29
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
30
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
31
+ if (decorator = decorators[i])
32
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
33
+ if (kind && result) __defProp(target, key, result);
34
+ return result;
35
+ };
36
+ var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
31
37
  var session_authz_module_exports = {};
32
38
  __export(session_authz_module_exports, {
33
39
  cereateSessionAuthzModule: () => cereateSessionAuthzModule
@@ -45,83 +51,60 @@ var import_session_authz = require("./session-authz.guard");
45
51
  var import_session_authz2 = require("./session-authz.interface");
46
52
  var import_session_authz3 = require("./session-authz.service");
47
53
  var import_session_authz4 = require("./session-authz.strategy");
48
- function _ts_decorate(decorators, target, key, desc) {
49
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
50
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
51
- 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;
52
- return c > 3 && r && Object.defineProperty(target, key, r), r;
53
- }
54
- __name(_ts_decorate, "_ts_decorate");
55
- function _ts_metadata(k, v) {
56
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
57
- }
58
- __name(_ts_metadata, "_ts_metadata");
59
- function _ts_param(paramIndex, decorator) {
60
- return function(target, key) {
61
- decorator(target, key, paramIndex);
62
- };
63
- }
64
- __name(_ts_param, "_ts_param");
65
54
  const store = {
66
55
  globalInited: 0
67
56
  };
68
57
  const { ConfigurableModuleClass, MODULE_OPTIONS_TOKEN, ASYNC_OPTIONS_TYPE, OPTIONS_TYPE } = new import_common.ConfigurableModuleBuilder({
69
58
  moduleName: "SessionAuthModule"
70
- }).setFactoryMethodName("createSessionAuthzModuleOptions").setExtras({
71
- authzProvider: void 0,
72
- global: false
73
- }, (definition, extras) => {
74
- const { authzProvider, global } = extras;
75
- if (!authzProvider) {
76
- throw new import_errors.AuthzError(`InternalError: Missing parameter 'authzProvider' in configuration.`);
77
- }
78
- const routes = (0, import_utils.normalizedArray)(extras.routes) ?? [];
79
- const excludes = (0, import_utils.normalizedArray)(extras.excludes) ?? [];
80
- if (!global && !routes.length) {
81
- throw new import_errors.AuthzError(`InternalError: Missing parameter 'global' or 'routes' in configuration.`);
82
- }
83
- if (store.globalInited) {
84
- throw new import_errors.AuthzError(`InternalError: Cannot initialize mutiple global modules. Only one global module is allowed.`);
85
- }
86
- if (global) {
87
- store.globalInited += 1;
88
- }
89
- return (0, import_utils.mergeDynamicModuleConfigs)(definition, {
90
- global,
91
- providers: [
92
- {
93
- provide: import_constants.ROUTES_OPTIONS,
94
- useValue: {
95
- global,
96
- excludes,
97
- routes
59
+ }).setFactoryMethodName("createSessionAuthzModuleOptions").setExtras(
60
+ {
61
+ authzProvider: void 0,
62
+ global: false
63
+ },
64
+ (definition, extras) => {
65
+ const { authzProvider, global } = extras;
66
+ if (!authzProvider) {
67
+ throw new import_errors.AuthzError(`InternalError: Missing parameter 'authzProvider' in configuration.`);
68
+ }
69
+ const routes = (0, import_utils.normalizedArray)(extras.routes) ?? [];
70
+ const excludes = (0, import_utils.normalizedArray)(extras.excludes) ?? [];
71
+ if (!global && !routes.length) {
72
+ throw new import_errors.AuthzError(`InternalError: Missing parameter 'global' or 'routes' in configuration.`);
73
+ }
74
+ if (store.globalInited) {
75
+ throw new import_errors.AuthzError(
76
+ `InternalError: Cannot initialize mutiple global modules. Only one global module is allowed.`
77
+ );
78
+ }
79
+ if (global) {
80
+ store.globalInited += 1;
81
+ }
82
+ return (0, import_utils.mergeDynamicModuleConfigs)(definition, {
83
+ global,
84
+ providers: [
85
+ {
86
+ provide: import_constants.ROUTES_OPTIONS,
87
+ useValue: {
88
+ global,
89
+ excludes,
90
+ routes
91
+ }
98
92
  }
99
- }
100
- ],
101
- exports: []
102
- });
103
- }).build();
104
- const cereateSessionAuthzModule = /* @__PURE__ */ __name((authzProvider) => {
105
- var _a;
93
+ ],
94
+ exports: []
95
+ });
96
+ }
97
+ ).build();
98
+ const cereateSessionAuthzModule = (authzProvider) => {
106
99
  const id = `${import_constants.PREFIX}${(0, import_uid.uid)()}`;
107
100
  const SESSION_STRATEGY = `${id}_SESSION_STRATEGY`;
108
101
  const AUTHZ_PROVIDER = `${id}_AUTHZ_PROVIDER`;
109
102
  const ALS_PROVIDER = `${id}_ALS_PROVIDER`;
110
103
  const SESSION_AUTHZ_OPTIONS = `${id}_SESSION_AUTHZ_OPTIONS`;
111
104
  const SESSION_META_KEY = `${id}_SESSION_META_KEY`;
112
- const SessionAuthzStrategy = (0, import_session_authz4.createSessionAuthzStrategy)([
113
- SESSION_STRATEGY,
114
- AUTHZ_PROVIDER,
115
- ALS_PROVIDER
116
- ]);
117
- const SessionAuthzService = (0, import_session_authz3.createSessionAuthzService)([
118
- AUTHZ_PROVIDER,
119
- ALS_PROVIDER
120
- ]);
121
- const SessionAuthzAlsMiddleware = (0, import_session_authz_als.createSessionAuthzAlsMiddleware)([
122
- ALS_PROVIDER,
123
- SESSION_AUTHZ_OPTIONS
124
- ]);
105
+ const SessionAuthzStrategy = (0, import_session_authz4.createSessionAuthzStrategy)([SESSION_STRATEGY, AUTHZ_PROVIDER, ALS_PROVIDER]);
106
+ const SessionAuthzService = (0, import_session_authz3.createSessionAuthzService)([AUTHZ_PROVIDER, ALS_PROVIDER]);
107
+ const SessionAuthzAlsMiddleware = (0, import_session_authz_als.createSessionAuthzAlsMiddleware)([ALS_PROVIDER, SESSION_AUTHZ_OPTIONS]);
125
108
  const als = new import_node_async_hooks.AsyncLocalStorage();
126
109
  let isStrategyInited = false;
127
110
  const SessionAuthzGuard = (0, import_session_authz.createSessionAuthzGuard)([
@@ -132,21 +115,18 @@ const cereateSessionAuthzModule = /* @__PURE__ */ __name((authzProvider) => {
132
115
  SESSION_META_KEY
133
116
  ]);
134
117
  const Verify = (0, import_utils.createAuthzDecoratorFactory)(SESSION_META_KEY);
135
- const NoVerify = /* @__PURE__ */ __name(() => {
118
+ const NoVerify = () => {
136
119
  return (0, import_common.SetMetadata)(SESSION_META_KEY, {
137
- options: {
138
- public: true,
139
- override: true
140
- }
120
+ options: { public: true, override: true }
141
121
  });
142
- }, "NoVerify");
143
- const Apply = /* @__PURE__ */ __name((...rest) => {
122
+ };
123
+ const Apply = (...rest) => {
144
124
  return (0, import_common.applyDecorators)(SessionAuthzGuard.Verify(...rest), (0, import_common.UseGuards)(SessionAuthzGuard));
145
- }, "Apply");
125
+ };
146
126
  SessionAuthzGuard.Verify = Verify;
147
127
  SessionAuthzGuard.NoVerify = NoVerify;
148
128
  SessionAuthzGuard.Apply = Apply;
149
- const getCommonConfigs = /* @__PURE__ */ __name(() => {
129
+ const getCommonConfigs = () => {
150
130
  const configs = {
151
131
  providers: [
152
132
  {
@@ -157,39 +137,28 @@ const cereateSessionAuthzModule = /* @__PURE__ */ __name((authzProvider) => {
157
137
  provide: ALS_PROVIDER,
158
138
  useValue: als
159
139
  },
160
- ...!isStrategyInited ? [
161
- SessionAuthzStrategy
162
- ] : [],
140
+ ...!isStrategyInited ? [SessionAuthzStrategy] : [],
163
141
  SessionAuthzService
164
142
  ],
165
- exports: [
166
- AUTHZ_PROVIDER,
167
- ALS_PROVIDER,
168
- SESSION_AUTHZ_OPTIONS,
169
- SessionAuthzService
170
- ]
143
+ exports: [AUTHZ_PROVIDER, ALS_PROVIDER, SESSION_AUTHZ_OPTIONS, SessionAuthzService]
171
144
  };
172
145
  isStrategyInited = true;
173
146
  return configs;
174
- }, "getCommonConfigs");
175
- let SessionAuthzModule = (_a = class extends ConfigurableModuleClass {
147
+ };
148
+ let SessionAuthzModule = class extends ConfigurableModuleClass {
176
149
  constructor(routesOpt, sessionAuthzOptions) {
177
150
  super();
178
- __publicField(this, "routesOpt");
179
- __publicField(this, "sessionAuthzOptions");
180
- this.routesOpt = routesOpt, this.sessionAuthzOptions = sessionAuthzOptions;
151
+ this.routesOpt = routesOpt;
152
+ this.sessionAuthzOptions = sessionAuthzOptions;
181
153
  }
182
154
  /**
183
- * Configures authz module.
184
- *
185
- * Note: DO NOT register the same routes in multiple session authz modules, or import the same session authz module in the same module multiple times, express-session middleware will not work properly.
186
- */
155
+ * Configures authz module.
156
+ *
157
+ * Note: DO NOT register the same routes in multiple session authz modules, or import the same session authz module in the same module multiple times, express-session middleware will not work properly.
158
+ */
187
159
  static register(options) {
188
160
  const sessionAuthzOptions = (0, import_session_authz2.normalizedSessionAuthzModuleOptions)(options);
189
- return (0, import_utils.mergeDynamicModuleConfigs)(super.register({
190
- ...options,
191
- authzProvider
192
- }), getCommonConfigs(), {
161
+ return (0, import_utils.mergeDynamicModuleConfigs)(super.register({ ...options, authzProvider }), getCommonConfigs(), {
193
162
  providers: [
194
163
  {
195
164
  provide: SESSION_AUTHZ_OPTIONS,
@@ -199,100 +168,88 @@ const cereateSessionAuthzModule = /* @__PURE__ */ __name((authzProvider) => {
199
168
  });
200
169
  }
201
170
  /**
202
- * Configures authz module asynchronously.
203
- *
204
- * Note: DO NOT register the same routes in multiple session authz modules, express-session middleware will not work properly.
205
- */
171
+ * Configures authz module asynchronously.
172
+ *
173
+ * Note: DO NOT register the same routes in multiple session authz modules, express-session middleware will not work properly.
174
+ */
206
175
  static registerAsync(options) {
207
- return (0, import_utils.mergeDynamicModuleConfigs)(super.registerAsync({
208
- ...options,
209
- authzProvider
210
- }), getCommonConfigs(), {
176
+ return (0, import_utils.mergeDynamicModuleConfigs)(super.registerAsync({ ...options, authzProvider }), getCommonConfigs(), {
211
177
  providers: [
212
178
  {
213
179
  provide: SESSION_AUTHZ_OPTIONS,
214
- useFactory: /* @__PURE__ */ __name((moduleOptions) => {
180
+ useFactory: (moduleOptions) => {
215
181
  return (0, import_session_authz2.normalizedSessionAuthzModuleOptions)(moduleOptions);
216
- }, "useFactory"),
217
- inject: [
218
- MODULE_OPTIONS_TOKEN
219
- ]
182
+ },
183
+ inject: [MODULE_OPTIONS_TOKEN]
220
184
  }
221
185
  ]
222
186
  });
223
187
  }
224
188
  configure(consumer) {
225
- consumer.apply((0, import_express_session.default)(this.sessionAuthzOptions.session), SessionAuthzAlsMiddleware).exclude(...this.routesOpt.excludes).forRoutes(...this.routesOpt.global ? [
226
- "*"
227
- ] : this.routesOpt.routes);
189
+ consumer.apply((0, import_express_session.default)(this.sessionAuthzOptions.session), SessionAuthzAlsMiddleware).exclude(...this.routesOpt.excludes).forRoutes(...this.routesOpt.global ? ["*"] : this.routesOpt.routes);
228
190
  }
229
- }, __name(_a, "SessionAuthzModule"), _a);
230
- SessionAuthzModule = _ts_decorate([
191
+ };
192
+ SessionAuthzModule = __decorateClass([
231
193
  (0, import_common.Module)({}),
232
- _ts_param(0, (0, import_common.Inject)(import_constants.ROUTES_OPTIONS)),
233
- _ts_param(1, (0, import_common.Inject)(SESSION_AUTHZ_OPTIONS)),
234
- _ts_metadata("design:type", Function),
235
- _ts_metadata("design:paramtypes", [
236
- typeof RoutesOptions === "undefined" ? Object : RoutesOptions,
237
- typeof SessionAuthzOptions === "undefined" ? Object : SessionAuthzOptions
238
- ])
194
+ __decorateParam(0, (0, import_common.Inject)(import_constants.ROUTES_OPTIONS)),
195
+ __decorateParam(1, (0, import_common.Inject)(SESSION_AUTHZ_OPTIONS))
239
196
  ], SessionAuthzModule);
240
197
  return {
241
198
  /**
242
- * A dynamic module used to configure session based authentication and authorization features for the application.
243
- *
244
- * This module can be configured using 2 static methods:
245
- *
246
- * - `register`
247
- * - `registerAsync`
248
- *
249
- * ### Usage
250
- *
251
- * ```typescript
252
- * ⁣@Module({
253
- * imports: [
254
- * // Import and configure session strategy
255
- * AuthzModule.register({
256
- * session: {
257
- * name: 'custom-session-id-name',
258
- * secret: '1234567890'
259
- * },
260
- * // Define routes that use AuthzGuard
261
- * routes: [BusinessController]
262
- * })
263
- * ],
264
- * controllers: [BusinessController]
265
- * })
266
- * export class BusinessModule {}
267
- * ```
268
- */
199
+ * A dynamic module used to configure session based authentication and authorization features for the application.
200
+ *
201
+ * This module can be configured using 2 static methods:
202
+ *
203
+ * - `register`
204
+ * - `registerAsync`
205
+ *
206
+ * ### Usage
207
+ *
208
+ * ```typescript
209
+ * ⁣@Module({
210
+ * imports: [
211
+ * // Import and configure session strategy
212
+ * AuthzModule.register({
213
+ * session: {
214
+ * name: 'custom-session-id-name',
215
+ * secret: '1234567890'
216
+ * },
217
+ * // Define routes that use AuthzGuard
218
+ * routes: [BusinessController]
219
+ * })
220
+ * ],
221
+ * controllers: [BusinessController]
222
+ * })
223
+ * export class BusinessModule {}
224
+ * ```
225
+ */
269
226
  AuthzModule: SessionAuthzModule,
270
227
  /**
271
- * A custom guard that applies authentication to controllers.
272
- *
273
- * This guard also provides 3 utility decorators to apply and modify authorization:
274
- *
275
- * - `@AuthzGuard.Verify`: Used to verify the user's authorization for specific meta data.
276
- * - `@AuthzGuard.NoVerify`: Used to `skip` authentication & authorization checks for specific routes.
277
- * - `@AuthzGuard.Apply`: A simplified version of `@UseGuards(AuthzGuard)` and `@AuthzGuard.Verify`, combining both for convenience.
278
- *
279
- * ### Usage:
280
- *
281
- * ```typescript
282
- * ⁣@UseGuards(AuthzGuard)
283
- * ⁣@Controller(/⁣/ ...)
284
- * export class BusinessController {
285
- * // ...
286
- * }
287
- * ```
288
- */
228
+ * A custom guard that applies authentication to controllers.
229
+ *
230
+ * This guard also provides 3 utility decorators to apply and modify authorization:
231
+ *
232
+ * - `@AuthzGuard.Verify`: Used to verify the user's authorization for specific meta data.
233
+ * - `@AuthzGuard.NoVerify`: Used to `skip` authentication & authorization checks for specific routes.
234
+ * - `@AuthzGuard.Apply`: A simplified version of `@UseGuards(AuthzGuard)` and `@AuthzGuard.Verify`, combining both for convenience.
235
+ *
236
+ * ### Usage:
237
+ *
238
+ * ```typescript
239
+ * ⁣@UseGuards(AuthzGuard)
240
+ * ⁣@Controller(/⁣/ ...)
241
+ * export class BusinessController {
242
+ * // ...
243
+ * }
244
+ * ```
245
+ */
289
246
  AuthzGuard: SessionAuthzGuard,
290
247
  /**
291
- * A custom servcie to provide methods to handle authentication and authorization.
292
- */
248
+ * A custom servcie to provide methods to handle authentication and authorization.
249
+ */
293
250
  AuthzService: SessionAuthzService
294
251
  };
295
- }, "cereateSessionAuthzModule");
252
+ };
296
253
  // Annotate the CommonJS export names for ESM import in node:
297
254
  0 && (module.exports = {
298
255
  cereateSessionAuthzModule
@@ -2,8 +2,6 @@ var __defProp = Object.defineProperty;
2
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
5
  var __export = (target, all) => {
8
6
  for (var name in all)
9
7
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -17,90 +15,73 @@ var __copyProps = (to, from, except, desc) => {
17
15
  return to;
18
16
  };
19
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
18
+ var __decorateClass = (decorators, target, key, kind) => {
19
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
20
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
21
+ if (decorator = decorators[i])
22
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
23
+ if (kind && result) __defProp(target, key, result);
24
+ return result;
25
+ };
26
+ var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
21
27
  var session_authz_service_exports = {};
22
28
  __export(session_authz_service_exports, {
23
29
  createSessionAuthzService: () => createSessionAuthzService
24
30
  });
25
31
  module.exports = __toCommonJS(session_authz_service_exports);
26
- var import_node_async_hooks = require("node:async_hooks");
27
32
  var import_common = require("@nestjs/common");
28
- var import_authz = require("../authz.provider");
29
33
  var import_errors = require("../errors");
30
34
  var import_utils = require("../utils");
31
- function _ts_decorate(decorators, target, key, desc) {
32
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
33
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
34
- 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;
35
- return c > 3 && r && Object.defineProperty(target, key, r), r;
36
- }
37
- __name(_ts_decorate, "_ts_decorate");
38
- function _ts_metadata(k, v) {
39
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
40
- }
41
- __name(_ts_metadata, "_ts_metadata");
42
- function _ts_param(paramIndex, decorator) {
43
- return function(target, key) {
44
- decorator(target, key, paramIndex);
45
- };
46
- }
47
- __name(_ts_param, "_ts_param");
48
- const createSessionAuthzService = /* @__PURE__ */ __name(([AUTHZ_PROVIDER, ALS_PROVIDER]) => {
49
- var _a;
50
- let SessionAuthzService = (_a = class {
35
+ const createSessionAuthzService = ([AUTHZ_PROVIDER, ALS_PROVIDER]) => {
36
+ let SessionAuthzService = class {
51
37
  constructor(authzProvider, als) {
52
- __publicField(this, "authzProvider");
53
- __publicField(this, "als");
54
38
  this.authzProvider = authzProvider;
55
39
  this.als = als;
56
40
  if (typeof this.authzProvider.createPayload !== "function") {
57
- throw new import_errors.AuthzError(`InternalError: Method 'createPayload' from abstract class 'AuthzProvider' must be implemented.`);
41
+ throw new import_errors.AuthzError(
42
+ `InternalError: Method 'createPayload' from abstract class 'AuthzProvider' must be implemented.`
43
+ );
58
44
  }
59
45
  }
60
46
  /**
61
- * Creates a session id with a payload generated by AuthzProviderClass.createPayload().
62
- *
63
- * @param user - User entity
64
- */
47
+ * Creates a session id with a payload generated by AuthzProviderClass.createPayload().
48
+ *
49
+ * @param user - User entity
50
+ */
65
51
  async logIn(user) {
66
52
  const store = (0, import_utils.getAlsStore)(this.als);
67
53
  const payload = await this.authzProvider.createPayload(user);
68
54
  return store.logIn(payload);
69
55
  }
70
56
  /**
71
- * Clears current user session.
72
- */
57
+ * Clears current user session.
58
+ */
73
59
  async logOut() {
74
60
  const store = (0, import_utils.getAlsStore)(this.als);
75
61
  return store.logOut();
76
62
  }
77
63
  /**
78
- * Sets a secure HTTP cookie with the given name, value, and optional cookie options.
79
- */
64
+ * Sets a secure HTTP cookie with the given name, value, and optional cookie options.
65
+ */
80
66
  setCookie(...rest) {
81
67
  const store = (0, import_utils.getAlsStore)(this.als);
82
68
  store.setCookie(...rest);
83
69
  }
84
70
  /**
85
- * Retrieves the current user associated with the request, if available.
86
- */
71
+ * Retrieves the current user associated with the request, if available.
72
+ */
87
73
  getUser() {
88
74
  const store = (0, import_utils.getAlsStore)(this.als);
89
75
  const user = store.user;
90
76
  return user;
91
77
  }
92
- }, __name(_a, "SessionAuthzService"), _a);
93
- SessionAuthzService = _ts_decorate([
94
- _ts_param(0, (0, import_common.Inject)(AUTHZ_PROVIDER)),
95
- _ts_param(1, (0, import_common.Inject)(ALS_PROVIDER)),
96
- _ts_metadata("design:type", Function),
97
- _ts_metadata("design:paramtypes", [
98
- typeof import_authz.AuthzProviderClass === "undefined" ? Object : import_authz.AuthzProviderClass,
99
- typeof import_node_async_hooks.AsyncLocalStorage === "undefined" ? Object : import_node_async_hooks.AsyncLocalStorage
100
- ])
78
+ };
79
+ SessionAuthzService = __decorateClass([
80
+ __decorateParam(0, (0, import_common.Inject)(AUTHZ_PROVIDER)),
81
+ __decorateParam(1, (0, import_common.Inject)(ALS_PROVIDER))
101
82
  ], SessionAuthzService);
102
83
  return (0, import_common.mixin)(SessionAuthzService);
103
- }, "createSessionAuthzService");
84
+ };
104
85
  // Annotate the CommonJS export names for ESM import in node:
105
86
  0 && (module.exports = {
106
87
  createSessionAuthzService
@@ -2,8 +2,6 @@ var __defProp = Object.defineProperty;
2
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
5
  var __export = (target, all) => {
8
6
  for (var name in all)
9
7
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -17,47 +15,36 @@ var __copyProps = (to, from, except, desc) => {
17
15
  return to;
18
16
  };
19
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
18
+ var __decorateClass = (decorators, target, key, kind) => {
19
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
20
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
21
+ if (decorator = decorators[i])
22
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
23
+ if (kind && result) __defProp(target, key, result);
24
+ return result;
25
+ };
26
+ var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
21
27
  var session_authz_strategy_exports = {};
22
28
  __export(session_authz_strategy_exports, {
23
29
  createSessionAuthzStrategy: () => createSessionAuthzStrategy
24
30
  });
25
31
  module.exports = __toCommonJS(session_authz_strategy_exports);
26
- var import_node_async_hooks = require("node:async_hooks");
27
32
  var import_common = require("@nestjs/common");
28
33
  var import_passport = require("@nestjs/passport");
29
34
  var import_passport_custom = require("passport-custom");
30
- var import_authz = require("../authz.provider");
31
35
  var import_constants = require("../constants");
32
36
  var import_errors = require("../errors");
33
37
  var import_utils = require("../utils");
34
- function _ts_decorate(decorators, target, key, desc) {
35
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
36
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
37
- 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;
38
- return c > 3 && r && Object.defineProperty(target, key, r), r;
39
- }
40
- __name(_ts_decorate, "_ts_decorate");
41
- function _ts_metadata(k, v) {
42
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
43
- }
44
- __name(_ts_metadata, "_ts_metadata");
45
- function _ts_param(paramIndex, decorator) {
46
- return function(target, key) {
47
- decorator(target, key, paramIndex);
48
- };
49
- }
50
- __name(_ts_param, "_ts_param");
51
- const createSessionAuthzStrategy = /* @__PURE__ */ __name(([SESSION_STRATEGY, AUTHZ_PROVIDER, ALS_PROVIDER]) => {
52
- var _a;
53
- let SessionAuthzStrategy = (_a = class extends (0, import_passport.PassportStrategy)(import_passport_custom.Strategy, SESSION_STRATEGY) {
38
+ const createSessionAuthzStrategy = ([SESSION_STRATEGY, AUTHZ_PROVIDER, ALS_PROVIDER]) => {
39
+ let SessionAuthzStrategy = class extends (0, import_passport.PassportStrategy)(import_passport_custom.Strategy, SESSION_STRATEGY) {
54
40
  constructor(authzProvider, als) {
55
41
  super();
56
- __publicField(this, "authzProvider");
57
- __publicField(this, "als");
58
- this.authzProvider = authzProvider, this.als = als;
42
+ this.authzProvider = authzProvider;
43
+ this.als = als;
59
44
  if (typeof this.authzProvider.authenticate !== "function") {
60
- throw new import_errors.AuthzError(`InternalError: Method 'authenticate' from abstract class 'AuthzProvider' must be implemented.`);
45
+ throw new import_errors.AuthzError(
46
+ `InternalError: Method 'authenticate' from abstract class 'AuthzProvider' must be implemented.`
47
+ );
61
48
  }
62
49
  }
63
50
  async validate(req) {
@@ -66,10 +53,7 @@ const createSessionAuthzStrategy = /* @__PURE__ */ __name(([SESSION_STRATEGY, AU
66
53
  req[import_constants.PASSPORT_PROPERTY] = authOptions.passportProperty;
67
54
  const payload = req?.session?.[import_constants.SESSION_PASSPORT_KEY]?.user;
68
55
  if (!payload) {
69
- return [
70
- null,
71
- new import_errors.AuthzAnonymousError("AnonymousError: Cannnot find session.")
72
- ];
56
+ return [null, new import_errors.AuthzAnonymousError("AnonymousError: Cannnot find session.")];
73
57
  }
74
58
  let user = void 0;
75
59
  try {
@@ -82,25 +66,17 @@ const createSessionAuthzStrategy = /* @__PURE__ */ __name(([SESSION_STRATEGY, AU
82
66
  }
83
67
  store.user = user;
84
68
  if (!user) {
85
- return [
86
- null,
87
- new import_errors.AuthzAnonymousError("AnonymousError: Cannnot find user.")
88
- ];
69
+ return [null, new import_errors.AuthzAnonymousError("AnonymousError: Cannnot find user.")];
89
70
  }
90
71
  return user;
91
72
  }
92
- }, __name(_a, "SessionAuthzStrategy"), _a);
93
- SessionAuthzStrategy = _ts_decorate([
94
- _ts_param(0, (0, import_common.Inject)(AUTHZ_PROVIDER)),
95
- _ts_param(1, (0, import_common.Inject)(ALS_PROVIDER)),
96
- _ts_metadata("design:type", Function),
97
- _ts_metadata("design:paramtypes", [
98
- typeof import_authz.AuthzProviderClass === "undefined" ? Object : import_authz.AuthzProviderClass,
99
- typeof import_node_async_hooks.AsyncLocalStorage === "undefined" ? Object : import_node_async_hooks.AsyncLocalStorage
100
- ])
73
+ };
74
+ SessionAuthzStrategy = __decorateClass([
75
+ __decorateParam(0, (0, import_common.Inject)(AUTHZ_PROVIDER)),
76
+ __decorateParam(1, (0, import_common.Inject)(ALS_PROVIDER))
101
77
  ], SessionAuthzStrategy);
102
78
  return (0, import_common.mixin)(SessionAuthzStrategy);
103
- }, "createSessionAuthzStrategy");
79
+ };
104
80
  // Annotate the CommonJS export names for ESM import in node:
105
81
  0 && (module.exports = {
106
82
  createSessionAuthzStrategy
@@ -2,7 +2,6 @@ var __defProp = Object.defineProperty;
2
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
5
  var __export = (target, all) => {
7
6
  for (var name in all)
8
7
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -24,10 +23,10 @@ __export(user_decorator_exports, {
24
23
  module.exports = __toCommonJS(user_decorator_exports);
25
24
  var import_common = require("@nestjs/common");
26
25
  var import_utils = require("./utils");
27
- const userDecoratorFactory = /* @__PURE__ */ __name((_data, ctx) => {
26
+ const userDecoratorFactory = (_data, ctx) => {
28
27
  const request = ctx.switchToHttp().getRequest();
29
28
  return (0, import_utils.getPassportProperty)(request);
30
- }, "userDecoratorFactory");
29
+ };
31
30
  const User = (0, import_common.createParamDecorator)(userDecoratorFactory);
32
31
  // Annotate the CommonJS export names for ESM import in node:
33
32
  0 && (module.exports = {