@optimatech88/titomeet-shared-lib 1.0.7 → 1.0.8
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/.github/workflows/npm-publish.yml +34 -34
- package/.prettierrc +4 -4
- package/dist/auth/admin.middleware.d.ts +11 -0
- package/dist/auth/admin.middleware.d.ts.map +1 -0
- package/dist/auth/admin.middleware.js +26 -0
- package/dist/auth/admin.middleware.js.map +1 -0
- package/dist/auth/auth.guard.d.ts +17 -0
- package/dist/auth/auth.guard.d.ts.map +1 -0
- package/dist/auth/auth.guard.js +89 -0
- package/dist/auth/auth.guard.js.map +1 -0
- package/dist/auth/auth.module.d.ts +9 -0
- package/dist/auth/auth.module.d.ts.map +1 -0
- package/dist/auth/auth.module.js +32 -0
- package/dist/auth/auth.module.js.map +1 -0
- package/dist/cache/cache.module.d.ts +5 -0
- package/dist/cache/cache.module.d.ts.map +1 -0
- package/dist/cache/cache.module.js +41 -0
- package/dist/cache/cache.module.js.map +1 -0
- package/dist/cache/cache.service.d.ts +9 -0
- package/dist/cache/cache.service.d.ts.map +1 -0
- package/dist/cache/cache.service.js +38 -0
- package/dist/cache/cache.service.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +39 -0
- package/dist/index.js.map +1 -0
- package/dist/prisma/prisma.module.d.ts +3 -0
- package/dist/prisma/prisma.module.d.ts.map +1 -0
- package/dist/prisma/prisma.module.js +22 -0
- package/dist/prisma/prisma.module.js.map +1 -0
- package/dist/prisma/prisma.service.d.ts +7 -0
- package/dist/prisma/prisma.service.d.ts.map +1 -0
- package/dist/prisma/prisma.service.js +24 -0
- package/dist/prisma/prisma.service.js.map +1 -0
- package/dist/prisma/prisma.service.spec.d.ts +2 -0
- package/dist/prisma/prisma.service.spec.d.ts.map +1 -0
- package/dist/prisma/prisma.service.spec.js +17 -0
- package/dist/prisma/prisma.service.spec.js.map +1 -0
- package/dist/types/index.d.ts +12 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/api/endpoints.d.ts +7 -0
- package/dist/utils/api/endpoints.d.ts.map +1 -0
- package/dist/utils/api/endpoints.js +10 -0
- package/dist/utils/api/endpoints.js.map +1 -0
- package/dist/utils/constants.d.ts +3 -0
- package/dist/utils/constants.d.ts.map +1 -0
- package/dist/utils/constants.js +15 -0
- package/dist/utils/constants.js.map +1 -0
- package/dist/utils/events.d.ts +7 -0
- package/dist/utils/events.d.ts.map +1 -0
- package/dist/utils/events.js +10 -0
- package/dist/utils/events.js.map +1 -0
- package/dist/utils/index.d.ts +8 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +14 -0
- package/dist/utils/index.js.map +1 -0
- package/package.json +1 -1
- package/src/auth/admin.middleware.ts +20 -20
- package/src/auth/auth.guard.ts +98 -98
- package/src/auth/auth.module.ts +24 -24
- package/src/cache/cache.module.ts +25 -25
- package/src/cache/cache.service.ts +19 -19
- package/src/index.ts +29 -29
- package/src/prisma/prisma.module.ts +9 -9
- package/src/prisma/prisma.service.ts +13 -13
- package/src/types/index.ts +12 -12
- package/src/utils/api/endpoints.ts +6 -6
- package/src/utils/constants.ts +13 -13
- package/src/utils/events.ts +7 -7
- package/src/utils/index.ts +11 -11
- package/tsconfig.json +24 -24
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.API_ENDPOINTS = exports.PROPERTIES_API_URL = exports.CHAT_API_URL = void 0;
|
|
4
|
+
exports.CHAT_API_URL = "api/chats";
|
|
5
|
+
exports.PROPERTIES_API_URL = "api/properties";
|
|
6
|
+
exports.API_ENDPOINTS = {
|
|
7
|
+
CHAT: 'api/chats',
|
|
8
|
+
PROPERTIES_API_URL: 'api/properties',
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=endpoints.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"endpoints.js","sourceRoot":"","sources":["../../../src/utils/api/endpoints.ts"],"names":[],"mappings":";;;AAAa,QAAA,YAAY,GAAW,WAAW,CAAA;AAClC,QAAA,kBAAkB,GAAW,gBAAgB,CAAA;AAE7C,QAAA,aAAa,GAAG;IAC3B,IAAI,EAAE,WAAW;IACjB,kBAAkB,EAAE,gBAAgB;CACrC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/utils/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB,0EACwC,CAAC;AAE1E,eAAO,MAAM,uBAAuB,UASnC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TEMPORARY_EMAIL_DOMAINS = exports.DEFAULT_AVATAR_IMAGE = void 0;
|
|
4
|
+
exports.DEFAULT_AVATAR_IMAGE = 'https://immob-bucket-2.s3.us-east-2.amazonaws.com/pictures/images.png';
|
|
5
|
+
exports.TEMPORARY_EMAIL_DOMAINS = [
|
|
6
|
+
'10minutemail.com',
|
|
7
|
+
'guerrillamail.com',
|
|
8
|
+
'mailinator.com',
|
|
9
|
+
'dispostable.com',
|
|
10
|
+
'yopmail.com',
|
|
11
|
+
'trashmail.com',
|
|
12
|
+
'tempmail.com',
|
|
13
|
+
'temp-mail.org',
|
|
14
|
+
];
|
|
15
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/utils/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,oBAAoB,GAC/B,uEAAuE,CAAC;AAE7D,QAAA,uBAAuB,GAAG;IACrC,kBAAkB;IAClB,mBAAmB;IACnB,gBAAgB;IAChB,iBAAiB;IACjB,aAAa;IACb,eAAe;IACf,cAAc;IACd,eAAe;CAChB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/utils/events.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa;;;;;CAKzB,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SOCKET_EVENTS = void 0;
|
|
4
|
+
exports.SOCKET_EVENTS = {
|
|
5
|
+
INBOX_OPENED: 'events.sockets.inboxOpened',
|
|
6
|
+
INBOX_CHANGED: 'events.sockets.inboxChanged',
|
|
7
|
+
NEW_MESSAGE: 'events.sockets.newMessage',
|
|
8
|
+
GET_UNREAD_MESSAGES_COUNT: 'events.sockets.getUnreadMessagesCount',
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/utils/events.ts"],"names":[],"mappings":";;;AAAa,QAAA,aAAa,GAAG;IACzB,YAAY,EAAE,4BAA4B;IAC1C,aAAa,EAAE,6BAA6B;IAC5C,WAAW,EAAE,2BAA2B;IACxC,yBAAyB,EAAE,uCAAuC;CACrE,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PaginationQuery } from "@/types";
|
|
2
|
+
export declare const getPaginationData: (query: PaginationQuery) => {
|
|
3
|
+
page: number;
|
|
4
|
+
skip: number;
|
|
5
|
+
limit: number;
|
|
6
|
+
};
|
|
7
|
+
export declare const getUserChannel: (userId: string) => string;
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE1C,eAAO,MAAM,iBAAiB,UAAW,eAAe;;;;CAOvD,CAAC;AAEF,eAAO,MAAM,cAAc,WAAY,MAAM,WAA8B,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getUserChannel = exports.getPaginationData = void 0;
|
|
4
|
+
const getPaginationData = (query) => {
|
|
5
|
+
const page = query.page;
|
|
6
|
+
const PAGE = parseInt(page, 10) || 1;
|
|
7
|
+
const LIMIT = Number(query.limit) || 10;
|
|
8
|
+
const SKIP = (PAGE - 1) * LIMIT;
|
|
9
|
+
return { page: PAGE, skip: SKIP, limit: LIMIT };
|
|
10
|
+
};
|
|
11
|
+
exports.getPaginationData = getPaginationData;
|
|
12
|
+
const getUserChannel = (userId) => `channels-user-${userId}`;
|
|
13
|
+
exports.getUserChannel = getUserChannel;
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;AAEO,MAAM,iBAAiB,GAAG,CAAC,KAAsB,EAAE,EAAE;IAC1D,MAAM,IAAI,GAAG,KAAK,CAAC,IAAc,CAAC;IAClC,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC;IACrC,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;IACxC,MAAM,IAAI,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC;IAEhC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;AAClD,CAAC,CAAC;AAPW,QAAA,iBAAiB,qBAO5B;AAEK,MAAM,cAAc,GAAG,CAAC,MAAc,EAAE,EAAE,CAAC,iBAAiB,MAAM,EAAE,CAAC;AAA/D,QAAA,cAAc,kBAAiD"}
|
package/package.json
CHANGED
|
@@ -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
|
+
}
|
package/src/auth/auth.guard.ts
CHANGED
|
@@ -1,98 +1,98 @@
|
|
|
1
|
-
import {
|
|
2
|
-
CanActivate,
|
|
3
|
-
ExecutionContext,
|
|
4
|
-
Injectable,
|
|
5
|
-
UnauthorizedException,
|
|
6
|
-
} from '@nestjs/common';
|
|
7
|
-
import { JwtService } from '@nestjs/jwt';
|
|
8
|
-
import { PrismaClient } from '@prisma/client';
|
|
9
|
-
import { Request } from 'express';
|
|
10
|
-
import { IncomingHttpHeaders } from 'http';
|
|
11
|
-
|
|
12
|
-
@Injectable()
|
|
13
|
-
export class AuthGuard implements CanActivate {
|
|
14
|
-
private prisma: PrismaClient;
|
|
15
|
-
|
|
16
|
-
constructor(
|
|
17
|
-
private jwtService: JwtService,
|
|
18
|
-
) {
|
|
19
|
-
this.prisma = new PrismaClient();
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
async canActivate(context: ExecutionContext): Promise<boolean> {
|
|
23
|
-
const request = context.switchToHttp().getRequest();
|
|
24
|
-
const token = this.extractTokenFromHeader(request);
|
|
25
|
-
if (!token) {
|
|
26
|
-
throw new UnauthorizedException();
|
|
27
|
-
}
|
|
28
|
-
try {
|
|
29
|
-
const payload = (await this.jwtService.verifyAsync(token)) as {
|
|
30
|
-
userId: string;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const user = await this.prisma.user.findUnique({
|
|
34
|
-
where: { id: payload.userId }
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
if (!user) {
|
|
38
|
-
throw new UnauthorizedException();
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
request['user'] = user;
|
|
42
|
-
} catch {
|
|
43
|
-
throw new UnauthorizedException();
|
|
44
|
-
}
|
|
45
|
-
return true;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
private extractTokenFromHeader(request: Request & { headers: IncomingHttpHeaders }): string | undefined {
|
|
49
|
-
const [type, token] = request.headers.authorization?.split(' ') ?? [];
|
|
50
|
-
return type === 'Bearer' ? token : undefined;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
//optional auth guard
|
|
55
|
-
@Injectable()
|
|
56
|
-
export class OptionalAuthGuard implements CanActivate {
|
|
57
|
-
private prisma: PrismaClient;
|
|
58
|
-
|
|
59
|
-
constructor(
|
|
60
|
-
private jwtService: JwtService,
|
|
61
|
-
) {
|
|
62
|
-
this.prisma = new PrismaClient();
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
async canActivate(context: ExecutionContext): Promise<boolean> {
|
|
66
|
-
const request = context.switchToHttp().getRequest();
|
|
67
|
-
const token = this.extractTokenFromHeader(request);
|
|
68
|
-
if (!token) {
|
|
69
|
-
return true;
|
|
70
|
-
}
|
|
71
|
-
try {
|
|
72
|
-
const payload = (await this.jwtService.verifyAsync(token)) as {
|
|
73
|
-
userId: string;
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
const user = await this.prisma.user.findUnique({
|
|
77
|
-
where: { id: payload.userId }
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
if (!user) {
|
|
81
|
-
throw new UnauthorizedException();
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
request['user'] = user;
|
|
85
|
-
|
|
86
|
-
// Continue without setting user
|
|
87
|
-
} catch {
|
|
88
|
-
// Continue without setting user
|
|
89
|
-
}
|
|
90
|
-
return true;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
private extractTokenFromHeader(request: Request & { headers: IncomingHttpHeaders }): string | undefined {
|
|
94
|
-
const [type, token] = request.headers.authorization?.split(' ') ?? [];
|
|
95
|
-
return type === 'Bearer' ? token : undefined;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
1
|
+
import {
|
|
2
|
+
CanActivate,
|
|
3
|
+
ExecutionContext,
|
|
4
|
+
Injectable,
|
|
5
|
+
UnauthorizedException,
|
|
6
|
+
} from '@nestjs/common';
|
|
7
|
+
import { JwtService } from '@nestjs/jwt';
|
|
8
|
+
import { PrismaClient } from '@prisma/client';
|
|
9
|
+
import { Request } from 'express';
|
|
10
|
+
import { IncomingHttpHeaders } from 'http';
|
|
11
|
+
|
|
12
|
+
@Injectable()
|
|
13
|
+
export class AuthGuard implements CanActivate {
|
|
14
|
+
private prisma: PrismaClient;
|
|
15
|
+
|
|
16
|
+
constructor(
|
|
17
|
+
private jwtService: JwtService,
|
|
18
|
+
) {
|
|
19
|
+
this.prisma = new PrismaClient();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async canActivate(context: ExecutionContext): Promise<boolean> {
|
|
23
|
+
const request = context.switchToHttp().getRequest();
|
|
24
|
+
const token = this.extractTokenFromHeader(request);
|
|
25
|
+
if (!token) {
|
|
26
|
+
throw new UnauthorizedException();
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
const payload = (await this.jwtService.verifyAsync(token)) as {
|
|
30
|
+
userId: string;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const user = await this.prisma.user.findUnique({
|
|
34
|
+
where: { id: payload.userId }
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
if (!user) {
|
|
38
|
+
throw new UnauthorizedException();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
request['user'] = user;
|
|
42
|
+
} catch {
|
|
43
|
+
throw new UnauthorizedException();
|
|
44
|
+
}
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
private extractTokenFromHeader(request: Request & { headers: IncomingHttpHeaders }): string | undefined {
|
|
49
|
+
const [type, token] = request.headers.authorization?.split(' ') ?? [];
|
|
50
|
+
return type === 'Bearer' ? token : undefined;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
//optional auth guard
|
|
55
|
+
@Injectable()
|
|
56
|
+
export class OptionalAuthGuard implements CanActivate {
|
|
57
|
+
private prisma: PrismaClient;
|
|
58
|
+
|
|
59
|
+
constructor(
|
|
60
|
+
private jwtService: JwtService,
|
|
61
|
+
) {
|
|
62
|
+
this.prisma = new PrismaClient();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async canActivate(context: ExecutionContext): Promise<boolean> {
|
|
66
|
+
const request = context.switchToHttp().getRequest();
|
|
67
|
+
const token = this.extractTokenFromHeader(request);
|
|
68
|
+
if (!token) {
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
try {
|
|
72
|
+
const payload = (await this.jwtService.verifyAsync(token)) as {
|
|
73
|
+
userId: string;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const user = await this.prisma.user.findUnique({
|
|
77
|
+
where: { id: payload.userId }
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
if (!user) {
|
|
81
|
+
throw new UnauthorizedException();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
request['user'] = user;
|
|
85
|
+
|
|
86
|
+
// Continue without setting user
|
|
87
|
+
} catch {
|
|
88
|
+
// Continue without setting user
|
|
89
|
+
}
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
private extractTokenFromHeader(request: Request & { headers: IncomingHttpHeaders }): string | undefined {
|
|
94
|
+
const [type, token] = request.headers.authorization?.split(' ') ?? [];
|
|
95
|
+
return type === 'Bearer' ? token : undefined;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
package/src/auth/auth.module.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
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
|
-
return {
|
|
14
|
-
module: AuthModule,
|
|
15
|
-
imports: [
|
|
16
|
-
JwtModule.register({
|
|
17
|
-
secret: options.jwtSecret,
|
|
18
|
-
signOptions: { expiresIn: options.jwtExpiresIn || '7d' },
|
|
19
|
-
}),
|
|
20
|
-
],
|
|
21
|
-
exports: [JwtModule],
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
}
|
|
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
|
+
return {
|
|
14
|
+
module: AuthModule,
|
|
15
|
+
imports: [
|
|
16
|
+
JwtModule.register({
|
|
17
|
+
secret: options.jwtSecret,
|
|
18
|
+
signOptions: { expiresIn: options.jwtExpiresIn || '7d' },
|
|
19
|
+
}),
|
|
20
|
+
],
|
|
21
|
+
exports: [JwtModule],
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -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
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
export * from './auth/auth.guard';
|
|
2
|
-
export {
|
|
3
|
-
PrismaClient, User, Account,
|
|
4
|
-
UserRole, Event, EventAccess,
|
|
5
|
-
EventVisibility, EventStatus,
|
|
6
|
-
EventPrice, Address, Participant,
|
|
7
|
-
ParticipantStatus,
|
|
8
|
-
Provider,
|
|
9
|
-
ProviderStatus,
|
|
10
|
-
EventCategory
|
|
11
|
-
} from '@prisma/client';
|
|
12
|
-
|
|
13
|
-
//auth
|
|
14
|
-
export * from './auth/auth.guard';
|
|
15
|
-
export * from './auth/auth.module';
|
|
16
|
-
|
|
17
|
-
//cache
|
|
18
|
-
export * from './cache/cache.module';
|
|
19
|
-
export * from './cache/cache.service';
|
|
20
|
-
|
|
21
|
-
//prisma
|
|
22
|
-
export * from './prisma/prisma.module';
|
|
23
|
-
export * from './prisma/prisma.service';
|
|
24
|
-
|
|
25
|
-
export * from './types';
|
|
26
|
-
export * from './utils';
|
|
27
|
-
export * from './utils/api/endpoints';
|
|
28
|
-
export * from './utils/events';
|
|
29
|
-
|
|
1
|
+
export * from './auth/auth.guard';
|
|
2
|
+
export {
|
|
3
|
+
PrismaClient, User, Account,
|
|
4
|
+
UserRole, Event, EventAccess,
|
|
5
|
+
EventVisibility, EventStatus,
|
|
6
|
+
EventPrice, Address, Participant,
|
|
7
|
+
ParticipantStatus,
|
|
8
|
+
Provider,
|
|
9
|
+
ProviderStatus,
|
|
10
|
+
EventCategory
|
|
11
|
+
} from '@prisma/client';
|
|
12
|
+
|
|
13
|
+
//auth
|
|
14
|
+
export * from './auth/auth.guard';
|
|
15
|
+
export * from './auth/auth.module';
|
|
16
|
+
|
|
17
|
+
//cache
|
|
18
|
+
export * from './cache/cache.module';
|
|
19
|
+
export * from './cache/cache.service';
|
|
20
|
+
|
|
21
|
+
//prisma
|
|
22
|
+
export * from './prisma/prisma.module';
|
|
23
|
+
export * from './prisma/prisma.service';
|
|
24
|
+
|
|
25
|
+
export * from './types';
|
|
26
|
+
export * from './utils';
|
|
27
|
+
export * from './utils/api/endpoints';
|
|
28
|
+
export * from './utils/events';
|
|
29
|
+
|
|
30
30
|
export { JwtService } from "@nestjs/jwt";
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Module, Global } from '@nestjs/common';
|
|
2
|
-
import { PrismaService } from './prisma.service';
|
|
3
|
-
|
|
4
|
-
@Global()
|
|
5
|
-
@Module({
|
|
6
|
-
providers: [PrismaService],
|
|
7
|
-
exports: [PrismaService],
|
|
8
|
-
})
|
|
9
|
-
export class PrismaModule {}
|
|
1
|
+
import { Module, Global } from '@nestjs/common';
|
|
2
|
+
import { PrismaService } from './prisma.service';
|
|
3
|
+
|
|
4
|
+
@Global()
|
|
5
|
+
@Module({
|
|
6
|
+
providers: [PrismaService],
|
|
7
|
+
exports: [PrismaService],
|
|
8
|
+
})
|
|
9
|
+
export class PrismaModule {}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { Injectable, OnModuleDestroy, OnModuleInit } from '@nestjs/common';
|
|
2
|
-
import { PrismaClient } from '@prisma/client';
|
|
3
|
-
|
|
4
|
-
@Injectable()
|
|
5
|
-
export class PrismaService extends PrismaClient implements OnModuleInit, OnModuleDestroy {
|
|
6
|
-
async onModuleInit() {
|
|
7
|
-
await this.$connect();
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
async onModuleDestroy() {
|
|
11
|
-
await this.$disconnect();
|
|
12
|
-
}
|
|
13
|
-
}
|
|
1
|
+
import { Injectable, OnModuleDestroy, OnModuleInit } from '@nestjs/common';
|
|
2
|
+
import { PrismaClient } from '@prisma/client';
|
|
3
|
+
|
|
4
|
+
@Injectable()
|
|
5
|
+
export class PrismaService extends PrismaClient implements OnModuleInit, OnModuleDestroy {
|
|
6
|
+
async onModuleInit() {
|
|
7
|
+
await this.$connect();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
async onModuleDestroy() {
|
|
11
|
+
await this.$disconnect();
|
|
12
|
+
}
|
|
13
|
+
}
|
package/src/types/index.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export interface PaginatedData<T> {
|
|
2
|
-
items: T[];
|
|
3
|
-
total: number;
|
|
4
|
-
page: number;
|
|
5
|
-
limit: number;
|
|
6
|
-
totalPages: number;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export interface PaginationQuery {
|
|
10
|
-
page?: string;
|
|
11
|
-
limit?: string;
|
|
12
|
-
}
|
|
1
|
+
export interface PaginatedData<T> {
|
|
2
|
+
items: T[];
|
|
3
|
+
total: number;
|
|
4
|
+
page: number;
|
|
5
|
+
limit: number;
|
|
6
|
+
totalPages: number;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface PaginationQuery {
|
|
10
|
+
page?: string;
|
|
11
|
+
limit?: string;
|
|
12
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export const CHAT_API_URL: string = "api/chats"
|
|
2
|
-
export const PROPERTIES_API_URL: string = "api/properties"
|
|
3
|
-
|
|
4
|
-
export const API_ENDPOINTS = {
|
|
5
|
-
CHAT: 'api/chats',
|
|
6
|
-
PROPERTIES_API_URL: 'api/properties',
|
|
1
|
+
export const CHAT_API_URL: string = "api/chats"
|
|
2
|
+
export const PROPERTIES_API_URL: string = "api/properties"
|
|
3
|
+
|
|
4
|
+
export const API_ENDPOINTS = {
|
|
5
|
+
CHAT: 'api/chats',
|
|
6
|
+
PROPERTIES_API_URL: 'api/properties',
|
|
7
7
|
}
|