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/ProstglesTypes.ts
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import { FileColumnConfig } from "prostgles-types";
|
|
2
2
|
import { Auth, AuthRequestParams, SessionUser } from "./Auth/AuthTypes";
|
|
3
3
|
import { EventTriggerTagFilter } from "./Event_Trigger_Tags";
|
|
4
|
-
import {
|
|
5
|
-
CloudClient,
|
|
6
|
-
ImageOptions,
|
|
7
|
-
LocalConfig,
|
|
8
|
-
} from "./FileManager/FileManager";
|
|
4
|
+
import { CloudClient, ImageOptions, LocalConfig } from "./FileManager/FileManager";
|
|
9
5
|
import { DbConnection, OnReadyCallback } from "./initProstgles";
|
|
10
6
|
import { EventInfo } from "./Logging";
|
|
11
7
|
import { ExpressApp, RestApiConfig } from "./RestApi";
|
|
@@ -20,11 +16,7 @@ import pg from "pg-promise/typescript/pg-subset";
|
|
|
20
16
|
import { AnyObject } from "prostgles-types";
|
|
21
17
|
import type { Server } from "socket.io";
|
|
22
18
|
import { DB } from "./Prostgles";
|
|
23
|
-
import {
|
|
24
|
-
Publish,
|
|
25
|
-
PublishMethods,
|
|
26
|
-
PublishParams,
|
|
27
|
-
} from "./PublishParser/PublishParser";
|
|
19
|
+
import { Awaitable, Publish, PublishMethods, PublishParams } from "./PublishParser/PublishParser";
|
|
28
20
|
|
|
29
21
|
/**
|
|
30
22
|
* Allows uploading and downloading files.
|
|
@@ -102,12 +94,7 @@ export type FileTableConfig = {
|
|
|
102
94
|
localConfig?: LocalConfig;
|
|
103
95
|
};
|
|
104
96
|
|
|
105
|
-
export const JOIN_TYPES = [
|
|
106
|
-
"one-many",
|
|
107
|
-
"many-one",
|
|
108
|
-
"one-one",
|
|
109
|
-
"many-many",
|
|
110
|
-
] as const;
|
|
97
|
+
export const JOIN_TYPES = ["one-many", "many-one", "one-one", "many-many"] as const;
|
|
111
98
|
export type Join = {
|
|
112
99
|
tables: [string, string];
|
|
113
100
|
on: { [key: string]: string }[]; // Allow multi references to table
|
|
@@ -115,10 +102,7 @@ export type Join = {
|
|
|
115
102
|
};
|
|
116
103
|
type Joins = Join[] | "inferred";
|
|
117
104
|
|
|
118
|
-
export type ProstglesInitOptions<
|
|
119
|
-
S = void,
|
|
120
|
-
SUser extends SessionUser = SessionUser,
|
|
121
|
-
> = {
|
|
105
|
+
export type ProstglesInitOptions<S = void, SUser extends SessionUser = SessionUser> = {
|
|
122
106
|
/**
|
|
123
107
|
* Database connection details and options
|
|
124
108
|
*/
|
|
@@ -187,9 +171,7 @@ export type ProstglesInitOptions<
|
|
|
187
171
|
/**
|
|
188
172
|
* If defined and resolves to true then the connected client can run SQL queries
|
|
189
173
|
*/
|
|
190
|
-
publishRawSQL?(
|
|
191
|
-
params: PublishParams<S, SUser>,
|
|
192
|
-
): (boolean | "*") | Promise<boolean | "*">;
|
|
174
|
+
publishRawSQL?(params: PublishParams<S, SUser>): Awaitable<boolean | "*">;
|
|
193
175
|
|
|
194
176
|
/**
|
|
195
177
|
* Server-side functions that can be invoked by the client
|
|
@@ -236,14 +218,14 @@ export type ProstglesInitOptions<
|
|
|
236
218
|
* Use for connection verification. Will disconnect socket on any errors
|
|
237
219
|
*/
|
|
238
220
|
onSocketConnect?: (
|
|
239
|
-
args: AuthRequestParams<S, SUser> & { socket: PRGLIOSocket }
|
|
221
|
+
args: AuthRequestParams<S, SUser> & { socket: PRGLIOSocket }
|
|
240
222
|
) => void | Promise<void>;
|
|
241
223
|
|
|
242
224
|
/**
|
|
243
225
|
* Called when a socket disconnects
|
|
244
226
|
*/
|
|
245
227
|
onSocketDisconnect?: (
|
|
246
|
-
args: AuthRequestParams<S, SUser> & { socket: PRGLIOSocket }
|
|
228
|
+
args: AuthRequestParams<S, SUser> & { socket: PRGLIOSocket }
|
|
247
229
|
) => void | Promise<void>;
|
|
248
230
|
|
|
249
231
|
/**
|
|
@@ -281,11 +263,7 @@ export type ProstglesInitOptions<
|
|
|
281
263
|
* - `OnSchemaChangeCallback` - custom callback to be fired. Nothing else triggered
|
|
282
264
|
* Useful for development
|
|
283
265
|
*/
|
|
284
|
-
watchSchema?:
|
|
285
|
-
| boolean
|
|
286
|
-
| EventTriggerTagFilter
|
|
287
|
-
| "hotReloadMode"
|
|
288
|
-
| OnSchemaChangeCallback;
|
|
266
|
+
watchSchema?: boolean | EventTriggerTagFilter | "hotReloadMode" | OnSchemaChangeCallback;
|
|
289
267
|
|
|
290
268
|
/**
|
|
291
269
|
* Called when a notice is received from the database
|
|
@@ -357,6 +335,6 @@ type OnMigrate = (args: {
|
|
|
357
335
|
getConstraints: (
|
|
358
336
|
table: string,
|
|
359
337
|
column?: string,
|
|
360
|
-
types?: ColConstraint["type"][]
|
|
338
|
+
types?: ColConstraint["type"][]
|
|
361
339
|
) => Promise<ColConstraint[]>;
|
|
362
340
|
}) => void;
|
|
@@ -295,7 +295,7 @@ export class PubSubManager {
|
|
|
295
295
|
|
|
296
296
|
await this.db
|
|
297
297
|
.tx((t) => t.any(query))
|
|
298
|
-
.catch((e) => {
|
|
298
|
+
.catch((e: any) => {
|
|
299
299
|
console.error("prepareTriggers failed: ", e);
|
|
300
300
|
throw e;
|
|
301
301
|
});
|
|
@@ -545,10 +545,10 @@ export class PubSubManager {
|
|
|
545
545
|
socketId: socket?.id,
|
|
546
546
|
state: !addedTrigger.tbl ? "fail" : "ok",
|
|
547
547
|
error: addedTrigger.error,
|
|
548
|
-
sid: this.dboBuilder.prostgles.authHandler?.getSIDNoError({ socket }),
|
|
548
|
+
sid: socket && this.dboBuilder.prostgles.authHandler?.getSIDNoError({ socket }),
|
|
549
549
|
tableName: addedTrigger.tbl ?? params.table_name,
|
|
550
550
|
connectedSocketIds: this.dboBuilder.prostgles.connectedSockets.map((s) => s.id),
|
|
551
|
-
localParams: { socket },
|
|
551
|
+
localParams: socket && { clientReq: { socket } },
|
|
552
552
|
});
|
|
553
553
|
|
|
554
554
|
if (addedTrigger.error) throw addedTrigger.error;
|
|
@@ -15,9 +15,7 @@ export async function addSync(
|
|
|
15
15
|
this: PubSubManager,
|
|
16
16
|
syncParams: AddSyncParams
|
|
17
17
|
): Promise<{ channelName: string }> {
|
|
18
|
-
const sid = this.dboBuilder.prostgles.authHandler?.getSIDNoError({
|
|
19
|
-
socket: syncParams.socket,
|
|
20
|
-
});
|
|
18
|
+
const sid = this.dboBuilder.prostgles.authHandler?.getSIDNoError({ socket: syncParams.socket });
|
|
21
19
|
const res = await tryCatchV2(async () => {
|
|
22
20
|
const {
|
|
23
21
|
socket = null,
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Method, getObjectEntries, isObject } from "prostgles-types";
|
|
2
|
-
import { AuthResult, SessionUser } from "../Auth/AuthTypes";
|
|
3
|
-
import {
|
|
2
|
+
import { AuthClientRequest, AuthResult, SessionUser } from "../Auth/AuthTypes";
|
|
3
|
+
import { PublishFullyTyped } from "../DBSchemaBuilder";
|
|
4
4
|
import { DB, DBHandlerServer, Prostgles } from "../Prostgles";
|
|
5
|
+
import { ProstglesInitOptions } from "../ProstglesTypes";
|
|
5
6
|
import { VoidFunction } from "../SchemaWatch/SchemaWatch";
|
|
6
7
|
import { getFileTableRules } from "./getFileTableRules";
|
|
7
8
|
import { getSchemaFromPublish } from "./getSchemaFromPublish";
|
|
@@ -16,8 +17,6 @@ import {
|
|
|
16
17
|
RULE_TO_METHODS,
|
|
17
18
|
TableRule,
|
|
18
19
|
} from "./publishTypesAndUtils";
|
|
19
|
-
import { ProstglesInitOptions } from "../ProstglesTypes";
|
|
20
|
-
import { PublishFullyTyped } from "../DBSchemaBuilder";
|
|
21
20
|
|
|
22
21
|
export class PublishParser {
|
|
23
22
|
publish: ProstglesInitOptions["publish"];
|
|
@@ -27,44 +26,37 @@ export class PublishParser {
|
|
|
27
26
|
db: DB;
|
|
28
27
|
prostgles: Prostgles;
|
|
29
28
|
|
|
30
|
-
constructor(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
db
|
|
36
|
-
|
|
37
|
-
) {
|
|
38
|
-
this.publish = publish;
|
|
39
|
-
this.publishMethods = publishMethods;
|
|
40
|
-
this.publishRawSQL = publishRawSQL;
|
|
29
|
+
constructor(prostgles: Prostgles) {
|
|
30
|
+
this.prostgles = prostgles;
|
|
31
|
+
this.publish = prostgles.opts.publish;
|
|
32
|
+
this.publishMethods = prostgles.opts.publishMethods;
|
|
33
|
+
this.publishRawSQL = prostgles.opts.publishRawSQL;
|
|
34
|
+
const { dbo, db } = prostgles;
|
|
35
|
+
if (!dbo || !db) throw "INTERNAL ERROR: dbo and/or db missing";
|
|
41
36
|
this.dbo = dbo;
|
|
42
37
|
this.db = db;
|
|
43
|
-
this.prostgles = prostgles;
|
|
44
|
-
|
|
45
|
-
if (!this.publish) throw "INTERNAL ERROR: dbo and/or publish missing";
|
|
46
38
|
}
|
|
47
39
|
|
|
48
40
|
async getPublishParams(
|
|
49
|
-
|
|
41
|
+
clientReq: AuthClientRequest,
|
|
50
42
|
clientInfo?: AuthResult
|
|
51
43
|
): Promise<PublishParams> {
|
|
52
44
|
return {
|
|
53
|
-
...(clientInfo || (await this.prostgles.authHandler?.
|
|
45
|
+
...(clientInfo || (await this.prostgles.authHandler?.getUserFromRequest(clientReq))),
|
|
54
46
|
dbo: this.dbo as any,
|
|
55
47
|
db: this.db,
|
|
56
|
-
|
|
48
|
+
clientReq,
|
|
57
49
|
tables: this.prostgles.dboBuilder.tables,
|
|
58
50
|
};
|
|
59
51
|
}
|
|
60
52
|
|
|
61
53
|
async getAllowedMethods(
|
|
62
|
-
|
|
63
|
-
userData
|
|
54
|
+
clientReq: AuthClientRequest,
|
|
55
|
+
userData: AuthResult | undefined
|
|
64
56
|
): Promise<{ [key: string]: Method }> {
|
|
65
57
|
const methods: { [key: string]: Method } = {};
|
|
66
58
|
|
|
67
|
-
const publishParams = await this.getPublishParams(
|
|
59
|
+
const publishParams = await this.getPublishParams(clientReq, userData);
|
|
68
60
|
const _methods = await applyParamsIfFunc(this.publishMethods, publishParams);
|
|
69
61
|
|
|
70
62
|
if (_methods && Object.keys(_methods).length) {
|
|
@@ -90,10 +82,10 @@ export class PublishParser {
|
|
|
90
82
|
* Parses the first level of publish. (If false then nothing if * then all tables and views)
|
|
91
83
|
*/
|
|
92
84
|
async getPublish(
|
|
93
|
-
|
|
94
|
-
clientInfo
|
|
85
|
+
clientReq: AuthClientRequest,
|
|
86
|
+
clientInfo: AuthResult
|
|
95
87
|
): Promise<PublishFullyTyped | undefined> {
|
|
96
|
-
const publishParams = await this.getPublishParams(
|
|
88
|
+
const publishParams = await this.getPublishParams(clientReq, clientInfo);
|
|
97
89
|
const _publish = await applyParamsIfFunc(this.publish, publishParams);
|
|
98
90
|
|
|
99
91
|
if (_publish === "*") {
|
|
@@ -106,32 +98,30 @@ export class PublishParser {
|
|
|
106
98
|
|
|
107
99
|
return _publish || undefined;
|
|
108
100
|
}
|
|
101
|
+
|
|
109
102
|
async getValidatedRequestRuleWusr({
|
|
110
103
|
tableName,
|
|
111
104
|
command,
|
|
112
|
-
|
|
105
|
+
clientReq,
|
|
113
106
|
}: DboTableCommand): Promise<TableRule> {
|
|
114
|
-
const clientInfo = await this.prostgles.authHandler
|
|
115
|
-
const rules = await this.getValidatedRequestRule(
|
|
116
|
-
{ tableName, command, localParams },
|
|
117
|
-
clientInfo
|
|
118
|
-
);
|
|
107
|
+
const clientInfo = await this.prostgles.authHandler?.getUserFromRequest(clientReq);
|
|
108
|
+
const rules = await this.getValidatedRequestRule({ tableName, command, clientReq }, clientInfo);
|
|
119
109
|
return rules;
|
|
120
110
|
}
|
|
121
111
|
|
|
122
112
|
async getValidatedRequestRule(
|
|
123
|
-
{ tableName, command,
|
|
124
|
-
clientInfo
|
|
113
|
+
{ tableName, command, clientReq }: DboTableCommand,
|
|
114
|
+
clientInfo: AuthResult | undefined
|
|
125
115
|
): Promise<TableRule> {
|
|
126
116
|
if (!command || !tableName) throw "command OR tableName are missing";
|
|
127
117
|
|
|
128
|
-
const rtm = RULE_TO_METHODS.find((rtms) =>
|
|
118
|
+
const rtm = RULE_TO_METHODS.find((rtms) => rtms.methods.some((v) => v === command));
|
|
129
119
|
if (!rtm) {
|
|
130
120
|
throw "Invalid command: " + command;
|
|
131
121
|
}
|
|
132
122
|
|
|
133
123
|
/* Must be local request -> allow everything */
|
|
134
|
-
if (!
|
|
124
|
+
if (!clientReq) {
|
|
135
125
|
return RULE_TO_METHODS.reduce(
|
|
136
126
|
(a, v) => ({
|
|
137
127
|
...a,
|
|
@@ -145,19 +135,19 @@ export class PublishParser {
|
|
|
145
135
|
if (!this.publish) throw "publish is missing";
|
|
146
136
|
|
|
147
137
|
/* Get any publish errors for socket */
|
|
148
|
-
const errorInfo =
|
|
138
|
+
const errorInfo = clientReq.socket?.prostgles?.tableSchemaErrors[tableName]?.[command];
|
|
149
139
|
|
|
150
140
|
if (errorInfo) throw errorInfo.error;
|
|
151
141
|
|
|
152
|
-
const
|
|
153
|
-
if (!
|
|
142
|
+
const tableRule = await this.getTableRules({ tableName, clientReq }, clientInfo);
|
|
143
|
+
if (!tableRule)
|
|
154
144
|
throw {
|
|
155
145
|
stack: ["getValidatedRequestRule()"],
|
|
156
146
|
message: "Invalid or disallowed table: " + tableName,
|
|
157
147
|
};
|
|
158
148
|
|
|
159
149
|
if (command === "upsert") {
|
|
160
|
-
if (!
|
|
150
|
+
if (!tableRule.update || !tableRule.insert) {
|
|
161
151
|
throw {
|
|
162
152
|
stack: ["getValidatedRequestRule()"],
|
|
163
153
|
message: `Invalid or disallowed command: upsert`,
|
|
@@ -165,8 +155,8 @@ export class PublishParser {
|
|
|
165
155
|
}
|
|
166
156
|
}
|
|
167
157
|
|
|
168
|
-
if (
|
|
169
|
-
return
|
|
158
|
+
if (tableRule[rtm.rule]) {
|
|
159
|
+
return tableRule;
|
|
170
160
|
} else
|
|
171
161
|
throw {
|
|
172
162
|
stack: ["getValidatedRequestRule()"],
|
|
@@ -176,14 +166,14 @@ export class PublishParser {
|
|
|
176
166
|
|
|
177
167
|
async getTableRules(
|
|
178
168
|
args: DboTable,
|
|
179
|
-
clientInfo
|
|
169
|
+
clientInfo: AuthResult | undefined
|
|
180
170
|
): Promise<ParsedPublishTable | undefined> {
|
|
181
171
|
if (this.dbo[args.tableName]?.is_media) {
|
|
182
172
|
const fileTablePublishRules = await this.getTableRulesWithoutFileTable(args, clientInfo);
|
|
183
173
|
const { rules } = await getFileTableRules.bind(this)(
|
|
184
174
|
args.tableName,
|
|
185
175
|
fileTablePublishRules,
|
|
186
|
-
args.
|
|
176
|
+
args.clientReq,
|
|
187
177
|
clientInfo
|
|
188
178
|
);
|
|
189
179
|
return rules;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { AnyObject, FullFilter, isDefined } from "prostgles-types";
|
|
2
|
-
import { AuthResult } from "../Auth/AuthTypes";
|
|
3
|
-
import { LocalParams } from "../DboBuilder/DboBuilder";
|
|
2
|
+
import { AuthClientRequest, AuthResult } from "../Auth/AuthTypes";
|
|
4
3
|
import { parseFieldFilter } from "../DboBuilder/ViewHandler/parseFieldFilter";
|
|
5
4
|
import { PublishParser } from "./PublishParser";
|
|
6
5
|
import { ParsedPublishTable, UpdateRule } from "./publishTypesAndUtils";
|
|
@@ -17,8 +16,8 @@ export async function getFileTableRules(
|
|
|
17
16
|
this: PublishParser,
|
|
18
17
|
fileTableName: string,
|
|
19
18
|
fileTablePublishRules: ParsedPublishTable | undefined,
|
|
20
|
-
|
|
21
|
-
clientInfo: AuthResult | undefined
|
|
19
|
+
clientReq: AuthClientRequest | undefined,
|
|
20
|
+
clientInfo: AuthResult | undefined
|
|
22
21
|
) {
|
|
23
22
|
const forcedDeleteFilters: FullFilter<AnyObject, void>[] = [];
|
|
24
23
|
const forcedSelectFilters: FullFilter<AnyObject, void>[] = [];
|
|
@@ -28,7 +27,7 @@ export async function getFileTableRules(
|
|
|
28
27
|
?.filter((t) => !t.is_view && t.name !== fileTableName)
|
|
29
28
|
.map((t) => {
|
|
30
29
|
const refCols = t.columns.filter((c) =>
|
|
31
|
-
c.references?.some((r) => r.ftable === fileTableName)
|
|
30
|
+
c.references?.some((r) => r.ftable === fileTableName)
|
|
32
31
|
);
|
|
33
32
|
if (!refCols.length) return undefined;
|
|
34
33
|
return {
|
|
@@ -39,65 +38,46 @@ export async function getFileTableRules(
|
|
|
39
38
|
})
|
|
40
39
|
.filter(isDefined);
|
|
41
40
|
if (referencedColumns?.length) {
|
|
42
|
-
for await (const {
|
|
43
|
-
tableName,
|
|
44
|
-
|
|
45
|
-
allColumns,
|
|
46
|
-
} of referencedColumns) {
|
|
47
|
-
const table_rules = await this.getTableRules(
|
|
48
|
-
{ localParams, tableName },
|
|
49
|
-
clientInfo,
|
|
50
|
-
);
|
|
51
|
-
if (table_rules) {
|
|
41
|
+
for await (const { tableName, fileColumns, allColumns } of referencedColumns) {
|
|
42
|
+
const tableRules = await this.getTableRules({ clientReq, tableName }, clientInfo);
|
|
43
|
+
if (tableRules) {
|
|
52
44
|
fileColumns.map((column) => {
|
|
53
45
|
const path = [{ table: tableName, on: [{ id: column }] }];
|
|
54
|
-
if (
|
|
46
|
+
if (tableRules.delete) {
|
|
55
47
|
forcedDeleteFilters.push({
|
|
56
48
|
$existsJoined: {
|
|
57
49
|
path,
|
|
58
|
-
filter:
|
|
50
|
+
filter: tableRules.delete.forcedFilter ?? {},
|
|
59
51
|
},
|
|
60
52
|
});
|
|
61
53
|
}
|
|
62
|
-
if (
|
|
63
|
-
const parsedFields = parseFieldFilter(
|
|
64
|
-
table_rules.select.fields,
|
|
65
|
-
false,
|
|
66
|
-
allColumns,
|
|
67
|
-
);
|
|
54
|
+
if (tableRules.select) {
|
|
55
|
+
const parsedFields = parseFieldFilter(tableRules.select.fields, false, allColumns);
|
|
68
56
|
/** Must be allowed to view this column */
|
|
69
57
|
if (parsedFields.includes(column as any)) {
|
|
70
58
|
forcedSelectFilters.push({
|
|
71
59
|
$existsJoined: {
|
|
72
60
|
path,
|
|
73
|
-
filter:
|
|
61
|
+
filter: tableRules.select.forcedFilter ?? {},
|
|
74
62
|
},
|
|
75
63
|
});
|
|
76
64
|
}
|
|
77
65
|
}
|
|
78
|
-
if (
|
|
79
|
-
const parsedFields = parseFieldFilter(
|
|
80
|
-
table_rules.insert.fields,
|
|
81
|
-
false,
|
|
82
|
-
allColumns,
|
|
83
|
-
);
|
|
66
|
+
if (tableRules.insert) {
|
|
67
|
+
const parsedFields = parseFieldFilter(tableRules.insert.fields, false, allColumns);
|
|
84
68
|
/** Must be allowed to view this column */
|
|
85
69
|
if (parsedFields.includes(column as any)) {
|
|
86
70
|
allowedNestedInserts.push({ table: tableName, column });
|
|
87
71
|
}
|
|
88
72
|
}
|
|
89
|
-
if (
|
|
90
|
-
const parsedFields = parseFieldFilter(
|
|
91
|
-
table_rules.update.fields,
|
|
92
|
-
false,
|
|
93
|
-
allColumns,
|
|
94
|
-
);
|
|
73
|
+
if (tableRules.update) {
|
|
74
|
+
const parsedFields = parseFieldFilter(tableRules.update.fields, false, allColumns);
|
|
95
75
|
/** Must be allowed to view this column */
|
|
96
76
|
if (parsedFields.includes(column as any)) {
|
|
97
77
|
forcedUpdateFilters.push({
|
|
98
78
|
$existsJoined: {
|
|
99
79
|
path,
|
|
100
|
-
filter:
|
|
80
|
+
filter: tableRules.update.forcedFilter ?? {},
|
|
101
81
|
},
|
|
102
82
|
});
|
|
103
83
|
}
|
|
@@ -113,15 +93,13 @@ export async function getFileTableRules(
|
|
|
113
93
|
|
|
114
94
|
const getForcedFilter = (
|
|
115
95
|
rule: Pick<UpdateRule, "forcedFilter"> | undefined,
|
|
116
|
-
forcedFilters: FullFilter<AnyObject, void>[]
|
|
96
|
+
forcedFilters: FullFilter<AnyObject, void>[]
|
|
117
97
|
) => {
|
|
118
|
-
return rule && !rule.forcedFilter
|
|
119
|
-
|
|
98
|
+
return rule && !rule.forcedFilter ?
|
|
99
|
+
{}
|
|
120
100
|
: {
|
|
121
101
|
forcedFilter: {
|
|
122
|
-
$or: forcedFilters.concat(
|
|
123
|
-
rule?.forcedFilter ? [rule.forcedFilter] : [],
|
|
124
|
-
),
|
|
102
|
+
$or: forcedFilters.concat(rule?.forcedFilter ? [rule.forcedFilter] : []),
|
|
125
103
|
},
|
|
126
104
|
};
|
|
127
105
|
};
|
|
@@ -151,17 +129,15 @@ export async function getFileTableRules(
|
|
|
151
129
|
fileTableRule.insert = {
|
|
152
130
|
fields: "*",
|
|
153
131
|
...fileTablePublishRules?.insert,
|
|
154
|
-
allowedNestedInserts: fileTablePublishRules?.insert
|
|
155
|
-
? undefined
|
|
156
|
-
: allowedNestedInserts,
|
|
132
|
+
allowedNestedInserts: fileTablePublishRules?.insert ? undefined : allowedNestedInserts,
|
|
157
133
|
};
|
|
158
134
|
}
|
|
159
135
|
|
|
160
136
|
/** Add missing implied methods (getColumns, getInfo) */
|
|
161
137
|
const rules = await this.getTableRulesWithoutFileTable.bind(this)(
|
|
162
|
-
{
|
|
138
|
+
{ clientReq, tableName: fileTableName },
|
|
163
139
|
clientInfo,
|
|
164
|
-
{ [fileTableName]: fileTableRule }
|
|
140
|
+
{ [fileTableName]: fileTableRule }
|
|
165
141
|
);
|
|
166
142
|
return { rules, allowedInserts: allowedNestedInserts };
|
|
167
143
|
}
|
|
@@ -1,27 +1,18 @@
|
|
|
1
1
|
import {
|
|
2
2
|
DBSchemaTable,
|
|
3
|
+
getKeys,
|
|
3
4
|
MethodKey,
|
|
5
|
+
pickKeys,
|
|
4
6
|
TableInfo,
|
|
5
7
|
TableSchemaErrors,
|
|
6
8
|
TableSchemaForClient,
|
|
7
|
-
getKeys,
|
|
8
|
-
pickKeys,
|
|
9
9
|
} from "prostgles-types";
|
|
10
|
-
import {
|
|
11
|
-
import { getErrorAsObject
|
|
12
|
-
import { PublishObject, PublishParser } from "./PublishParser";
|
|
10
|
+
import { AuthClientRequest, AuthResult } from "../Auth/AuthTypes";
|
|
11
|
+
import { getErrorAsObject } from "../DboBuilder/DboBuilder";
|
|
13
12
|
import { TABLE_METHODS } from "../Prostgles";
|
|
13
|
+
import { PublishObject, PublishParser } from "./PublishParser";
|
|
14
14
|
|
|
15
|
-
type Args =
|
|
16
|
-
| {
|
|
17
|
-
socket: PRGLIOSocket;
|
|
18
|
-
httpReq?: undefined;
|
|
19
|
-
}
|
|
20
|
-
| {
|
|
21
|
-
httpReq: ExpressReq;
|
|
22
|
-
socket?: undefined;
|
|
23
|
-
}
|
|
24
|
-
) & {
|
|
15
|
+
type Args = AuthClientRequest & {
|
|
25
16
|
userData: AuthResult | undefined;
|
|
26
17
|
};
|
|
27
18
|
|
|
@@ -39,7 +30,8 @@ export async function getSchemaFromPublish(
|
|
|
39
30
|
|
|
40
31
|
try {
|
|
41
32
|
/* Publish tables and views based on socket */
|
|
42
|
-
const clientInfo =
|
|
33
|
+
const clientInfo =
|
|
34
|
+
userData ?? (await this.prostgles.authHandler?.getUserFromRequest(clientReq));
|
|
43
35
|
|
|
44
36
|
let _publish: PublishObject | undefined;
|
|
45
37
|
try {
|
|
@@ -81,10 +73,7 @@ export async function getSchemaFromPublish(
|
|
|
81
73
|
throw errMsg;
|
|
82
74
|
}
|
|
83
75
|
|
|
84
|
-
const table_rules = await this.getTableRules(
|
|
85
|
-
{ localParams: clientReq, tableName },
|
|
86
|
-
clientInfo
|
|
87
|
-
);
|
|
76
|
+
const table_rules = await this.getTableRules({ clientReq, tableName }, clientInfo);
|
|
88
77
|
|
|
89
78
|
if (table_rules && Object.keys(table_rules).length) {
|
|
90
79
|
schema[tableName] = {};
|
|
@@ -117,13 +106,13 @@ export async function getSchemaFromPublish(
|
|
|
117
106
|
: {};
|
|
118
107
|
|
|
119
108
|
/* Test for issues with the common table CRUD methods () */
|
|
120
|
-
if (TABLE_METHODS.
|
|
109
|
+
if (TABLE_METHODS.some((tm) => tm === method)) {
|
|
121
110
|
try {
|
|
122
111
|
const valid_table_command_rules = await this.getValidatedRequestRule(
|
|
123
112
|
{
|
|
124
113
|
tableName,
|
|
125
114
|
command: method,
|
|
126
|
-
|
|
115
|
+
clientReq,
|
|
127
116
|
},
|
|
128
117
|
clientInfo
|
|
129
118
|
);
|
|
@@ -156,7 +145,7 @@ export async function getSchemaFromPublish(
|
|
|
156
145
|
|
|
157
146
|
if (method === "getInfo" || method === "getColumns") {
|
|
158
147
|
const tableRules = await this.getValidatedRequestRule(
|
|
159
|
-
{ tableName, command: method,
|
|
148
|
+
{ tableName, command: method, clientReq },
|
|
160
149
|
clientInfo
|
|
161
150
|
);
|
|
162
151
|
const res = await (this.dbo[tableName] as any)[method](
|