@nestjs-kitchen/authz 2.0.3 → 2.0.5

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 +3 -4
  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,156 +1,134 @@
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_guard_exports = {};
28
- __export(jwt_authz_guard_exports, {
29
- createJwtAuthzGuard: () => createJwtAuthzGuard,
30
- createJwtRefreshAuthzGuard: () => createJwtRefreshAuthzGuard
31
- });
32
- module.exports = __toCommonJS(jwt_authz_guard_exports);
33
- var import_common = require("@nestjs/common");
34
- var import_passport = require("@nestjs/passport");
35
- var import_errors = require("../errors");
36
- var import_utils = require("../utils");
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) {
46
- constructor(reflector, authzProvider, jwtAuthzOptions, als) {
47
- super();
48
- this.reflector = reflector;
49
- this.authzProvider = authzProvider;
50
- this.jwtAuthzOptions = jwtAuthzOptions;
51
- this.als = als;
52
- }
53
- getAuthenticateOptions() {
54
- return {
55
- property: this.jwtAuthzOptions.passportProperty,
56
- session: false
57
- };
58
- }
59
- /**
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
- */
70
- handleRequest(_err, user, info) {
71
- const store = (0, import_utils.getAlsStore)(this.als);
72
- if (info) {
73
- if (store.allowAnonymous && info.name === import_errors.AuthzAnonymousError.name) {
74
- return user;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.createJwtRefreshAuthzGuard = exports.createJwtAuthzGuard = void 0;
16
+ const common_1 = require("@nestjs/common");
17
+ const core_1 = require("@nestjs/core");
18
+ const passport_1 = require("@nestjs/passport");
19
+ const authz_provider_1 = require("../authz.provider");
20
+ const errors_1 = require("../errors");
21
+ const utils_1 = require("../utils");
22
+ const createJwtAuthzGuard = ([JWT_STRATEGY, AUTHZ_PROVIDER, JWT_AUTHZ_OPTIONS, ALS_PROVIDER, JWT_META_KEY, JWT_REFRESH_META_KEY]) => {
23
+ let JwtAuthzGuard = class JwtAuthzGuard extends (0, passport_1.AuthGuard)(JWT_STRATEGY) {
24
+ constructor(reflector, authzProvider, jwtAuthzOptions, als) {
25
+ super();
26
+ this.reflector = reflector;
27
+ this.authzProvider = authzProvider;
28
+ this.jwtAuthzOptions = jwtAuthzOptions;
29
+ this.als = als;
75
30
  }
76
- store.guardResult = false;
77
- throw info;
78
- }
79
- return user;
80
- }
81
- async canActivate(context) {
82
- const store = (0, import_utils.getAlsStore)(this.als);
83
- if ((0, import_utils.isNotFalsy)(store.guardResult)) {
84
- return store.guardResult;
85
- }
86
- const jwtRefreshMetaCollection = (0, import_utils.normalizedArray)(
87
- this.reflector.getAll(JWT_REFRESH_META_KEY, [context.getClass(), context.getHandler()])
88
- );
89
- if (Boolean(this.jwtAuthzOptions.refresh) && jwtRefreshMetaCollection.length) {
90
- store.guardResult = true;
91
- return true;
92
- }
93
- const paramsList = (0, import_utils.normalizedArray)(
94
- this.reflector.getAll(JWT_META_KEY, [context.getClass(), context.getHandler()])
95
- );
96
- if (paramsList.length && Boolean(paramsList[paramsList.length - 1].options?.public)) {
97
- store.guardResult = true;
98
- return true;
99
- }
100
- const contextParamsList = (0, import_utils.getContextAuthzMetaParamsList)(paramsList, {
101
- defaultOverride: this.jwtAuthzOptions.defaultOverride,
102
- skipFalsyMetadata: this.jwtAuthzOptions.skipFalsyMetadata
103
- });
104
- const req = context.switchToHttp().getRequest();
105
- store.allowAnonymous = (0, import_utils.getAllowAnonymous)(contextParamsList, {
106
- defaultAllowAnonymous: this.jwtAuthzOptions.defaultAllowAnonymous
107
- });
108
- await super.canActivate(context);
109
- const user = (0, import_utils.getPassportProperty)(req);
110
- if (store.allowAnonymous && !user) {
111
- return true;
112
- }
113
- for (const ele of contextParamsList) {
114
- if (!await this.authzProvider.authorize(user, ele.metaData)) {
115
- return false;
31
+ getAuthenticateOptions() {
32
+ return {
33
+ property: this.jwtAuthzOptions.passportProperty,
34
+ session: false
35
+ };
116
36
  }
117
- }
118
- return true;
119
- }
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))
125
- ], JwtAuthzGuard);
126
- return (0, import_common.mixin)(JwtAuthzGuard);
37
+ /**
38
+ *
39
+ * recives err, user, info from JwtStrategy.validate
40
+ *
41
+ * will return request.user=null if allowAnonymous=true
42
+ *
43
+ * @param _err will always be null
44
+ * @param user if user is null, then info will be AuthError. if user is defined, then info will be undefined.
45
+ * @param info AuthzError or undefined
46
+ * @returns
47
+ */
48
+ handleRequest(_err, user, info) {
49
+ const store = (0, utils_1.getAlsStore)(this.als);
50
+ if (info) {
51
+ if (store.allowAnonymous && info.name === errors_1.AuthzAnonymousError.name) {
52
+ // user is null.
53
+ return user;
54
+ }
55
+ store.guardResult = false;
56
+ throw info;
57
+ }
58
+ return user;
59
+ }
60
+ async canActivate(context) {
61
+ const store = (0, utils_1.getAlsStore)(this.als);
62
+ if ((0, utils_1.isNotFalsy)(store.guardResult)) {
63
+ return store.guardResult;
64
+ }
65
+ const jwtRefreshMetaCollection = (0, utils_1.normalizedArray)(this.reflector.getAll(JWT_REFRESH_META_KEY, [context.getClass(), context.getHandler()]));
66
+ // authz decorator will be ignore when use refresh decorator together.
67
+ if (Boolean(this.jwtAuthzOptions.refresh) && jwtRefreshMetaCollection.length) {
68
+ store.guardResult = true;
69
+ return true;
70
+ }
71
+ const paramsList = (0, utils_1.normalizedArray)(this.reflector.getAll(JWT_META_KEY, [context.getClass(), context.getHandler()]));
72
+ // bypass if last meta is public
73
+ if (paramsList.length && Boolean(paramsList[paramsList.length - 1].options?.public)) {
74
+ store.guardResult = true;
75
+ return true;
76
+ }
77
+ const contextParamsList = (0, utils_1.getContextAuthzMetaParamsList)(paramsList, {
78
+ defaultOverride: this.jwtAuthzOptions.defaultOverride,
79
+ skipFalsyMetadata: this.jwtAuthzOptions.skipFalsyMetadata
80
+ });
81
+ const req = context.switchToHttp().getRequest();
82
+ store.allowAnonymous = (0, utils_1.getAllowAnonymous)(contextParamsList, {
83
+ defaultAllowAnonymous: this.jwtAuthzOptions.defaultAllowAnonymous
84
+ });
85
+ await super.canActivate(context);
86
+ // will be null if allowAnonymous=true.
87
+ const user = (0, utils_1.getPassportProperty)(req);
88
+ if (store.allowAnonymous && !user) {
89
+ return true;
90
+ }
91
+ for (const ele of contextParamsList) {
92
+ if (!(await this.authzProvider.authorize(user, ele.metaData))) {
93
+ return false;
94
+ }
95
+ }
96
+ return true;
97
+ }
98
+ };
99
+ JwtAuthzGuard = __decorate([
100
+ __param(1, (0, common_1.Inject)(AUTHZ_PROVIDER)),
101
+ __param(2, (0, common_1.Inject)(JWT_AUTHZ_OPTIONS)),
102
+ __param(3, (0, common_1.Inject)(ALS_PROVIDER)),
103
+ __metadata("design:paramtypes", [core_1.Reflector,
104
+ authz_provider_1.AuthzProviderClass, Object, Function])
105
+ ], JwtAuthzGuard);
106
+ return (0, common_1.mixin)(JwtAuthzGuard);
127
107
  };
108
+ exports.createJwtAuthzGuard = createJwtAuthzGuard;
128
109
  const createJwtRefreshAuthzGuard = ([JWT_REFRESH_STRATEGY, JWT_AUTHZ_OPTIONS]) => {
129
- let JwtRefreshAuthzGuard = class extends (0, import_passport.AuthGuard)(JWT_REFRESH_STRATEGY) {
130
- constructor(jwtAuthzOptions) {
131
- super();
132
- this.jwtAuthzOptions = jwtAuthzOptions;
133
- }
134
- getAuthenticateOptions() {
135
- return {
136
- property: this.jwtAuthzOptions.passportProperty,
137
- session: false
138
- };
139
- }
140
- handleRequest(_err, user, info) {
141
- if (info) {
142
- throw info;
143
- }
144
- return user;
145
- }
146
- };
147
- JwtRefreshAuthzGuard = __decorateClass([
148
- __decorateParam(0, (0, import_common.Inject)(JWT_AUTHZ_OPTIONS))
149
- ], JwtRefreshAuthzGuard);
150
- return (0, import_common.mixin)(JwtRefreshAuthzGuard);
110
+ let JwtRefreshAuthzGuard = class JwtRefreshAuthzGuard extends (0, passport_1.AuthGuard)(JWT_REFRESH_STRATEGY) {
111
+ constructor(jwtAuthzOptions) {
112
+ super();
113
+ this.jwtAuthzOptions = jwtAuthzOptions;
114
+ }
115
+ getAuthenticateOptions() {
116
+ return {
117
+ property: this.jwtAuthzOptions.passportProperty,
118
+ session: false
119
+ };
120
+ }
121
+ handleRequest(_err, user, info) {
122
+ if (info) {
123
+ throw info;
124
+ }
125
+ return user;
126
+ }
127
+ };
128
+ JwtRefreshAuthzGuard = __decorate([
129
+ __param(0, (0, common_1.Inject)(JWT_AUTHZ_OPTIONS)),
130
+ __metadata("design:paramtypes", [Object])
131
+ ], JwtRefreshAuthzGuard);
132
+ return (0, common_1.mixin)(JwtRefreshAuthzGuard);
151
133
  };
152
- // Annotate the CommonJS export names for ESM import in node:
153
- 0 && (module.exports = {
154
- createJwtAuthzGuard,
155
- createJwtRefreshAuthzGuard
156
- });
134
+ exports.createJwtRefreshAuthzGuard = createJwtRefreshAuthzGuard;
@@ -1,14 +1,7 @@
1
- import * as crypto from 'crypto';
2
- import { VerifyOptions, SignOptions, Secret, PrivateKey, PublicKey } from 'jsonwebtoken';
3
- import { AuthzModuleBaseOptions } from '../utils/types.js';
4
- import { JwtFromRequestFunction } from './extract-jwt.js';
5
- import '@nestjs/common';
6
- import '@nestjs/common/interfaces';
7
- import 'express';
8
- import '../authz.provider.js';
9
- import 'cookie';
10
-
11
- type JwtOptions = Omit<VerifyOptions, 'algorithms' | 'audience' | 'issuer'> & SignOptions & {
1
+ import { type PrivateKey, type PublicKey, type Secret, type SignOptions, type VerifyOptions } from 'jsonwebtoken';
2
+ import { type AuthzModuleBaseOptions } from '../utils';
3
+ import type { JwtFromRequestFunction } from './extract-jwt';
4
+ export type JwtOptions = Omit<VerifyOptions, 'algorithms' | 'audience' | 'issuer'> & SignOptions & {
12
5
  /**
13
6
  * Function that accepts a request as the only parameter and returns either the JWT as a string or null.
14
7
  *
@@ -28,7 +21,7 @@ type JwtOptions = Omit<VerifyOptions, 'algorithms' | 'audience' | 'issuer'> & Si
28
21
  */
29
22
  publicKey?: PublicKey;
30
23
  };
31
- type JwtAuthzModuleOptions = Partial<AuthzModuleBaseOptions> & {
24
+ export type JwtAuthzModuleOptions = Partial<AuthzModuleBaseOptions> & {
32
25
  /**
33
26
  * JWT sign & verify options.
34
27
  *
@@ -44,41 +37,39 @@ type JwtAuthzModuleOptions = Partial<AuthzModuleBaseOptions> & {
44
37
  */
45
38
  refresh?: JwtOptions;
46
39
  };
47
- declare const normalizedJwtAuthzModuleOptions: (options: JwtAuthzModuleOptions) => {
40
+ export declare const normalizedJwtAuthzModuleOptions: (options: JwtAuthzModuleOptions) => {
48
41
  defaultOverride: boolean;
49
42
  passportProperty: string;
50
43
  skipFalsyMetadata: boolean;
51
44
  defaultAllowAnonymous: boolean;
52
45
  jwt: {
53
- secretOrPrivateKey: string | Buffer<ArrayBufferLike> | crypto.KeyObject | {
46
+ secretOrPrivateKey: string | Buffer<ArrayBufferLike> | import("crypto").KeyObject | {
54
47
  key: string | Buffer;
55
48
  passphrase: string;
56
- } | crypto.PrivateKeyInput | crypto.JsonWebKeyInput | null;
57
- secretOrPublicKey: string | Buffer<ArrayBufferLike> | crypto.KeyObject | {
49
+ } | import("crypto").PrivateKeyInput | import("crypto").JsonWebKeyInput | null;
50
+ secretOrPublicKey: string | Buffer<ArrayBufferLike> | import("crypto").KeyObject | {
58
51
  key: string | Buffer;
59
52
  passphrase: string;
60
- } | crypto.JsonWebKeyInput | crypto.PublicKeyInput | null;
53
+ } | import("crypto").JsonWebKeyInput | import("crypto").PublicKeyInput | null;
61
54
  jwtFromRequest: JwtFromRequestFunction<any>[];
62
55
  sign: SignOptions;
63
56
  verify: VerifyOptions;
64
57
  };
65
58
  refresh: {
66
- secretOrPrivateKey: string | Buffer<ArrayBufferLike> | crypto.KeyObject | {
59
+ secretOrPrivateKey: string | Buffer<ArrayBufferLike> | import("crypto").KeyObject | {
67
60
  key: string | Buffer;
68
61
  passphrase: string;
69
- } | crypto.PrivateKeyInput | crypto.JsonWebKeyInput | null;
70
- secretOrPublicKey: string | Buffer<ArrayBufferLike> | crypto.KeyObject | {
62
+ } | import("crypto").PrivateKeyInput | import("crypto").JsonWebKeyInput | null;
63
+ secretOrPublicKey: string | Buffer<ArrayBufferLike> | import("crypto").KeyObject | {
71
64
  key: string | Buffer;
72
65
  passphrase: string;
73
- } | crypto.JsonWebKeyInput | crypto.PublicKeyInput | null;
66
+ } | import("crypto").JsonWebKeyInput | import("crypto").PublicKeyInput | null;
74
67
  jwtFromRequest: JwtFromRequestFunction<any>[];
75
68
  sign: SignOptions;
76
69
  verify: VerifyOptions;
77
70
  } | undefined;
78
71
  };
79
- type JwtAuthzOptions = ReturnType<typeof normalizedJwtAuthzModuleOptions>;
80
- interface RefreshPayload {
72
+ export type JwtAuthzOptions = ReturnType<typeof normalizedJwtAuthzModuleOptions>;
73
+ export interface RefreshPayload {
81
74
  data: string;
82
75
  }
83
-
84
- export { type JwtAuthzModuleOptions, type JwtAuthzOptions, type JwtOptions, type RefreshPayload, normalizedJwtAuthzModuleOptions };
@@ -1,119 +1,71 @@
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_authz_interface_exports = {};
19
- __export(jwt_authz_interface_exports, {
20
- normalizedJwtAuthzModuleOptions: () => normalizedJwtAuthzModuleOptions
21
- });
22
- module.exports = __toCommonJS(jwt_authz_interface_exports);
23
- var import_constants = require("../constants");
24
- var import_utils = require("../utils");
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizedJwtAuthzModuleOptions = void 0;
4
+ const constants_1 = require("../constants");
5
+ const utils_1 = require("../utils");
25
6
  const normalizedJwtOptions = (jwtOptions) => {
26
- if (!jwtOptions) {
27
- return void 0;
28
- }
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;
56
- const formattedJwtFromRequest = (0, import_utils.normalizedArray)(jwtFromRequest);
57
- const algorithms = (0, import_utils.normalizedArray)(algorithm);
58
- const sign = {
59
- algorithm: algorithms?.[0],
60
- audience,
61
- issuer,
62
- jwtid,
63
- subject,
64
- allowInsecureKeySizes,
65
- encoding,
66
- expiresIn,
67
- header,
68
- keyid,
69
- mutatePayload,
70
- notBefore,
71
- noTimestamp,
72
- allowInvalidAsymmetricKeyTypes
73
- };
74
- const verify = {
75
- algorithms,
76
- audience,
77
- clockTimestamp,
78
- clockTolerance,
79
- complete,
80
- ignoreExpiration,
81
- ignoreNotBefore,
82
- issuer,
83
- jwtid,
84
- maxAge,
85
- nonce,
86
- subject,
87
- allowInvalidAsymmetricKeyTypes
88
- };
89
- let secretOrPrivateKey = secret;
90
- let secretOrPublicKey = secret;
91
- if (privateKey || publicKey) {
92
- secretOrPrivateKey = privateKey;
93
- secretOrPublicKey = publicKey;
94
- if (secret) {
95
- console.warn(`Both secret and privateKey/publicKey have been set, only privateKey/publicKey will take effect.`);
7
+ if (!jwtOptions) {
8
+ return undefined;
9
+ }
10
+ 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;
11
+ const formattedJwtFromRequest = (0, utils_1.normalizedArray)(jwtFromRequest);
12
+ const algorithms = (0, utils_1.normalizedArray)(algorithm);
13
+ const sign = {
14
+ algorithm: algorithms?.[0],
15
+ audience,
16
+ issuer,
17
+ jwtid,
18
+ subject,
19
+ allowInsecureKeySizes,
20
+ encoding,
21
+ expiresIn,
22
+ header,
23
+ keyid,
24
+ mutatePayload,
25
+ notBefore,
26
+ noTimestamp,
27
+ allowInvalidAsymmetricKeyTypes
28
+ };
29
+ const verify = {
30
+ algorithms,
31
+ audience,
32
+ clockTimestamp,
33
+ clockTolerance,
34
+ complete,
35
+ ignoreExpiration,
36
+ ignoreNotBefore,
37
+ issuer,
38
+ jwtid,
39
+ maxAge,
40
+ nonce,
41
+ subject,
42
+ allowInvalidAsymmetricKeyTypes
43
+ };
44
+ let secretOrPrivateKey = secret;
45
+ let secretOrPublicKey = secret;
46
+ if (privateKey || publicKey) {
47
+ secretOrPrivateKey = privateKey;
48
+ secretOrPublicKey = publicKey;
49
+ if (secret) {
50
+ console.warn(`Both secret and privateKey/publicKey have been set, only privateKey/publicKey will take effect.`);
51
+ }
96
52
  }
97
- }
98
- return {
99
- secretOrPrivateKey: secretOrPrivateKey ?? null,
100
- secretOrPublicKey: secretOrPublicKey ?? null,
101
- jwtFromRequest: formattedJwtFromRequest ?? [],
102
- sign: (0, import_utils.normalizedObject)(sign) ?? {},
103
- verify: (0, import_utils.normalizedObject)(verify) ?? {}
104
- };
53
+ return {
54
+ secretOrPrivateKey: secretOrPrivateKey ?? null,
55
+ secretOrPublicKey: secretOrPublicKey ?? null,
56
+ jwtFromRequest: formattedJwtFromRequest ?? [],
57
+ sign: (0, utils_1.normalizedObject)(sign) ?? {},
58
+ verify: (0, utils_1.normalizedObject)(verify) ?? {}
59
+ };
105
60
  };
106
61
  const normalizedJwtAuthzModuleOptions = (options) => {
107
- return {
108
- defaultOverride: options?.defaultOverride || false,
109
- passportProperty: options?.passportProperty || import_constants.DEFAULT_PASSPORT_PROPERTY_VALUE,
110
- skipFalsyMetadata: options?.skipFalsyMetadata || false,
111
- defaultAllowAnonymous: options.defaultAllowAnonymous || false,
112
- jwt: normalizedJwtOptions(options?.jwt),
113
- refresh: normalizedJwtOptions(options?.refresh)
114
- };
62
+ return {
63
+ defaultOverride: options?.defaultOverride || false,
64
+ passportProperty: options?.passportProperty || constants_1.DEFAULT_PASSPORT_PROPERTY_VALUE,
65
+ skipFalsyMetadata: options?.skipFalsyMetadata || false,
66
+ defaultAllowAnonymous: options.defaultAllowAnonymous || false,
67
+ jwt: normalizedJwtOptions(options?.jwt),
68
+ refresh: normalizedJwtOptions(options?.refresh)
69
+ };
115
70
  };
116
- // Annotate the CommonJS export names for ESM import in node:
117
- 0 && (module.exports = {
118
- normalizedJwtAuthzModuleOptions
119
- });
71
+ exports.normalizedJwtAuthzModuleOptions = normalizedJwtAuthzModuleOptions;
@@ -1,26 +1,15 @@
1
- import './extract-jwt.js';
2
- import * as _nestjs_core from '@nestjs/core';
3
- import { JwtOptions, JwtAuthzModuleOptions, JwtAuthzOptions } from './jwt-authz.interface.js';
4
- import { AuthzProviderClass } from '../authz.provider.js';
5
- import { AbstractConstructor, RoutesOptions, AuthzModuleBaseOptions, AuthzModuleRoutesOptions, AuthzDecoParams, MethodParameters, ApplyDecorators, CookieOptionsWithSecret, DeepReadonly } from '../utils/types.js';
6
1
  import { AsyncLocalStorage } from 'node:async_hooks';
7
- import * as _nestjs_common from '@nestjs/common';
8
- import { MiddlewareConsumer, Type, DynamicModule } from '@nestjs/common';
9
- import { AuthzError } from '../errors.js';
10
- import { JwtAlsType } from './jwt-authz-als.middleware.js';
11
- import 'cookie';
12
- import 'crypto';
13
- import 'jsonwebtoken';
14
- import '@nestjs/common/interfaces';
15
- import 'express';
16
- import '../constants.js';
17
-
18
- declare const ASYNC_OPTIONS_TYPE: _nestjs_common.ConfigurableModuleAsyncOptions<JwtAuthzModuleOptions, "createJwtAuthzModuleOptions"> & Partial<{
2
+ import { DynamicModule, MiddlewareConsumer, type Type } from '@nestjs/common';
3
+ import { AuthzProviderClass } from '../authz.provider';
4
+ import { AuthzError } from '../errors';
5
+ import { type AbstractConstructor, type ApplyDecorators, type AuthzModuleRoutesOptions, type RoutesOptions } from '../utils';
6
+ import { type JwtAlsType } from './jwt-authz-als.middleware';
7
+ import { type JwtAuthzModuleOptions, type JwtAuthzOptions } from './jwt-authz.interface';
8
+ declare const ASYNC_OPTIONS_TYPE: import("@nestjs/common").ConfigurableModuleAsyncOptions<JwtAuthzModuleOptions, "createJwtAuthzModuleOptions"> & Partial<{
19
9
  authzProvider?: Type<AuthzProviderClass<unknown, unknown>>;
20
- } & AuthzModuleRoutesOptions>;
21
- declare const OPTIONS_TYPE: Partial<AuthzModuleBaseOptions> & {
22
- jwt: JwtOptions;
23
- refresh?: JwtOptions;
10
+ } & AuthzModuleRoutesOptions>, OPTIONS_TYPE: Partial<import("../utils").AuthzModuleBaseOptions> & {
11
+ jwt: import("./jwt-authz.interface").JwtOptions;
12
+ refresh?: import("./jwt-authz.interface").JwtOptions;
24
13
  } & Partial<{
25
14
  authzProvider?: Type<AuthzProviderClass<unknown, unknown>>;
26
15
  } & AuthzModuleRoutesOptions>;
@@ -31,7 +20,7 @@ declare const OPTIONS_TYPE: Partial<AuthzModuleBaseOptions> & {
31
20
  * @param authzProvider - The implementation class of `AuthzProviderClass`
32
21
  * @returns \{AuthzModule, AuthzGuard, AuthzService}
33
22
  */
34
- declare const createJwtAuthzModule: <P, U, T extends AuthzProviderClass<P, U>>(authzProvider: AbstractConstructor<T, P, U>) => {
23
+ export declare const createJwtAuthzModule: <P, U, T extends AuthzProviderClass<P, U>>(authzProvider: AbstractConstructor<T, P, U>) => {
35
24
  /**
36
25
  * A dynamic module used to configure JWT based authentication and authorization features for the application.
37
26
  *
@@ -103,7 +92,7 @@ declare const createJwtAuthzModule: <P, U, T extends AuthzProviderClass<P, U>>(a
103
92
  * ```
104
93
  */
105
94
  AuthzGuard: Type<Omit<{
106
- readonly reflector: _nestjs_core.Reflector;
95
+ readonly reflector: import("@nestjs/core").Reflector;
107
96
  readonly authzProvider: AuthzProviderClass<unknown, unknown>;
108
97
  readonly jwtAuthzOptions: JwtAuthzOptions;
109
98
  readonly als: AsyncLocalStorage<JwtAlsType<unknown>>;
@@ -112,11 +101,11 @@ declare const createJwtAuthzModule: <P, U, T extends AuthzProviderClass<P, U>>(a
112
101
  session: boolean;
113
102
  };
114
103
  handleRequest<T_1>(_err: unknown, user: T_1, info?: AuthzError): T_1;
115
- canActivate(context: _nestjs_common.ExecutionContext): Promise<boolean>;
104
+ canActivate(context: import("@nestjs/common").ExecutionContext): Promise<boolean>;
116
105
  logIn<TRequest extends {
117
106
  logIn: Function;
118
107
  } = any>(request: TRequest): Promise<void>;
119
- getRequest(context: _nestjs_common.ExecutionContext): any;
108
+ getRequest(context: import("@nestjs/common").ExecutionContext): any;
120
109
  }, "als" | "jwtAuthzOptions" | "reflector" | "authzProvider">> & {
121
110
  /**
122
111
  * Verifies the user's authorization for specific meta data.
@@ -135,7 +124,7 @@ declare const createJwtAuthzModule: <P, U, T extends AuthzProviderClass<P, U>>(a
135
124
  * }
136
125
  * ```
137
126
  */
138
- Verify: (...args: AuthzDecoParams<MethodParameters<T, "authorize">[1]>) => ApplyDecorators;
127
+ Verify: (...args: import("../utils").AuthzDecoParams<import("../utils").MethodParameters<T, "authorize">[1]>) => ApplyDecorators;
139
128
  /**
140
129
  * Skips authentication & authorization checks for specific routes.
141
130
  *
@@ -188,7 +177,7 @@ declare const createJwtAuthzModule: <P, U, T extends AuthzProviderClass<P, U>>(a
188
177
  * }
189
178
  * ```
190
179
  */
191
- Apply: (...rest: Parameters<(...args: AuthzDecoParams<MethodParameters<T, "authorize">[1]>) => ApplyDecorators>) => <TFunction extends Function, Y>(target: TFunction | object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
180
+ Apply: (...rest: Parameters<(...args: import("../utils").AuthzDecoParams<import("../utils").MethodParameters<T, "authorize">[1]>) => ApplyDecorators>) => <TFunction extends Function, Y>(target: TFunction | object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
192
181
  };
193
182
  /**
194
183
  * A custom servcie to provide methods to handle authentication and authorization.
@@ -207,9 +196,8 @@ declare const createJwtAuthzModule: <P, U, T extends AuthzProviderClass<P, U>>(a
207
196
  refresh(user?: U | undefined): Promise<{
208
197
  token: string;
209
198
  } | undefined>;
210
- setCookie(name: string, value: string, options?: CookieOptionsWithSecret | undefined): void;
211
- getUser(): DeepReadonly<U> | undefined;
199
+ setCookie(name: string, value: string, options?: import("../utils").CookieOptionsWithSecret | undefined): void;
200
+ getUser(): import("../utils").DeepReadonly<U> | undefined;
212
201
  }, "als" | "jwtAuthzOptions" | "authzProvider">>;
213
202
  };
214
-
215
- export { createJwtAuthzModule };
203
+ export {};