@nest-omni/core 1.0.30 → 1.0.33

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.
@@ -1,12 +0,0 @@
1
- export interface IOmniAuth {
2
- uid: string;
3
- username: string;
4
- tenantId: string;
5
- appId: string;
6
- admin: boolean;
7
- role: string;
8
- }
9
- export declare const OmniAuth: (...dataOrPipes: (import("@nestjs/common").PipeTransform<any, any> | import("@nestjs/common").Type<import("@nestjs/common").PipeTransform<any, any>> | keyof IOmniAuth)[]) => ParameterDecorator;
10
- export declare function getOmniAuthData<T extends keyof IOmniAuth>(request: {
11
- headers: Record<string, string>;
12
- }, key?: T): IOmniAuth[T] | IOmniAuth;
@@ -1,41 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getOmniAuthData = exports.OmniAuth = void 0;
4
- const common_1 = require("@nestjs/common");
5
- const lodash_1 = require("lodash");
6
- const config_1 = require("@nestjs/config");
7
- exports.OmniAuth = (0, common_1.createParamDecorator)((key, ctx) => {
8
- return getOmniAuthData(ctx.switchToHttp().getRequest(), key);
9
- });
10
- function getOmniAuthData(request, key) {
11
- const headers = request.headers;
12
- let user;
13
- const configService = new config_1.ConfigService(request);
14
- if ((0, lodash_1.isEmpty)(headers['x-userid']) || (0, lodash_1.isEmpty)(headers['x-username'])) {
15
- if (process.env.NODE_ENV === 'dev') {
16
- user = {
17
- uid: configService.get('MOCK_UID'),
18
- username: configService.get('MOCK_USERNAME'),
19
- appId: configService.get('MOCK_APP_ID'),
20
- tenantId: configService.get('MOCK_TENANT_ID'),
21
- admin: configService.get('MOCK_ADMIN', false),
22
- role: configService.get('MOCK_ROLE', ''),
23
- };
24
- }
25
- else {
26
- throw new Error('User information not found in headers.');
27
- }
28
- }
29
- else {
30
- user = {
31
- uid: headers['x-userid'] || '',
32
- username: headers['x-username'] || '',
33
- appId: headers['x-appid'] || '',
34
- tenantId: headers['x-tenantid'] || '',
35
- admin: headers['x-admin'] === '1',
36
- role: headers['x-role'] || '',
37
- };
38
- }
39
- return key ? user[key] : user;
40
- }
41
- exports.getOmniAuthData = getOmniAuthData;
@@ -1,4 +0,0 @@
1
- import { type CallHandler, type ExecutionContext, type NestInterceptor } from '@nestjs/common';
2
- export declare class AuthUserInterceptor implements NestInterceptor {
3
- intercept(context: ExecutionContext, next: CallHandler): import("rxjs").Observable<any>;
4
- }
@@ -1,24 +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
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.AuthUserInterceptor = void 0;
10
- const common_1 = require("@nestjs/common");
11
- const providers_1 = require("../providers");
12
- const omni_auth_decorator_1 = require("../decorators/omni-auth.decorator");
13
- let AuthUserInterceptor = class AuthUserInterceptor {
14
- intercept(context, next) {
15
- const req = context.switchToHttp().getRequest();
16
- req.user = (0, omni_auth_decorator_1.getOmniAuthData)(req);
17
- providers_1.ContextProvider.setAuthUser(req.user);
18
- return next.handle();
19
- }
20
- };
21
- exports.AuthUserInterceptor = AuthUserInterceptor;
22
- exports.AuthUserInterceptor = AuthUserInterceptor = __decorate([
23
- (0, common_1.Injectable)()
24
- ], AuthUserInterceptor);