@optimatech88/titomeet-shared-lib 1.0.25 → 1.0.26

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.
Files changed (75) hide show
  1. package/.github/workflows/npm-publish.yml +34 -34
  2. package/.prettierrc +4 -4
  3. package/package.json +1 -1
  4. package/prisma/schema.prisma +15 -0
  5. package/src/auth/admin.middleware.ts +20 -20
  6. package/src/auth/auth.guard.ts +154 -154
  7. package/src/auth/auth.module.ts +25 -25
  8. package/src/cache/cache.module.ts +25 -25
  9. package/src/cache/cache.service.ts +19 -19
  10. package/src/index.ts +40 -40
  11. package/src/prisma/prisma.module.ts +9 -9
  12. package/src/prisma/prisma.service.ts +13 -13
  13. package/src/prisma/seed.ts +82 -82
  14. package/src/types/index.ts +12 -12
  15. package/src/utils/api/endpoints.ts +6 -6
  16. package/src/utils/constants.ts +13 -13
  17. package/src/utils/events.ts +7 -7
  18. package/src/utils/index.ts +11 -11
  19. package/tsconfig.json +24 -24
  20. package/dist/auth/admin.middleware.d.ts +0 -11
  21. package/dist/auth/admin.middleware.d.ts.map +0 -1
  22. package/dist/auth/admin.middleware.js +0 -26
  23. package/dist/auth/admin.middleware.js.map +0 -1
  24. package/dist/auth/auth.guard.d.ts +0 -25
  25. package/dist/auth/auth.guard.d.ts.map +0 -1
  26. package/dist/auth/auth.guard.js +0 -136
  27. package/dist/auth/auth.guard.js.map +0 -1
  28. package/dist/auth/auth.module.d.ts +0 -9
  29. package/dist/auth/auth.module.d.ts.map +0 -1
  30. package/dist/auth/auth.module.js +0 -33
  31. package/dist/auth/auth.module.js.map +0 -1
  32. package/dist/cache/cache.module.d.ts +0 -5
  33. package/dist/cache/cache.module.d.ts.map +0 -1
  34. package/dist/cache/cache.module.js +0 -41
  35. package/dist/cache/cache.module.js.map +0 -1
  36. package/dist/cache/cache.service.d.ts +0 -9
  37. package/dist/cache/cache.service.d.ts.map +0 -1
  38. package/dist/cache/cache.service.js +0 -38
  39. package/dist/cache/cache.service.js.map +0 -1
  40. package/dist/index.d.ts +0 -16
  41. package/dist/index.d.ts.map +0 -1
  42. package/dist/index.js +0 -43
  43. package/dist/index.js.map +0 -1
  44. package/dist/prisma/prisma.module.d.ts +0 -3
  45. package/dist/prisma/prisma.module.d.ts.map +0 -1
  46. package/dist/prisma/prisma.module.js +0 -22
  47. package/dist/prisma/prisma.module.js.map +0 -1
  48. package/dist/prisma/prisma.service.d.ts +0 -7
  49. package/dist/prisma/prisma.service.d.ts.map +0 -1
  50. package/dist/prisma/prisma.service.js +0 -24
  51. package/dist/prisma/prisma.service.js.map +0 -1
  52. package/dist/prisma/seed.d.ts +0 -2
  53. package/dist/prisma/seed.d.ts.map +0 -1
  54. package/dist/prisma/seed.js +0 -73
  55. package/dist/prisma/seed.js.map +0 -1
  56. package/dist/types/index.d.ts +0 -12
  57. package/dist/types/index.d.ts.map +0 -1
  58. package/dist/types/index.js +0 -3
  59. package/dist/types/index.js.map +0 -1
  60. package/dist/utils/api/endpoints.d.ts +0 -7
  61. package/dist/utils/api/endpoints.d.ts.map +0 -1
  62. package/dist/utils/api/endpoints.js +0 -10
  63. package/dist/utils/api/endpoints.js.map +0 -1
  64. package/dist/utils/constants.d.ts +0 -3
  65. package/dist/utils/constants.d.ts.map +0 -1
  66. package/dist/utils/constants.js +0 -15
  67. package/dist/utils/constants.js.map +0 -1
  68. package/dist/utils/events.d.ts +0 -7
  69. package/dist/utils/events.d.ts.map +0 -1
  70. package/dist/utils/events.js +0 -10
  71. package/dist/utils/events.js.map +0 -1
  72. package/dist/utils/index.d.ts +0 -8
  73. package/dist/utils/index.d.ts.map +0 -1
  74. package/dist/utils/index.js +0 -14
  75. package/dist/utils/index.js.map +0 -1
@@ -1,34 +1,34 @@
1
- # This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
2
- # For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
3
-
4
- name: Node.js Package
5
-
6
- on:
7
- push:
8
- branches:
9
- - main # Or your main branch
10
-
11
- jobs:
12
- build:
13
- runs-on: ubuntu-latest
14
- steps:
15
- - uses: actions/checkout@v4
16
- - uses: actions/setup-node@v4
17
- with:
18
- node-version: 20
19
- - run: npm ci
20
- - run: npm run build
21
-
22
- publish-npm:
23
- needs: build
24
- runs-on: ubuntu-latest
25
- steps:
26
- - uses: actions/checkout@v4
27
- - uses: actions/setup-node@v4
28
- with:
29
- node-version: 20
30
- registry-url: https://registry.npmjs.org/
31
- - run: npm ci
32
- - run: npm publish --access public
33
- env:
34
- NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
1
+ # This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
2
+ # For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
3
+
4
+ name: Node.js Package
5
+
6
+ on:
7
+ push:
8
+ branches:
9
+ - main # Or your main branch
10
+
11
+ jobs:
12
+ build:
13
+ runs-on: ubuntu-latest
14
+ steps:
15
+ - uses: actions/checkout@v4
16
+ - uses: actions/setup-node@v4
17
+ with:
18
+ node-version: 20
19
+ - run: npm ci
20
+ - run: npm run build
21
+
22
+ publish-npm:
23
+ needs: build
24
+ runs-on: ubuntu-latest
25
+ steps:
26
+ - uses: actions/checkout@v4
27
+ - uses: actions/setup-node@v4
28
+ with:
29
+ node-version: 20
30
+ registry-url: https://registry.npmjs.org/
31
+ - run: npm ci
32
+ - run: npm publish --access public
33
+ env:
34
+ NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
package/.prettierrc CHANGED
@@ -1,5 +1,5 @@
1
- {
2
- "singleQuote": true,
3
- "trailingComma": "all",
4
- "endOfLine":"auto"
1
+ {
2
+ "singleQuote": true,
3
+ "trailingComma": "all",
4
+ "endOfLine":"auto"
5
5
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optimatech88/titomeet-shared-lib",
3
- "version": "1.0.25",
3
+ "version": "1.0.26",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {
@@ -20,6 +20,12 @@ enum UserRole {
20
20
  USER
21
21
  }
22
22
 
23
+ enum UserStatus {
24
+ ACTIVE
25
+ INACTIVE
26
+ DELETED
27
+ }
28
+
23
29
  model User {
24
30
  id String @id @default(cuid())
25
31
  username String @unique
@@ -31,6 +37,7 @@ model User {
31
37
 
32
38
  profilePicture String?
33
39
  emailVerified Boolean @default(false)
40
+ status UserStatus @default(ACTIVE)
34
41
 
35
42
  createdAt DateTime @default(now())
36
43
  updatedAt DateTime @updatedAt
@@ -181,6 +188,13 @@ model ChatUser {
181
188
  updatedAt DateTime @updatedAt
182
189
  }
183
190
 
191
+ enum MediaType {
192
+ image
193
+ video
194
+ audio
195
+ pdf
196
+ }
197
+
184
198
  model Message {
185
199
  id String @id @default(cuid())
186
200
  text String
@@ -190,6 +204,7 @@ model Message {
190
204
  senderId String
191
205
 
192
206
  mediaUrl String?
207
+ mediaType MediaType?
193
208
 
194
209
  createdAt DateTime @default(now())
195
210
  updatedAt DateTime @updatedAt
@@ -1,20 +1,20 @@
1
- import { Injectable, NestMiddleware, UnauthorizedException } from '@nestjs/common';
2
- import { Request, Response, NextFunction } from 'express';
3
- import { UserRole, User } from '@prisma/client';
4
-
5
- interface RequestWithUser extends Request {
6
- user?: User;
7
- }
8
-
9
- @Injectable()
10
- export class AdminMiddleware implements NestMiddleware {
11
- use(req: RequestWithUser, res: Response, next: NextFunction) {
12
- const user = req.user;
13
-
14
- if (!user || !user.role?.includes(UserRole.ADMIN)) {
15
- throw new UnauthorizedException('Access denied. Admins only.');
16
- }
17
-
18
- next();
19
- }
20
- }
1
+ import { Injectable, NestMiddleware, UnauthorizedException } from '@nestjs/common';
2
+ import { Request, Response, NextFunction } from 'express';
3
+ import { UserRole, User } from '@prisma/client';
4
+
5
+ interface RequestWithUser extends Request {
6
+ user?: User;
7
+ }
8
+
9
+ @Injectable()
10
+ export class AdminMiddleware implements NestMiddleware {
11
+ use(req: RequestWithUser, res: Response, next: NextFunction) {
12
+ const user = req.user;
13
+
14
+ if (!user || !user.role?.includes(UserRole.ADMIN)) {
15
+ throw new UnauthorizedException('Access denied. Admins only.');
16
+ }
17
+
18
+ next();
19
+ }
20
+ }
@@ -1,154 +1,154 @@
1
- import {
2
- CanActivate,
3
- ExecutionContext,
4
- Injectable,
5
- UnauthorizedException,
6
- } from '@nestjs/common';
7
- import { JwtService } from '@nestjs/jwt';
8
- import { PrismaClient, UserRole } from '@prisma/client';
9
- import { Request } from 'express';
10
- import { IncomingHttpHeaders } from 'http';
11
- import { Logger } from '@nestjs/common';
12
-
13
- @Injectable()
14
- export class AuthGuard implements CanActivate {
15
- private prisma: PrismaClient;
16
- private logger = new Logger(AuthGuard.name);
17
-
18
- constructor(
19
- private jwtService: JwtService,
20
- ) {
21
- this.prisma = new PrismaClient();
22
- }
23
-
24
- async canActivate(context: ExecutionContext): Promise<boolean> {
25
- this.logger.log('canActivate');
26
- const request = context.switchToHttp().getRequest();
27
- const token = this.extractTokenFromHeader(request);
28
- if (!token) {
29
- throw new UnauthorizedException();
30
- }
31
- try {
32
- const payload = (await this.jwtService.verifyAsync(token)) as {
33
- userId: string;
34
- };
35
-
36
- this.logger.log('payload', payload);
37
-
38
- const user = await this.prisma.user.findUnique({
39
- where: { id: payload.userId }
40
- });
41
-
42
- this.logger.log('user', user);
43
-
44
- if (!user) {
45
- throw new UnauthorizedException();
46
- }
47
-
48
- request['user'] = user;
49
- } catch {
50
- throw new UnauthorizedException();
51
- }
52
- return true;
53
- }
54
-
55
- private extractTokenFromHeader(request: Request & { headers: IncomingHttpHeaders }): string | undefined {
56
- const [type, token] = request.headers.authorization?.split(' ') ?? [];
57
- this.logger.log('extractTokenFromHeader', {type, token});
58
- return type === 'Bearer' ? token : undefined;
59
- }
60
- }
61
-
62
- //optional auth guard
63
- @Injectable()
64
- export class OptionalAuthGuard implements CanActivate {
65
- private prisma: PrismaClient;
66
-
67
- constructor(
68
- private jwtService: JwtService,
69
- ) {
70
- this.prisma = new PrismaClient();
71
- }
72
-
73
- async canActivate(context: ExecutionContext): Promise<boolean> {
74
- const request = context.switchToHttp().getRequest();
75
- const token = this.extractTokenFromHeader(request);
76
- if (!token) {
77
- return true;
78
- }
79
- try {
80
- const payload = (await this.jwtService.verifyAsync(token)) as {
81
- userId: string;
82
- };
83
-
84
- const user = await this.prisma.user.findUnique({
85
- where: { id: payload.userId }
86
- });
87
-
88
- if (!user) {
89
- throw new UnauthorizedException();
90
- }
91
-
92
- request['user'] = user;
93
-
94
- // Continue without setting user
95
- } catch {
96
- // Continue without setting user
97
- }
98
- return true;
99
- }
100
-
101
- private extractTokenFromHeader(request: Request & { headers: IncomingHttpHeaders }): string | undefined {
102
- const [type, token] = request.headers.authorization?.split(' ') ?? [];
103
- return type === 'Bearer' ? token : undefined;
104
- }
105
- }
106
-
107
- //admin auth guard
108
- @Injectable()
109
- export class AdminAuthGuard implements CanActivate {
110
- private prisma: PrismaClient;
111
-
112
- constructor(
113
- private jwtService: JwtService,
114
- ) {
115
- this.prisma = new PrismaClient();
116
- }
117
-
118
- async canActivate(context: ExecutionContext): Promise<boolean> {
119
- const request = context.switchToHttp().getRequest();
120
- const token = this.extractTokenFromHeader(request);
121
- if (!token) {
122
- throw new UnauthorizedException();
123
- }
124
- try {
125
- const payload = (await this.jwtService.verifyAsync(token)) as {
126
- userId: string;
127
- };
128
-
129
- const user = await this.prisma.user.findUnique({
130
- where: { id: payload.userId }
131
- });
132
-
133
- if (!user) {
134
- throw new UnauthorizedException();
135
- }
136
-
137
- if(user.role !== UserRole.ADMIN && user.role !== UserRole.SUPER_ADMIN) {
138
- throw new UnauthorizedException();
139
- }
140
-
141
- request['user'] = user;
142
- } catch {
143
- throw new UnauthorizedException();
144
- }
145
- return true;
146
- }
147
-
148
- private extractTokenFromHeader(request: Request & { headers: IncomingHttpHeaders }): string | undefined {
149
- const [type, token] = request.headers.authorization?.split(' ') ?? [];
150
- return type === 'Bearer' ? token : undefined;
151
- }
152
- }
153
-
154
-
1
+ import {
2
+ CanActivate,
3
+ ExecutionContext,
4
+ Injectable,
5
+ UnauthorizedException,
6
+ } from '@nestjs/common';
7
+ import { JwtService } from '@nestjs/jwt';
8
+ import { PrismaClient, UserRole } from '@prisma/client';
9
+ import { Request } from 'express';
10
+ import { IncomingHttpHeaders } from 'http';
11
+ import { Logger } from '@nestjs/common';
12
+
13
+ @Injectable()
14
+ export class AuthGuard implements CanActivate {
15
+ private prisma: PrismaClient;
16
+ private logger = new Logger(AuthGuard.name);
17
+
18
+ constructor(
19
+ private jwtService: JwtService,
20
+ ) {
21
+ this.prisma = new PrismaClient();
22
+ }
23
+
24
+ async canActivate(context: ExecutionContext): Promise<boolean> {
25
+ const request = context.switchToHttp().getRequest();
26
+ const token = this.extractTokenFromHeader(request);
27
+ if (!token) {
28
+ throw new UnauthorizedException();
29
+ }
30
+ try {
31
+ const payload = (await this.jwtService.verifyAsync(token)) as {
32
+ userId: string;
33
+ };
34
+
35
+ //this.logger.log('payload', payload);
36
+
37
+ const user = await this.prisma.user.findUnique({
38
+ where: { id: payload.userId }
39
+ });
40
+
41
+ //this.logger.log('user', user);
42
+
43
+ if (!user) {
44
+ throw new UnauthorizedException();
45
+ }
46
+
47
+ request['user'] = user;
48
+ } catch {
49
+ this.logger.log('UnauthorizedException');
50
+ throw new UnauthorizedException();
51
+ }
52
+ return true;
53
+ }
54
+
55
+ private extractTokenFromHeader(request: Request & { headers: IncomingHttpHeaders }): string | undefined {
56
+ const [type, token] = request.headers.authorization?.split(' ') ?? [];
57
+ //this.logger.log('extractTokenFromHeader', {type, token});
58
+ return type === 'Bearer' ? token : undefined;
59
+ }
60
+ }
61
+
62
+ //optional auth guard
63
+ @Injectable()
64
+ export class OptionalAuthGuard implements CanActivate {
65
+ private prisma: PrismaClient;
66
+
67
+ constructor(
68
+ private jwtService: JwtService,
69
+ ) {
70
+ this.prisma = new PrismaClient();
71
+ }
72
+
73
+ async canActivate(context: ExecutionContext): Promise<boolean> {
74
+ const request = context.switchToHttp().getRequest();
75
+ const token = this.extractTokenFromHeader(request);
76
+ if (!token) {
77
+ return true;
78
+ }
79
+ try {
80
+ const payload = (await this.jwtService.verifyAsync(token)) as {
81
+ userId: string;
82
+ };
83
+
84
+ const user = await this.prisma.user.findUnique({
85
+ where: { id: payload.userId }
86
+ });
87
+
88
+ if (!user) {
89
+ throw new UnauthorizedException();
90
+ }
91
+
92
+ request['user'] = user;
93
+
94
+ // Continue without setting user
95
+ } catch {
96
+ // Continue without setting user
97
+ }
98
+ return true;
99
+ }
100
+
101
+ private extractTokenFromHeader(request: Request & { headers: IncomingHttpHeaders }): string | undefined {
102
+ const [type, token] = request.headers.authorization?.split(' ') ?? [];
103
+ return type === 'Bearer' ? token : undefined;
104
+ }
105
+ }
106
+
107
+ //admin auth guard
108
+ @Injectable()
109
+ export class AdminAuthGuard implements CanActivate {
110
+ private prisma: PrismaClient;
111
+
112
+ constructor(
113
+ private jwtService: JwtService,
114
+ ) {
115
+ this.prisma = new PrismaClient();
116
+ }
117
+
118
+ async canActivate(context: ExecutionContext): Promise<boolean> {
119
+ const request = context.switchToHttp().getRequest();
120
+ const token = this.extractTokenFromHeader(request);
121
+ if (!token) {
122
+ throw new UnauthorizedException();
123
+ }
124
+ try {
125
+ const payload = (await this.jwtService.verifyAsync(token)) as {
126
+ userId: string;
127
+ };
128
+
129
+ const user = await this.prisma.user.findUnique({
130
+ where: { id: payload.userId }
131
+ });
132
+
133
+ if (!user) {
134
+ throw new UnauthorizedException();
135
+ }
136
+
137
+ if(user.role !== UserRole.ADMIN && user.role !== UserRole.SUPER_ADMIN) {
138
+ throw new UnauthorizedException();
139
+ }
140
+
141
+ request['user'] = user;
142
+ } catch {
143
+ throw new UnauthorizedException();
144
+ }
145
+ return true;
146
+ }
147
+
148
+ private extractTokenFromHeader(request: Request & { headers: IncomingHttpHeaders }): string | undefined {
149
+ const [type, token] = request.headers.authorization?.split(' ') ?? [];
150
+ return type === 'Bearer' ? token : undefined;
151
+ }
152
+ }
153
+
154
+
@@ -1,25 +1,25 @@
1
- import { Module, DynamicModule, Global } from '@nestjs/common';
2
- import { JwtModule } from '@nestjs/jwt';
3
-
4
- export interface AuthModuleOptions {
5
- jwtSecret: string;
6
- jwtExpiresIn?: string | number;
7
- }
8
-
9
- @Global()
10
- @Module({})
11
- export class AuthModule {
12
- static forRoot(options: AuthModuleOptions): DynamicModule {
13
- console.log('AuthModule.forRoot', options);
14
- return {
15
- module: AuthModule,
16
- imports: [
17
- JwtModule.register({
18
- secret: options.jwtSecret,
19
- signOptions: { expiresIn: options.jwtExpiresIn || '7d' },
20
- }),
21
- ],
22
- exports: [JwtModule],
23
- };
24
- }
25
- }
1
+ import { Module, DynamicModule, Global } from '@nestjs/common';
2
+ import { JwtModule } from '@nestjs/jwt';
3
+
4
+ export interface AuthModuleOptions {
5
+ jwtSecret: string;
6
+ jwtExpiresIn?: string | number;
7
+ }
8
+
9
+ @Global()
10
+ @Module({})
11
+ export class AuthModule {
12
+ static forRoot(options: AuthModuleOptions): DynamicModule {
13
+ console.log('AuthModule.forRoot', options);
14
+ return {
15
+ module: AuthModule,
16
+ imports: [
17
+ JwtModule.register({
18
+ secret: options.jwtSecret,
19
+ signOptions: { expiresIn: options.jwtExpiresIn || '7d' },
20
+ }),
21
+ ],
22
+ exports: [JwtModule],
23
+ };
24
+ }
25
+ }
@@ -1,25 +1,25 @@
1
- import { Module, DynamicModule, Global } from '@nestjs/common';
2
- import { Cacheable } from 'cacheable';
3
- import { CacheService } from './cache.service';
4
- import KeyvRedis from '@keyv/redis';
5
-
6
- @Global()
7
- @Module({})
8
- export class CacheModule {
9
- static forRoot(redisUrl: string): DynamicModule {
10
- return {
11
- module: CacheModule,
12
- providers: [
13
- {
14
- provide: 'CACHE_INSTANCE',
15
- useFactory: () => {
16
- const secondary = new KeyvRedis(redisUrl);
17
- return new Cacheable({ secondary, ttl: '1h' });
18
- },
19
- },
20
- CacheService,
21
- ],
22
- exports: ['CACHE_INSTANCE', CacheService],
23
- };
24
- }
25
- }
1
+ import { Module, DynamicModule, Global } from '@nestjs/common';
2
+ import { Cacheable } from 'cacheable';
3
+ import { CacheService } from './cache.service';
4
+ import KeyvRedis from '@keyv/redis';
5
+
6
+ @Global()
7
+ @Module({})
8
+ export class CacheModule {
9
+ static forRoot(redisUrl: string): DynamicModule {
10
+ return {
11
+ module: CacheModule,
12
+ providers: [
13
+ {
14
+ provide: 'CACHE_INSTANCE',
15
+ useFactory: () => {
16
+ const secondary = new KeyvRedis(redisUrl);
17
+ return new Cacheable({ secondary, ttl: '1h' });
18
+ },
19
+ },
20
+ CacheService,
21
+ ],
22
+ exports: ['CACHE_INSTANCE', CacheService],
23
+ };
24
+ }
25
+ }
@@ -1,19 +1,19 @@
1
- import { Inject, Injectable } from '@nestjs/common';
2
- import { Cacheable } from 'cacheable';
3
-
4
- @Injectable()
5
- export class CacheService<T> {
6
- constructor(@Inject('CACHE_INSTANCE') private readonly cache: Cacheable) {}
7
-
8
- async get<T>(key: string): Promise<T> {
9
- return await this.cache.get(key);
10
- }
11
-
12
- async set(key: string, value: T, ttl?: number | string): Promise<void> {
13
- await this.cache.set(key, value, ttl);
14
- }
15
-
16
- async delete(key: string): Promise<void> {
17
- await this.cache.delete(key);
18
- }
19
- }
1
+ import { Inject, Injectable } from '@nestjs/common';
2
+ import { Cacheable } from 'cacheable';
3
+
4
+ @Injectable()
5
+ export class CacheService<T> {
6
+ constructor(@Inject('CACHE_INSTANCE') private readonly cache: Cacheable) {}
7
+
8
+ async get<T>(key: string): Promise<T> {
9
+ return await this.cache.get(key);
10
+ }
11
+
12
+ async set(key: string, value: T, ttl?: number | string): Promise<void> {
13
+ await this.cache.set(key, value, ttl);
14
+ }
15
+
16
+ async delete(key: string): Promise<void> {
17
+ await this.cache.delete(key);
18
+ }
19
+ }