@nestjs-kitchen/authz 1.0.0

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 (66) hide show
  1. package/README.md +0 -0
  2. package/dist/authz.provider.d.ts +7 -0
  3. package/dist/authz.provider.js +34 -0
  4. package/dist/constants.d.ts +11 -0
  5. package/dist/constants.js +46 -0
  6. package/dist/errors.d.ts +12 -0
  7. package/dist/errors.js +60 -0
  8. package/dist/index.d.ts +21 -0
  9. package/dist/index.js +43 -0
  10. package/dist/jwt/extract-jwt.d.ts +71 -0
  11. package/dist/jwt/extract-jwt.js +162 -0
  12. package/dist/jwt/index.d.ts +16 -0
  13. package/dist/jwt/index.js +30 -0
  14. package/dist/jwt/jwt-authz-als.middleware.d.ts +28 -0
  15. package/dist/jwt/jwt-authz-als.middleware.js +83 -0
  16. package/dist/jwt/jwt-authz.guard.d.ts +60 -0
  17. package/dist/jwt/jwt-authz.guard.js +182 -0
  18. package/dist/jwt/jwt-authz.interface.d.ts +58 -0
  19. package/dist/jwt/jwt-authz.interface.js +94 -0
  20. package/dist/jwt/jwt-authz.module.d.ts +80 -0
  21. package/dist/jwt/jwt-authz.module.js +244 -0
  22. package/dist/jwt/jwt-authz.service.d.ts +33 -0
  23. package/dist/jwt/jwt-authz.service.js +144 -0
  24. package/dist/jwt/jwt-authz.strategy.d.ts +40 -0
  25. package/dist/jwt/jwt-authz.strategy.js +194 -0
  26. package/dist/session/index.d.ts +12 -0
  27. package/dist/session/index.js +27 -0
  28. package/dist/session/session-authz-als.middleware.d.ts +25 -0
  29. package/dist/session/session-authz-als.middleware.js +134 -0
  30. package/dist/session/session-authz.guard.d.ts +43 -0
  31. package/dist/session/session-authz.guard.js +142 -0
  32. package/dist/session/session-authz.interface.d.ts +23 -0
  33. package/dist/session/session-authz.interface.js +43 -0
  34. package/dist/session/session-authz.module.d.ts +71 -0
  35. package/dist/session/session-authz.module.js +245 -0
  36. package/dist/session/session-authz.service.d.ts +20 -0
  37. package/dist/session/session-authz.service.js +93 -0
  38. package/dist/session/session-authz.strategy.d.ts +24 -0
  39. package/dist/session/session-authz.strategy.js +107 -0
  40. package/dist/user.decorator.d.ts +6 -0
  41. package/dist/user.decorator.js +36 -0
  42. package/dist/utils/cookie-parsers.d.ts +12 -0
  43. package/dist/utils/cookie-parsers.js +77 -0
  44. package/dist/utils/create-authz-decorator-factory.d.ts +9 -0
  45. package/dist/utils/create-authz-decorator-factory.js +56 -0
  46. package/dist/utils/create-set-cookie-fn.d.ts +9 -0
  47. package/dist/utils/create-set-cookie-fn.js +46 -0
  48. package/dist/utils/generics.d.ts +6 -0
  49. package/dist/utils/generics.js +66 -0
  50. package/dist/utils/get-allow-anonymous.d.ts +11 -0
  51. package/dist/utils/get-allow-anonymous.js +30 -0
  52. package/dist/utils/get-als-store.d.ts +5 -0
  53. package/dist/utils/get-als-store.js +35 -0
  54. package/dist/utils/get-context-authz-meta-params-list.d.ts +12 -0
  55. package/dist/utils/get-context-authz-meta-params-list.js +36 -0
  56. package/dist/utils/get-passport-property.d.ts +3 -0
  57. package/dist/utils/get-passport-property.js +31 -0
  58. package/dist/utils/index.d.ts +16 -0
  59. package/dist/utils/index.js +41 -0
  60. package/dist/utils/merge-dynamic-module-configs.d.ts +5 -0
  61. package/dist/utils/merge-dynamic-module-configs.js +50 -0
  62. package/dist/utils/msgpackrs.d.ts +4 -0
  63. package/dist/utils/msgpackrs.js +37 -0
  64. package/dist/utils/types.d.ts +56 -0
  65. package/dist/utils/types.js +15 -0
  66. package/package.json +68 -0
@@ -0,0 +1,60 @@
1
+ import * as rxjs from 'rxjs';
2
+ import * as _nestjs_common from '@nestjs/common';
3
+ import { ExecutionContext } from '@nestjs/common';
4
+ import { AsyncLocalStorage } from 'node:async_hooks';
5
+ 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<{
20
+ readonly reflector: Reflector;
21
+ readonly authzProvider: AuthzProviderClass<unknown, unknown>;
22
+ readonly jwtAuthzOptions: JwtAuthzOptions;
23
+ readonly als: AsyncLocalStorage<JwtAlsType<unknown>>;
24
+ getAuthenticateOptions(): {
25
+ property: string;
26
+ session: boolean;
27
+ };
28
+ /**
29
+ *
30
+ * recives err, user, info from JwtStrategy.validate
31
+ *
32
+ * will return request.user=null if allowAnonymous=true
33
+ *
34
+ * @param _err will always be null
35
+ * @param user if user is null, then info will be AuthError. if user is defined, then info will be undefined.
36
+ * @param info AuthzError or undefined
37
+ * @returns
38
+ */
39
+ handleRequest<T>(_err: unknown, user: T, info?: AuthzError): T;
40
+ canActivate(context: ExecutionContext): Promise<boolean>;
41
+ logIn<TRequest extends {
42
+ logIn: Function;
43
+ } = any>(request: TRequest): Promise<void>;
44
+ getRequest(context: ExecutionContext): any;
45
+ }, "als" | "jwtAuthzOptions" | "reflector" | "authzProvider">>;
46
+ declare const createJwtRefreshAuthzGuard: ([JWT_REFRESH_STRATEGY, JWT_AUTHZ_OPTIONS]: [string, any]) => _nestjs_common.Type<Omit<{
47
+ readonly jwtAuthzOptions: JwtAuthzOptions;
48
+ getAuthenticateOptions(): {
49
+ property: string;
50
+ session: boolean;
51
+ };
52
+ handleRequest<T>(_err: unknown, user: T, info?: AuthzError): T;
53
+ canActivate(context: ExecutionContext): boolean | Promise<boolean> | rxjs.Observable<boolean>;
54
+ logIn<TRequest extends {
55
+ logIn: Function;
56
+ } = any>(request: TRequest): Promise<void>;
57
+ getRequest(context: ExecutionContext): any;
58
+ }, "jwtAuthzOptions">>;
59
+
60
+ export { createJwtAuthzGuard, createJwtRefreshAuthzGuard };
@@ -0,0 +1,182 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
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
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
21
+ var jwt_authz_guard_exports = {};
22
+ __export(jwt_authz_guard_exports, {
23
+ createJwtAuthzGuard: () => createJwtAuthzGuard,
24
+ createJwtRefreshAuthzGuard: () => createJwtRefreshAuthzGuard
25
+ });
26
+ module.exports = __toCommonJS(jwt_authz_guard_exports);
27
+ var import_common = require("@nestjs/common");
28
+ var import_core = require("@nestjs/core");
29
+ var import_passport = require("@nestjs/passport");
30
+ var import_authz = require("../authz.provider");
31
+ var import_errors = require("../errors");
32
+ 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) {
53
+ constructor(reflector, authzProvider, jwtAuthzOptions, als) {
54
+ 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;
60
+ }
61
+ getAuthenticateOptions() {
62
+ return {
63
+ property: this.jwtAuthzOptions.passportProperty,
64
+ session: false
65
+ };
66
+ }
67
+ /**
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
+ */
78
+ handleRequest(_err, user, info) {
79
+ const store = (0, import_utils.getAlsStore)(this.als);
80
+ if (info) {
81
+ if (store.allowAnonymous && info.name === import_errors.AuthzAnonymousError.name) {
82
+ return user;
83
+ }
84
+ store.guardResult = false;
85
+ throw info;
86
+ }
87
+ return user;
88
+ }
89
+ async canActivate(context) {
90
+ const store = (0, import_utils.getAlsStore)(this.als);
91
+ if ((0, import_utils.isNotFalsy)(store.guardResult)) {
92
+ return store.guardResult;
93
+ }
94
+ const jwtRefreshMetaCollection = (0, import_utils.normalizedArray)(this.reflector.getAll(JWT_REFRESH_META_KEY, [
95
+ context.getClass(),
96
+ context.getHandler()
97
+ ]));
98
+ if (Boolean(this.jwtAuthzOptions.refresh) && jwtRefreshMetaCollection.length) {
99
+ store.guardResult = true;
100
+ return true;
101
+ }
102
+ const paramsList = (0, import_utils.normalizedArray)(this.reflector.getAll(JWT_META_KEY, [
103
+ context.getClass(),
104
+ context.getHandler()
105
+ ]));
106
+ const contextParamsList = (0, import_utils.getContextAuthzMetaParamsList)(paramsList, {
107
+ defaultOverride: this.jwtAuthzOptions.defaultOverride,
108
+ skipFalsyMetadata: this.jwtAuthzOptions.skipFalsyMetadata
109
+ });
110
+ if (!contextParamsList.length) {
111
+ return true;
112
+ }
113
+ const req = context.switchToHttp().getRequest();
114
+ store.allowAnonymous = (0, import_utils.getAllowAnonymous)(contextParamsList, {
115
+ defaultAllowAnonymous: this.jwtAuthzOptions.defaultAllowAnonymous
116
+ });
117
+ await super.canActivate(context);
118
+ if (typeof this.authzProvider.authorize !== "function") {
119
+ store.guardResult = true;
120
+ return true;
121
+ }
122
+ const user = (0, import_utils.getPassportProperty)(req);
123
+ if (!user && store.allowAnonymous) {
124
+ return true;
125
+ }
126
+ for (const ele of contextParamsList) {
127
+ if (!await this.authzProvider.authorize(user, ele.metaData)) {
128
+ return false;
129
+ }
130
+ }
131
+ return true;
132
+ }
133
+ }, __name(_a, "JwtAuthzGuard"), _a);
134
+ JwtAuthzGuard = _ts_decorate([
135
+ _ts_param(1, (0, import_common.Inject)(AUTHZ_PROVIDER)),
136
+ _ts_param(2, (0, import_common.Inject)(JWT_AUTHZ_OPTIONS)),
137
+ _ts_param(3, (0, import_common.Inject)(ALS_PROVIDER)),
138
+ _ts_metadata("design:type", Function),
139
+ _ts_metadata("design:paramtypes", [
140
+ typeof import_core.Reflector === "undefined" ? Object : import_core.Reflector,
141
+ typeof import_authz.AuthzProviderClass === "undefined" ? Object : import_authz.AuthzProviderClass,
142
+ typeof JwtAuthzOptions === "undefined" ? Object : JwtAuthzOptions,
143
+ typeof AsyncLocalStorage === "undefined" ? Object : AsyncLocalStorage
144
+ ])
145
+ ], JwtAuthzGuard);
146
+ return (0, import_common.mixin)(JwtAuthzGuard);
147
+ }, "createJwtAuthzGuard");
148
+ const createJwtRefreshAuthzGuard = /* @__PURE__ */ __name(([JWT_REFRESH_STRATEGY, JWT_AUTHZ_OPTIONS]) => {
149
+ var _a;
150
+ let JwtRefreshAuthzGuard = (_a = class extends (0, import_passport.AuthGuard)(JWT_REFRESH_STRATEGY) {
151
+ constructor(jwtAuthzOptions) {
152
+ super();
153
+ __publicField(this, "jwtAuthzOptions");
154
+ this.jwtAuthzOptions = jwtAuthzOptions;
155
+ }
156
+ getAuthenticateOptions() {
157
+ return {
158
+ property: this.jwtAuthzOptions.passportProperty,
159
+ session: false
160
+ };
161
+ }
162
+ handleRequest(_err, user, info) {
163
+ if (info) {
164
+ throw info;
165
+ }
166
+ return user;
167
+ }
168
+ }, __name(_a, "JwtRefreshAuthzGuard"), _a);
169
+ JwtRefreshAuthzGuard = _ts_decorate([
170
+ _ts_param(0, (0, import_common.Inject)(JWT_AUTHZ_OPTIONS)),
171
+ _ts_metadata("design:type", Function),
172
+ _ts_metadata("design:paramtypes", [
173
+ typeof JwtAuthzOptions === "undefined" ? Object : JwtAuthzOptions
174
+ ])
175
+ ], JwtRefreshAuthzGuard);
176
+ return (0, import_common.mixin)(JwtRefreshAuthzGuard);
177
+ }, "createJwtRefreshAuthzGuard");
178
+ // Annotate the CommonJS export names for ESM import in node:
179
+ 0 && (module.exports = {
180
+ createJwtAuthzGuard,
181
+ createJwtRefreshAuthzGuard
182
+ });
@@ -0,0 +1,58 @@
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 & {
12
+ jwtFromRequest: JwtFromRequestFunction | JwtFromRequestFunction[];
13
+ secret?: Secret;
14
+ privateKey?: PrivateKey;
15
+ publicKey?: PublicKey;
16
+ };
17
+ type JwtAuthzModuleOptions = Partial<AuthzModuleBaseOptions> & {
18
+ jwt: JwtOptions;
19
+ refresh?: JwtOptions;
20
+ };
21
+ declare const normalizedJwtAuthzModuleOptions: (options: JwtAuthzModuleOptions) => {
22
+ defaultOverride: boolean;
23
+ passportProperty: string;
24
+ skipFalsyMetadata: boolean;
25
+ defaultAllowAnonymous: boolean;
26
+ jwt: {
27
+ secretOrPrivateKey: string | Buffer<ArrayBufferLike> | crypto.KeyObject | {
28
+ key: string | Buffer;
29
+ passphrase: string;
30
+ } | crypto.PrivateKeyInput | crypto.JsonWebKeyInput | null;
31
+ secretOrPublicKey: string | Buffer<ArrayBufferLike> | crypto.KeyObject | {
32
+ key: string | Buffer;
33
+ passphrase: string;
34
+ } | crypto.JsonWebKeyInput | crypto.PublicKeyInput | null;
35
+ jwtFromRequest: JwtFromRequestFunction<any>[];
36
+ sign: SignOptions;
37
+ verify: VerifyOptions;
38
+ };
39
+ refresh: {
40
+ secretOrPrivateKey: string | Buffer<ArrayBufferLike> | crypto.KeyObject | {
41
+ key: string | Buffer;
42
+ passphrase: string;
43
+ } | crypto.PrivateKeyInput | crypto.JsonWebKeyInput | null;
44
+ secretOrPublicKey: string | Buffer<ArrayBufferLike> | crypto.KeyObject | {
45
+ key: string | Buffer;
46
+ passphrase: string;
47
+ } | crypto.JsonWebKeyInput | crypto.PublicKeyInput | null;
48
+ jwtFromRequest: JwtFromRequestFunction<any>[];
49
+ sign: SignOptions;
50
+ verify: VerifyOptions;
51
+ } | undefined;
52
+ };
53
+ type JwtAuthzOptions = ReturnType<typeof normalizedJwtAuthzModuleOptions>;
54
+ interface RefreshPayload {
55
+ data: string;
56
+ }
57
+
58
+ export { type JwtAuthzModuleOptions, type JwtAuthzOptions, type JwtOptions, type RefreshPayload, normalizedJwtAuthzModuleOptions };
@@ -0,0 +1,94 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var jwt_authz_interface_exports = {};
20
+ __export(jwt_authz_interface_exports, {
21
+ normalizedJwtAuthzModuleOptions: () => normalizedJwtAuthzModuleOptions
22
+ });
23
+ module.exports = __toCommonJS(jwt_authz_interface_exports);
24
+ var import_constants = require("../constants");
25
+ var import_utils = require("../utils");
26
+ const normalizedJwtOptions = /* @__PURE__ */ __name((jwtOptions) => {
27
+ if (!jwtOptions) {
28
+ return void 0;
29
+ }
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;
31
+ const formattedJwtFromRequest = (0, import_utils.normalizedArray)(jwtFromRequest);
32
+ const algorithms = (0, import_utils.normalizedArray)(algorithm);
33
+ const sign = {
34
+ algorithm: algorithms?.[0],
35
+ audience,
36
+ issuer,
37
+ jwtid,
38
+ subject,
39
+ allowInsecureKeySizes,
40
+ encoding,
41
+ expiresIn,
42
+ header,
43
+ keyid,
44
+ mutatePayload,
45
+ notBefore,
46
+ noTimestamp,
47
+ allowInvalidAsymmetricKeyTypes
48
+ };
49
+ const verify = {
50
+ algorithms,
51
+ audience,
52
+ clockTimestamp,
53
+ clockTolerance,
54
+ complete,
55
+ ignoreExpiration,
56
+ ignoreNotBefore,
57
+ issuer,
58
+ jwtid,
59
+ maxAge,
60
+ nonce,
61
+ subject,
62
+ allowInvalidAsymmetricKeyTypes
63
+ };
64
+ let secretOrPrivateKey = secret;
65
+ let secretOrPublicKey = secret;
66
+ if (privateKey || publicKey) {
67
+ secretOrPrivateKey = privateKey;
68
+ secretOrPublicKey = publicKey;
69
+ if (secret) {
70
+ console.warn(`Both secret and privateKey/publicKey have been set, only privateKey/publicKey will take effect.`);
71
+ }
72
+ }
73
+ return {
74
+ secretOrPrivateKey: secretOrPrivateKey ?? null,
75
+ secretOrPublicKey: secretOrPublicKey ?? null,
76
+ jwtFromRequest: formattedJwtFromRequest ?? [],
77
+ sign: (0, import_utils.normalizedObject)(sign) ?? {},
78
+ verify: (0, import_utils.normalizedObject)(verify) ?? {}
79
+ };
80
+ }, "normalizedJwtOptions");
81
+ const normalizedJwtAuthzModuleOptions = /* @__PURE__ */ __name((options) => {
82
+ return {
83
+ defaultOverride: options?.defaultOverride || false,
84
+ passportProperty: options?.passportProperty || import_constants.DEFAULT_PASSPORT_PROPERTY_VALUE,
85
+ skipFalsyMetadata: options?.skipFalsyMetadata || false,
86
+ defaultAllowAnonymous: options.defaultAllowAnonymous || false,
87
+ jwt: normalizedJwtOptions(options?.jwt),
88
+ refresh: normalizedJwtOptions(options?.refresh)
89
+ };
90
+ }, "normalizedJwtAuthzModuleOptions");
91
+ // Annotate the CommonJS export names for ESM import in node:
92
+ 0 && (module.exports = {
93
+ normalizedJwtAuthzModuleOptions
94
+ });
@@ -0,0 +1,80 @@
1
+ import './extract-jwt.js';
2
+ import * as _nestjs_core from '@nestjs/core';
3
+ import { JwtAuthzOptions, JwtAuthzModuleOptions, JwtOptions } from './jwt-authz.interface.js';
4
+ import { AuthzProviderClass } from '../authz.provider.js';
5
+ import { AbstractConstructor, RoutesOptions, AuthzDecoParams, MethodParameters, ApplyDecorators, CookieOptionsWithSecret, AuthzModuleRoutesOptions, AuthzModuleBaseOptions } from '../utils/types.js';
6
+ import { AsyncLocalStorage } from 'node:async_hooks';
7
+ import * as _nestjs_common from '@nestjs/common';
8
+ import { MiddlewareConsumer, DynamicModule, Type } 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<{
19
+ authzProvider?: Type<AuthzProviderClass<unknown, unknown>>;
20
+ } & AuthzModuleRoutesOptions>;
21
+ declare const OPTIONS_TYPE: Partial<AuthzModuleBaseOptions> & {
22
+ jwt: JwtOptions;
23
+ refresh?: JwtOptions;
24
+ } & Partial<{
25
+ authzProvider?: Type<AuthzProviderClass<unknown, unknown>>;
26
+ } & AuthzModuleRoutesOptions>;
27
+ declare const createJwtAuthzModule: <P, U, T extends AuthzProviderClass<P, U>>(authzProvider: AbstractConstructor<T, P, U>) => {
28
+ AuthzModule: {
29
+ new (routesOpt: RoutesOptions): {
30
+ [x: string]: any;
31
+ readonly routesOpt: RoutesOptions;
32
+ configure(consumer: MiddlewareConsumer): void;
33
+ };
34
+ register(options: Omit<typeof OPTIONS_TYPE, "authzProvider">): DynamicModule;
35
+ registerAsync(options: Omit<typeof ASYNC_OPTIONS_TYPE, "authzProvider">): DynamicModule;
36
+ };
37
+ AuthzGuard: Type<Omit<{
38
+ readonly reflector: _nestjs_core.Reflector;
39
+ readonly authzProvider: AuthzProviderClass<unknown, unknown>;
40
+ readonly jwtAuthzOptions: JwtAuthzOptions;
41
+ readonly als: AsyncLocalStorage<JwtAlsType<unknown>>;
42
+ getAuthenticateOptions(): {
43
+ property: string;
44
+ session: boolean;
45
+ };
46
+ handleRequest<T_1>(_err: unknown, user: T_1, info?: AuthzError): T_1;
47
+ canActivate(context: _nestjs_common.ExecutionContext): Promise<boolean>;
48
+ logIn<TRequest extends {
49
+ logIn: Function;
50
+ } = any>(request: TRequest): Promise<void>;
51
+ getRequest(context: _nestjs_common.ExecutionContext): any;
52
+ }, "als" | "jwtAuthzOptions" | "reflector" | "authzProvider">> & {
53
+ Verify: (...args: AuthzDecoParams<MethodParameters<T, "authorize">[1]>) => ApplyDecorators;
54
+ NoVerify: () => MethodDecorator & ClassDecorator;
55
+ /**
56
+ * take highest priority
57
+ */
58
+ Refresh: () => MethodDecorator & ClassDecorator;
59
+ Apply: (...rest: Parameters<(...args: AuthzDecoParams<MethodParameters<T, "authorize">[1]>) => ApplyDecorators>) => <TFunction extends Function, Y>(target: TFunction | object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
60
+ };
61
+ AuthzService: Type<Omit<{
62
+ readonly authzProvider: AuthzProviderClass<P, U>;
63
+ readonly jwtAuthzOptions: JwtAuthzOptions;
64
+ readonly als: AsyncLocalStorage<JwtAlsType<U>>;
65
+ logIn(user: U): Promise<{
66
+ token: string;
67
+ refresh: string;
68
+ } | {
69
+ token: string;
70
+ refresh?: undefined;
71
+ }>;
72
+ refresh(user?: U | undefined): Promise<{
73
+ token: string;
74
+ } | undefined>;
75
+ setCookie(name: string, value: string, options?: CookieOptionsWithSecret | undefined): void;
76
+ getUser(): U | undefined;
77
+ }, "als" | "jwtAuthzOptions" | "authzProvider">>;
78
+ };
79
+
80
+ export { createJwtAuthzModule };