@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,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 });
@@ -21,27 +20,25 @@ __export(authz_provider_exports, {
21
20
  AuthzProviderClass: () => AuthzProviderClass
22
21
  });
23
22
  module.exports = __toCommonJS(authz_provider_exports);
24
- const _AuthzProviderClass = class _AuthzProviderClass {
23
+ class AuthzProviderClass {
25
24
  /**
26
- * (**Optional**: Implement this method only if authorization is required.)
27
- *
28
- * Authorizes a user based on the provided metadata.
29
- *
30
- * This method checks if the given user is authorized to perform a specific action based on
31
- * the provided metadata. If implemented, this method enables the authorization check; otherwise,
32
- * only authentication will be performed.
33
- *
34
- * @param {User} _user - The user entity that needs to be authorized.
35
- * @param {unknown} [_metaData] - Optional metadata that can influence the authorization decision.
36
- * @returns {boolean | Promise<boolean>} `true` if the user is authorized, `false` otherwise,
37
- * or a promise that resolves to the authorization result.
38
- */
25
+ * (**Optional**: Implement this method only if authorization is required.)
26
+ *
27
+ * Authorizes a user based on the provided metadata.
28
+ *
29
+ * This method checks if the given user is authorized to perform a specific action based on
30
+ * the provided metadata. If implemented, this method enables the authorization check; otherwise,
31
+ * only authentication will be performed.
32
+ *
33
+ * @param {User} _user - The user entity that needs to be authorized.
34
+ * @param {unknown} [_metaData] - Optional metadata that can influence the authorization decision.
35
+ * @returns {boolean | Promise<boolean>} `true` if the user is authorized, `false` otherwise,
36
+ * or a promise that resolves to the authorization result.
37
+ */
39
38
  authorize(_user, _metaData) {
40
39
  return true;
41
40
  }
42
- };
43
- __name(_AuthzProviderClass, "AuthzProviderClass");
44
- let AuthzProviderClass = _AuthzProviderClass;
41
+ }
45
42
  // Annotate the CommonJS export names for ESM import in node:
46
43
  0 && (module.exports = {
47
44
  AuthzProviderClass
package/dist/constants.js CHANGED
@@ -29,11 +29,11 @@ const DEFAULT_PASSPORT_PROPERTY_VALUE = "user";
29
29
  const PASSPORT_PROPERTY = Symbol("PASSPORT_PROPERTY");
30
30
  const PREFIX = "`<`:";
31
31
  const ROUTES_OPTIONS = Symbol("ROUTES_OPTIONS");
32
- var JwtValidationType = /* @__PURE__ */ function(JwtValidationType2) {
32
+ var JwtValidationType = /* @__PURE__ */ ((JwtValidationType2) => {
33
33
  JwtValidationType2[JwtValidationType2["JWT"] = 0] = "JWT";
34
34
  JwtValidationType2[JwtValidationType2["REFRESH"] = 1] = "REFRESH";
35
35
  return JwtValidationType2;
36
- }({});
36
+ })(JwtValidationType || {});
37
37
  const SESSION_PASSPORT_KEY = "passport";
38
38
  // Annotate the CommonJS export names for ESM import in node:
39
39
  0 && (module.exports = {
package/dist/errors.js CHANGED
@@ -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,6 @@ 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);
21
18
  var errors_exports = {};
22
19
  __export(errors_exports, {
23
20
  AuthzAnonymousError: () => AuthzAnonymousError,
@@ -25,33 +22,26 @@ __export(errors_exports, {
25
22
  AuthzVerificationError: () => AuthzVerificationError
26
23
  });
27
24
  module.exports = __toCommonJS(errors_exports);
28
- const _AuthzError = class _AuthzError extends Error {
25
+ class AuthzError extends Error {
29
26
  constructor(message, cause) {
30
27
  super(message);
31
- __publicField(this, "cause");
32
28
  this.name = "AuthzError";
33
29
  this.cause = cause;
34
30
  Object.setPrototypeOf(this, new.target.prototype);
35
31
  }
36
- };
37
- __name(_AuthzError, "AuthzError");
38
- let AuthzError = _AuthzError;
39
- const _AuthzVerificationError = class _AuthzVerificationError extends AuthzError {
32
+ }
33
+ class AuthzVerificationError extends AuthzError {
40
34
  constructor(message, cause) {
41
35
  super(message, cause);
42
36
  this.name = "AuthzVerificationError";
43
37
  }
44
- };
45
- __name(_AuthzVerificationError, "AuthzVerificationError");
46
- let AuthzVerificationError = _AuthzVerificationError;
47
- const _AuthzAnonymousError = class _AuthzAnonymousError extends AuthzError {
38
+ }
39
+ class AuthzAnonymousError extends AuthzError {
48
40
  constructor(message, cause) {
49
41
  super(message, cause);
50
42
  this.name = "AuthzAnonymousError";
51
43
  }
52
- };
53
- __name(_AuthzAnonymousError, "AuthzAnonymousError");
54
- let AuthzAnonymousError = _AuthzAnonymousError;
44
+ }
55
45
  // Annotate the CommonJS export names for ESM import in node:
56
46
  0 && (module.exports = {
57
47
  AuthzAnonymousError,
@@ -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 });
@@ -25,26 +24,23 @@ module.exports = __toCommonJS(extract_jwt_exports);
25
24
  var import_node_url = require("node:url");
26
25
  var import_utils = require("../utils");
27
26
  const re = /(\S+)\s+(\S+)/;
28
- const parseAuthHeader = /* @__PURE__ */ __name((hdrValue) => {
27
+ const parseAuthHeader = (hdrValue) => {
29
28
  if (typeof hdrValue !== "string") {
30
29
  return null;
31
30
  }
32
31
  var matches = hdrValue.match(re);
33
- return matches && {
34
- scheme: matches[1],
35
- value: matches[2]
36
- };
37
- }, "parseAuthHeader");
32
+ return matches && { scheme: matches[1], value: matches[2] };
33
+ };
38
34
  const AUTH_HEADER = "authorization";
39
35
  const BEARER_AUTH_SCHEME = "bearer";
40
36
  const ExtractJwt = {
41
37
  /**
42
- * Creates an extractor function to retrieve a token from the request header.
43
- *
44
- * @param {string} header_name - The name of the header to extract the token from.
45
- * @returns {JwtFromRequestFunction} A function that takes a request object and returns the extracted token.
46
- */
47
- fromHeader: /* @__PURE__ */ __name((header_name) => {
38
+ * Creates an extractor function to retrieve a token from the request header.
39
+ *
40
+ * @param {string} header_name - The name of the header to extract the token from.
41
+ * @returns {JwtFromRequestFunction} A function that takes a request object and returns the extracted token.
42
+ */
43
+ fromHeader: (header_name) => {
48
44
  return function(request) {
49
45
  let token = null;
50
46
  if (request.headers[header_name]) {
@@ -52,14 +48,14 @@ const ExtractJwt = {
52
48
  }
53
49
  return token;
54
50
  };
55
- }, "fromHeader"),
51
+ },
56
52
  /**
57
- * Creates an extractor function to retrieve a token from a field in the request body.
58
- *
59
- * @param {string} field_name - The name of the field to extract the token from.
60
- * @returns {JwtFromRequestFunction} A function that takes a request object and returns the extracted token.
61
- */
62
- fromBodyField: /* @__PURE__ */ __name((field_name) => {
53
+ * Creates an extractor function to retrieve a token from a field in the request body.
54
+ *
55
+ * @param {string} field_name - The name of the field to extract the token from.
56
+ * @returns {JwtFromRequestFunction} A function that takes a request object and returns the extracted token.
57
+ */
58
+ fromBodyField: (field_name) => {
63
59
  return function(request) {
64
60
  let token = null;
65
61
  if (request.body && Object.prototype.hasOwnProperty.call(request.body, field_name)) {
@@ -67,14 +63,14 @@ const ExtractJwt = {
67
63
  }
68
64
  return token;
69
65
  };
70
- }, "fromBodyField"),
66
+ },
71
67
  /**
72
- * Creates an extractor function to retrieve a token from a query parameter in the URL.
73
- *
74
- * @param {string} param_name - The name of the query parameter to extract the token from.
75
- * @returns {JwtFromRequestFunction} A function that takes a request object and returns the extracted token.
76
- */
77
- fromUrlQueryParameter: /* @__PURE__ */ __name((param_name) => {
68
+ * Creates an extractor function to retrieve a token from a query parameter in the URL.
69
+ *
70
+ * @param {string} param_name - The name of the query parameter to extract the token from.
71
+ * @returns {JwtFromRequestFunction} A function that takes a request object and returns the extracted token.
72
+ */
73
+ fromUrlQueryParameter: (param_name) => {
78
74
  return function(request) {
79
75
  let token = null;
80
76
  const parsed_url = (0, import_node_url.parse)(request.url, true);
@@ -83,14 +79,14 @@ const ExtractJwt = {
83
79
  }
84
80
  return token;
85
81
  };
86
- }, "fromUrlQueryParameter"),
82
+ },
87
83
  /**
88
- * Creates an extractor function to retrieve a token from the authorization header with a specific scheme.
89
- *
90
- * @param {string} auth_scheme - The authorization scheme (e.g., 'Bearer').
91
- * @returns {JwtFromRequestFunction} A function that takes a request object and returns the extracted token.
92
- */
93
- fromAuthHeaderWithScheme: /* @__PURE__ */ __name((auth_scheme) => {
84
+ * Creates an extractor function to retrieve a token from the authorization header with a specific scheme.
85
+ *
86
+ * @param {string} auth_scheme - The authorization scheme (e.g., 'Bearer').
87
+ * @returns {JwtFromRequestFunction} A function that takes a request object and returns the extracted token.
88
+ */
89
+ fromAuthHeaderWithScheme: (auth_scheme) => {
94
90
  var auth_scheme_lower = auth_scheme.toLowerCase();
95
91
  return function(request) {
96
92
  let token = null;
@@ -102,23 +98,23 @@ const ExtractJwt = {
102
98
  }
103
99
  return token;
104
100
  };
105
- }, "fromAuthHeaderWithScheme"),
101
+ },
106
102
  /**
107
- * Creates an extractor function to retrieve a token from the authorization header as a Bearer token.
108
- *
109
- * @returns {JwtFromRequestFunction} A function that takes a request object and returns the extracted token.
110
- */
111
- fromAuthHeaderAsBearerToken: /* @__PURE__ */ __name(() => {
103
+ * Creates an extractor function to retrieve a token from the authorization header as a Bearer token.
104
+ *
105
+ * @returns {JwtFromRequestFunction} A function that takes a request object and returns the extracted token.
106
+ */
107
+ fromAuthHeaderAsBearerToken: () => {
112
108
  return ExtractJwt.fromAuthHeaderWithScheme(BEARER_AUTH_SCHEME);
113
- }, "fromAuthHeaderAsBearerToken"),
109
+ },
114
110
  /**
115
- * Creates an extractor function to retrieve a token from the request header. Respects cookie-parser middleware if applied.
116
- *
117
- * @param cookie_name - The name of the cookie to extract the token from.
118
- * @param options - Options to parse request cookie header.
119
- * @returns A function that takes a request object and returns the extracted token.
120
- */
121
- fromCookies: /* @__PURE__ */ __name((cookie_name, options) => {
111
+ * Creates an extractor function to retrieve a token from the request header. Respects cookie-parser middleware if applied.
112
+ *
113
+ * @param cookie_name - The name of the cookie to extract the token from.
114
+ * @param options - Options to parse request cookie header.
115
+ * @returns A function that takes a request object and returns the extracted token.
116
+ */
117
+ fromCookies: (cookie_name, options) => {
122
118
  const cookie_name_lower = cookie_name.toLowerCase();
123
119
  const { secret, decode } = options ?? {};
124
120
  const secrets = (0, import_utils.normalizedArray)(secret) ?? [];
@@ -133,14 +129,14 @@ const ExtractJwt = {
133
129
  }
134
130
  return token;
135
131
  };
136
- }, "fromCookies"),
132
+ },
137
133
  /**
138
- * Creates an extractor function that combines multiple extractor functions.
139
- *
140
- * @param {JwtFromRequestFunction[]} extractors - An array of extractor functions.
141
- * @returns {JwtFromRequestFunction} A function that takes a request object and returns the extracted token.
142
- */
143
- fromExtractors: /* @__PURE__ */ __name((extractors) => {
134
+ * Creates an extractor function that combines multiple extractor functions.
135
+ *
136
+ * @param {JwtFromRequestFunction[]} extractors - An array of extractor functions.
137
+ * @returns {JwtFromRequestFunction} A function that takes a request object and returns the extracted token.
138
+ */
139
+ fromExtractors: (extractors) => {
144
140
  if (!Array.isArray(extractors)) {
145
141
  throw new TypeError("extractors.fromExtractors expects an array");
146
142
  }
@@ -153,7 +149,7 @@ const ExtractJwt = {
153
149
  }
154
150
  return token;
155
151
  };
156
- }, "fromExtractors")
152
+ }
157
153
  };
158
154
  // Annotate the CommonJS export names for ESM import in node:
159
155
  0 && (module.exports = {
@@ -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,66 +15,51 @@ 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_als_middleware_exports = {};
22
28
  __export(jwt_authz_als_middleware_exports, {
23
29
  createJwtAuthzAlsMiddleware: () => createJwtAuthzAlsMiddleware
24
30
  });
25
31
  module.exports = __toCommonJS(jwt_authz_als_middleware_exports);
26
- var import_node_async_hooks = require("node:async_hooks");
27
32
  var import_common = require("@nestjs/common");
28
33
  var import_utils = require("../utils");
29
- function _ts_decorate(decorators, target, key, desc) {
30
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
31
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
32
- 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;
33
- return c > 3 && r && Object.defineProperty(target, key, r), r;
34
- }
35
- __name(_ts_decorate, "_ts_decorate");
36
- function _ts_metadata(k, v) {
37
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
38
- }
39
- __name(_ts_metadata, "_ts_metadata");
40
- function _ts_param(paramIndex, decorator) {
41
- return function(target, key) {
42
- decorator(target, key, paramIndex);
43
- };
44
- }
45
- __name(_ts_param, "_ts_param");
46
- const createJwtAuthzAlsMiddleware = /* @__PURE__ */ __name(([ALS_PROVIDER, JWT_AUTHZ_OPTIONS]) => {
47
- var _a;
48
- let JwtAuthzAlsMiddleware = (_a = class {
34
+ const createJwtAuthzAlsMiddleware = ([ALS_PROVIDER, JWT_AUTHZ_OPTIONS]) => {
35
+ let JwtAuthzAlsMiddleware = class {
49
36
  constructor(als, jwtAuthzOptions) {
50
- __publicField(this, "als");
51
- __publicField(this, "jwtAuthzOptions");
52
37
  this.als = als;
53
38
  this.jwtAuthzOptions = jwtAuthzOptions;
54
39
  }
55
40
  use(req, res, next) {
56
- this.als.run({
57
- user: void 0,
58
- jwtVerifiedBy: void 0,
59
- allowAnonymous: void 0,
60
- guardResult: void 0,
61
- // a workaround to pass jwtAuthzOptions to passport strategy.
62
- authOptions: this.jwtAuthzOptions,
63
- setCookie: (0, import_utils.createSetCookieFn)(req, res)
64
- }, () => {
65
- next();
66
- });
41
+ this.als.run(
42
+ {
43
+ user: void 0,
44
+ jwtVerifiedBy: void 0,
45
+ allowAnonymous: void 0,
46
+ guardResult: void 0,
47
+ // a workaround to pass jwtAuthzOptions to passport strategy.
48
+ authOptions: this.jwtAuthzOptions,
49
+ setCookie: (0, import_utils.createSetCookieFn)(req, res)
50
+ },
51
+ () => {
52
+ next();
53
+ }
54
+ );
67
55
  }
68
- }, __name(_a, "JwtAuthzAlsMiddleware"), _a);
69
- JwtAuthzAlsMiddleware = _ts_decorate([
70
- _ts_param(0, (0, import_common.Inject)(ALS_PROVIDER)),
71
- _ts_param(1, (0, import_common.Inject)(JWT_AUTHZ_OPTIONS)),
72
- _ts_metadata("design:type", Function),
73
- _ts_metadata("design:paramtypes", [
74
- typeof import_node_async_hooks.AsyncLocalStorage === "undefined" ? Object : import_node_async_hooks.AsyncLocalStorage,
75
- typeof JwtAuthzOptions === "undefined" ? Object : JwtAuthzOptions
76
- ])
56
+ };
57
+ JwtAuthzAlsMiddleware = __decorateClass([
58
+ __decorateParam(0, (0, import_common.Inject)(ALS_PROVIDER)),
59
+ __decorateParam(1, (0, import_common.Inject)(JWT_AUTHZ_OPTIONS))
77
60
  ], JwtAuthzAlsMiddleware);
78
61
  return (0, import_common.mixin)(JwtAuthzAlsMiddleware);
79
- }, "createJwtAuthzAlsMiddleware");
62
+ };
80
63
  // Annotate the CommonJS export names for ESM import in node:
81
64
  0 && (module.exports = {
82
65
  createJwtAuthzAlsMiddleware
@@ -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_guard_exports = {};
22
28
  __export(jwt_authz_guard_exports, {
23
29
  createJwtAuthzGuard: () => createJwtAuthzGuard,
@@ -25,38 +31,24 @@ __export(jwt_authz_guard_exports, {
25
31
  });
26
32
  module.exports = __toCommonJS(jwt_authz_guard_exports);
27
33
  var import_common = require("@nestjs/common");
28
- var import_core = require("@nestjs/core");
29
34
  var import_passport = require("@nestjs/passport");
30
- var import_authz = require("../authz.provider");
31
35
  var import_errors = require("../errors");
32
36
  var import_utils = require("../utils");
33
- function _ts_decorate(decorators, target, key, desc) {
34
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
35
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
36
- 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;
37
- return c > 3 && r && Object.defineProperty(target, key, r), r;
38
- }
39
- __name(_ts_decorate, "_ts_decorate");
40
- function _ts_metadata(k, v) {
41
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
42
- }
43
- __name(_ts_metadata, "_ts_metadata");
44
- function _ts_param(paramIndex, decorator) {
45
- return function(target, key) {
46
- decorator(target, key, paramIndex);
47
- };
48
- }
49
- __name(_ts_param, "_ts_param");
50
- const createJwtAuthzGuard = /* @__PURE__ */ __name(([JWT_STRATEGY, AUTHZ_PROVIDER, JWT_AUTHZ_OPTIONS, ALS_PROVIDER, JWT_META_KEY, JWT_REFRESH_META_KEY]) => {
51
- var _a;
52
- let JwtAuthzGuard = (_a = class extends (0, import_passport.AuthGuard)(JWT_STRATEGY) {
37
+ const createJwtAuthzGuard = ([
38
+ JWT_STRATEGY,
39
+ AUTHZ_PROVIDER,
40
+ JWT_AUTHZ_OPTIONS,
41
+ ALS_PROVIDER,
42
+ JWT_META_KEY,
43
+ JWT_REFRESH_META_KEY
44
+ ]) => {
45
+ let JwtAuthzGuard = class extends (0, import_passport.AuthGuard)(JWT_STRATEGY) {
53
46
  constructor(reflector, authzProvider, jwtAuthzOptions, als) {
54
47
  super();
55
- __publicField(this, "reflector");
56
- __publicField(this, "authzProvider");
57
- __publicField(this, "jwtAuthzOptions");
58
- __publicField(this, "als");
59
- this.reflector = reflector, this.authzProvider = authzProvider, this.jwtAuthzOptions = jwtAuthzOptions, this.als = als;
48
+ this.reflector = reflector;
49
+ this.authzProvider = authzProvider;
50
+ this.jwtAuthzOptions = jwtAuthzOptions;
51
+ this.als = als;
60
52
  }
61
53
  getAuthenticateOptions() {
62
54
  return {
@@ -65,16 +57,16 @@ const createJwtAuthzGuard = /* @__PURE__ */ __name(([JWT_STRATEGY, AUTHZ_PROVIDE
65
57
  };
66
58
  }
67
59
  /**
68
- *
69
- * recives err, user, info from JwtStrategy.validate
70
- *
71
- * will return request.user=null if allowAnonymous=true
72
- *
73
- * @param _err will always be null
74
- * @param user if user is null, then info will be AuthError. if user is defined, then info will be undefined.
75
- * @param info AuthzError or undefined
76
- * @returns
77
- */
60
+ *
61
+ * recives err, user, info from JwtStrategy.validate
62
+ *
63
+ * will return request.user=null if allowAnonymous=true
64
+ *
65
+ * @param _err will always be null
66
+ * @param user if user is null, then info will be AuthError. if user is defined, then info will be undefined.
67
+ * @param info AuthzError or undefined
68
+ * @returns
69
+ */
78
70
  handleRequest(_err, user, info) {
79
71
  const store = (0, import_utils.getAlsStore)(this.als);
80
72
  if (info) {
@@ -91,18 +83,16 @@ const createJwtAuthzGuard = /* @__PURE__ */ __name(([JWT_STRATEGY, AUTHZ_PROVIDE
91
83
  if ((0, import_utils.isNotFalsy)(store.guardResult)) {
92
84
  return store.guardResult;
93
85
  }
94
- const jwtRefreshMetaCollection = (0, import_utils.normalizedArray)(this.reflector.getAll(JWT_REFRESH_META_KEY, [
95
- context.getClass(),
96
- context.getHandler()
97
- ]));
86
+ const jwtRefreshMetaCollection = (0, import_utils.normalizedArray)(
87
+ this.reflector.getAll(JWT_REFRESH_META_KEY, [context.getClass(), context.getHandler()])
88
+ );
98
89
  if (Boolean(this.jwtAuthzOptions.refresh) && jwtRefreshMetaCollection.length) {
99
90
  store.guardResult = true;
100
91
  return true;
101
92
  }
102
- const paramsList = (0, import_utils.normalizedArray)(this.reflector.getAll(JWT_META_KEY, [
103
- context.getClass(),
104
- context.getHandler()
105
- ]));
93
+ const paramsList = (0, import_utils.normalizedArray)(
94
+ this.reflector.getAll(JWT_META_KEY, [context.getClass(), context.getHandler()])
95
+ );
106
96
  if (paramsList.length && Boolean(paramsList[paramsList.length - 1].options?.public)) {
107
97
  store.guardResult = true;
108
98
  return true;
@@ -127,27 +117,18 @@ const createJwtAuthzGuard = /* @__PURE__ */ __name(([JWT_STRATEGY, AUTHZ_PROVIDE
127
117
  }
128
118
  return true;
129
119
  }
130
- }, __name(_a, "JwtAuthzGuard"), _a);
131
- JwtAuthzGuard = _ts_decorate([
132
- _ts_param(1, (0, import_common.Inject)(AUTHZ_PROVIDER)),
133
- _ts_param(2, (0, import_common.Inject)(JWT_AUTHZ_OPTIONS)),
134
- _ts_param(3, (0, import_common.Inject)(ALS_PROVIDER)),
135
- _ts_metadata("design:type", Function),
136
- _ts_metadata("design:paramtypes", [
137
- typeof import_core.Reflector === "undefined" ? Object : import_core.Reflector,
138
- typeof import_authz.AuthzProviderClass === "undefined" ? Object : import_authz.AuthzProviderClass,
139
- typeof JwtAuthzOptions === "undefined" ? Object : JwtAuthzOptions,
140
- typeof AsyncLocalStorage === "undefined" ? Object : AsyncLocalStorage
141
- ])
120
+ };
121
+ JwtAuthzGuard = __decorateClass([
122
+ __decorateParam(1, (0, import_common.Inject)(AUTHZ_PROVIDER)),
123
+ __decorateParam(2, (0, import_common.Inject)(JWT_AUTHZ_OPTIONS)),
124
+ __decorateParam(3, (0, import_common.Inject)(ALS_PROVIDER))
142
125
  ], JwtAuthzGuard);
143
126
  return (0, import_common.mixin)(JwtAuthzGuard);
144
- }, "createJwtAuthzGuard");
145
- const createJwtRefreshAuthzGuard = /* @__PURE__ */ __name(([JWT_REFRESH_STRATEGY, JWT_AUTHZ_OPTIONS]) => {
146
- var _a;
147
- let JwtRefreshAuthzGuard = (_a = class extends (0, import_passport.AuthGuard)(JWT_REFRESH_STRATEGY) {
127
+ };
128
+ const createJwtRefreshAuthzGuard = ([JWT_REFRESH_STRATEGY, JWT_AUTHZ_OPTIONS]) => {
129
+ let JwtRefreshAuthzGuard = class extends (0, import_passport.AuthGuard)(JWT_REFRESH_STRATEGY) {
148
130
  constructor(jwtAuthzOptions) {
149
131
  super();
150
- __publicField(this, "jwtAuthzOptions");
151
132
  this.jwtAuthzOptions = jwtAuthzOptions;
152
133
  }
153
134
  getAuthenticateOptions() {
@@ -162,16 +143,12 @@ const createJwtRefreshAuthzGuard = /* @__PURE__ */ __name(([JWT_REFRESH_STRATEGY
162
143
  }
163
144
  return user;
164
145
  }
165
- }, __name(_a, "JwtRefreshAuthzGuard"), _a);
166
- JwtRefreshAuthzGuard = _ts_decorate([
167
- _ts_param(0, (0, import_common.Inject)(JWT_AUTHZ_OPTIONS)),
168
- _ts_metadata("design:type", Function),
169
- _ts_metadata("design:paramtypes", [
170
- typeof JwtAuthzOptions === "undefined" ? Object : JwtAuthzOptions
171
- ])
146
+ };
147
+ JwtRefreshAuthzGuard = __decorateClass([
148
+ __decorateParam(0, (0, import_common.Inject)(JWT_AUTHZ_OPTIONS))
172
149
  ], JwtRefreshAuthzGuard);
173
150
  return (0, import_common.mixin)(JwtRefreshAuthzGuard);
174
- }, "createJwtRefreshAuthzGuard");
151
+ };
175
152
  // Annotate the CommonJS export names for ESM import in node:
176
153
  0 && (module.exports = {
177
154
  createJwtAuthzGuard,
@@ -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 });
@@ -23,11 +22,37 @@ __export(jwt_authz_interface_exports, {
23
22
  module.exports = __toCommonJS(jwt_authz_interface_exports);
24
23
  var import_constants = require("../constants");
25
24
  var import_utils = require("../utils");
26
- const normalizedJwtOptions = /* @__PURE__ */ __name((jwtOptions) => {
25
+ const normalizedJwtOptions = (jwtOptions) => {
27
26
  if (!jwtOptions) {
28
27
  return void 0;
29
28
  }
30
- const { jwtFromRequest, algorithm, audience, clockTimestamp, clockTolerance, complete, ignoreExpiration, ignoreNotBefore, issuer, jwtid, maxAge, nonce, privateKey, publicKey, secret, subject, allowInsecureKeySizes, encoding, expiresIn, header, keyid, mutatePayload, noTimestamp, notBefore, allowInvalidAsymmetricKeyTypes } = jwtOptions;
29
+ const {
30
+ jwtFromRequest,
31
+ algorithm,
32
+ audience,
33
+ clockTimestamp,
34
+ clockTolerance,
35
+ complete,
36
+ ignoreExpiration,
37
+ ignoreNotBefore,
38
+ issuer,
39
+ jwtid,
40
+ maxAge,
41
+ nonce,
42
+ privateKey,
43
+ publicKey,
44
+ secret,
45
+ subject,
46
+ allowInsecureKeySizes,
47
+ encoding,
48
+ expiresIn,
49
+ header,
50
+ keyid,
51
+ mutatePayload,
52
+ noTimestamp,
53
+ notBefore,
54
+ allowInvalidAsymmetricKeyTypes
55
+ } = jwtOptions;
31
56
  const formattedJwtFromRequest = (0, import_utils.normalizedArray)(jwtFromRequest);
32
57
  const algorithms = (0, import_utils.normalizedArray)(algorithm);
33
58
  const sign = {
@@ -77,8 +102,8 @@ const normalizedJwtOptions = /* @__PURE__ */ __name((jwtOptions) => {
77
102
  sign: (0, import_utils.normalizedObject)(sign) ?? {},
78
103
  verify: (0, import_utils.normalizedObject)(verify) ?? {}
79
104
  };
80
- }, "normalizedJwtOptions");
81
- const normalizedJwtAuthzModuleOptions = /* @__PURE__ */ __name((options) => {
105
+ };
106
+ const normalizedJwtAuthzModuleOptions = (options) => {
82
107
  return {
83
108
  defaultOverride: options?.defaultOverride || false,
84
109
  passportProperty: options?.passportProperty || import_constants.DEFAULT_PASSPORT_PROPERTY_VALUE,
@@ -87,7 +112,7 @@ const normalizedJwtAuthzModuleOptions = /* @__PURE__ */ __name((options) => {
87
112
  jwt: normalizedJwtOptions(options?.jwt),
88
113
  refresh: normalizedJwtOptions(options?.refresh)
89
114
  };
90
- }, "normalizedJwtAuthzModuleOptions");
115
+ };
91
116
  // Annotate the CommonJS export names for ESM import in node:
92
117
  0 && (module.exports = {
93
118
  normalizedJwtAuthzModuleOptions