@nestjs-kitchen/authz 2.0.7 → 3.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.
package/README.md CHANGED
@@ -31,6 +31,22 @@ Once completed NestJS project setup, install this package and its dependencies:
31
31
  $ npm install --save @nestjs/passport passport @nestjs-kitchen/authz
32
32
  ```
33
33
 
34
+ ## Beark change
35
+
36
+ - From `@nestjs-kitchen/authz` **v3**, [`express-session`](https://www.npmjs.com/package/express-session) had been removed from dependency. Please setup session manually:
37
+
38
+ ```typescript
39
+ import * as session from 'express-session';
40
+ // somewhere in your initialization file
41
+ app.use(
42
+ session({
43
+ secret: 'my-secret',
44
+ resave: false,
45
+ saveUninitialized: false,
46
+ }),
47
+ );
48
+ ```
49
+
34
50
  ## Usage
35
51
 
36
52
  1. Create file `authz.provider.ts`:
@@ -1,13 +1,6 @@
1
- import session from 'express-session';
2
1
  import type { AuthzModuleBaseOptions } from '../utils';
3
- export type SessionOptions = Parameters<typeof session>[0];
4
2
  export type SessionAuthzModuleOptions = Partial<AuthzModuleBaseOptions> & {
5
- /**
6
- * Session options.
7
- *
8
- * Same as `express-session` [session options](https://www.npmjs.com/package/express-session#options).
9
- */
10
- session: SessionOptions & {
3
+ session?: {
11
4
  /**
12
5
  * Option to keep session information after regenerating.
13
6
  *
@@ -22,6 +15,5 @@ export declare const normalizedSessionAuthzModuleOptions: (options?: Partial<Ses
22
15
  skipFalsyMetadata: boolean;
23
16
  defaultAllowAnonymous: boolean;
24
17
  keepSessionInfo: boolean | undefined;
25
- session: SessionOptions;
26
18
  };
27
19
  export type SessionAuthzOptions = ReturnType<typeof normalizedSessionAuthzModuleOptions>;
@@ -3,18 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.normalizedSessionAuthzModuleOptions = void 0;
4
4
  const constants_1 = require("../constants");
5
5
  const normalizedSessionAuthzModuleOptions = (options = {}) => {
6
- const { keepSessionInfo, ...sessionOpts } = options.session ?? {};
6
+ const { keepSessionInfo } = options.session ?? {};
7
7
  return {
8
8
  defaultOverride: options.defaultOverride || false,
9
9
  passportProperty: options.passportProperty || constants_1.DEFAULT_PASSPORT_PROPERTY_VALUE,
10
10
  skipFalsyMetadata: options.skipFalsyMetadata || false,
11
11
  defaultAllowAnonymous: options.defaultAllowAnonymous || false,
12
- keepSessionInfo,
13
- session: {
14
- resave: false,
15
- saveUninitialized: false,
16
- ...sessionOpts
17
- }
12
+ keepSessionInfo
18
13
  };
19
14
  };
20
15
  exports.normalizedSessionAuthzModuleOptions = normalizedSessionAuthzModuleOptions;
@@ -5,11 +5,11 @@ import { AuthzProviderClass } from '../authz.provider';
5
5
  import { AuthzError } from '../errors';
6
6
  import { type AbstractConstructor, type ApplyDecorators, type AuthzDecoParams, type AuthzModuleBaseOptions, type AuthzModuleRoutesOptions, type CookieOptionsWithSecret, type DeepReadonly, type MethodParameters, type RoutesOptions } from '../utils';
7
7
  import { type SessionAlsType } from './session-authz-als.middleware';
8
- import { type SessionAuthzModuleOptions, type SessionAuthzOptions, type SessionOptions } from './session-authz.interface';
8
+ import { type SessionAuthzModuleOptions, type SessionAuthzOptions } from './session-authz.interface';
9
9
  declare const ASYNC_OPTIONS_TYPE: ConfigurableModuleAsyncOptions<SessionAuthzModuleOptions, "createSessionAuthzModuleOptions"> & Partial<{
10
10
  authzProvider?: Type<AuthzProviderClass<unknown, unknown>>;
11
11
  } & AuthzModuleRoutesOptions>, OPTIONS_TYPE: Partial<AuthzModuleBaseOptions> & {
12
- session: SessionOptions & {
12
+ session?: {
13
13
  keepSessionInfo?: boolean;
14
14
  };
15
15
  } & Partial<{
@@ -61,13 +61,11 @@ export declare const cereateSessionAuthzModule: <P, U, T extends AuthzProviderCl
61
61
  /**
62
62
  * Configures authz module.
63
63
  *
64
- * Note: DO NOT register the same routes in multiple session authz modules, or import the same session authz module in the same module multiple times, express-session middleware will not work properly.
65
64
  */
66
65
  register(options: Omit<typeof OPTIONS_TYPE, "authzProvider">): DynamicModule;
67
66
  /**
68
67
  * Configures authz module asynchronously.
69
68
  *
70
- * Note: DO NOT register the same routes in multiple session authz modules, express-session middleware will not work properly.
71
69
  */
72
70
  registerAsync(options: typeof ASYNC_OPTIONS_TYPE): DynamicModule;
73
71
  };
@@ -11,14 +11,10 @@ var __metadata = (this && this.__metadata) || function (k, v) {
11
11
  var __param = (this && this.__param) || function (paramIndex, decorator) {
12
12
  return function (target, key) { decorator(target, key, paramIndex); }
13
13
  };
14
- var __importDefault = (this && this.__importDefault) || function (mod) {
15
- return (mod && mod.__esModule) ? mod : { "default": mod };
16
- };
17
14
  Object.defineProperty(exports, "__esModule", { value: true });
18
15
  exports.cereateSessionAuthzModule = void 0;
19
16
  const node_async_hooks_1 = require("node:async_hooks");
20
17
  const common_1 = require("@nestjs/common");
21
- const express_session_1 = __importDefault(require("express-session"));
22
18
  const uid_1 = require("uid");
23
19
  const constants_1 = require("../constants");
24
20
  const errors_1 = require("../errors");
@@ -141,7 +137,6 @@ const cereateSessionAuthzModule = (authzProvider) => {
141
137
  /**
142
138
  * Configures authz module.
143
139
  *
144
- * Note: DO NOT register the same routes in multiple session authz modules, or import the same session authz module in the same module multiple times, express-session middleware will not work properly.
145
140
  */
146
141
  static register(options) {
147
142
  const sessionAuthzOptions = (0, session_authz_interface_1.normalizedSessionAuthzModuleOptions)(options);
@@ -157,7 +152,6 @@ const cereateSessionAuthzModule = (authzProvider) => {
157
152
  /**
158
153
  * Configures authz module asynchronously.
159
154
  *
160
- * Note: DO NOT register the same routes in multiple session authz modules, express-session middleware will not work properly.
161
155
  */
162
156
  static registerAsync(options) {
163
157
  return (0, utils_1.mergeDynamicModuleConfigs)(super.registerAsync({ ...options, authzProvider }), getCommonConfigs(), {
@@ -179,7 +173,7 @@ const cereateSessionAuthzModule = (authzProvider) => {
179
173
  }
180
174
  configure(consumer) {
181
175
  consumer
182
- .apply((0, express_session_1.default)(this.sessionAuthzOptions.session), SessionAuthzAlsMiddleware)
176
+ .apply(SessionAuthzAlsMiddleware)
183
177
  .exclude(...this.routesOpt.excludes)
184
178
  // nestjs v11 will be compatible with splat wildcard.
185
179
  .forRoutes(...(this.routesOpt.global ? ['*'] : this.routesOpt.routes));
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@nestjs-kitchen/authz",
3
3
  "private": false,
4
4
  "description": "Simplest authentication & authorization module in NextJS",
5
- "version": "2.0.7",
5
+ "version": "3.0.0",
6
6
  "homepage": "https://github.com/yikenman/nestjs-kitchen",
7
7
  "repository": "https://github.com/yikenman/nestjs-kitchen",
8
8
  "author": "yikenman",
@@ -20,7 +20,6 @@
20
20
  "dependencies": {
21
21
  "cookie": "^1.0.2",
22
22
  "cookie-parser": "^1.4.7",
23
- "express-session": "^1.18.1",
24
23
  "jsonwebtoken": "^9.0.2",
25
24
  "msgpackr": "^1.11.2",
26
25
  "passport-custom": "^1.1.1",
@@ -36,6 +35,7 @@
36
35
  "@types/node": "^22.13.9",
37
36
  "@types/passport": "^1.0.17",
38
37
  "@types/supertest": "^6.0.2",
38
+ "express-session": "^1.18.1",
39
39
  "jest": "^29.7.0",
40
40
  "rimraf": "^6.0.1",
41
41
  "supertest": "^7.1.0",