prostgles-server 4.2.347 → 4.2.348
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/endpoints/setOAuthRequestHandlers.d.ts.map +1 -1
- package/dist/Auth/endpoints/setOAuthRequestHandlers.js +3 -1
- package/dist/Auth/endpoints/setOAuthRequestHandlers.js.map +1 -1
- package/dist/DboBuilder/DboBuilder.d.ts +2 -0
- package/dist/DboBuilder/DboBuilder.d.ts.map +1 -1
- package/dist/DboBuilder/DboBuilder.js +5 -1
- package/dist/DboBuilder/DboBuilder.js.map +1 -1
- package/dist/DboBuilder/QueryStreamer.d.ts.map +1 -1
- package/dist/DboBuilder/QueryStreamer.js +1 -1
- package/dist/DboBuilder/QueryStreamer.js.map +1 -1
- package/dist/DboBuilder/dboBuilderUtils.d.ts +1 -1
- package/dist/DboBuilder/dboBuilderUtils.d.ts.map +1 -1
- package/dist/DboBuilder/dboBuilderUtils.js +5 -27
- package/dist/DboBuilder/dboBuilderUtils.js.map +1 -1
- package/dist/DboBuilder/runSQL.d.ts +1 -1
- package/dist/Prostgles.d.ts.map +1 -1
- package/dist/Prostgles.js +4 -2
- package/dist/Prostgles.js.map +1 -1
- package/dist/PublishParser/PublishParser.d.ts +1 -3
- package/dist/PublishParser/PublishParser.d.ts.map +1 -1
- package/dist/PublishParser/PublishParser.js +6 -3
- package/dist/PublishParser/PublishParser.js.map +1 -1
- package/dist/PublishParser/getTableRulesWithoutFileTable.d.ts.map +1 -1
- package/dist/PublishParser/getTableRulesWithoutFileTable.js +1 -1
- package/dist/PublishParser/getTableRulesWithoutFileTable.js.map +1 -1
- package/dist/WebsocketAPI/getClientSchema.js +1 -1
- package/dist/WebsocketAPI/getClientSchema.js.map +1 -1
- package/dist/WebsocketAPI/onSocketConnected.d.ts.map +1 -1
- package/dist/WebsocketAPI/onSocketConnected.js +2 -2
- package/dist/WebsocketAPI/onSocketConnected.js.map +1 -1
- package/dist/initProstgles.js +0 -3
- package/dist/initProstgles.js.map +1 -1
- package/dist/runClientRequest.d.ts +9 -9
- package/dist/runClientRequest.d.ts.map +1 -1
- package/dist/runClientRequest.js +34 -8
- package/dist/runClientRequest.js.map +1 -1
- package/dist/shortestPath.js +1 -1
- package/dist/shortestPath.js.map +1 -1
- package/lib/Auth/endpoints/setOAuthRequestHandlers.ts +5 -2
- package/lib/DboBuilder/DboBuilder.ts +6 -1
- package/lib/DboBuilder/QueryStreamer.ts +3 -10
- package/lib/DboBuilder/dboBuilderUtils.ts +6 -32
- package/lib/Prostgles.ts +8 -3
- package/lib/PublishParser/PublishParser.ts +10 -9
- package/lib/PublishParser/getTableRulesWithoutFileTable.ts +3 -5
- package/lib/WebsocketAPI/getClientSchema.ts +1 -1
- package/lib/WebsocketAPI/onSocketConnected.ts +4 -3
- package/lib/initProstgles.ts +0 -4
- package/lib/runClientRequest.ts +57 -19
- package/lib/shortestPath.ts +1 -1
- package/package.json +2 -2
package/lib/runClientRequest.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
SQLRequest,
|
|
3
|
-
TableHandler,
|
|
4
|
-
UserLike} from "prostgles-types";
|
|
1
|
+
import type { SQLRequest, TableHandler, UserLike } from "prostgles-types";
|
|
5
2
|
import {
|
|
3
|
+
getJSONBObjectSchemaValidationError,
|
|
6
4
|
getKeys,
|
|
7
5
|
pickKeys,
|
|
8
6
|
type AnyObject,
|
|
@@ -13,7 +11,7 @@ import type { TableHandler as TableHandlerServer } from "./DboBuilder/TableHandl
|
|
|
13
11
|
import { parseFieldFilter } from "./DboBuilder/ViewHandler/parseFieldFilter";
|
|
14
12
|
import { canRunSQL } from "./DboBuilder/runSQL";
|
|
15
13
|
import type { Prostgles } from "./Prostgles";
|
|
16
|
-
import type { ParsedTableRule} from "./PublishParser/publishTypesAndUtils";
|
|
14
|
+
import type { ParsedTableRule } from "./PublishParser/publishTypesAndUtils";
|
|
17
15
|
import { type PermissionScope } from "./PublishParser/publishTypesAndUtils";
|
|
18
16
|
|
|
19
17
|
const TABLE_METHODS = {
|
|
@@ -41,11 +39,11 @@ const SOCKET_ONLY_COMMANDS = [
|
|
|
41
39
|
] as const satisfies typeof TABLE_METHODS_KEYS;
|
|
42
40
|
|
|
43
41
|
type Args = {
|
|
44
|
-
tableName:
|
|
45
|
-
command:
|
|
46
|
-
param1:
|
|
47
|
-
param2:
|
|
48
|
-
param3:
|
|
42
|
+
tableName: unknown;
|
|
43
|
+
command: unknown;
|
|
44
|
+
param1: unknown;
|
|
45
|
+
param2: unknown;
|
|
46
|
+
param3: unknown;
|
|
49
47
|
};
|
|
50
48
|
|
|
51
49
|
type TableMethodFunctionWithRulesAndLocalParams = (
|
|
@@ -58,7 +56,7 @@ type TableMethodFunctionWithRulesAndLocalParams = (
|
|
|
58
56
|
|
|
59
57
|
export const runClientRequest = async function (
|
|
60
58
|
this: Prostgles,
|
|
61
|
-
|
|
59
|
+
nonValidatedArgs: Args,
|
|
62
60
|
clientReq: AuthClientRequest,
|
|
63
61
|
scope: PermissionScope | undefined
|
|
64
62
|
) {
|
|
@@ -67,11 +65,22 @@ export const runClientRequest = async function (
|
|
|
67
65
|
throw "socket/httpReq or authhandler missing";
|
|
68
66
|
}
|
|
69
67
|
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
68
|
+
const validation = getJSONBObjectSchemaValidationError(
|
|
69
|
+
{
|
|
70
|
+
tableName: { type: "string" },
|
|
71
|
+
command: { enum: TABLE_METHODS_KEYS },
|
|
72
|
+
param1: { type: "any", optional: true },
|
|
73
|
+
param2: { type: "any", optional: true },
|
|
74
|
+
param3: { type: "any", optional: true },
|
|
75
|
+
},
|
|
76
|
+
nonValidatedArgs,
|
|
77
|
+
"tableName"
|
|
78
|
+
);
|
|
79
|
+
if (validation.error !== undefined) {
|
|
80
|
+
throw validation.error;
|
|
73
81
|
}
|
|
74
|
-
const command
|
|
82
|
+
const { tableName, command, param1, param2, param3 } = validation.data;
|
|
83
|
+
|
|
75
84
|
if (!clientReq.socket && SOCKET_ONLY_COMMANDS.some((v) => v === command)) {
|
|
76
85
|
throw (
|
|
77
86
|
"The following commands cannot be completed over a non-websocket connection: " +
|
|
@@ -79,6 +88,10 @@ export const runClientRequest = async function (
|
|
|
79
88
|
);
|
|
80
89
|
}
|
|
81
90
|
|
|
91
|
+
if (!this.dboBuilder.dboMap.has(tableName)) {
|
|
92
|
+
throw `tableName ${tableName} is invalid or not allowed`;
|
|
93
|
+
}
|
|
94
|
+
|
|
82
95
|
const clientInfo = await this.authHandler?.getSidAndUserFromRequest(clientReq);
|
|
83
96
|
if (clientInfo === "new-session-redirect") {
|
|
84
97
|
throw clientInfo;
|
|
@@ -159,7 +172,7 @@ export const clientCanRunSqlRequest = async function (
|
|
|
159
172
|
|
|
160
173
|
export const runClientSqlRequest = async function (
|
|
161
174
|
this: Prostgles,
|
|
162
|
-
|
|
175
|
+
unvalidatedArgs: SQLRequest,
|
|
163
176
|
clientReq: AuthClientRequest
|
|
164
177
|
) {
|
|
165
178
|
const { allowed } = await clientCanRunSqlRequest.bind(this)(clientReq);
|
|
@@ -167,23 +180,48 @@ export const runClientSqlRequest = async function (
|
|
|
167
180
|
throw "Not allowed to execute sql";
|
|
168
181
|
}
|
|
169
182
|
if (!this.dbo?.sql) throw "Internal error: sql handler missing";
|
|
183
|
+
const validation = getJSONBObjectSchemaValidationError(
|
|
184
|
+
{
|
|
185
|
+
query: { type: "string" },
|
|
186
|
+
params: { type: "any", optional: true },
|
|
187
|
+
options: { type: "any", optional: true },
|
|
188
|
+
},
|
|
189
|
+
unvalidatedArgs,
|
|
190
|
+
"query"
|
|
191
|
+
);
|
|
192
|
+
if (validation.error !== undefined) {
|
|
193
|
+
throw validation.error;
|
|
194
|
+
}
|
|
195
|
+
const reqData = validation.data;
|
|
170
196
|
const { query, params, options } = reqData;
|
|
171
197
|
return this.dbo.sql(query, params, options, { clientReq });
|
|
172
198
|
};
|
|
173
199
|
|
|
174
200
|
type ArgsMethod = {
|
|
175
|
-
method:
|
|
201
|
+
method: unknown;
|
|
176
202
|
params?: any[];
|
|
177
203
|
};
|
|
178
204
|
export const runClientMethod = async function (
|
|
179
205
|
this: Prostgles,
|
|
180
|
-
|
|
206
|
+
unvalidatedArgs: ArgsMethod,
|
|
181
207
|
clientReq: AuthClientRequest
|
|
182
208
|
) {
|
|
209
|
+
const validation = getJSONBObjectSchemaValidationError(
|
|
210
|
+
{
|
|
211
|
+
method: { type: "string" },
|
|
212
|
+
params: { type: "any[]", optional: true },
|
|
213
|
+
},
|
|
214
|
+
unvalidatedArgs,
|
|
215
|
+
"method"
|
|
216
|
+
);
|
|
217
|
+
if (validation.error !== undefined) {
|
|
218
|
+
throw validation.error;
|
|
219
|
+
}
|
|
220
|
+
const reqArgs = validation.data;
|
|
183
221
|
const { method, params = [] } = reqArgs;
|
|
184
222
|
const methods = await this.publishParser?.getAllowedMethods(clientReq, undefined);
|
|
185
223
|
|
|
186
|
-
const methodDef = methods?.
|
|
224
|
+
const methodDef = methods?.get(method);
|
|
187
225
|
if (!methods || !methodDef) {
|
|
188
226
|
throw "Disallowed/missing method " + JSON.stringify(method);
|
|
189
227
|
}
|
package/lib/shortestPath.ts
CHANGED
|
@@ -25,7 +25,7 @@ export const findShortestPath = (
|
|
|
25
25
|
// establish object for recording distances from the start node
|
|
26
26
|
let distances: AnyObject = {};
|
|
27
27
|
distances[endNode] = "Infinity";
|
|
28
|
-
distances =
|
|
28
|
+
distances = { ...distances, ...graph[startNode] };
|
|
29
29
|
|
|
30
30
|
// track paths
|
|
31
31
|
const parents: AnyObject = { endNode: null };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prostgles-server",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.348",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"pg": "^8.15.6",
|
|
58
58
|
"pg-cursor": "^2.14.6",
|
|
59
59
|
"pg-promise": "^11.13.0",
|
|
60
|
-
"prostgles-types": "^4.0.
|
|
60
|
+
"prostgles-types": "^4.0.183"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@eslint/js": "^9.22.0",
|