@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.
@@ -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,7 +15,15 @@ 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 jwt_authz_module_exports = {};
22
28
  __export(jwt_authz_module_exports, {
23
29
  createJwtAuthzModule: () => createJwtAuthzModule
@@ -34,64 +40,51 @@ var import_jwt_authz = require("./jwt-authz.guard");
34
40
  var import_jwt_authz2 = require("./jwt-authz.interface");
35
41
  var import_jwt_authz3 = require("./jwt-authz.service");
36
42
  var import_jwt_authz4 = require("./jwt-authz.strategy");
37
- function _ts_decorate(decorators, target, key, desc) {
38
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
39
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
40
- 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;
41
- return c > 3 && r && Object.defineProperty(target, key, r), r;
42
- }
43
- __name(_ts_decorate, "_ts_decorate");
44
- function _ts_metadata(k, v) {
45
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
46
- }
47
- __name(_ts_metadata, "_ts_metadata");
48
- function _ts_param(paramIndex, decorator) {
49
- return function(target, key) {
50
- decorator(target, key, paramIndex);
51
- };
52
- }
53
- __name(_ts_param, "_ts_param");
54
43
  const store = {
55
44
  globalInited: 0
56
45
  };
57
46
  const { ConfigurableModuleClass, MODULE_OPTIONS_TOKEN, ASYNC_OPTIONS_TYPE, OPTIONS_TYPE } = new import_common.ConfigurableModuleBuilder({
58
47
  moduleName: "JwtAuthModule"
59
- }).setFactoryMethodName("createJwtAuthzModuleOptions").setExtras({
60
- authzProvider: void 0,
61
- global: false
62
- }, (definition, extras) => {
63
- const { authzProvider, global } = extras;
64
- if (!authzProvider) {
65
- throw new import_errors.AuthzError(`InternalError: Missing parameter 'authzProvider' in configuration.`);
66
- }
67
- const routes = (0, import_utils.normalizedArray)(extras.routes) ?? [];
68
- const excludes = (0, import_utils.normalizedArray)(extras.excludes) ?? [];
69
- if (!global && !routes.length) {
70
- throw new import_errors.AuthzError(`InternalError: Missing parameter 'global' or 'routes' in configuration.`);
71
- }
72
- if (store.globalInited) {
73
- throw new import_errors.AuthzError(`InternalError: Cannot initialize mutiple global modules. Only one global module is allowed.`);
74
- }
75
- if (global) {
76
- store.globalInited += 1;
77
- }
78
- return (0, import_utils.mergeDynamicModuleConfigs)(definition, {
79
- global,
80
- providers: [
81
- {
82
- provide: import_constants.ROUTES_OPTIONS,
83
- useValue: {
84
- global,
85
- excludes,
86
- routes
48
+ }).setFactoryMethodName("createJwtAuthzModuleOptions").setExtras(
49
+ {
50
+ authzProvider: void 0,
51
+ global: false
52
+ },
53
+ (definition, extras) => {
54
+ const { authzProvider, global } = extras;
55
+ if (!authzProvider) {
56
+ throw new import_errors.AuthzError(`InternalError: Missing parameter 'authzProvider' in configuration.`);
57
+ }
58
+ const routes = (0, import_utils.normalizedArray)(extras.routes) ?? [];
59
+ const excludes = (0, import_utils.normalizedArray)(extras.excludes) ?? [];
60
+ if (!global && !routes.length) {
61
+ throw new import_errors.AuthzError(`InternalError: Missing parameter 'global' or 'routes' in configuration.`);
62
+ }
63
+ if (store.globalInited) {
64
+ throw new import_errors.AuthzError(
65
+ `InternalError: Cannot initialize mutiple global modules. Only one global module is allowed.`
66
+ );
67
+ }
68
+ if (global) {
69
+ store.globalInited += 1;
70
+ }
71
+ return (0, import_utils.mergeDynamicModuleConfigs)(definition, {
72
+ global,
73
+ providers: [
74
+ {
75
+ provide: import_constants.ROUTES_OPTIONS,
76
+ useValue: {
77
+ global,
78
+ excludes,
79
+ routes
80
+ }
87
81
  }
88
- }
89
- ],
90
- exports: []
91
- });
92
- }).build();
93
- const createJwtAuthzModule = /* @__PURE__ */ __name((authzProvider) => {
94
- var _a;
82
+ ],
83
+ exports: []
84
+ });
85
+ }
86
+ ).build();
87
+ const createJwtAuthzModule = (authzProvider) => {
95
88
  const id = `${import_constants.PREFIX}${(0, import_uid.uid)()}`;
96
89
  const JWT_STRATEGY = `${id}_JWT_STRATEGY`;
97
90
  const JWT_REFRESH_STRATEGY = `${id}_REFRESH_STRATEGY`;
@@ -100,31 +93,13 @@ const createJwtAuthzModule = /* @__PURE__ */ __name((authzProvider) => {
100
93
  const JWT_AUTHZ_OPTIONS = `${id}_JWT_AUTHZ_OPTIONS`;
101
94
  const JWT_META_KEY = `${id}_JWT_META_KEY`;
102
95
  const JWT_REFRESH_META_KEY = `${id}_REFRESH_META_KEY`;
103
- const JwtAuthzService = (0, import_jwt_authz3.createJwtAuthzService)([
104
- AUTHZ_PROVIDER,
105
- JWT_AUTHZ_OPTIONS,
106
- ALS_PROVIDER
107
- ]);
108
- const JwtAuthzAlsMiddleware = (0, import_jwt_authz_als.createJwtAuthzAlsMiddleware)([
109
- ALS_PROVIDER,
110
- JWT_AUTHZ_OPTIONS
111
- ]);
96
+ const JwtAuthzService = (0, import_jwt_authz3.createJwtAuthzService)([AUTHZ_PROVIDER, JWT_AUTHZ_OPTIONS, ALS_PROVIDER]);
97
+ const JwtAuthzAlsMiddleware = (0, import_jwt_authz_als.createJwtAuthzAlsMiddleware)([ALS_PROVIDER, JWT_AUTHZ_OPTIONS]);
112
98
  const als = new import_node_async_hooks.AsyncLocalStorage();
113
- const JwtStrategy = (0, import_jwt_authz4.createJwtStrategy)([
114
- JWT_STRATEGY,
115
- AUTHZ_PROVIDER,
116
- ALS_PROVIDER
117
- ]);
118
- const RefreshStrategy = (0, import_jwt_authz4.createRefreshStrategy)([
119
- JWT_REFRESH_STRATEGY,
120
- AUTHZ_PROVIDER,
121
- ALS_PROVIDER
122
- ]);
99
+ const JwtStrategy = (0, import_jwt_authz4.createJwtStrategy)([JWT_STRATEGY, AUTHZ_PROVIDER, ALS_PROVIDER]);
100
+ const RefreshStrategy = (0, import_jwt_authz4.createRefreshStrategy)([JWT_REFRESH_STRATEGY, AUTHZ_PROVIDER, ALS_PROVIDER]);
123
101
  let isStrategyInited = false;
124
- const RefreshAuthzGuard = (0, import_jwt_authz.createJwtRefreshAuthzGuard)([
125
- JWT_REFRESH_STRATEGY,
126
- JWT_AUTHZ_OPTIONS
127
- ]);
102
+ const RefreshAuthzGuard = (0, import_jwt_authz.createJwtRefreshAuthzGuard)([JWT_REFRESH_STRATEGY, JWT_AUTHZ_OPTIONS]);
128
103
  const JwtAuthzGuard = (0, import_jwt_authz.createJwtAuthzGuard)([
129
104
  JWT_STRATEGY,
130
105
  AUTHZ_PROVIDER,
@@ -134,25 +109,26 @@ const createJwtAuthzModule = /* @__PURE__ */ __name((authzProvider) => {
134
109
  JWT_REFRESH_META_KEY
135
110
  ]);
136
111
  const Verify = (0, import_utils.createAuthzDecoratorFactory)(JWT_META_KEY);
137
- const NoVerify = /* @__PURE__ */ __name(() => {
112
+ const NoVerify = () => {
138
113
  return (0, import_common.SetMetadata)(JWT_META_KEY, {
139
- options: {
140
- public: true,
141
- override: true
142
- }
114
+ options: { public: true, override: true }
143
115
  });
144
- }, "NoVerify");
145
- const Refresh = /* @__PURE__ */ __name(() => {
146
- return (0, import_common.applyDecorators)(JwtAuthzGuard.NoVerify(), (0, import_common.SetMetadata)(JWT_REFRESH_META_KEY, true), (0, import_common.UseGuards)(RefreshAuthzGuard));
147
- }, "Refresh");
148
- const Apply = /* @__PURE__ */ __name((...rest) => {
116
+ };
117
+ const Refresh = () => {
118
+ return (0, import_common.applyDecorators)(
119
+ JwtAuthzGuard.NoVerify(),
120
+ (0, import_common.SetMetadata)(JWT_REFRESH_META_KEY, true),
121
+ (0, import_common.UseGuards)(RefreshAuthzGuard)
122
+ );
123
+ };
124
+ const Apply = (...rest) => {
149
125
  return (0, import_common.applyDecorators)(JwtAuthzGuard.Verify(...rest), (0, import_common.UseGuards)(JwtAuthzGuard));
150
- }, "Apply");
126
+ };
151
127
  JwtAuthzGuard.Verify = Verify;
152
128
  JwtAuthzGuard.NoVerify = NoVerify;
153
129
  JwtAuthzGuard.Refresh = Refresh;
154
130
  JwtAuthzGuard.Apply = Apply;
155
- const getCommonConfigs = /* @__PURE__ */ __name(() => {
131
+ const getCommonConfigs = () => {
156
132
  const configs = {
157
133
  providers: [
158
134
  {
@@ -163,37 +139,25 @@ const createJwtAuthzModule = /* @__PURE__ */ __name((authzProvider) => {
163
139
  provide: ALS_PROVIDER,
164
140
  useValue: als
165
141
  },
166
- ...!isStrategyInited ? [
167
- JwtStrategy,
168
- RefreshStrategy
169
- ] : [],
142
+ ...!isStrategyInited ? [JwtStrategy, RefreshStrategy] : [],
170
143
  JwtAuthzService
171
144
  ],
172
- exports: [
173
- AUTHZ_PROVIDER,
174
- ALS_PROVIDER,
175
- JWT_AUTHZ_OPTIONS,
176
- JwtAuthzService
177
- ]
145
+ exports: [AUTHZ_PROVIDER, ALS_PROVIDER, JWT_AUTHZ_OPTIONS, JwtAuthzService]
178
146
  };
179
147
  isStrategyInited = true;
180
148
  return configs;
181
- }, "getCommonConfigs");
182
- let JwtAuthzModule = (_a = class extends ConfigurableModuleClass {
149
+ };
150
+ let JwtAuthzModule = class extends ConfigurableModuleClass {
183
151
  constructor(routesOpt) {
184
152
  super();
185
- __publicField(this, "routesOpt");
186
153
  this.routesOpt = routesOpt;
187
154
  }
188
155
  /**
189
- * Configures authz module.
190
- */
156
+ * Configures authz module.
157
+ */
191
158
  static register(options) {
192
159
  const jwtAuthzOptions = (0, import_jwt_authz2.normalizedJwtAuthzModuleOptions)(options);
193
- return (0, import_utils.mergeDynamicModuleConfigs)(super.register({
194
- ...options,
195
- authzProvider
196
- }), getCommonConfigs(), {
160
+ return (0, import_utils.mergeDynamicModuleConfigs)(super.register({ ...options, authzProvider }), getCommonConfigs(), {
197
161
  providers: [
198
162
  {
199
163
  provide: JWT_AUTHZ_OPTIONS,
@@ -203,105 +167,94 @@ const createJwtAuthzModule = /* @__PURE__ */ __name((authzProvider) => {
203
167
  });
204
168
  }
205
169
  /**
206
- * Configures authz module asynchronously.
207
- */
170
+ * Configures authz module asynchronously.
171
+ */
208
172
  static registerAsync(options) {
209
- return (0, import_utils.mergeDynamicModuleConfigs)(super.registerAsync({
210
- ...options,
211
- authzProvider
212
- }), getCommonConfigs(), {
173
+ return (0, import_utils.mergeDynamicModuleConfigs)(super.registerAsync({ ...options, authzProvider }), getCommonConfigs(), {
213
174
  providers: [
214
175
  {
215
176
  provide: JWT_AUTHZ_OPTIONS,
216
- useFactory: /* @__PURE__ */ __name((moduleOptions) => {
177
+ useFactory: (moduleOptions) => {
217
178
  const jwtAuthzOptions = (0, import_jwt_authz2.normalizedJwtAuthzModuleOptions)(moduleOptions);
218
179
  return jwtAuthzOptions;
219
- }, "useFactory"),
220
- inject: [
221
- MODULE_OPTIONS_TOKEN
222
- ]
180
+ },
181
+ inject: [MODULE_OPTIONS_TOKEN]
223
182
  }
224
183
  ]
225
184
  });
226
185
  }
227
186
  configure(consumer) {
228
- consumer.apply(JwtAuthzAlsMiddleware).exclude(...this.routesOpt.excludes).forRoutes(...this.routesOpt.global ? [
229
- "*"
230
- ] : this.routesOpt.routes);
187
+ consumer.apply(JwtAuthzAlsMiddleware).exclude(...this.routesOpt.excludes).forRoutes(...this.routesOpt.global ? ["*"] : this.routesOpt.routes);
231
188
  }
232
- }, __name(_a, "JwtAuthzModule"), _a);
233
- JwtAuthzModule = _ts_decorate([
189
+ };
190
+ JwtAuthzModule = __decorateClass([
234
191
  (0, import_common.Module)({}),
235
- _ts_param(0, (0, import_common.Inject)(import_constants.ROUTES_OPTIONS)),
236
- _ts_metadata("design:type", Function),
237
- _ts_metadata("design:paramtypes", [
238
- typeof RoutesOptions === "undefined" ? Object : RoutesOptions
239
- ])
192
+ __decorateParam(0, (0, import_common.Inject)(import_constants.ROUTES_OPTIONS))
240
193
  ], JwtAuthzModule);
241
194
  return {
242
195
  /**
243
- * A dynamic module used to configure JWT based authentication and authorization features for the application.
244
- *
245
- * This module can be configured using 2 static methods:
246
- *
247
- * - `register`
248
- * - `registerAsync`
249
- *
250
- * ### Usage
251
- *
252
- * ```typescript
253
- * ⁣@Module({
254
- * imports: [
255
- * // Import and configure JWT strategy
256
- * AuthzModule.register({
257
- * jwt: {
258
- * jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
259
- * secret: '1234567890',
260
- * algorithm: 'HS256'
261
- * },
262
- * // Enable refresh token handling
263
- * refresh: {
264
- * jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
265
- * secret: '0987654321',
266
- * algorithm: 'HS256'
267
- * },
268
- * // Apply strategy to specific controllers.
269
- * routes: [BusinessController]
270
- * })
271
- * ],
272
- * controllers: [BusinessController]
273
- * })
274
- * export class BusinessModule {}
275
- * ```
276
- */
196
+ * A dynamic module used to configure JWT based authentication and authorization features for the application.
197
+ *
198
+ * This module can be configured using 2 static methods:
199
+ *
200
+ * - `register`
201
+ * - `registerAsync`
202
+ *
203
+ * ### Usage
204
+ *
205
+ * ```typescript
206
+ * ⁣@Module({
207
+ * imports: [
208
+ * // Import and configure JWT strategy
209
+ * AuthzModule.register({
210
+ * jwt: {
211
+ * jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
212
+ * secret: '1234567890',
213
+ * algorithm: 'HS256'
214
+ * },
215
+ * // Enable refresh token handling
216
+ * refresh: {
217
+ * jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
218
+ * secret: '0987654321',
219
+ * algorithm: 'HS256'
220
+ * },
221
+ * // Apply strategy to specific controllers.
222
+ * routes: [BusinessController]
223
+ * })
224
+ * ],
225
+ * controllers: [BusinessController]
226
+ * })
227
+ * export class BusinessModule {}
228
+ * ```
229
+ */
277
230
  AuthzModule: JwtAuthzModule,
278
231
  /**
279
- * A custom guard that applies authentication to controllers.
280
- *
281
- * This guard also provides 4 utility decorators to apply and modify authorization:
282
- *
283
- * - `@AuthzGuard.Verify`: Used to verify the user's authorization for specific meta data.
284
- * - `@AuthzGuard.NoVerify`: Used to `skip` authentication & authorization checks for specific routes.
285
- * - `@AuthzGuard.Apply`: A simplified version of `@UseGuards(AuthzGuard)` and `@AuthzGuard.Verify`, combining both for convenience.
286
- * - `@AuthzGuard.Refresh`: Used to ensure that only using refresh token for authentication on specific routes, for refreshing JWT tokens.
287
- *
288
- * ### Usage:
289
- *
290
- * ```typescript
291
- * ⁣@UseGuards(AuthzGuard)
292
- * ⁣@Controller(/⁣/ ...)
293
- * export class BusinessController {
294
- * // ...
295
- * }
296
- * ```
297
- */
232
+ * A custom guard that applies authentication to controllers.
233
+ *
234
+ * This guard also provides 4 utility decorators to apply and modify authorization:
235
+ *
236
+ * - `@AuthzGuard.Verify`: Used to verify the user's authorization for specific meta data.
237
+ * - `@AuthzGuard.NoVerify`: Used to `skip` authentication & authorization checks for specific routes.
238
+ * - `@AuthzGuard.Apply`: A simplified version of `@UseGuards(AuthzGuard)` and `@AuthzGuard.Verify`, combining both for convenience.
239
+ * - `@AuthzGuard.Refresh`: Used to ensure that only using refresh token for authentication on specific routes, for refreshing JWT tokens.
240
+ *
241
+ * ### Usage:
242
+ *
243
+ * ```typescript
244
+ * ⁣@UseGuards(AuthzGuard)
245
+ * ⁣@Controller(/⁣/ ...)
246
+ * export class BusinessController {
247
+ * // ...
248
+ * }
249
+ * ```
250
+ */
298
251
  AuthzGuard: JwtAuthzGuard,
299
252
  /**
300
- * A custom servcie to provide methods to handle authentication and authorization.
301
- */
253
+ * A custom servcie to provide methods to handle authentication and authorization.
254
+ */
302
255
  AuthzService: JwtAuthzService
303
256
  };
304
- }, "createJwtAuthzModule");
257
+ };
305
258
  // Annotate the CommonJS export names for ESM import in node:
306
259
  0 && (module.exports = {
307
260
  createJwtAuthzModule
@@ -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,48 +25,35 @@ 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 jwt_authz_service_exports = {};
32
38
  __export(jwt_authz_service_exports, {
33
39
  createJwtAuthzService: () => createJwtAuthzService
34
40
  });
35
41
  module.exports = __toCommonJS(jwt_authz_service_exports);
36
- var import_node_async_hooks = require("node:async_hooks");
37
42
  var import_common = require("@nestjs/common");
38
43
  var import_jsonwebtoken = __toESM(require("jsonwebtoken"));
39
- var import_authz = require("../authz.provider");
40
44
  var import_constants = require("../constants");
41
45
  var import_errors = require("../errors");
42
46
  var import_utils = require("../utils");
43
- function _ts_decorate(decorators, target, key, desc) {
44
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
45
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
46
- 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;
47
- return c > 3 && r && Object.defineProperty(target, key, r), r;
48
- }
49
- __name(_ts_decorate, "_ts_decorate");
50
- function _ts_metadata(k, v) {
51
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
52
- }
53
- __name(_ts_metadata, "_ts_metadata");
54
- function _ts_param(paramIndex, decorator) {
55
- return function(target, key) {
56
- decorator(target, key, paramIndex);
57
- };
58
- }
59
- __name(_ts_param, "_ts_param");
60
- const createJwtAuthzService = /* @__PURE__ */ __name(([AUTHZ_PROVIDER, JWT_AUTHZ_OPTIONS, ALS_PROVIDER]) => {
61
- var _a;
62
- let JwtAuthzService = (_a = class {
47
+ const createJwtAuthzService = ([AUTHZ_PROVIDER, JWT_AUTHZ_OPTIONS, ALS_PROVIDER]) => {
48
+ let JwtAuthzService = class {
63
49
  constructor(authzProvider, jwtAuthzOptions, als) {
64
- __publicField(this, "authzProvider");
65
- __publicField(this, "jwtAuthzOptions");
66
- __publicField(this, "als");
67
50
  this.authzProvider = authzProvider;
68
51
  this.jwtAuthzOptions = jwtAuthzOptions;
69
52
  this.als = als;
70
53
  if (typeof this.authzProvider.createPayload !== "function") {
71
- throw new import_errors.AuthzError(`InternalError: Method 'createPayload' from abstract class 'AuthzProvider' must be implemented.`);
54
+ throw new import_errors.AuthzError(
55
+ `InternalError: Method 'createPayload' from abstract class 'AuthzProvider' must be implemented.`
56
+ );
72
57
  }
73
58
  if (!jwtAuthzOptions.jwt?.sign) {
74
59
  throw new import_errors.AuthzError(`InternalError: Missing JWT sign options.`);
@@ -78,20 +63,24 @@ const createJwtAuthzService = /* @__PURE__ */ __name(([AUTHZ_PROVIDER, JWT_AUTHZ
78
63
  }
79
64
  }
80
65
  /**
81
- * Creates a JWT token with a payload generated by AuthzProviderClass.createPayload(). Optionally, includes a refresh token if configured.
82
- *
83
- * @param user - User entity
84
- * @returns
85
- * - `token` : The generated JWT access token.
86
- * - `refresh` (optional): The generated refresh token, if enabled.
87
- */
66
+ * Creates a JWT token with a payload generated by AuthzProviderClass.createPayload(). Optionally, includes a refresh token if configured.
67
+ *
68
+ * @param user - User entity
69
+ * @returns
70
+ * - `token` : The generated JWT access token.
71
+ * - `refresh` (optional): The generated refresh token, if enabled.
72
+ */
88
73
  async logIn(user) {
89
74
  const payload = await this.authzProvider.createPayload(user);
90
75
  const token = import_jsonwebtoken.default.sign(payload, this.jwtAuthzOptions.jwt.secretOrPrivateKey, this.jwtAuthzOptions.jwt.sign);
91
76
  if (this.jwtAuthzOptions.refresh) {
92
- const refresh = import_jsonwebtoken.default.sign({
93
- data: (0, import_utils.encodeMsgpackrString)(payload)
94
- }, this.jwtAuthzOptions.refresh.secretOrPrivateKey, this.jwtAuthzOptions.refresh.sign);
77
+ const refresh = import_jsonwebtoken.default.sign(
78
+ {
79
+ data: (0, import_utils.encodeMsgpackrString)(payload)
80
+ },
81
+ this.jwtAuthzOptions.refresh.secretOrPrivateKey,
82
+ this.jwtAuthzOptions.refresh.sign
83
+ );
95
84
  return {
96
85
  token,
97
86
  refresh
@@ -102,12 +91,12 @@ const createJwtAuthzService = /* @__PURE__ */ __name(([AUTHZ_PROVIDER, JWT_AUTHZ
102
91
  };
103
92
  }
104
93
  /**
105
- * Refreshes the JWT token for the provided user. If no user is provided, it attempts to retrieve the
106
- * current user and generate a new token.
107
- *
108
- * @param [user] - User entity
109
- * @returns
110
- */
94
+ * Refreshes the JWT token for the provided user. If no user is provided, it attempts to retrieve the
95
+ * current user and generate a new token.
96
+ *
97
+ * @param [user] - User entity
98
+ * @returns
99
+ */
111
100
  async refresh(user) {
112
101
  if (!this.jwtAuthzOptions.refresh) {
113
102
  console.warn(`'refresh' method can only be called when configured in module options.`);
@@ -117,7 +106,9 @@ const createJwtAuthzService = /* @__PURE__ */ __name(([AUTHZ_PROVIDER, JWT_AUTHZ
117
106
  if (!user) {
118
107
  const store = (0, import_utils.getAlsStore)(this.als);
119
108
  if (store.jwtVerifiedBy !== import_constants.JwtValidationType.REFRESH) {
120
- throw new import_errors.AuthzError(`InvocationError: Calling 'refresh' method without user parameter can only be called under @Refresh().`);
109
+ throw new import_errors.AuthzError(
110
+ `InvocationError: Calling 'refresh' method without user parameter can only be called under @Refresh().`
111
+ );
121
112
  }
122
113
  userParams = store.user;
123
114
  }
@@ -131,34 +122,28 @@ const createJwtAuthzService = /* @__PURE__ */ __name(([AUTHZ_PROVIDER, JWT_AUTHZ
131
122
  };
132
123
  }
133
124
  /**
134
- * Sets a secure HTTP cookie with the given name, value, and optional cookie options.
135
- */
125
+ * Sets a secure HTTP cookie with the given name, value, and optional cookie options.
126
+ */
136
127
  setCookie(...rest) {
137
128
  const store = (0, import_utils.getAlsStore)(this.als);
138
129
  store.setCookie(...rest);
139
130
  }
140
131
  /**
141
- * Retrieves the current user associated with the request, if available.
142
- */
132
+ * Retrieves the current user associated with the request, if available.
133
+ */
143
134
  getUser() {
144
135
  const store = (0, import_utils.getAlsStore)(this.als);
145
136
  const user = store.user;
146
137
  return user;
147
138
  }
148
- }, __name(_a, "JwtAuthzService"), _a);
149
- JwtAuthzService = _ts_decorate([
150
- _ts_param(0, (0, import_common.Inject)(AUTHZ_PROVIDER)),
151
- _ts_param(1, (0, import_common.Inject)(JWT_AUTHZ_OPTIONS)),
152
- _ts_param(2, (0, import_common.Inject)(ALS_PROVIDER)),
153
- _ts_metadata("design:type", Function),
154
- _ts_metadata("design:paramtypes", [
155
- typeof import_authz.AuthzProviderClass === "undefined" ? Object : import_authz.AuthzProviderClass,
156
- typeof JwtAuthzOptions === "undefined" ? Object : JwtAuthzOptions,
157
- typeof import_node_async_hooks.AsyncLocalStorage === "undefined" ? Object : import_node_async_hooks.AsyncLocalStorage
158
- ])
139
+ };
140
+ JwtAuthzService = __decorateClass([
141
+ __decorateParam(0, (0, import_common.Inject)(AUTHZ_PROVIDER)),
142
+ __decorateParam(1, (0, import_common.Inject)(JWT_AUTHZ_OPTIONS)),
143
+ __decorateParam(2, (0, import_common.Inject)(ALS_PROVIDER))
159
144
  ], JwtAuthzService);
160
145
  return (0, import_common.mixin)(JwtAuthzService);
161
- }, "createJwtAuthzService");
146
+ };
162
147
  // Annotate the CommonJS export names for ESM import in node:
163
148
  0 && (module.exports = {
164
149
  createJwtAuthzService