@nest-boot/auth 7.3.0 → 7.4.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/dist/auth-module-options.interface.d.ts +1 -0
- package/dist/auth.middleware.js +25 -20
- package/dist/auth.middleware.js.map +1 -1
- package/dist/auth.module-definition.d.ts +1 -3
- package/dist/auth.module-definition.js +1 -6
- package/dist/auth.module-definition.js.map +1 -1
- package/dist/auth.module.d.ts +5 -8
- package/dist/auth.module.js +35 -31
- package/dist/auth.module.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +2 -4
- package/dist/auth.interceptor.d.ts +0 -17
- package/dist/auth.interceptor.js +0 -91
- package/dist/auth.interceptor.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nest-boot/auth",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.4.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "d4rkcr0w <me@d4rkcr0w.com>",
|
|
6
6
|
"homepage": "",
|
|
@@ -15,10 +15,9 @@
|
|
|
15
15
|
],
|
|
16
16
|
"devDependencies": {
|
|
17
17
|
"@mikro-orm/core": "^6.5.8",
|
|
18
|
-
"@mikro-orm/postgresql": "^6.5.8",
|
|
19
18
|
"@nest-boot/eslint-config": "^7.0.0",
|
|
20
19
|
"@nest-boot/eslint-plugin": "^7.0.0",
|
|
21
|
-
"@nest-boot/request-context": "^7.
|
|
20
|
+
"@nest-boot/request-context": "^7.2.0",
|
|
22
21
|
"@nest-boot/tsconfig": "^7.0.0",
|
|
23
22
|
"@nestjs/common": "^11.1.6",
|
|
24
23
|
"@nestjs/config": "^4.0.2",
|
|
@@ -37,7 +36,6 @@
|
|
|
37
36
|
},
|
|
38
37
|
"peerDependencies": {
|
|
39
38
|
"@mikro-orm/core": "^6.0.0",
|
|
40
|
-
"@mikro-orm/postgresql": "^6.0.0",
|
|
41
39
|
"@nest-boot/request-context": "^7.0.0",
|
|
42
40
|
"@nestjs/common": "^11.0.0",
|
|
43
41
|
"@nestjs/core": "^11.0.0",
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { EntityManager } from "@mikro-orm/core";
|
|
2
|
-
import { type CallHandler, type ExecutionContext, type NestInterceptor } from "@nestjs/common";
|
|
3
|
-
import { Request, Response } from "express";
|
|
4
|
-
import { AuthTransactionContext } from "./auth.transaction-context";
|
|
5
|
-
export declare class AuthInterceptor implements NestInterceptor {
|
|
6
|
-
protected readonly em: EntityManager;
|
|
7
|
-
constructor(em: EntityManager);
|
|
8
|
-
getRequest(context: ExecutionContext): Promise<Request>;
|
|
9
|
-
getResponse(context: ExecutionContext): Promise<Response>;
|
|
10
|
-
/**
|
|
11
|
-
* 扩展事务上下文
|
|
12
|
-
* 子类可以重写此方法来添加自定义的上下文信息
|
|
13
|
-
*/
|
|
14
|
-
extendTransactionContext(transactionContext: AuthTransactionContext, executionContext: ExecutionContext): void | Promise<void>;
|
|
15
|
-
private setTransactionAuthContext;
|
|
16
|
-
intercept<T>(executionContext: ExecutionContext, next: CallHandler<T>): import("rxjs").Observable<T>;
|
|
17
|
-
}
|
package/dist/auth.interceptor.js
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
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;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.AuthInterceptor = void 0;
|
|
13
|
-
const core_1 = require("@mikro-orm/core");
|
|
14
|
-
const request_context_1 = require("@nest-boot/request-context");
|
|
15
|
-
const common_1 = require("@nestjs/common");
|
|
16
|
-
const rxjs_1 = require("rxjs");
|
|
17
|
-
const auth_transaction_context_1 = require("./auth.transaction-context");
|
|
18
|
-
let AuthInterceptor = class AuthInterceptor {
|
|
19
|
-
constructor(em) {
|
|
20
|
-
this.em = em;
|
|
21
|
-
}
|
|
22
|
-
async getRequest(context) {
|
|
23
|
-
if (context.getType() === "graphql") {
|
|
24
|
-
return context.getArgByIndex(2).req;
|
|
25
|
-
}
|
|
26
|
-
return await context.switchToHttp().getRequest();
|
|
27
|
-
}
|
|
28
|
-
async getResponse(context) {
|
|
29
|
-
if (context.getType() === "graphql") {
|
|
30
|
-
return context.getArgByIndex(2).req.res;
|
|
31
|
-
}
|
|
32
|
-
return await context.switchToHttp().getResponse();
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* 扩展事务上下文
|
|
36
|
-
* 子类可以重写此方法来添加自定义的上下文信息
|
|
37
|
-
*/
|
|
38
|
-
extendTransactionContext(
|
|
39
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
40
|
-
transactionContext,
|
|
41
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
42
|
-
executionContext) {
|
|
43
|
-
//
|
|
44
|
-
}
|
|
45
|
-
async setTransactionAuthContext(executionContext, knex) {
|
|
46
|
-
if (!knex) {
|
|
47
|
-
throw new Error("Knex is not found in transaction context");
|
|
48
|
-
}
|
|
49
|
-
const res = await this.getResponse(executionContext);
|
|
50
|
-
const user = res.locals.user;
|
|
51
|
-
const session = res.locals.session;
|
|
52
|
-
if (user && session) {
|
|
53
|
-
const transactionContext = new auth_transaction_context_1.AuthTransactionContext()
|
|
54
|
-
.set("user_id", user.id)
|
|
55
|
-
.set("user_name", user.name)
|
|
56
|
-
.set("user_email", user.email)
|
|
57
|
-
.set("session_id", session.id)
|
|
58
|
-
.set("session_token", session.token)
|
|
59
|
-
.set("session_expires_at", session.expiresAt.toISOString())
|
|
60
|
-
.set("session_ip_address", session.ipAddress ?? "")
|
|
61
|
-
.set("session_user_agent", session.userAgent ?? "");
|
|
62
|
-
await this.extendTransactionContext(transactionContext, executionContext);
|
|
63
|
-
await knex.raw([
|
|
64
|
-
/* SQL */ `SET LOCAL ROLE authenticated;`,
|
|
65
|
-
transactionContext.toSQL(),
|
|
66
|
-
].join("\n"));
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
await knex.raw(/* SQL */ `SET LOCAL ROLE anonymous;`);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
intercept(executionContext, next) {
|
|
73
|
-
const knex = this.em.getTransactionContext();
|
|
74
|
-
if (knex) {
|
|
75
|
-
return (0, rxjs_1.from)(this.setTransactionAuthContext(executionContext, knex)).pipe((0, rxjs_1.concatMap)(() => next.handle()));
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
return (0, rxjs_1.from)(request_context_1.RequestContext.child(() => this.em.transactional(async (em) => {
|
|
79
|
-
request_context_1.RequestContext.set(core_1.EntityManager, em);
|
|
80
|
-
await this.setTransactionAuthContext(executionContext, em.getTransactionContext());
|
|
81
|
-
return await (0, rxjs_1.lastValueFrom)(next.handle());
|
|
82
|
-
})));
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
exports.AuthInterceptor = AuthInterceptor;
|
|
87
|
-
exports.AuthInterceptor = AuthInterceptor = __decorate([
|
|
88
|
-
(0, common_1.Injectable)(),
|
|
89
|
-
__metadata("design:paramtypes", [core_1.EntityManager])
|
|
90
|
-
], AuthInterceptor);
|
|
91
|
-
//# sourceMappingURL=auth.interceptor.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auth.interceptor.js","sourceRoot":"","sources":["../src/auth.interceptor.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,0CAAgD;AAEhD,gEAA4D;AAC5D,2CAKwB;AAExB,+BAAsD;AAEtD,yEAAoE;AAI7D,IAAM,eAAe,GAArB,MAAM,eAAe;IAC1B,YAA+B,EAAiB;QAAjB,OAAE,GAAF,EAAE,CAAe;IAAG,CAAC;IAEpD,KAAK,CAAC,UAAU,CAAC,OAAyB;QACxC,IAAI,OAAO,CAAC,OAAO,EAAa,KAAK,SAAS,EAAE,CAAC;YAC/C,OAAO,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;QACtC,CAAC;QAED,OAAO,MAAM,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC;IACnD,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,OAAyB;QACzC,IAAI,OAAO,CAAC,OAAO,EAAa,KAAK,SAAS,EAAE,CAAC;YAC/C,OAAO,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC;QAC1C,CAAC;QAED,OAAO,MAAM,OAAO,CAAC,YAAY,EAAE,CAAC,WAAW,EAAE,CAAC;IACpD,CAAC;IAED;;;OAGG;IACH,wBAAwB;IACtB,6DAA6D;IAC7D,kBAA0C;IAC1C,6DAA6D;IAC7D,gBAAkC;QAElC,EAAE;IACJ,CAAC;IAEO,KAAK,CAAC,yBAAyB,CACrC,gBAAkC,EAClC,IAAW;QAEX,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;QAC9D,CAAC;QAED,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,gBAAgB,CAAC,CAAC;QAErD,MAA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