prostgles-server 4.2.192 → 4.2.193
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/Auth/AuthHandler.d.ts +8 -13
- package/dist/Auth/AuthHandler.d.ts.map +1 -1
- package/dist/Auth/AuthHandler.js +34 -89
- package/dist/Auth/AuthHandler.js.map +1 -1
- package/dist/Auth/AuthTypes.d.ts +16 -6
- package/dist/Auth/AuthTypes.d.ts.map +1 -1
- package/dist/Auth/authProviders/setOAuthProviders.js +1 -1
- package/dist/Auth/authProviders/setOAuthProviders.js.map +1 -1
- package/dist/Auth/endpoints/getConfirmEmailRequestHandler.js +1 -1
- package/dist/Auth/endpoints/getConfirmEmailRequestHandler.js.map +1 -1
- package/dist/Auth/endpoints/getRegisterRequestHandler.js +1 -1
- package/dist/Auth/endpoints/getRegisterRequestHandler.js.map +1 -1
- package/dist/Auth/setupAuthRoutes.d.ts.map +1 -1
- package/dist/Auth/setupAuthRoutes.js +16 -10
- package/dist/Auth/setupAuthRoutes.js.map +1 -1
- package/dist/Auth/utils/getUserFromRequest.d.ts +7 -0
- package/dist/Auth/utils/getUserFromRequest.d.ts.map +1 -0
- package/dist/Auth/utils/getUserFromRequest.js +66 -0
- package/dist/Auth/utils/getUserFromRequest.js.map +1 -0
- package/dist/DboBuilder/DboBuilder.d.ts +1 -1
- package/dist/DboBuilder/DboBuilder.d.ts.map +1 -1
- package/dist/DboBuilder/DboBuilder.js +6 -1
- package/dist/DboBuilder/DboBuilder.js.map +1 -1
- package/dist/DboBuilder/DboBuilderTypes.d.ts +15 -7
- package/dist/DboBuilder/DboBuilderTypes.d.ts.map +1 -1
- package/dist/DboBuilder/DboBuilderTypes.js.map +1 -1
- package/dist/DboBuilder/QueryBuilder/getNewQuery.js +2 -2
- package/dist/DboBuilder/QueryBuilder/getNewQuery.js.map +1 -1
- package/dist/DboBuilder/QueryStreamer.js +1 -1
- package/dist/DboBuilder/QueryStreamer.js.map +1 -1
- package/dist/DboBuilder/TableHandler/TableHandler.d.ts.map +1 -1
- package/dist/DboBuilder/TableHandler/TableHandler.js +2 -3
- package/dist/DboBuilder/TableHandler/TableHandler.js.map +1 -1
- package/dist/DboBuilder/TableHandler/insert.js +2 -2
- package/dist/DboBuilder/TableHandler/update.js +1 -1
- package/dist/DboBuilder/TableHandler/update.js.map +1 -1
- package/dist/DboBuilder/ViewHandler/ViewHandler.d.ts +0 -4
- package/dist/DboBuilder/ViewHandler/ViewHandler.d.ts.map +1 -1
- package/dist/DboBuilder/ViewHandler/ViewHandler.js +37 -24
- package/dist/DboBuilder/ViewHandler/ViewHandler.js.map +1 -1
- package/dist/DboBuilder/ViewHandler/find.js +1 -1
- package/dist/DboBuilder/ViewHandler/find.js.map +1 -1
- package/dist/DboBuilder/ViewHandler/getExistsCondition.js +4 -4
- package/dist/DboBuilder/ViewHandler/getExistsCondition.js.map +1 -1
- package/dist/DboBuilder/ViewHandler/subscribe.d.ts.map +1 -1
- package/dist/DboBuilder/ViewHandler/subscribe.js +9 -15
- package/dist/DboBuilder/ViewHandler/subscribe.js.map +1 -1
- package/dist/DboBuilder/dboBuilderUtils.d.ts.map +1 -1
- package/dist/DboBuilder/dboBuilderUtils.js +3 -1
- package/dist/DboBuilder/dboBuilderUtils.js.map +1 -1
- package/dist/DboBuilder/insertNestedRecords.d.ts +4 -3
- package/dist/DboBuilder/insertNestedRecords.d.ts.map +1 -1
- package/dist/DboBuilder/insertNestedRecords.js +12 -12
- package/dist/DboBuilder/insertNestedRecords.js.map +1 -1
- package/dist/DboBuilder/runSQL.d.ts +3 -2
- package/dist/DboBuilder/runSQL.d.ts.map +1 -1
- package/dist/DboBuilder/runSQL.js +12 -15
- package/dist/DboBuilder/runSQL.js.map +1 -1
- package/dist/FileManager/initFileManager.d.ts.map +1 -1
- package/dist/FileManager/initFileManager.js +5 -4
- package/dist/FileManager/initFileManager.js.map +1 -1
- package/dist/Prostgles.d.ts +3 -2
- package/dist/Prostgles.d.ts.map +1 -1
- package/dist/Prostgles.js +8 -16
- package/dist/Prostgles.js.map +1 -1
- package/dist/ProstglesTypes.d.ts +2 -2
- package/dist/ProstglesTypes.d.ts.map +1 -1
- package/dist/ProstglesTypes.js +1 -6
- package/dist/ProstglesTypes.js.map +1 -1
- package/dist/PubSubManager/PubSubManager.js +2 -2
- package/dist/PubSubManager/PubSubManager.js.map +1 -1
- package/dist/PubSubManager/addSync.d.ts.map +1 -1
- package/dist/PubSubManager/addSync.js +1 -3
- package/dist/PubSubManager/addSync.js.map +1 -1
- package/dist/PublishParser/PublishParser.d.ts +11 -18
- package/dist/PublishParser/PublishParser.d.ts.map +1 -1
- package/dist/PublishParser/PublishParser.js +28 -27
- package/dist/PublishParser/PublishParser.js.map +1 -1
- package/dist/PublishParser/getFileTableRules.d.ts +2 -3
- package/dist/PublishParser/getFileTableRules.d.ts.map +1 -1
- package/dist/PublishParser/getFileTableRules.js +18 -20
- package/dist/PublishParser/getFileTableRules.js.map +1 -1
- package/dist/PublishParser/getSchemaFromPublish.d.ts +2 -9
- package/dist/PublishParser/getSchemaFromPublish.d.ts.map +1 -1
- package/dist/PublishParser/getSchemaFromPublish.js +5 -5
- package/dist/PublishParser/getSchemaFromPublish.js.map +1 -1
- package/dist/PublishParser/getTableRulesWithoutFileTable.d.ts +1 -1
- package/dist/PublishParser/getTableRulesWithoutFileTable.d.ts.map +1 -1
- package/dist/PublishParser/getTableRulesWithoutFileTable.js +30 -33
- package/dist/PublishParser/getTableRulesWithoutFileTable.js.map +1 -1
- package/dist/PublishParser/publishTypesAndUtils.d.ts +6 -11
- package/dist/PublishParser/publishTypesAndUtils.d.ts.map +1 -1
- package/dist/PublishParser/publishTypesAndUtils.js.map +1 -1
- package/dist/RestApi.d.ts +1 -1
- package/dist/RestApi.d.ts.map +1 -1
- package/dist/RestApi.js +19 -16
- package/dist/RestApi.js.map +1 -1
- package/dist/initProstgles.d.ts.map +1 -1
- package/dist/initProstgles.js +11 -15
- package/dist/initProstgles.js.map +1 -1
- package/dist/onSocketConnected.d.ts.map +1 -1
- package/dist/onSocketConnected.js +5 -5
- package/dist/onSocketConnected.js.map +1 -1
- package/dist/runClientRequest.d.ts +14 -29
- package/dist/runClientRequest.d.ts.map +1 -1
- package/dist/runClientRequest.js +20 -34
- package/dist/runClientRequest.js.map +1 -1
- package/lib/Auth/AuthHandler.ts +45 -103
- package/lib/Auth/AuthTypes.ts +19 -8
- package/lib/Auth/authProviders/setOAuthProviders.ts +1 -1
- package/lib/Auth/endpoints/getConfirmEmailRequestHandler.ts +1 -1
- package/lib/Auth/endpoints/getRegisterRequestHandler.ts +1 -1
- package/lib/Auth/setupAuthRoutes.ts +17 -13
- package/lib/Auth/utils/getUserFromRequest.ts +71 -0
- package/lib/DboBuilder/DboBuilder.ts +7 -3
- package/lib/DboBuilder/DboBuilderTypes.ts +19 -17
- package/lib/DboBuilder/QueryBuilder/getNewQuery.ts +2 -2
- package/lib/DboBuilder/QueryStreamer.ts +1 -1
- package/lib/DboBuilder/TableHandler/TableHandler.ts +2 -3
- package/lib/DboBuilder/TableHandler/insert.ts +2 -2
- package/lib/DboBuilder/TableHandler/update.ts +1 -1
- package/lib/DboBuilder/ViewHandler/ViewHandler.ts +38 -37
- package/lib/DboBuilder/ViewHandler/find.ts +1 -1
- package/lib/DboBuilder/ViewHandler/getExistsCondition.ts +4 -4
- package/lib/DboBuilder/ViewHandler/subscribe.ts +22 -41
- package/lib/DboBuilder/dboBuilderUtils.ts +3 -1
- package/lib/DboBuilder/insertNestedRecords.ts +18 -16
- package/lib/DboBuilder/runSQL.ts +14 -16
- package/lib/FileManager/initFileManager.ts +16 -12
- package/lib/Prostgles.ts +10 -24
- package/lib/ProstglesTypes.ts +9 -31
- package/lib/PubSubManager/PubSubManager.ts +3 -3
- package/lib/PubSubManager/addSync.ts +1 -3
- package/lib/PublishParser/PublishParser.ts +35 -45
- package/lib/PublishParser/getFileTableRules.ts +24 -48
- package/lib/PublishParser/getSchemaFromPublish.ts +12 -23
- package/lib/PublishParser/getTableRulesWithoutFileTable.ts +30 -41
- package/lib/PublishParser/publishTypesAndUtils.ts +8 -21
- package/lib/RestApi.ts +43 -31
- package/lib/initProstgles.ts +51 -64
- package/lib/onSocketConnected.ts +12 -9
- package/lib/runClientRequest.ts +50 -66
- package/package.json +3 -3
package/lib/runClientRequest.ts
CHANGED
|
@@ -1,31 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {
|
|
2
|
+
AnyObject,
|
|
3
|
+
SQLOptions,
|
|
4
|
+
SQLRequest,
|
|
5
|
+
TableHandler,
|
|
6
|
+
UserLike,
|
|
7
|
+
getKeys,
|
|
8
|
+
pickKeys,
|
|
9
|
+
} from "prostgles-types";
|
|
10
|
+
import { AuthClientRequest } from "./Auth/AuthTypes";
|
|
11
|
+
import { LocalParams } from "./DboBuilder/DboBuilder";
|
|
12
|
+
import { TableHandler as TableHandlerServer } from "./DboBuilder/TableHandler/TableHandler";
|
|
4
13
|
import { parseFieldFilter } from "./DboBuilder/ViewHandler/parseFieldFilter";
|
|
5
14
|
import { canRunSQL } from "./DboBuilder/runSQL";
|
|
6
15
|
import { Prostgles } from "./Prostgles";
|
|
7
|
-
import { TableHandler as TableHandlerServer } from "./DboBuilder/TableHandler/TableHandler";
|
|
8
16
|
import { TableRule } from "./PublishParser/publishTypesAndUtils";
|
|
9
17
|
|
|
10
|
-
type ReqInfo =
|
|
11
|
-
| {
|
|
12
|
-
type: "socket";
|
|
13
|
-
socket: PRGLIOSocket;
|
|
14
|
-
httpReq?: undefined;
|
|
15
|
-
}
|
|
16
|
-
| {
|
|
17
|
-
type: "http";
|
|
18
|
-
httpReq: ExpressReq;
|
|
19
|
-
socket?: undefined;
|
|
20
|
-
};
|
|
21
|
-
type ReqInfoClient =
|
|
22
|
-
| {
|
|
23
|
-
socket: PRGLIOSocket;
|
|
24
|
-
}
|
|
25
|
-
| {
|
|
26
|
-
httpReq: ExpressReq;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
18
|
const TABLE_METHODS = {
|
|
30
19
|
find: 1,
|
|
31
20
|
findOne: 1,
|
|
@@ -50,7 +39,7 @@ const SOCKET_ONLY_COMMANDS = [
|
|
|
50
39
|
"sync",
|
|
51
40
|
] as const satisfies typeof TABLE_METHODS_KEYS;
|
|
52
41
|
|
|
53
|
-
type Args =
|
|
42
|
+
type Args = {
|
|
54
43
|
tableName: string;
|
|
55
44
|
command: string;
|
|
56
45
|
param1: any;
|
|
@@ -58,13 +47,6 @@ type Args = ReqInfo & {
|
|
|
58
47
|
param3: any;
|
|
59
48
|
};
|
|
60
49
|
|
|
61
|
-
const getReqInfoClient = (reqInfo: ReqInfo): ReqInfoClient => {
|
|
62
|
-
if (reqInfo.type === "socket") {
|
|
63
|
-
return { socket: reqInfo.socket };
|
|
64
|
-
}
|
|
65
|
-
return { httpReq: reqInfo.httpReq };
|
|
66
|
-
};
|
|
67
|
-
|
|
68
50
|
type TableMethodFunctionWithRulesAndLocalParams = (
|
|
69
51
|
arg1: any,
|
|
70
52
|
arg2: any,
|
|
@@ -73,17 +55,13 @@ type TableMethodFunctionWithRulesAndLocalParams = (
|
|
|
73
55
|
localParams: LocalParams
|
|
74
56
|
) => any;
|
|
75
57
|
|
|
76
|
-
export const runClientRequest = async function (
|
|
58
|
+
export const runClientRequest = async function (
|
|
59
|
+
this: Prostgles,
|
|
60
|
+
args: Args,
|
|
61
|
+
clientReq: AuthClientRequest
|
|
62
|
+
) {
|
|
77
63
|
/* Channel name will only include client-sent params so we ignore table_rules enforced params */
|
|
78
|
-
if (
|
|
79
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
80
|
-
(args.type === "socket" && !args.socket) ||
|
|
81
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
82
|
-
(args.type === "http" && !args.httpReq) ||
|
|
83
|
-
// !this.authHandler ||
|
|
84
|
-
!this.publishParser ||
|
|
85
|
-
!this.dbo
|
|
86
|
-
) {
|
|
64
|
+
if (!this.publishParser || !this.dbo) {
|
|
87
65
|
throw "socket/httpReq or authhandler missing";
|
|
88
66
|
}
|
|
89
67
|
|
|
@@ -92,17 +70,16 @@ export const runClientRequest = async function (this: Prostgles, args: Args) {
|
|
|
92
70
|
throw `Invalid command: ${nonValidatedCommand}. Expecting one of: ${TABLE_METHODS_KEYS};`;
|
|
93
71
|
}
|
|
94
72
|
const command = nonValidatedCommand as keyof TableHandler;
|
|
95
|
-
if (
|
|
73
|
+
if (!clientReq.socket && SOCKET_ONLY_COMMANDS.some((v) => v === command)) {
|
|
96
74
|
throw (
|
|
97
75
|
"The following commands cannot be completed over a non-websocket connection: " +
|
|
98
76
|
SOCKET_ONLY_COMMANDS
|
|
99
77
|
);
|
|
100
78
|
}
|
|
101
79
|
|
|
102
|
-
const
|
|
103
|
-
const clientInfo = await this.authHandler?.getClientInfo(args);
|
|
80
|
+
const clientInfo = await this.authHandler?.getUserFromRequest(clientReq);
|
|
104
81
|
const validRules = await this.publishParser.getValidatedRequestRule(
|
|
105
|
-
{ tableName, command,
|
|
82
|
+
{ tableName, command, clientReq },
|
|
106
83
|
clientInfo
|
|
107
84
|
);
|
|
108
85
|
|
|
@@ -123,11 +100,11 @@ export const runClientRequest = async function (this: Prostgles, args: Args) {
|
|
|
123
100
|
...(pickKeys(clientInfo.user, ["id", "type"]) as UserLike),
|
|
124
101
|
};
|
|
125
102
|
const localParams: LocalParams = {
|
|
126
|
-
|
|
103
|
+
clientReq,
|
|
127
104
|
isRemoteRequest: { user: sessionUser },
|
|
128
105
|
};
|
|
129
106
|
if (param3 && (param3 as LocalParams).returnQuery) {
|
|
130
|
-
const isAllowed = await canRunSQL(this,
|
|
107
|
+
const isAllowed = await canRunSQL(this, clientReq);
|
|
131
108
|
if (isAllowed) {
|
|
132
109
|
localParams.returnQuery = (param3 as LocalParams).returnQuery;
|
|
133
110
|
} else {
|
|
@@ -156,47 +133,54 @@ export const runClientRequest = async function (this: Prostgles, args: Args) {
|
|
|
156
133
|
// return result;
|
|
157
134
|
};
|
|
158
135
|
|
|
159
|
-
|
|
160
|
-
|
|
136
|
+
// const getReqInfoClient = <A extends AuthClientRequest>(args: A): AuthClientRequest =>
|
|
137
|
+
// args.httpReq ? { res: args.res, httpReq: args.httpReq } : { socket: args.socket };
|
|
138
|
+
|
|
139
|
+
export const clientCanRunSqlRequest = async function (
|
|
140
|
+
this: Prostgles,
|
|
141
|
+
clientReq: AuthClientRequest
|
|
142
|
+
) {
|
|
161
143
|
if (!this.opts.publishRawSQL || typeof this.opts.publishRawSQL !== "function") {
|
|
162
|
-
return { allowed: false,
|
|
144
|
+
return { allowed: false, clientReq };
|
|
163
145
|
}
|
|
164
146
|
const canRunSQL = async () => {
|
|
165
147
|
if (!this.authHandler) {
|
|
166
148
|
throw "authHandler missing";
|
|
167
149
|
}
|
|
168
|
-
const publishParams = await this.publishParser?.getPublishParams(
|
|
169
|
-
const res = await this.opts.publishRawSQL?.(publishParams
|
|
150
|
+
const publishParams = await this.publishParser?.getPublishParams(clientReq);
|
|
151
|
+
const res = publishParams && (await this.opts.publishRawSQL?.(publishParams));
|
|
170
152
|
return Boolean((res && typeof res === "boolean") || res === "*");
|
|
171
153
|
};
|
|
172
154
|
|
|
173
155
|
const allowed = await canRunSQL();
|
|
174
|
-
return { allowed, reqInfo };
|
|
156
|
+
return { allowed, reqInfo: clientReq };
|
|
175
157
|
};
|
|
176
158
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
const { allowed, reqInfo } = await clientCanRunSqlRequest.bind(this)(params);
|
|
159
|
+
export const runClientSqlRequest = async function (
|
|
160
|
+
this: Prostgles,
|
|
161
|
+
reqData: SQLRequest,
|
|
162
|
+
clientReq: AuthClientRequest
|
|
163
|
+
) {
|
|
164
|
+
const { allowed } = await clientCanRunSqlRequest.bind(this)(clientReq);
|
|
184
165
|
if (!allowed) {
|
|
185
166
|
throw "Not allowed to execute sql";
|
|
186
167
|
}
|
|
187
168
|
if (!this.dbo?.sql) throw "Internal error: sql handler missing";
|
|
188
|
-
const { query,
|
|
189
|
-
return this.dbo.sql(query,
|
|
169
|
+
const { query, params, options } = reqData;
|
|
170
|
+
return this.dbo.sql(query, params, options, { clientReq });
|
|
190
171
|
};
|
|
191
172
|
|
|
192
|
-
type ArgsMethod =
|
|
173
|
+
type ArgsMethod = {
|
|
193
174
|
method: string;
|
|
194
175
|
params?: any[];
|
|
195
176
|
};
|
|
196
|
-
export const runClientMethod = async function (
|
|
197
|
-
|
|
177
|
+
export const runClientMethod = async function (
|
|
178
|
+
this: Prostgles,
|
|
179
|
+
reqArgs: ArgsMethod,
|
|
180
|
+
clientReq: AuthClientRequest
|
|
181
|
+
) {
|
|
198
182
|
const { method, params = [] } = reqArgs;
|
|
199
|
-
const methods = await this.publishParser?.getAllowedMethods(
|
|
183
|
+
const methods = await this.publishParser?.getAllowedMethods(clientReq, undefined);
|
|
200
184
|
|
|
201
185
|
if (!methods || !methods[method]) {
|
|
202
186
|
throw "Disallowed/missing method " + JSON.stringify(method);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prostgles-server",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.193",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -55,12 +55,12 @@
|
|
|
55
55
|
"pg": "^8.11.5",
|
|
56
56
|
"pg-cursor": "^2.11.0",
|
|
57
57
|
"pg-promise": "^11.9.1",
|
|
58
|
-
"prostgles-types": "^4.0.
|
|
58
|
+
"prostgles-types": "^4.0.133"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@types/express": "^4.17.21",
|
|
62
62
|
"@types/json-schema": "^7.0.15",
|
|
63
|
-
"@types/node": "^22.
|
|
63
|
+
"@types/node": "^22.10.2",
|
|
64
64
|
"@types/nodemailer": "^6.4.17",
|
|
65
65
|
"@types/pg": "^8.11.5",
|
|
66
66
|
"@types/pg-cursor": "^2.7.2",
|