@nestjs-kitchen/authz 2.0.3 → 2.0.4

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.
Files changed (65) hide show
  1. package/dist/authz.provider.d.ts +1 -3
  2. package/dist/authz.provider.js +27 -43
  3. package/dist/constants.d.ts +6 -8
  4. package/dist/constants.js +13 -46
  5. package/dist/errors.d.ts +3 -5
  6. package/dist/errors.js +29 -44
  7. package/dist/index.d.ts +5 -21
  8. package/dist/index.js +16 -45
  9. package/dist/jwt/extract-jwt.d.ts +4 -7
  10. package/dist/jwt/extract-jwt.js +136 -152
  11. package/dist/jwt/index.d.ts +2 -16
  12. package/dist/jwt/index.js +7 -30
  13. package/dist/jwt/jwt-authz-als.middleware.d.ts +6 -16
  14. package/dist/jwt/jwt-authz-als.middleware.js +40 -60
  15. package/dist/jwt/jwt-authz.guard.d.ts +8 -21
  16. package/dist/jwt/jwt-authz.guard.js +126 -148
  17. package/dist/jwt/jwt-authz.interface.d.ts +16 -25
  18. package/dist/jwt/jwt-authz.interface.js +66 -114
  19. package/dist/jwt/jwt-authz.module.d.ts +19 -31
  20. package/dist/jwt/jwt-authz.module.js +240 -242
  21. package/dist/jwt/jwt-authz.service.d.ts +6 -17
  22. package/dist/jwt/jwt-authz.service.js +113 -144
  23. package/dist/jwt/jwt-authz.strategy.d.ts +5 -17
  24. package/dist/jwt/jwt-authz.strategy.js +127 -150
  25. package/dist/session/index.d.ts +1 -12
  26. package/dist/session/index.js +5 -27
  27. package/dist/session/session-authz-als.middleware.d.ts +5 -12
  28. package/dist/session/session-authz-als.middleware.js +95 -109
  29. package/dist/session/session-authz.guard.d.ts +6 -15
  30. package/dist/session/session-authz.guard.js +96 -116
  31. package/dist/session/session-authz.interface.d.ts +5 -12
  32. package/dist/session/session-authz.interface.js +18 -40
  33. package/dist/session/session-authz.module.d.ts +18 -26
  34. package/dist/session/session-authz.module.js +231 -237
  35. package/dist/session/session-authz.service.d.ts +5 -13
  36. package/dist/session/session-authz.service.js +66 -83
  37. package/dist/session/session-authz.strategy.d.ts +4 -12
  38. package/dist/session/session-authz.strategy.js +65 -78
  39. package/dist/user.decorator.d.ts +3 -6
  40. package/dist/user.decorator.js +25 -33
  41. package/dist/utils/cookie-parsers.d.ts +3 -6
  42. package/dist/utils/cookie-parsers.js +62 -63
  43. package/dist/utils/create-authz-decorator-factory.d.ts +3 -9
  44. package/dist/utils/create-authz-decorator-factory.js +29 -50
  45. package/dist/utils/create-set-cookie-fn.d.ts +3 -9
  46. package/dist/utils/create-set-cookie-fn.js +21 -42
  47. package/dist/utils/generics.d.ts +4 -6
  48. package/dist/utils/generics.js +31 -54
  49. package/dist/utils/get-allow-anonymous.d.ts +2 -9
  50. package/dist/utils/get-allow-anonymous.js +6 -27
  51. package/dist/utils/get-als-store.d.ts +2 -5
  52. package/dist/utils/get-als-store.js +10 -32
  53. package/dist/utils/get-context-authz-meta-params-list.d.ts +2 -9
  54. package/dist/utils/get-context-authz-meta-params-list.js +15 -33
  55. package/dist/utils/get-passport-property.d.ts +1 -3
  56. package/dist/utils/get-passport-property.js +7 -28
  57. package/dist/utils/index.d.ts +11 -16
  58. package/dist/utils/index.js +26 -40
  59. package/dist/utils/merge-dynamic-module-configs.d.ts +2 -5
  60. package/dist/utils/merge-dynamic-module-configs.js +13 -38
  61. package/dist/utils/msgpackrs.d.ts +2 -4
  62. package/dist/utils/msgpackrs.js +9 -32
  63. package/dist/utils/types.d.ts +23 -26
  64. package/dist/utils/types.js +2 -15
  65. package/package.json +4 -4
@@ -1,158 +1,142 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var extract_jwt_exports = {};
19
- __export(extract_jwt_exports, {
20
- ExtractJwt: () => ExtractJwt,
21
- parseAuthHeader: () => parseAuthHeader
22
- });
23
- module.exports = __toCommonJS(extract_jwt_exports);
24
- var import_node_url = require("node:url");
25
- var import_utils = require("../utils");
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ExtractJwt = exports.parseAuthHeader = void 0;
4
+ /**
5
+ * fork from https://github.com/mikenicholson/passport-jwt/blob/master/lib/extract_jwt.js
6
+ */
7
+ const node_url_1 = require("node:url");
8
+ const utils_1 = require("../utils");
26
9
  const re = /(\S+)\s+(\S+)/;
27
10
  const parseAuthHeader = (hdrValue) => {
28
- if (typeof hdrValue !== "string") {
29
- return null;
30
- }
31
- var matches = hdrValue.match(re);
32
- return matches && { scheme: matches[1], value: matches[2] };
11
+ if (typeof hdrValue !== 'string') {
12
+ return null;
13
+ }
14
+ var matches = hdrValue.match(re);
15
+ return matches && { scheme: matches[1], value: matches[2] };
33
16
  };
34
- const AUTH_HEADER = "authorization";
35
- const BEARER_AUTH_SCHEME = "bearer";
36
- const ExtractJwt = {
37
- /**
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) => {
44
- return function(request) {
45
- let token = null;
46
- if (request.headers[header_name]) {
47
- token = request.headers[header_name];
48
- }
49
- return token;
50
- };
51
- },
52
- /**
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) => {
59
- return function(request) {
60
- let token = null;
61
- if (request.body && Object.prototype.hasOwnProperty.call(request.body, field_name)) {
62
- token = request.body[field_name];
63
- }
64
- return token;
65
- };
66
- },
67
- /**
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) => {
74
- return function(request) {
75
- let token = null;
76
- const parsed_url = (0, import_node_url.parse)(request.url, true);
77
- if (parsed_url.query && Object.prototype.hasOwnProperty.call(parsed_url.query, param_name)) {
78
- token = parsed_url.query[param_name];
79
- }
80
- return token;
81
- };
82
- },
83
- /**
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) => {
90
- var auth_scheme_lower = auth_scheme.toLowerCase();
91
- return function(request) {
92
- let token = null;
93
- if (request.headers[AUTH_HEADER]) {
94
- var auth_params = parseAuthHeader(request.headers[AUTH_HEADER]);
95
- if (auth_params && auth_scheme_lower === auth_params.scheme.toLowerCase()) {
96
- token = auth_params.value;
17
+ exports.parseAuthHeader = parseAuthHeader;
18
+ const AUTH_HEADER = 'authorization';
19
+ const BEARER_AUTH_SCHEME = 'bearer';
20
+ /**
21
+ * Utility factory function for creating extractor functions that retrieve JWT from HTTP requests.
22
+ *
23
+ * Same as `passportjs` [jwt extractors](https://www.passportjs.org/packages/passport-jwt/#included-extractors)
24
+ */
25
+ exports.ExtractJwt = {
26
+ /**
27
+ * Creates an extractor function to retrieve a token from the request header.
28
+ *
29
+ * @param {string} header_name - The name of the header to extract the token from.
30
+ * @returns {JwtFromRequestFunction} A function that takes a request object and returns the extracted token.
31
+ */
32
+ fromHeader: (header_name) => {
33
+ return function (request) {
34
+ let token = null;
35
+ if (request.headers[header_name]) {
36
+ token = request.headers[header_name];
37
+ }
38
+ return token;
39
+ };
40
+ },
41
+ /**
42
+ * Creates an extractor function to retrieve a token from a field in the request body.
43
+ *
44
+ * @param {string} field_name - The name of the field to extract the token from.
45
+ * @returns {JwtFromRequestFunction} A function that takes a request object and returns the extracted token.
46
+ */
47
+ fromBodyField: (field_name) => {
48
+ return function (request) {
49
+ let token = null;
50
+ if (request.body && Object.prototype.hasOwnProperty.call(request.body, field_name)) {
51
+ token = request.body[field_name];
52
+ }
53
+ return token;
54
+ };
55
+ },
56
+ /**
57
+ * Creates an extractor function to retrieve a token from a query parameter in the URL.
58
+ *
59
+ * @param {string} param_name - The name of the query parameter to extract the token from.
60
+ * @returns {JwtFromRequestFunction} A function that takes a request object and returns the extracted token.
61
+ */
62
+ fromUrlQueryParameter: (param_name) => {
63
+ return function (request) {
64
+ let token = null;
65
+ const parsed_url = (0, node_url_1.parse)(request.url, true);
66
+ if (parsed_url.query && Object.prototype.hasOwnProperty.call(parsed_url.query, param_name)) {
67
+ token = parsed_url.query[param_name];
68
+ }
69
+ return token;
70
+ };
71
+ },
72
+ /**
73
+ * Creates an extractor function to retrieve a token from the authorization header with a specific scheme.
74
+ *
75
+ * @param {string} auth_scheme - The authorization scheme (e.g., 'Bearer').
76
+ * @returns {JwtFromRequestFunction} A function that takes a request object and returns the extracted token.
77
+ */
78
+ fromAuthHeaderWithScheme: (auth_scheme) => {
79
+ var auth_scheme_lower = auth_scheme.toLowerCase();
80
+ return function (request) {
81
+ let token = null;
82
+ if (request.headers[AUTH_HEADER]) {
83
+ var auth_params = (0, exports.parseAuthHeader)(request.headers[AUTH_HEADER]);
84
+ if (auth_params && auth_scheme_lower === auth_params.scheme.toLowerCase()) {
85
+ token = auth_params.value;
86
+ }
87
+ }
88
+ return token;
89
+ };
90
+ },
91
+ /**
92
+ * Creates an extractor function to retrieve a token from the authorization header as a Bearer token.
93
+ *
94
+ * @returns {JwtFromRequestFunction} A function that takes a request object and returns the extracted token.
95
+ */
96
+ fromAuthHeaderAsBearerToken: () => {
97
+ return exports.ExtractJwt.fromAuthHeaderWithScheme(BEARER_AUTH_SCHEME);
98
+ },
99
+ /**
100
+ * Creates an extractor function to retrieve a token from the request header. Respects cookie-parser middleware if applied.
101
+ *
102
+ * @param cookie_name - The name of the cookie to extract the token from.
103
+ * @param options - Options to parse request cookie header.
104
+ * @returns A function that takes a request object and returns the extracted token.
105
+ */
106
+ fromCookies: (cookie_name, options) => {
107
+ const cookie_name_lower = cookie_name.toLowerCase();
108
+ const { secret, decode } = options ?? {};
109
+ const secrets = (0, utils_1.normalizedArray)(secret) ?? [];
110
+ const signed = options?.signed ?? Boolean(secrets.length);
111
+ const targetParser = Boolean(secrets.length) ? utils_1.customCookieParser : utils_1.normalCookieParser;
112
+ return (req) => {
113
+ const { cookies, signedCookies } = targetParser(req, secrets, decode);
114
+ let token = null;
115
+ const targetCookies = signed ? signedCookies : cookies;
116
+ if (targetCookies[cookie_name_lower]) {
117
+ token = targetCookies[cookie_name_lower];
118
+ }
119
+ return token;
120
+ };
121
+ },
122
+ /**
123
+ * Creates an extractor function that combines multiple extractor functions.
124
+ *
125
+ * @param {JwtFromRequestFunction[]} extractors - An array of extractor functions.
126
+ * @returns {JwtFromRequestFunction} A function that takes a request object and returns the extracted token.
127
+ */
128
+ fromExtractors: (extractors) => {
129
+ if (!Array.isArray(extractors)) {
130
+ throw new TypeError('extractors.fromExtractors expects an array');
97
131
  }
98
- }
99
- return token;
100
- };
101
- },
102
- /**
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: () => {
108
- return ExtractJwt.fromAuthHeaderWithScheme(BEARER_AUTH_SCHEME);
109
- },
110
- /**
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) => {
118
- const cookie_name_lower = cookie_name.toLowerCase();
119
- const { secret, decode } = options ?? {};
120
- const secrets = (0, import_utils.normalizedArray)(secret) ?? [];
121
- const signed = options?.signed ?? Boolean(secrets.length);
122
- const targetParser = Boolean(secrets.length) ? import_utils.customCookieParser : import_utils.normalCookieParser;
123
- return (req) => {
124
- const { cookies, signedCookies } = targetParser(req, secrets, decode);
125
- let token = null;
126
- const targetCookies = signed ? signedCookies : cookies;
127
- if (targetCookies[cookie_name_lower]) {
128
- token = targetCookies[cookie_name_lower];
129
- }
130
- return token;
131
- };
132
- },
133
- /**
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) => {
140
- if (!Array.isArray(extractors)) {
141
- throw new TypeError("extractors.fromExtractors expects an array");
132
+ return function (request) {
133
+ let token = null;
134
+ let index = 0;
135
+ while (!token && index < extractors.length) {
136
+ token = extractors[index].call(this, request);
137
+ index++;
138
+ }
139
+ return token;
140
+ };
142
141
  }
143
- return function(request) {
144
- let token = null;
145
- let index = 0;
146
- while (!token && index < extractors.length) {
147
- token = extractors[index].call(this, request);
148
- index++;
149
- }
150
- return token;
151
- };
152
- }
153
142
  };
154
- // Annotate the CommonJS export names for ESM import in node:
155
- 0 && (module.exports = {
156
- ExtractJwt,
157
- parseAuthHeader
158
- });
@@ -1,16 +1,2 @@
1
- export { ExtractJwt, JwtFromRequestFunction } from './extract-jwt.js';
2
- export { createJwtAuthzModule } from './jwt-authz.module.js';
3
- import 'cookie';
4
- import '@nestjs/core';
5
- import './jwt-authz.interface.js';
6
- import 'crypto';
7
- import 'jsonwebtoken';
8
- import '../utils/types.js';
9
- import '@nestjs/common';
10
- import '@nestjs/common/interfaces';
11
- import 'express';
12
- import '../authz.provider.js';
13
- import 'node:async_hooks';
14
- import '../errors.js';
15
- import './jwt-authz-als.middleware.js';
16
- import '../constants.js';
1
+ export { ExtractJwt, type JwtFromRequestFunction } from './extract-jwt';
2
+ export { createJwtAuthzModule } from './jwt-authz.module';
package/dist/jwt/index.js CHANGED
@@ -1,30 +1,7 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var jwt_exports = {};
19
- __export(jwt_exports, {
20
- ExtractJwt: () => import_extract_jwt.ExtractJwt,
21
- createJwtAuthzModule: () => import_jwt_authz.createJwtAuthzModule
22
- });
23
- module.exports = __toCommonJS(jwt_exports);
24
- var import_extract_jwt = require("./extract-jwt");
25
- var import_jwt_authz = require("./jwt-authz.module");
26
- // Annotate the CommonJS export names for ESM import in node:
27
- 0 && (module.exports = {
28
- ExtractJwt,
29
- createJwtAuthzModule
30
- });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createJwtAuthzModule = exports.ExtractJwt = void 0;
4
+ var extract_jwt_1 = require("./extract-jwt");
5
+ Object.defineProperty(exports, "ExtractJwt", { enumerable: true, get: function () { return extract_jwt_1.ExtractJwt; } });
6
+ var jwt_authz_module_1 = require("./jwt-authz.module");
7
+ Object.defineProperty(exports, "createJwtAuthzModule", { enumerable: true, get: function () { return jwt_authz_module_1.createJwtAuthzModule; } });
@@ -1,17 +1,9 @@
1
- import * as _nestjs_common from '@nestjs/common';
2
1
  import { AsyncLocalStorage } from 'node:async_hooks';
3
- import { Request, Response, NextFunction } from 'express';
4
- import { JwtValidationType } from '../constants.js';
5
- import { CookieOptionsWithSecret } from '../utils/types.js';
6
- import { JwtAuthzOptions } from './jwt-authz.interface.js';
7
- import '@nestjs/common/interfaces';
8
- import '../authz.provider.js';
9
- import 'crypto';
10
- import 'jsonwebtoken';
11
- import './extract-jwt.js';
12
- import 'cookie';
13
-
14
- interface JwtAlsType<U> {
2
+ import type { NextFunction, Request, Response } from 'express';
3
+ import { JwtValidationType } from '../constants';
4
+ import { type CookieOptionsWithSecret } from '../utils';
5
+ import type { JwtAuthzOptions } from './jwt-authz.interface';
6
+ export interface JwtAlsType<U> {
15
7
  user?: U;
16
8
  jwtVerifiedBy?: JwtValidationType;
17
9
  allowAnonymous?: boolean;
@@ -19,10 +11,8 @@ interface JwtAlsType<U> {
19
11
  authOptions: JwtAuthzOptions;
20
12
  setCookie: (name: string, value: string, options?: CookieOptionsWithSecret) => void;
21
13
  }
22
- declare const createJwtAuthzAlsMiddleware: ([ALS_PROVIDER, JWT_AUTHZ_OPTIONS]: [any, any]) => _nestjs_common.Type<Omit<{
14
+ export declare const createJwtAuthzAlsMiddleware: ([ALS_PROVIDER, JWT_AUTHZ_OPTIONS]: [any, any]) => import("@nestjs/common").Type<Omit<{
23
15
  readonly als: AsyncLocalStorage<JwtAlsType<unknown>>;
24
16
  readonly jwtAuthzOptions: JwtAuthzOptions;
25
17
  use(req: Request, res: Response, next: NextFunction): void;
26
18
  }, "als" | "jwtAuthzOptions">>;
27
-
28
- export { type JwtAlsType, createJwtAuthzAlsMiddleware };
@@ -1,66 +1,46 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ 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;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
8
7
  };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
16
10
  };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
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;
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
25
13
  };
26
- var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
27
- var jwt_authz_als_middleware_exports = {};
28
- __export(jwt_authz_als_middleware_exports, {
29
- createJwtAuthzAlsMiddleware: () => createJwtAuthzAlsMiddleware
30
- });
31
- module.exports = __toCommonJS(jwt_authz_als_middleware_exports);
32
- var import_common = require("@nestjs/common");
33
- var import_utils = require("../utils");
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.createJwtAuthzAlsMiddleware = void 0;
16
+ const node_async_hooks_1 = require("node:async_hooks");
17
+ const common_1 = require("@nestjs/common");
18
+ const utils_1 = require("../utils");
34
19
  const createJwtAuthzAlsMiddleware = ([ALS_PROVIDER, JWT_AUTHZ_OPTIONS]) => {
35
- let JwtAuthzAlsMiddleware = class {
36
- constructor(als, jwtAuthzOptions) {
37
- this.als = als;
38
- this.jwtAuthzOptions = jwtAuthzOptions;
39
- }
40
- use(req, res, next) {
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();
20
+ let JwtAuthzAlsMiddleware = class JwtAuthzAlsMiddleware {
21
+ constructor(als, jwtAuthzOptions) {
22
+ this.als = als;
23
+ this.jwtAuthzOptions = jwtAuthzOptions;
53
24
  }
54
- );
55
- }
56
- };
57
- JwtAuthzAlsMiddleware = __decorateClass([
58
- __decorateParam(0, (0, import_common.Inject)(ALS_PROVIDER)),
59
- __decorateParam(1, (0, import_common.Inject)(JWT_AUTHZ_OPTIONS))
60
- ], JwtAuthzAlsMiddleware);
61
- return (0, import_common.mixin)(JwtAuthzAlsMiddleware);
25
+ use(req, res, next) {
26
+ this.als.run({
27
+ user: undefined,
28
+ jwtVerifiedBy: undefined,
29
+ allowAnonymous: undefined,
30
+ guardResult: undefined,
31
+ // a workaround to pass jwtAuthzOptions to passport strategy.
32
+ authOptions: this.jwtAuthzOptions,
33
+ setCookie: (0, utils_1.createSetCookieFn)(req, res)
34
+ }, () => {
35
+ next();
36
+ });
37
+ }
38
+ };
39
+ JwtAuthzAlsMiddleware = __decorate([
40
+ __param(0, (0, common_1.Inject)(ALS_PROVIDER)),
41
+ __param(1, (0, common_1.Inject)(JWT_AUTHZ_OPTIONS)),
42
+ __metadata("design:paramtypes", [node_async_hooks_1.AsyncLocalStorage, Object])
43
+ ], JwtAuthzAlsMiddleware);
44
+ return (0, common_1.mixin)(JwtAuthzAlsMiddleware);
62
45
  };
63
- // Annotate the CommonJS export names for ESM import in node:
64
- 0 && (module.exports = {
65
- createJwtAuthzAlsMiddleware
66
- });
46
+ exports.createJwtAuthzAlsMiddleware = createJwtAuthzAlsMiddleware;
@@ -1,22 +1,11 @@
1
- import * as rxjs from 'rxjs';
2
- import * as _nestjs_common from '@nestjs/common';
1
+ import type { AsyncLocalStorage } from 'node:async_hooks';
3
2
  import { ExecutionContext } from '@nestjs/common';
4
- import { AsyncLocalStorage } from 'node:async_hooks';
5
3
  import { Reflector } from '@nestjs/core';
6
- import { AuthzProviderClass } from '../authz.provider.js';
7
- import { AuthzError } from '../errors.js';
8
- import { JwtAlsType } from './jwt-authz-als.middleware.js';
9
- import { JwtAuthzOptions } from './jwt-authz.interface.js';
10
- import 'express';
11
- import '../constants.js';
12
- import '../utils/types.js';
13
- import '@nestjs/common/interfaces';
14
- import 'crypto';
15
- import 'jsonwebtoken';
16
- import './extract-jwt.js';
17
- import 'cookie';
18
-
19
- declare const createJwtAuthzGuard: ([JWT_STRATEGY, AUTHZ_PROVIDER, JWT_AUTHZ_OPTIONS, ALS_PROVIDER, JWT_META_KEY, JWT_REFRESH_META_KEY]: [string, any, any, any, any, any]) => _nestjs_common.Type<Omit<{
4
+ import { AuthzProviderClass } from '../authz.provider';
5
+ import { type AuthzError } from '../errors';
6
+ import type { JwtAlsType } from './jwt-authz-als.middleware';
7
+ import type { JwtAuthzOptions } from './jwt-authz.interface';
8
+ export declare const createJwtAuthzGuard: ([JWT_STRATEGY, AUTHZ_PROVIDER, JWT_AUTHZ_OPTIONS, ALS_PROVIDER, JWT_META_KEY, JWT_REFRESH_META_KEY]: [string, any, any, any, any, any]) => import("@nestjs/common").Type<Omit<{
20
9
  readonly reflector: Reflector;
21
10
  readonly authzProvider: AuthzProviderClass<unknown, unknown>;
22
11
  readonly jwtAuthzOptions: JwtAuthzOptions;
@@ -43,18 +32,16 @@ declare const createJwtAuthzGuard: ([JWT_STRATEGY, AUTHZ_PROVIDER, JWT_AUTHZ_OPT
43
32
  } = any>(request: TRequest): Promise<void>;
44
33
  getRequest(context: ExecutionContext): any;
45
34
  }, "als" | "jwtAuthzOptions" | "reflector" | "authzProvider">>;
46
- declare const createJwtRefreshAuthzGuard: ([JWT_REFRESH_STRATEGY, JWT_AUTHZ_OPTIONS]: [string, any]) => _nestjs_common.Type<Omit<{
35
+ export declare const createJwtRefreshAuthzGuard: ([JWT_REFRESH_STRATEGY, JWT_AUTHZ_OPTIONS]: [string, any]) => import("@nestjs/common").Type<Omit<{
47
36
  readonly jwtAuthzOptions: JwtAuthzOptions;
48
37
  getAuthenticateOptions(): {
49
38
  property: string;
50
39
  session: boolean;
51
40
  };
52
41
  handleRequest<T>(_err: unknown, user: T, info?: AuthzError): T;
53
- canActivate(context: ExecutionContext): boolean | Promise<boolean> | rxjs.Observable<boolean>;
42
+ canActivate(context: ExecutionContext): boolean | Promise<boolean> | import("rxjs").Observable<boolean>;
54
43
  logIn<TRequest extends {
55
44
  logIn: Function;
56
45
  } = any>(request: TRequest): Promise<void>;
57
46
  getRequest(context: ExecutionContext): any;
58
47
  }, "jwtAuthzOptions">>;
59
-
60
- export { createJwtAuthzGuard, createJwtRefreshAuthzGuard };