@appxdigital/appx-core 0.1.82 → 0.1.83
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/modules/auth/auth.controller.d.ts +1 -1
- package/dist/modules/auth/auth.controller.d.ts.map +1 -1
- package/dist/modules/auth/auth.service.d.ts +4 -4
- package/dist/modules/auth/auth.service.d.ts.map +1 -1
- package/dist/modules/user/user.service.d.ts +3 -2
- package/dist/modules/user/user.service.d.ts.map +1 -1
- package/dist/modules/user/user.service.js +3 -1
- package/dist/prisma/prisma.service.d.ts +1 -62
- package/dist/prisma/prisma.service.d.ts.map +1 -1
- package/dist/prisma/prisma.service.js +55 -213
- package/package.json +2 -1
|
@@ -2,7 +2,7 @@ import { AuthService } from './auth.service';
|
|
|
2
2
|
import { RegisterDto } from './dto/register.dto';
|
|
3
3
|
import { Request, Response } from 'express';
|
|
4
4
|
export declare class AuthController {
|
|
5
|
-
|
|
5
|
+
protected readonly authService: AuthService;
|
|
6
6
|
constructor(authService: AuthService);
|
|
7
7
|
register(registerDto: RegisterDto): Promise<{
|
|
8
8
|
message: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.controller.d.ts","sourceRoot":"","sources":["../../../src/modules/auth/auth.controller.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAC,WAAW,EAAC,MAAM,oBAAoB,CAAC;AAG/C,OAAO,EAAC,OAAO,EAAE,QAAQ,EAAC,MAAM,SAAS,CAAC;AAI1C,qBACa,cAAc;IACX,
|
|
1
|
+
{"version":3,"file":"auth.controller.d.ts","sourceRoot":"","sources":["../../../src/modules/auth/auth.controller.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAC,WAAW,EAAC,MAAM,oBAAoB,CAAC;AAG/C,OAAO,EAAC,OAAO,EAAE,QAAQ,EAAC,MAAM,SAAS,CAAC;AAI1C,qBACa,cAAc;IACX,SAAS,CAAC,QAAQ,CAAC,WAAW,EAAE,WAAW;gBAAxB,WAAW,EAAE,WAAW;IAGjD,QAAQ,CAAS,WAAW,EAAE,WAAW;;;;IAMzC,KAAK,CAAQ,GAAG,EAAE,OAAO,EAAS,GAAG,EAAE,QAAQ;IAW/C,MAAM,CAAQ,GAAG,EAAE,OAAO,EAAS,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAoBhE,EAAE,CAAQ,GAAG,EAAE,OAAO;;;IAQtB,iBAAiB,CAAQ,GAAG,EAAE,OAAO;;;IAOrC,gBAAgB,CAAQ,GAAG,EAAE,OAAO,EAAS,GAAG,EAAE,QAAQ;IAK1D,cAAc,CAAkB,MAAM,EAAE,MAAM,EAAS,GAAG,EAAE,OAAO;;;IAUnE,oBAAoB,CACF,SAAS,EAAE,MAAM,EAC9B,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,QAAQ;IAgBlB,QAAQ,CAAQ,GAAG,EAAE,OAAO;;;;;IAM5B,aAAa,CAAQ,GAAG,EAAE,OAAO;;;;IAOjC,SAAS,CAAQ,GAAG,EAAE,OAAO;;;CAQtC"}
|
|
@@ -6,10 +6,10 @@ import { Request, Response } from 'express';
|
|
|
6
6
|
import { JwtService } from "@nestjs/jwt";
|
|
7
7
|
import { User } from "@prisma/client";
|
|
8
8
|
export declare class AuthService {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
protected readonly userService: UserService;
|
|
10
|
+
protected readonly prisma: PrismaService;
|
|
11
|
+
protected readonly jwtService: JwtService;
|
|
12
|
+
protected readonly configService: ConfigService;
|
|
13
13
|
private readonly sessionCookieName;
|
|
14
14
|
constructor(userService: UserService, prisma: PrismaService, jwtService: JwtService, configService: ConfigService);
|
|
15
15
|
register(registerDto: RegisterDto): Promise<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.service.d.ts","sourceRoot":"","sources":["../../../src/modules/auth/auth.service.ts"],"names":[],"mappings":"AAOA,OAAO,EAAC,WAAW,EAAC,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAC,WAAW,EAAC,MAAM,oBAAoB,CAAC;AAE/C,OAAO,EAAC,aAAa,EAAC,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAC,aAAa,EAAC,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAC,OAAO,EAAE,QAAQ,EAAC,MAAM,SAAS,CAAC;AAC1C,OAAO,EAAC,UAAU,EAAC,MAAM,aAAa,CAAC;AAGvC,OAAO,EAAC,IAAI,EAAC,MAAM,gBAAgB,CAAC;AAEpC,qBACa,WAAW;IAIhB,
|
|
1
|
+
{"version":3,"file":"auth.service.d.ts","sourceRoot":"","sources":["../../../src/modules/auth/auth.service.ts"],"names":[],"mappings":"AAOA,OAAO,EAAC,WAAW,EAAC,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAC,WAAW,EAAC,MAAM,oBAAoB,CAAC;AAE/C,OAAO,EAAC,aAAa,EAAC,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAC,aAAa,EAAC,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAC,OAAO,EAAE,QAAQ,EAAC,MAAM,SAAS,CAAC;AAC1C,OAAO,EAAC,UAAU,EAAC,MAAM,aAAa,CAAC;AAGvC,OAAO,EAAC,IAAI,EAAC,MAAM,gBAAgB,CAAC;AAEpC,qBACa,WAAW;IAIhB,SAAS,CAAC,QAAQ,CAAC,WAAW,EAAE,WAAW;IAC3C,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,aAAa;IACxC,SAAS,CAAC,QAAQ,CAAC,UAAU,EAAE,UAAU;IACzC,SAAS,CAAC,QAAQ,CAAC,aAAa,EAAE,aAAa;IANnD,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAS;gBAGpB,WAAW,EAAE,WAAW,EACxB,MAAM,EAAE,aAAa,EACrB,UAAU,EAAE,UAAU,EACtB,aAAa,EAAE,aAAa;IAK7C,QAAQ,CAAC,WAAW,EAAE,WAAW;;cAaE,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC;;IAWzD,KAAK,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,GAAG,CAAA;KAAC,CAAC;IA8B1D,MAAM,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAgBlD,YAAY,CACd,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,MAAM,GACtB,OAAO,CAAC,GAAG,CAAC;IAuBT,cAAc,CAAC,GAAG,EAAE,OAAO;IAW3B,iBAAiB,CAAC,GAAG,EAAE,OAAO;IAW9B,oBAAoB,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ;IA0BhD,mBAAmB,CAAC,MAAM,EAAE,MAAM;IAMlC,oBAAoB,CAAC,SAAS,EAAE,MAAM;IAOtC,kBAAkB,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;YAQtC,cAAc;IAkCtB,aAAa,CAAC,yBAAyB,EAAE,GAAG,GAAG,OAAO,CAAC;QAAC,YAAY,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,MAAM,CAAA;KAAC,CAAC;IAuB3G,OAAO,CAAC,WAAW;IAUb,QAAQ,CAAC,iBAAiB,EAAE,GAAG,GAAG,OAAO,CAAC;QAAC,YAAY,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,GAAG,CAAA;KAAC,CAAC;IAUnG,0BAA0B,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAUlE"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { PrismaService } from '../../prisma/prisma.service';
|
|
2
2
|
import { UserCreateInput } from '../../common/interfaces/user.interface';
|
|
3
3
|
import { User } from '@prisma/client';
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
import { CoreService } from "../core/core.service";
|
|
5
|
+
export declare class UserService extends CoreService<User> {
|
|
6
|
+
protected prisma: PrismaService;
|
|
6
7
|
constructor(prisma: PrismaService);
|
|
7
8
|
createUser(createUserInput: UserCreateInput): Promise<User>;
|
|
8
9
|
findByField(field: string, value: any): Promise<any>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user.service.d.ts","sourceRoot":"","sources":["../../../src/modules/user/user.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,aAAa,EAAC,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAC,eAAe,EAAC,MAAM,wCAAwC,CAAC;AAEvE,OAAO,EAAC,IAAI,EAAC,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"user.service.d.ts","sourceRoot":"","sources":["../../../src/modules/user/user.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,aAAa,EAAC,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAC,eAAe,EAAC,MAAM,wCAAwC,CAAC;AAEvE,OAAO,EAAC,IAAI,EAAC,MAAM,gBAAgB,CAAC;AACpC,OAAO,EAAC,WAAW,EAAC,MAAM,sBAAsB,CAAC;AAEjD,qBACa,WAAY,SAAQ,WAAW,CAAC,IAAI,CAAC;IAClC,SAAS,CAAC,MAAM,EAAE,aAAa;gBAArB,MAAM,EAAE,aAAa;IAIrC,UAAU,CAAC,eAAe,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IAM3D,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;IAUpD,WAAW,CAAC,KAAK,EAAE,MAAM;CAYlC"}
|
|
@@ -12,8 +12,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.UserService = void 0;
|
|
13
13
|
const common_1 = require("@nestjs/common");
|
|
14
14
|
const prisma_service_1 = require("../../prisma/prisma.service");
|
|
15
|
-
|
|
15
|
+
const core_service_1 = require("../core/core.service");
|
|
16
|
+
let UserService = class UserService extends core_service_1.CoreService {
|
|
16
17
|
constructor(prisma) {
|
|
18
|
+
super(prisma.model.user);
|
|
17
19
|
this.prisma = prisma;
|
|
18
20
|
}
|
|
19
21
|
async createUser(createUserInput) {
|
|
@@ -6,7 +6,6 @@ export declare class PrismaService {
|
|
|
6
6
|
private readonly permissionsConfig;
|
|
7
7
|
private fieldConfigs;
|
|
8
8
|
prismaClient: PrismaClient;
|
|
9
|
-
private schemaPath;
|
|
10
9
|
constructor(prismaClient: PrismaClient, permissionsConfig: PermissionsConfigType);
|
|
11
10
|
$transaction<T>(fn: (prisma: Prisma.TransactionClient) => Promise<T>): any;
|
|
12
11
|
proxyModels(): void;
|
|
@@ -25,26 +24,6 @@ export declare class PrismaService {
|
|
|
25
24
|
* including custom annotations (e.g., @Role(CLIENT)) and enums.
|
|
26
25
|
*/
|
|
27
26
|
parseSchema(): void;
|
|
28
|
-
/**
|
|
29
|
-
* Extracts enums from the Prisma schema.
|
|
30
|
-
* @param schema - The raw schema content as a string.
|
|
31
|
-
* @returns An array of enum names.
|
|
32
|
-
*/
|
|
33
|
-
private extractEnumsFromSchema;
|
|
34
|
-
/**
|
|
35
|
-
* Extracts models and custom annotations from the Prisma schema.
|
|
36
|
-
* @param schema - The raw schema content as a string.
|
|
37
|
-
* @param enums - An array of enum names for determining scalar fields.
|
|
38
|
-
* @returns A parsed object with models and their custom annotations.
|
|
39
|
-
*/
|
|
40
|
-
private extractModelsFromSchema;
|
|
41
|
-
/**
|
|
42
|
-
* Extracts fields from the model and looks for custom annotations like @Role.
|
|
43
|
-
* @param modelBody - The body of the model in the schema.
|
|
44
|
-
* @returns A parsed object with fields and their custom annotations.
|
|
45
|
-
*/
|
|
46
|
-
private extractFieldsFromModel;
|
|
47
|
-
private isScalarType;
|
|
48
27
|
/**
|
|
49
28
|
* Applies field omission logic based on the user's role.
|
|
50
29
|
* Fields that the user does not have permission to access are removed from the query.
|
|
@@ -69,47 +48,7 @@ export declare class PrismaService {
|
|
|
69
48
|
* @throws ForbiddenException if no valid `where` conditions are present after applying permissions.
|
|
70
49
|
*/
|
|
71
50
|
private applyWhereConditions;
|
|
72
|
-
|
|
73
|
-
* Extracts the `where` conditions from a `select` object.
|
|
74
|
-
* Documentation specifies this structure, however depending on the relation it might not be possible.
|
|
75
|
-
const result = await prisma.user.findFirst({
|
|
76
|
-
select: {
|
|
77
|
-
posts: {
|
|
78
|
-
where: {
|
|
79
|
-
published: false,
|
|
80
|
-
},
|
|
81
|
-
select: {
|
|
82
|
-
title: true,
|
|
83
|
-
},
|
|
84
|
-
},
|
|
85
|
-
},
|
|
86
|
-
})
|
|
87
|
-
|
|
88
|
-
* Instead, do it this way:
|
|
89
|
-
const result = await prisma.user.findFirst({
|
|
90
|
-
where: {
|
|
91
|
-
posts: {
|
|
92
|
-
published: false,
|
|
93
|
-
},
|
|
94
|
-
},
|
|
95
|
-
select: {
|
|
96
|
-
posts: {
|
|
97
|
-
select: {
|
|
98
|
-
title: true,
|
|
99
|
-
},
|
|
100
|
-
},
|
|
101
|
-
},
|
|
102
|
-
})
|
|
103
|
-
|
|
104
|
-
*/
|
|
105
|
-
private extractWhereFromSelect;
|
|
106
|
-
getRelationType(parentModel: string, relatedField: string): {
|
|
107
|
-
relation: null;
|
|
108
|
-
identifier: null;
|
|
109
|
-
} | {
|
|
110
|
-
relation: string;
|
|
111
|
-
identifier: any;
|
|
112
|
-
};
|
|
51
|
+
getRelationType(parentModel: string, relatedField: string): any;
|
|
113
52
|
/**
|
|
114
53
|
* Builds dynamic conditions based on the type of clause (OR, AND, or field conditions).
|
|
115
54
|
* Each condition is processed, and placeholders (like `$USER_ID`) are replaced with actual values.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prisma.service.d.ts","sourceRoot":"","sources":["../../src/prisma/prisma.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,MAAM,EAAE,YAAY,EAAC,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAC,qBAAqB,EAAC,MAAM,yCAAyC,CAAC;AAI9E,OAAO,KAAK,EAAC,YAAY,IAAI,aAAa,EAAC,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"prisma.service.d.ts","sourceRoot":"","sources":["../../src/prisma/prisma.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,MAAM,EAAE,YAAY,EAAC,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAC,qBAAqB,EAAC,MAAM,yCAAyC,CAAC;AAI9E,OAAO,KAAK,EAAC,YAAY,IAAI,aAAa,EAAC,MAAM,gBAAgB,CAAC;AAGlE,KAAK,QAAQ,GAAG,MAAM,aAAa,CAAC;AAEpC,qBACa,aAAa;IAMY,OAAO,CAAC,QAAQ,CAAC,iBAAiB;IALpE,OAAO,CAAC,YAAY,CAA2B;IAC/C,YAAY,EAAE,YAAY,CAAC;gBAGvB,YAAY,EAAE,YAAY,EACqB,iBAAiB,EAAE,qBAAqB;IAO3F,YAAY,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,iBAAiB,KAAK,OAAO,CAAC,CAAC,CAAC;IAIpE,WAAW;IA6CX;;;;OAIG;IACH,gBAAgB,CAAC,CAAC,SAAS,QAAQ,EAAE,KAAK,EAAE,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC;IAYhE,IAAI,KAAK,IAAI,aAAa,CAUzB;IAED,IAAI,IAAI,IAAI,aAAa,CAAC,MAAM,CAAC,CAEhC;IAED,IAAI,OAAO,IAAI,aAAa,CAAC,SAAS,CAAC,CAEtC;IAED,IAAI,gBAAgB,QAEnB;IAED;;;OAGG;IACH,WAAW;IAoDX;;;;;;;;OAQG;IACH,OAAO,CAAC,kBAAkB;IAiC1B,IAAI,2BAA2B,QAM9B;IAED;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,oBAAoB;IAiG5B,eAAe,CAAC,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM;IAYzD;;;;;;;OAOG;IACH,OAAO,CAAC,eAAe;IAgBvB;;;;;;;OAOG;IACH,OAAO,CAAC,mBAAmB;IA2B3B;;;;;;;OAOG;IACH,OAAO,CAAC,eAAe;IAQvB;;;;;;;;;OASG;IACH,OAAO,CAAC,iBAAiB;IAkDzB;;;;;;;;OAQG;IACH,OAAO,CAAC,mBAAmB;CAgB9B"}
|
|
@@ -1,43 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
2
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
3
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
4
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
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;
|
|
22
6
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
7
|
};
|
|
24
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
-
var ownKeys = function(o) {
|
|
26
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
-
var ar = [];
|
|
28
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
-
return ar;
|
|
30
|
-
};
|
|
31
|
-
return ownKeys(o);
|
|
32
|
-
};
|
|
33
|
-
return function (mod) {
|
|
34
|
-
if (mod && mod.__esModule) return mod;
|
|
35
|
-
var result = {};
|
|
36
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
-
__setModuleDefault(result, mod);
|
|
38
|
-
return result;
|
|
39
|
-
};
|
|
40
|
-
})();
|
|
41
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
42
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
43
10
|
};
|
|
@@ -48,14 +15,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
48
15
|
exports.PrismaService = void 0;
|
|
49
16
|
const common_1 = require("@nestjs/common");
|
|
50
17
|
const client_1 = require("@prisma/client");
|
|
51
|
-
const path = __importStar(require("path"));
|
|
52
|
-
const fs = __importStar(require("fs"));
|
|
53
18
|
const nestjs_request_context_1 = require("nestjs-request-context");
|
|
54
19
|
let PrismaService = class PrismaService {
|
|
55
20
|
constructor(prismaClient, permissionsConfig) {
|
|
56
21
|
this.permissionsConfig = permissionsConfig;
|
|
57
22
|
this.fieldConfigs = {};
|
|
58
|
-
this.schemaPath = '';
|
|
59
23
|
this.prismaClient = prismaClient;
|
|
60
24
|
this.parseSchema();
|
|
61
25
|
this.proxyModels();
|
|
@@ -82,8 +46,6 @@ let PrismaService = class PrismaService {
|
|
|
82
46
|
params = this.applyFieldOmission(String(propKey), userRole, params);
|
|
83
47
|
if (!options?.BYPASS_FILTERING) {
|
|
84
48
|
params = this.applyWhereConditions(String(propKey), userRole, params, user, methodKey);
|
|
85
|
-
// Extract where conditions from inside select
|
|
86
|
-
params = this.extractWhereFromSelect(params);
|
|
87
49
|
// findUnique should be findFirst for where conditions to work properly
|
|
88
50
|
if (methodKey === 'findUnique')
|
|
89
51
|
methodKey = 'findFirst';
|
|
@@ -147,40 +109,41 @@ let PrismaService = class PrismaService {
|
|
|
147
109
|
* including custom annotations (e.g., @Role(CLIENT)) and enums.
|
|
148
110
|
*/
|
|
149
111
|
parseSchema() {
|
|
150
|
-
|
|
151
|
-
const
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
112
|
+
let data_model = this.prismaClient._runtimeDataModel;
|
|
113
|
+
for (const model_name in data_model.models) {
|
|
114
|
+
let fields = data_model.models[model_name].fields;
|
|
115
|
+
const allFields = [];
|
|
116
|
+
const fieldConfig = {};
|
|
117
|
+
const fieldTypes = {};
|
|
118
|
+
const scalarFields = [];
|
|
119
|
+
const relationFields = {};
|
|
120
|
+
for (const field of fields) {
|
|
121
|
+
let field_name = field.name;
|
|
122
|
+
const fieldType = field.type;
|
|
123
|
+
const commentPart = field.documentation || '';
|
|
124
|
+
if (commentPart) {
|
|
125
|
+
const roleMatch = commentPart.match(/@Role\((.*?)\)/);
|
|
126
|
+
if (roleMatch) {
|
|
127
|
+
fieldConfig[field_name] = roleMatch[1].split(',').map(role => role.trim());
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
allFields.push(field_name);
|
|
131
|
+
fieldTypes[field_name] = fieldType;
|
|
132
|
+
if (field.kind === 'scalar' || field.kind === 'enum') {
|
|
133
|
+
scalarFields.push(field_name);
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
relationFields[field_name] = {
|
|
137
|
+
model: field.type,
|
|
138
|
+
relation: field.isList ? 'hasMany' : 'belongsTo',
|
|
139
|
+
};
|
|
140
|
+
if (!field.isList && field.relationToFields && field.relationFromFields) {
|
|
141
|
+
relationFields[field_name].foreignKey = field.relationToFields[0];
|
|
142
|
+
relationFields[field_name].referencingColumn = field.relationFromFields[0];
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
this.fieldConfigs[model_name.toLowerCase()] = {
|
|
184
147
|
fieldConfig,
|
|
185
148
|
allFields,
|
|
186
149
|
fieldTypes,
|
|
@@ -188,62 +151,6 @@ let PrismaService = class PrismaService {
|
|
|
188
151
|
relationFields,
|
|
189
152
|
};
|
|
190
153
|
}
|
|
191
|
-
return models;
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* Extracts fields from the model and looks for custom annotations like @Role.
|
|
195
|
-
* @param modelBody - The body of the model in the schema.
|
|
196
|
-
* @returns A parsed object with fields and their custom annotations.
|
|
197
|
-
*/
|
|
198
|
-
extractFieldsFromModel(modelBody, enums) {
|
|
199
|
-
const allFields = [];
|
|
200
|
-
const fieldConfig = {};
|
|
201
|
-
const fieldTypes = {};
|
|
202
|
-
const scalarFields = [];
|
|
203
|
-
const relationFields = [];
|
|
204
|
-
const lines = modelBody.split('\n');
|
|
205
|
-
for (const line of lines) {
|
|
206
|
-
const trimmedLine = line.trim();
|
|
207
|
-
if (!trimmedLine || trimmedLine.startsWith('//')) {
|
|
208
|
-
continue;
|
|
209
|
-
}
|
|
210
|
-
const [codePart, commentPart] = trimmedLine.split('///');
|
|
211
|
-
const codeTokens = codePart.trim().split(/\s+/);
|
|
212
|
-
if (codeTokens.length < 2) {
|
|
213
|
-
continue;
|
|
214
|
-
}
|
|
215
|
-
const fieldName = codeTokens[0];
|
|
216
|
-
const fieldType = codeTokens[1];
|
|
217
|
-
const attributes = codeTokens.slice(2);
|
|
218
|
-
if (commentPart && commentPart.includes('@Role(')) {
|
|
219
|
-
const roleMatch = commentPart.match(/@Role\((.*?)\)/);
|
|
220
|
-
if (roleMatch) {
|
|
221
|
-
const roles = roleMatch[1].split(',').map(role => role.trim());
|
|
222
|
-
fieldConfig[fieldName] = roles;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
allFields.push(fieldName);
|
|
226
|
-
fieldTypes[fieldName] = fieldType;
|
|
227
|
-
let baseType = fieldType.replace('?', '').replace('[]', '');
|
|
228
|
-
if (this.isScalarType(baseType, enums)) {
|
|
229
|
-
scalarFields.push(fieldName);
|
|
230
|
-
}
|
|
231
|
-
else {
|
|
232
|
-
relationFields.push(fieldName);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
return {
|
|
236
|
-
allFields,
|
|
237
|
-
fieldConfig,
|
|
238
|
-
fieldTypes,
|
|
239
|
-
scalarFields,
|
|
240
|
-
relationFields,
|
|
241
|
-
};
|
|
242
|
-
}
|
|
243
|
-
// Helper method to identify scalar types
|
|
244
|
-
isScalarType(fieldType, enums) {
|
|
245
|
-
const scalarTypes = ['Int', 'String', 'Boolean', 'DateTime', 'Float', 'BigInt', 'Decimal', 'Json', 'Bytes', 'Unsupported'];
|
|
246
|
-
return scalarTypes.includes(fieldType) || enums.includes(fieldType);
|
|
247
154
|
}
|
|
248
155
|
/**
|
|
249
156
|
* Applies field omission logic based on the user's role.
|
|
@@ -301,21 +208,21 @@ let PrismaService = class PrismaService {
|
|
|
301
208
|
const normalizedName = modelName.toLowerCase().trim();
|
|
302
209
|
const permissions = permissionsConfig[normalizedName]?.[userRole];
|
|
303
210
|
if (args.select) {
|
|
304
|
-
for (const
|
|
305
|
-
|
|
211
|
+
for (const field of Object.keys(args.select)) {
|
|
212
|
+
let relation = this.getRelationType(modelName, field);
|
|
213
|
+
if (!relation) {
|
|
306
214
|
continue;
|
|
307
215
|
}
|
|
308
|
-
const relation = this.getRelationType(modelName, model);
|
|
309
216
|
if (relation.relation === 'belongsTo') {
|
|
310
|
-
const relatedPermissions = permissionsConfig[model.toLowerCase()]?.[userRole]?.[action];
|
|
217
|
+
const relatedPermissions = permissionsConfig[relation.model.toLowerCase()]?.[userRole]?.[action];
|
|
311
218
|
belongsToQueue.push({
|
|
312
|
-
|
|
219
|
+
field,
|
|
313
220
|
relation,
|
|
314
221
|
relatedPermissions,
|
|
315
222
|
});
|
|
316
223
|
continue;
|
|
317
224
|
}
|
|
318
|
-
if (permissionsConfig[model.toLowerCase()]) {
|
|
225
|
+
if (permissionsConfig[relation.model.toLowerCase()]) {
|
|
319
226
|
/* Where conditions are applied outside of the select. Example as per documentation:
|
|
320
227
|
const result = await prisma.user.findFirst({
|
|
321
228
|
select: {
|
|
@@ -330,11 +237,11 @@ let PrismaService = class PrismaService {
|
|
|
330
237
|
},
|
|
331
238
|
})
|
|
332
239
|
*/
|
|
333
|
-
args.select[
|
|
334
|
-
delete args.select[
|
|
240
|
+
args.select[field].where = this.applyWhereConditions(relation.model, userRole, args.select[field], user, action).where;
|
|
241
|
+
delete args.select[field].select.where;
|
|
335
242
|
}
|
|
336
243
|
else {
|
|
337
|
-
throw new common_1.ForbiddenException(`No permissions found for model ${model} and role ${userRole}`);
|
|
244
|
+
throw new common_1.ForbiddenException(`No permissions found for model ${relation.model} and role ${userRole}`);
|
|
338
245
|
}
|
|
339
246
|
}
|
|
340
247
|
}
|
|
@@ -357,12 +264,12 @@ let PrismaService = class PrismaService {
|
|
|
357
264
|
throw new common_1.ForbiddenException(`You are not authorized to access this record`);
|
|
358
265
|
}
|
|
359
266
|
for (const entry of belongsToQueue) {
|
|
360
|
-
const {
|
|
267
|
+
const { relatedPermissions, field } = entry;
|
|
361
268
|
args.where = {
|
|
362
269
|
...args.where,
|
|
363
|
-
[
|
|
270
|
+
[field]: {
|
|
364
271
|
AND: [
|
|
365
|
-
args?.where?.[
|
|
272
|
+
args?.where?.[field] ?? {},
|
|
366
273
|
this.buildConditions(relatedPermissions?.conditions, user)
|
|
367
274
|
]
|
|
368
275
|
}
|
|
@@ -370,78 +277,14 @@ let PrismaService = class PrismaService {
|
|
|
370
277
|
}
|
|
371
278
|
return args;
|
|
372
279
|
}
|
|
373
|
-
/**
|
|
374
|
-
* Extracts the `where` conditions from a `select` object.
|
|
375
|
-
* Documentation specifies this structure, however depending on the relation it might not be possible.
|
|
376
|
-
const result = await prisma.user.findFirst({
|
|
377
|
-
select: {
|
|
378
|
-
posts: {
|
|
379
|
-
where: {
|
|
380
|
-
published: false,
|
|
381
|
-
},
|
|
382
|
-
select: {
|
|
383
|
-
title: true,
|
|
384
|
-
},
|
|
385
|
-
},
|
|
386
|
-
},
|
|
387
|
-
})
|
|
388
|
-
|
|
389
|
-
* Instead, do it this way:
|
|
390
|
-
const result = await prisma.user.findFirst({
|
|
391
|
-
where: {
|
|
392
|
-
posts: {
|
|
393
|
-
published: false,
|
|
394
|
-
},
|
|
395
|
-
},
|
|
396
|
-
select: {
|
|
397
|
-
posts: {
|
|
398
|
-
select: {
|
|
399
|
-
title: true,
|
|
400
|
-
},
|
|
401
|
-
},
|
|
402
|
-
},
|
|
403
|
-
})
|
|
404
|
-
|
|
405
|
-
*/
|
|
406
|
-
extractWhereFromSelect(args) {
|
|
407
|
-
if (!args || !args.select) {
|
|
408
|
-
return args;
|
|
409
|
-
}
|
|
410
|
-
const whereConditions = {};
|
|
411
|
-
for (const key in args.select) {
|
|
412
|
-
if (args.select[key] && typeof args.select[key] === 'object') {
|
|
413
|
-
if (args.select[key].where) {
|
|
414
|
-
whereConditions[key] = args.select[key].where;
|
|
415
|
-
delete args.select[key].where;
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
if (Object.keys(whereConditions).length > 0) {
|
|
420
|
-
args.where = { ...args.where, ...whereConditions };
|
|
421
|
-
}
|
|
422
|
-
return args;
|
|
423
|
-
}
|
|
424
280
|
getRelationType(parentModel, relatedField) {
|
|
425
|
-
//TODO Remove what is now unnecessary since this is no longer used to determine the foreign key and it was very strict due to relying on the assumption that said fk would be [model name]_id
|
|
426
281
|
parentModel = parentModel.toLowerCase();
|
|
427
282
|
relatedField = relatedField.toLowerCase();
|
|
428
|
-
const
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
if (!relationKey)
|
|
434
|
-
return { relation: null, identifier: null };
|
|
435
|
-
const fieldType = parent.fieldTypes[relationKey];
|
|
436
|
-
if (fieldType.endsWith('[]')) {
|
|
437
|
-
return { relation: 'hasMany', identifier: null };
|
|
438
|
-
}
|
|
439
|
-
const foreignKeyName = `${relatedField}_id`;
|
|
440
|
-
const foreignKey = parent.scalarFields.find((key) => key.toLowerCase() === foreignKeyName);
|
|
441
|
-
if (foreignKey) {
|
|
442
|
-
return { relation: 'belongsTo', identifier: foreignKey };
|
|
443
|
-
}
|
|
444
|
-
return { relation: null, identifier: null };
|
|
283
|
+
const parent = this.fieldConfigs[parentModel];
|
|
284
|
+
const relation = parent.relationFields[relatedField];
|
|
285
|
+
if (!relation)
|
|
286
|
+
return null;
|
|
287
|
+
return relation;
|
|
445
288
|
}
|
|
446
289
|
/**
|
|
447
290
|
* Builds dynamic conditions based on the type of clause (OR, AND, or field conditions).
|
|
@@ -530,7 +373,7 @@ let PrismaService = class PrismaService {
|
|
|
530
373
|
}
|
|
531
374
|
if (includeRelations) {
|
|
532
375
|
for (const relationKey in includeRelations) {
|
|
533
|
-
if (!relationFields
|
|
376
|
+
if (!relationFields[relationKey])
|
|
534
377
|
continue;
|
|
535
378
|
let includedArgs = includeRelations[relationKey];
|
|
536
379
|
if (includedArgs === true) {
|
|
@@ -560,9 +403,8 @@ let PrismaService = class PrismaService {
|
|
|
560
403
|
if (!modelInfo) {
|
|
561
404
|
throw new Error(`Model information not found for ${parentModelName}`);
|
|
562
405
|
}
|
|
563
|
-
if (modelInfo.relationFields
|
|
564
|
-
|
|
565
|
-
return modelInfo.fieldTypes[relationKey].toLowerCase().replace('[]', '').replace('?', '');
|
|
406
|
+
if (modelInfo.relationFields[relationKey]) {
|
|
407
|
+
return modelInfo.relationFields[relationKey].model;
|
|
566
408
|
}
|
|
567
409
|
throw new Error(`Relation key ${relationKey} not found in model ${parentModelName}`);
|
|
568
410
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appxdigital/appx-core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.83",
|
|
4
4
|
"description": "Appx Core is a library that provides a set of tools to help you build your application faster.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"@nestjs/jwt": "^11.0.0",
|
|
21
21
|
"@paljs/plugins": "^8.1.0",
|
|
22
22
|
"@paralleldrive/cuid2": "^2.2.2",
|
|
23
|
+
"@prisma/sdk": "^4.0.0",
|
|
23
24
|
"@types/bcrypt": "^5.0.2",
|
|
24
25
|
"@types/express": "^5.0.0",
|
|
25
26
|
"@types/express-session": "^1.18.0",
|