@vercube/auth 1.3.0 → 1.3.1

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/dist/index.d.mts CHANGED
@@ -86,8 +86,6 @@ export declare function User(params?: UserDecoratorOptions): Function;
86
86
  */
87
87
  export declare class AuthMiddleware implements BaseMiddleware<AuthTypes.MiddlewareOptions> {
88
88
  private gContainer;
89
- private gLogger;
90
- private gAuthProvider;
91
89
  /**
92
90
  * Middleware function that processes the HTTP event.
93
91
  *
@@ -95,6 +93,8 @@ export declare class AuthMiddleware implements BaseMiddleware<AuthTypes.Middlewa
95
93
  * @param {Response} response - The HTTP response to be processed
96
94
  * @param {MiddlewareOptions} args - Additional arguments for the middleware
97
95
  * @returns {Promise<void>} - A promise that resolves when the processing is complete.
96
+ * @throws {InternalServerError} - If the auth provider is not registered in the container
97
+ * @throws {UnauthorizedError} - If authentication fails
98
98
  */
99
99
  onRequest(request: Request, response: Response, args: MiddlewareOptions<AuthTypes.MiddlewareOptions>): Promise<void>;
100
100
  }
package/dist/index.mjs CHANGED
@@ -1,6 +1,5 @@
1
- import { UnauthorizedError, addMetadataMiddleware, initializeMetadata, initializeMetadataMethod, setMetadataArg } from "@vercube/core";
2
- import { BaseDecorator, Container, Inject, InjectOptional, createDecorator } from "@vercube/di";
3
- import { Logger } from "@vercube/logger";
1
+ import { InternalServerError, UnauthorizedError, addMetadataMiddleware, initializeMetadata, initializeMetadataMethod, setMetadataArg } from "@vercube/core";
2
+ import { BaseDecorator, Container, Inject, createDecorator } from "@vercube/di";
4
3
  import { ValueType, createInstrument } from "@vercube/telemetry/instrument";
5
4
  //#region src/Services/AuthProvider.ts
6
5
  var AuthProvider = class {};
@@ -52,8 +51,6 @@ function recordOutcome(outcome) {
52
51
  */
53
52
  var AuthMiddleware = class {
54
53
  gContainer;
55
- gLogger;
56
- gAuthProvider;
57
54
  /**
58
55
  * Middleware function that processes the HTTP event.
59
56
  *
@@ -61,14 +58,15 @@ var AuthMiddleware = class {
61
58
  * @param {Response} response - The HTTP response to be processed
62
59
  * @param {MiddlewareOptions} args - Additional arguments for the middleware
63
60
  * @returns {Promise<void>} - A promise that resolves when the processing is complete.
61
+ * @throws {InternalServerError} - If the auth provider is not registered in the container
62
+ * @throws {UnauthorizedError} - If authentication fails
64
63
  */
65
64
  async onRequest(request, response, args) {
66
- let provider = this.gAuthProvider;
67
- if (args?.middlewareArgs?.provider) provider = this.gContainer.getOptional(args.middlewareArgs.provider);
65
+ const providerKey = args?.middlewareArgs?.provider ?? AuthProvider;
66
+ const provider = this.gContainer.getOptional(providerKey);
68
67
  if (!provider) {
69
- this.gLogger?.warn("AuthMiddleware::AuthProvider is not registered");
70
68
  recordOutcome("unconfigured");
71
- return;
69
+ throw new InternalServerError(`AuthMiddleware: auth provider "${providerKey.name}" is not registered in the container`);
72
70
  }
73
71
  const authenticationError = await provider.validate(request, args.middlewareArgs);
74
72
  if (authenticationError) {
@@ -79,8 +77,6 @@ var AuthMiddleware = class {
79
77
  }
80
78
  };
81
79
  __decorate([Inject(Container)], AuthMiddleware.prototype, "gContainer", void 0);
82
- __decorate([InjectOptional(Logger)], AuthMiddleware.prototype, "gLogger", void 0);
83
- __decorate([InjectOptional(AuthProvider)], AuthMiddleware.prototype, "gAuthProvider", void 0);
84
80
  //#endregion
85
81
  //#region src/Decorators/Auth.ts
86
82
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercube/auth",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "description": "Auth module for Vercube framework",
5
5
  "repository": {
6
6
  "type": "git",
@@ -22,10 +22,10 @@
22
22
  "README.md"
23
23
  ],
24
24
  "dependencies": {
25
- "@vercube/core": "1.3.0",
26
- "@vercube/di": "1.3.0",
27
- "@vercube/logger": "1.3.0",
28
- "@vercube/telemetry": "1.3.0"
25
+ "@vercube/core": "1.3.1",
26
+ "@vercube/di": "1.3.1",
27
+ "@vercube/logger": "1.3.1",
28
+ "@vercube/telemetry": "1.3.1"
29
29
  },
30
30
  "publishConfig": {
31
31
  "access": "public"