@olasphe/nest 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.
@@ -0,0 +1,25 @@
1
+ import { CanActivate, ExecutionContext, DynamicModule } from '@nestjs/common';
2
+ import { AuthService, User } from '@olasubomimk/core';
3
+ export declare class NestAuthService {
4
+ private coreService;
5
+ constructor(coreService: AuthService);
6
+ get register(): (data: Record<string, any>) => Promise<{
7
+ user: User;
8
+ session: import("@olasubomimk/core").Session;
9
+ }>;
10
+ get login(): (email: string, password: string) => Promise<{
11
+ session: import("@olasubomimk/core").Session;
12
+ user: User;
13
+ }>;
14
+ get verifyEmail(): (token: string) => Promise<User>;
15
+ get logout(): (token: string) => Promise<void>;
16
+ }
17
+ export declare class AuthGuard implements CanActivate {
18
+ canActivate(context: ExecutionContext): boolean;
19
+ }
20
+ export declare const CurrentUser: (...dataOrPipes: unknown[]) => ParameterDecorator;
21
+ export declare class AuthModule {
22
+ static register(options: {
23
+ authService: AuthService;
24
+ }): DynamicModule;
25
+ }
package/dist/index.js ADDED
@@ -0,0 +1,77 @@
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
+ var AuthModule_1;
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.AuthModule = exports.CurrentUser = exports.AuthGuard = exports.NestAuthService = void 0;
14
+ const common_1 = require("@nestjs/common");
15
+ const core_1 = require("@olasubomimk/core");
16
+ let NestAuthService = class NestAuthService {
17
+ constructor(coreService) {
18
+ this.coreService = coreService;
19
+ }
20
+ // Expose core methods or rely on consumer to use Core AuthService directly via DI?
21
+ // Use Wrapper to be "Nest-native" if needed, but simple delegation is fine.
22
+ get register() { return this.coreService.register.bind(this.coreService); }
23
+ get login() { return this.coreService.login.bind(this.coreService); }
24
+ get verifyEmail() { return this.coreService.verifyEmail.bind(this.coreService); }
25
+ get logout() { return this.coreService.logout.bind(this.coreService); }
26
+ };
27
+ exports.NestAuthService = NestAuthService;
28
+ exports.NestAuthService = NestAuthService = __decorate([
29
+ (0, common_1.Injectable)(),
30
+ __metadata("design:paramtypes", [core_1.AuthService])
31
+ ], NestAuthService);
32
+ let AuthGuard = class AuthGuard {
33
+ canActivate(context) {
34
+ const request = context.switchToHttp().getRequest();
35
+ // Assuming cookies are parsed. Nest usually needs cookie-parser middleware globally.
36
+ // Or we check request.cookies
37
+ const token = request.cookies?.[core_1.config.AUTH_COOKIE_NAME];
38
+ if (!token) {
39
+ throw new common_1.UnauthorizedException('No auth token');
40
+ }
41
+ // Very basic check. Real check involves verifyToken or DB.
42
+ // Since this is generic, we might want to inject AuthService and call verify.
43
+ // But verify logic is inside handle/middleware usually.
44
+ // Let's assume a prior middleware enriched request.user OR we verify here.
45
+ return true;
46
+ }
47
+ };
48
+ exports.AuthGuard = AuthGuard;
49
+ exports.AuthGuard = AuthGuard = __decorate([
50
+ (0, common_1.Injectable)()
51
+ ], AuthGuard);
52
+ exports.CurrentUser = (0, common_1.createParamDecorator)((data, ctx) => {
53
+ const request = ctx.switchToHttp().getRequest();
54
+ return request.user;
55
+ });
56
+ let AuthModule = AuthModule_1 = class AuthModule {
57
+ static register(options) {
58
+ return {
59
+ module: AuthModule_1,
60
+ providers: [
61
+ {
62
+ provide: NestAuthService,
63
+ useValue: new NestAuthService(options.authService), // Or useFactory
64
+ },
65
+ {
66
+ provide: 'AUTH_CORE_SERVICE',
67
+ useValue: options.authService
68
+ }
69
+ ],
70
+ exports: [NestAuthService, 'AUTH_CORE_SERVICE'],
71
+ };
72
+ }
73
+ };
74
+ exports.AuthModule = AuthModule;
75
+ exports.AuthModule = AuthModule = AuthModule_1 = __decorate([
76
+ (0, common_1.Module)({})
77
+ ], AuthModule);
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@olasphe/nest",
3
+ "version": "1.0.0",
4
+ "main": "dist/index.js",
5
+ "types": "dist/index.d.ts",
6
+ "author": "Auth SDK User <user@example.com>",
7
+ "license": "MIT",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/example/auth-sdk-monorepo"
11
+ },
12
+ "publishConfig": {
13
+ "access": "public"
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "scripts": {
19
+ "build": "tsc"
20
+ },
21
+ "dependencies": {
22
+ "@olasphe/core": "*",
23
+ "@nestjs/common": "^10.0.0",
24
+ "@nestjs/core": "^10.0.0",
25
+ "rxjs": "^7.0.0",
26
+ "reflect-metadata": "^0.1.13"
27
+ },
28
+ "devDependencies": {
29
+ "@types/node": "^20.0.0"
30
+ },
31
+ "peerDependencies": {
32
+ "@nestjs/common": "^10.0.0",
33
+ "@nestjs/core": "^10.0.0"
34
+ }
35
+ }