prostgles-server 4.2.270 → 4.2.271
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 +7 -6
- package/dist/Auth/AuthHandler.d.ts.map +1 -1
- package/dist/Auth/AuthHandler.js +22 -52
- package/dist/Auth/AuthHandler.js.map +1 -1
- package/dist/Auth/AuthTypes.d.ts +7 -1
- package/dist/Auth/AuthTypes.d.ts.map +1 -1
- package/dist/Auth/AuthTypes.js.map +1 -1
- package/dist/Auth/endpoints/setCatchAllRequestHandler.js +2 -2
- package/dist/Auth/endpoints/setCatchAllRequestHandler.js.map +1 -1
- package/dist/Auth/getClientAuth.js +2 -3
- package/dist/Auth/getClientAuth.js.map +1 -1
- package/dist/Auth/utils/getSidAndUserFromRequest.d.ts +1 -0
- package/dist/Auth/utils/getSidAndUserFromRequest.d.ts.map +1 -1
- package/dist/Auth/utils/getSidAndUserFromRequest.js +38 -24
- package/dist/Auth/utils/getSidAndUserFromRequest.js.map +1 -1
- package/dist/Auth/utils/getUserOrError.d.ts +9 -0
- package/dist/Auth/utils/getUserOrError.d.ts.map +1 -0
- package/dist/Auth/utils/getUserOrError.js +48 -0
- package/dist/Auth/utils/getUserOrError.js.map +1 -0
- package/dist/Auth/utils/handleGetUser.d.ts +6 -0
- package/dist/Auth/utils/handleGetUser.d.ts.map +1 -0
- package/dist/Auth/utils/handleGetUser.js +53 -0
- package/dist/Auth/utils/handleGetUser.js.map +1 -0
- package/dist/DboBuilder/DboBuilderTypes.d.ts +2 -1
- package/dist/DboBuilder/DboBuilderTypes.d.ts.map +1 -1
- package/dist/Prostgles.d.ts.map +1 -1
- package/dist/Prostgles.js.map +1 -1
- package/dist/PublishParser/PublishParser.d.ts.map +1 -1
- package/dist/PublishParser/PublishParser.js +3 -4
- package/dist/PublishParser/PublishParser.js.map +1 -1
- package/dist/PublishParser/getSchemaFromPublish.d.ts.map +1 -1
- package/dist/PublishParser/getSchemaFromPublish.js +67 -69
- package/dist/PublishParser/getSchemaFromPublish.js.map +1 -1
- package/dist/onSocketConnected.js +3 -3
- package/dist/onSocketConnected.js.map +1 -1
- package/lib/Auth/AuthHandler.ts +25 -76
- package/lib/Auth/AuthTypes.ts +9 -1
- package/lib/Auth/endpoints/setCatchAllRequestHandler.ts +2 -2
- package/lib/Auth/getClientAuth.ts +10 -10
- package/lib/Auth/utils/getSidAndUserFromRequest.ts +38 -31
- package/lib/Auth/utils/getUserOrError.ts +56 -0
- package/lib/Auth/utils/handleGetUser.ts +67 -0
- package/lib/DboBuilder/DboBuilderTypes.ts +2 -1
- package/lib/Prostgles.ts +1 -0
- package/lib/PublishParser/PublishParser.ts +4 -3
- package/lib/PublishParser/getSchemaFromPublish.ts +96 -95
- package/lib/onSocketConnected.ts +3 -3
- package/package.json +2 -2
|
@@ -14,10 +14,16 @@ export async function getClientAuth(
|
|
|
14
14
|
clientReq: AuthClientRequest
|
|
15
15
|
): Promise<{ auth: AuthSocketSchema; userData: AuthResultWithSID }> {
|
|
16
16
|
let pathGuard = false;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
const {
|
|
18
|
+
loginWithOAuth,
|
|
19
|
+
signupWithEmail: signupWithEmailAndPassword,
|
|
20
|
+
localLoginMode,
|
|
21
|
+
login,
|
|
22
|
+
publicRoutes,
|
|
23
|
+
disableSocketAuthGuard,
|
|
24
|
+
} = this.opts.loginSignupConfig ?? {};
|
|
25
|
+
|
|
26
|
+
if (publicRoutes && !disableSocketAuthGuard) {
|
|
21
27
|
pathGuard = true;
|
|
22
28
|
|
|
23
29
|
/**
|
|
@@ -64,12 +70,6 @@ export async function getClientAuth(
|
|
|
64
70
|
}
|
|
65
71
|
|
|
66
72
|
const userData = await this.getSidAndUserFromRequest(clientReq);
|
|
67
|
-
const {
|
|
68
|
-
loginWithOAuth,
|
|
69
|
-
signupWithEmail: signupWithEmailAndPassword,
|
|
70
|
-
localLoginMode,
|
|
71
|
-
login,
|
|
72
|
-
} = this.opts.loginSignupConfig ?? {};
|
|
73
73
|
|
|
74
74
|
const auth: AuthSocketSchema = {
|
|
75
75
|
providers: getOAuthProviders(loginWithOAuth),
|
|
@@ -6,6 +6,7 @@ import { throttledAuthCall } from "./throttledReject";
|
|
|
6
6
|
/**
|
|
7
7
|
* For a given sid return the user data if available using the auth handler's getUser method.
|
|
8
8
|
* Use socket session cache if configured in Auth
|
|
9
|
+
* Used in Publish Parser and AuthHandler
|
|
9
10
|
*/
|
|
10
11
|
export async function getSidAndUserFromRequest(
|
|
11
12
|
this: AuthHandler,
|
|
@@ -16,7 +17,7 @@ export async function getSidAndUserFromRequest(
|
|
|
16
17
|
*/
|
|
17
18
|
const getSessionForCaching = this.opts.cacheSession?.getSession;
|
|
18
19
|
if (clientReq.socket && getSessionForCaching && clientReq.socket.__prglCache) {
|
|
19
|
-
const { session,
|
|
20
|
+
const { session, userData } = clientReq.socket.__prglCache;
|
|
20
21
|
const isValid = this.isNonExpiredSocketSession(clientReq.socket, session);
|
|
21
22
|
if (isValid) {
|
|
22
23
|
return {
|
|
@@ -33,40 +34,46 @@ export async function getSidAndUserFromRequest(
|
|
|
33
34
|
* Get sid from request and fetch user data
|
|
34
35
|
*/
|
|
35
36
|
const authStart = Date.now();
|
|
36
|
-
const result = await throttledAuthCall(async () => {
|
|
37
|
-
|
|
37
|
+
// const result = await throttledAuthCall(async () => {
|
|
38
|
+
// const clientInfoOrErr = await this.opts.getUser(
|
|
39
|
+
// this.getValidatedSid(clientReq),
|
|
40
|
+
// this.dbo as DBOFullyTyped,
|
|
41
|
+
// this.db,
|
|
42
|
+
// getClientRequestIPsInfo(clientReq),
|
|
43
|
+
// clientReq
|
|
44
|
+
// );
|
|
45
|
+
// if (clientInfoOrErr && (typeof clientInfoOrErr === "string" || "success" in clientInfoOrErr))
|
|
46
|
+
// throw clientInfoOrErr;
|
|
47
|
+
// const clientInfo = clientInfoOrErr;
|
|
38
48
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
this.db,
|
|
46
|
-
getClientRequestIPsInfo(clientReq),
|
|
47
|
-
clientReq
|
|
48
|
-
)
|
|
49
|
-
);
|
|
50
|
-
if (clientInfoOrErr && (typeof clientInfoOrErr === "string" || "success" in clientInfoOrErr))
|
|
51
|
-
throw clientInfoOrErr;
|
|
52
|
-
const clientInfo = clientInfoOrErr;
|
|
53
|
-
if (getSessionForCaching && clientReq.socket && sid) {
|
|
54
|
-
const session = await getSessionForCaching(sid, this.dbo as DBOFullyTyped, this.db);
|
|
55
|
-
if (session && session.expires && clientInfo?.user) {
|
|
56
|
-
clientReq.socket.__prglCache = {
|
|
57
|
-
...clientInfo,
|
|
58
|
-
session,
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
}
|
|
49
|
+
// if (clientInfo && "type" in clientInfo) {
|
|
50
|
+
// if (!("httpReq" in clientReq) || !clientReq.httpReq) throw "httpReq missing";
|
|
51
|
+
// const { httpReq, res } = clientReq;
|
|
52
|
+
// this.setCookieAndGoToReturnURLIFSet(clientInfo.session, { req: httpReq, res });
|
|
53
|
+
// return;
|
|
54
|
+
// }
|
|
62
55
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
56
|
+
// const sid = this.getValidatedSid(clientReq);
|
|
57
|
+
// if (getSessionForCaching && clientReq.socket && sid) {
|
|
58
|
+
// const session = await getSessionForCaching(sid, this.dbo as DBOFullyTyped, this.db);
|
|
59
|
+
// if (session && session.expires && clientInfo?.user) {
|
|
60
|
+
// clientReq.socket.__prglCache = {
|
|
61
|
+
// userData: clientInfo,
|
|
62
|
+
// session,
|
|
63
|
+
// };
|
|
64
|
+
// }
|
|
65
|
+
// }
|
|
66
66
|
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
// if (clientInfo?.user && sid) {
|
|
68
|
+
// return { sid, ...clientInfo };
|
|
69
|
+
// }
|
|
69
70
|
|
|
71
|
+
// return { sid, preferredLogin: !clientInfo?.user ? clientInfo?.preferredLogin : undefined };
|
|
72
|
+
// }, 100);
|
|
73
|
+
const result = await this.handleGetUser(clientReq);
|
|
74
|
+
if (result.error) {
|
|
75
|
+
throw result.error;
|
|
76
|
+
}
|
|
70
77
|
await this.prostgles.opts.onLog?.({
|
|
71
78
|
type: "auth",
|
|
72
79
|
command: "getClientInfo",
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { AuthResponse } from "prostgles-types";
|
|
2
|
+
import { DBOFullyTyped } from "../../DBSchemaBuilder";
|
|
3
|
+
import type { AuthHandler } from "../AuthHandler";
|
|
4
|
+
import { AuthClientRequest, AuthResultWithSID } from "../AuthTypes";
|
|
5
|
+
import { getClientRequestIPsInfo } from "../utils/getClientRequestIPsInfo";
|
|
6
|
+
import { isAuthError } from "./handleGetUser";
|
|
7
|
+
import { throttledAuthCall } from "./throttledReject";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Used by:
|
|
11
|
+
* - setCatchAllRequestHandler
|
|
12
|
+
* - loginSignupConfig.use
|
|
13
|
+
*/
|
|
14
|
+
export async function getUserOrError(
|
|
15
|
+
this: AuthHandler,
|
|
16
|
+
clientReq: AuthClientRequest
|
|
17
|
+
): Promise<AuthResultWithSID> {
|
|
18
|
+
// const sid = this.getValidatedSid(clientReq);
|
|
19
|
+
// if (!sid) return { sid };
|
|
20
|
+
|
|
21
|
+
try {
|
|
22
|
+
// const userOrErrorCode = await throttledAuthCall(async () => {
|
|
23
|
+
// return this.opts.getUser(
|
|
24
|
+
// this.validateSid(sid),
|
|
25
|
+
// this.dbo as DBOFullyTyped,
|
|
26
|
+
// this.db,
|
|
27
|
+
// getClientRequestIPsInfo(clientReq),
|
|
28
|
+
// clientReq
|
|
29
|
+
// );
|
|
30
|
+
// }, 50);
|
|
31
|
+
|
|
32
|
+
// if (isAuthError(userOrErrorCode)) {
|
|
33
|
+
// const error: AuthResponse.AuthFailure | undefined =
|
|
34
|
+
// typeof userOrErrorCode === "string" ?
|
|
35
|
+
// { success: false, code: userOrErrorCode }
|
|
36
|
+
// : userOrErrorCode;
|
|
37
|
+
|
|
38
|
+
// return {
|
|
39
|
+
// sid,
|
|
40
|
+
// error,
|
|
41
|
+
// };
|
|
42
|
+
// }
|
|
43
|
+
// if (sid && userOrErrorCode?.user) {
|
|
44
|
+
// return { sid, ...userOrErrorCode };
|
|
45
|
+
// }
|
|
46
|
+
// return {
|
|
47
|
+
// sid,
|
|
48
|
+
// };
|
|
49
|
+
return this.handleGetUser(clientReq);
|
|
50
|
+
} catch (_err) {
|
|
51
|
+
return {
|
|
52
|
+
sid: this.getValidatedSid(clientReq),
|
|
53
|
+
error: { success: false, code: "server-error" },
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { DBOFullyTyped } from "../../DBSchemaBuilder";
|
|
2
|
+
import { tout } from "../../PubSubManager/initPubSubManager";
|
|
3
|
+
import { getClientRequestIPsInfo, type AuthHandler } from "../AuthHandler";
|
|
4
|
+
import type { AuthClientRequest, AuthResultOrError, AuthResultWithSID } from "../AuthTypes";
|
|
5
|
+
import { throttledAuthCall } from "./throttledReject";
|
|
6
|
+
import { AuthResponse, isObject } from "prostgles-types";
|
|
7
|
+
|
|
8
|
+
export async function handleGetUserThrottled(
|
|
9
|
+
this: AuthHandler,
|
|
10
|
+
clientReq: AuthClientRequest
|
|
11
|
+
): Promise<AuthResultWithSID> {
|
|
12
|
+
const getSessionForCaching = this.opts.cacheSession?.getSession;
|
|
13
|
+
const result = await throttledAuthCall(async () => {
|
|
14
|
+
const clientInfoOrErr = await this.opts.getUser(
|
|
15
|
+
this.getValidatedSid(clientReq),
|
|
16
|
+
this.dbo as DBOFullyTyped,
|
|
17
|
+
this.db,
|
|
18
|
+
getClientRequestIPsInfo(clientReq),
|
|
19
|
+
clientReq
|
|
20
|
+
);
|
|
21
|
+
if (isAuthError(clientInfoOrErr)) {
|
|
22
|
+
return {
|
|
23
|
+
error:
|
|
24
|
+
isObject(clientInfoOrErr) ? clientInfoOrErr : { success: false, code: clientInfoOrErr },
|
|
25
|
+
sid: this.getValidatedSid(clientReq),
|
|
26
|
+
} satisfies AuthResultWithSID;
|
|
27
|
+
}
|
|
28
|
+
const clientInfo = clientInfoOrErr;
|
|
29
|
+
|
|
30
|
+
if (clientInfo && "type" in clientInfo) {
|
|
31
|
+
if (!("httpReq" in clientReq) || !clientReq.httpReq)
|
|
32
|
+
throw "httpReq missing. new-session not implemented for sockets.";
|
|
33
|
+
const { httpReq, res } = clientReq;
|
|
34
|
+
this.setCookieAndGoToReturnURLIFSet(clientInfo.session, { req: httpReq, res });
|
|
35
|
+
/** Wait for refresh */
|
|
36
|
+
await tout(200);
|
|
37
|
+
return {
|
|
38
|
+
error: { success: false, code: "something-went-wrong" },
|
|
39
|
+
sid: this.getValidatedSid(clientReq),
|
|
40
|
+
} satisfies AuthResultWithSID;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const sid = this.getValidatedSid(clientReq);
|
|
44
|
+
if (getSessionForCaching && clientReq.socket && sid) {
|
|
45
|
+
const session = await getSessionForCaching(sid, this.dbo as DBOFullyTyped, this.db);
|
|
46
|
+
if (session && session.expires && clientInfo?.user) {
|
|
47
|
+
clientReq.socket.__prglCache = {
|
|
48
|
+
userData: clientInfo,
|
|
49
|
+
session,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (clientInfo?.user && sid) {
|
|
55
|
+
return { sid, ...clientInfo };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return { sid, preferredLogin: !clientInfo?.user ? clientInfo?.preferredLogin : undefined };
|
|
59
|
+
}, 100);
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export const isAuthError = (
|
|
64
|
+
dataOrError: AuthResultOrError
|
|
65
|
+
): dataOrError is AuthResponse.AuthFailure["code"] | AuthResponse.AuthFailure => {
|
|
66
|
+
return Boolean(typeof dataOrError === "string" || (dataOrError && "success" in dataOrError));
|
|
67
|
+
};
|
package/lib/Prostgles.ts
CHANGED
|
@@ -159,13 +159,14 @@ export class PublishParser {
|
|
|
159
159
|
}
|
|
160
160
|
}
|
|
161
161
|
|
|
162
|
-
if (tableRule[rtm.rule]) {
|
|
163
|
-
return tableRule;
|
|
164
|
-
} else
|
|
162
|
+
if (!tableRule[rtm.rule]) {
|
|
165
163
|
throw {
|
|
166
164
|
stack: ["getValidatedRequestRule()"],
|
|
167
165
|
message: `Invalid or disallowed command: ${tableName}.${command}`,
|
|
168
166
|
};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return tableRule;
|
|
169
170
|
}
|
|
170
171
|
|
|
171
172
|
async getTableRules(
|
|
@@ -1,20 +1,26 @@
|
|
|
1
1
|
import {
|
|
2
2
|
DBSchemaTable,
|
|
3
3
|
getKeys,
|
|
4
|
+
includes,
|
|
5
|
+
isEmpty,
|
|
6
|
+
isObject,
|
|
4
7
|
MethodKey,
|
|
5
8
|
pickKeys,
|
|
6
9
|
TableInfo,
|
|
7
10
|
TableSchemaErrors,
|
|
8
11
|
TableSchemaForClient,
|
|
12
|
+
type AnyObject,
|
|
9
13
|
} from "prostgles-types";
|
|
10
14
|
import { AuthClientRequest, AuthResultWithSID } from "../Auth/AuthTypes";
|
|
11
15
|
import { getErrorAsObject } from "../DboBuilder/DboBuilder";
|
|
16
|
+
import type { TableHandler } from "../DboBuilder/TableHandler/TableHandler";
|
|
12
17
|
import { TABLE_METHODS } from "../Prostgles";
|
|
13
18
|
import { type PublishObject, PublishParser } from "./PublishParser";
|
|
14
19
|
|
|
15
20
|
type Args = AuthClientRequest & {
|
|
16
21
|
userData: AuthResultWithSID | undefined;
|
|
17
22
|
};
|
|
23
|
+
const SUBSCRIBE_METHODS = ["subscribe", "subscribeOne", "sync", "unsubscribe", "unsync"] as const;
|
|
18
24
|
|
|
19
25
|
export async function getSchemaFromPublish(
|
|
20
26
|
this: PublishParser,
|
|
@@ -64,115 +70,110 @@ export async function getSchemaFromPublish(
|
|
|
64
70
|
}
|
|
65
71
|
await Promise.all(
|
|
66
72
|
tableNames.map(async (tableName) => {
|
|
73
|
+
const { canSubscribe, tablesOrViews } = this.prostgles.dboBuilder;
|
|
67
74
|
if (!this.dbo[tableName]) {
|
|
68
75
|
const errMsg = [
|
|
69
76
|
`Table ${tableName} does not exist`,
|
|
70
|
-
`Expecting one of: ${JSON.stringify(
|
|
71
|
-
`DBO tables: ${JSON.stringify(Object.keys(this.dbo).filter((k) => (this.dbo[k] as any).find))}`,
|
|
77
|
+
`Expecting one of: ${JSON.stringify(tablesOrViews?.map((tov) => tov.name))}`,
|
|
72
78
|
].join("\n");
|
|
73
79
|
throw errMsg;
|
|
74
80
|
}
|
|
75
81
|
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
if (
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
82
|
+
const tableRules = await this.getTableRules({ clientReq, tableName }, clientInfo);
|
|
83
|
+
|
|
84
|
+
if (!tableRules || isEmpty(tableRules)) return;
|
|
85
|
+
if (!isObject(tableRules)) {
|
|
86
|
+
throw `Invalid tableRules for table ${tableName}. Expecting an object`;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
schema[tableName] = {};
|
|
90
|
+
const tableSchema = schema[tableName]!;
|
|
91
|
+
const methods = getKeys(tableRules).filter(
|
|
92
|
+
(m) => canSubscribe || !includes(SUBSCRIBE_METHODS, m)
|
|
93
|
+
);
|
|
94
|
+
let tableInfo: TableInfo | undefined;
|
|
95
|
+
let tableColumns: DBSchemaTable["columns"] | undefined;
|
|
96
|
+
|
|
97
|
+
await Promise.all(
|
|
98
|
+
methods
|
|
99
|
+
.filter((m) => m !== "select")
|
|
100
|
+
.map(async (method) => {
|
|
101
|
+
if (method === "sync") {
|
|
102
|
+
/* Pass sync info */
|
|
103
|
+
tableSchema[method] = tableRules[method];
|
|
104
|
+
} else if (includes(getKeys(tableRules), method) && tableRules[method]) {
|
|
105
|
+
//@ts-ignore
|
|
106
|
+
tableSchema[method] =
|
|
107
|
+
method === "insert" ?
|
|
108
|
+
pickKeys(tableRules[method]!, ["allowedNestedInserts"])
|
|
109
|
+
: ({} as AnyObject);
|
|
110
|
+
|
|
111
|
+
/* Test for issues with the common table CRUD methods () */
|
|
112
|
+
if (includes(TABLE_METHODS, method)) {
|
|
113
|
+
try {
|
|
114
|
+
const parsedTableRule = await this.getValidatedRequestRule(
|
|
115
|
+
{
|
|
116
|
+
tableName,
|
|
117
|
+
command: method,
|
|
118
|
+
clientReq,
|
|
119
|
+
},
|
|
120
|
+
clientInfo
|
|
121
|
+
);
|
|
122
|
+
if (this.prostgles.opts.testRulesOnConnect) {
|
|
123
|
+
await (this.dbo[tableName] as TableHandler)[method](
|
|
124
|
+
{},
|
|
125
|
+
{},
|
|
126
|
+
undefined,
|
|
127
|
+
parsedTableRule,
|
|
112
128
|
{
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}
|
|
117
|
-
clientInfo
|
|
129
|
+
...clientReq,
|
|
130
|
+
isRemoteRequest: {},
|
|
131
|
+
testRule: true,
|
|
132
|
+
}
|
|
118
133
|
);
|
|
119
|
-
if (this.prostgles.opts.testRulesOnConnect) {
|
|
120
|
-
await (this.dbo[tableName] as any)[method](
|
|
121
|
-
{},
|
|
122
|
-
{},
|
|
123
|
-
{},
|
|
124
|
-
valid_table_command_rules,
|
|
125
|
-
{
|
|
126
|
-
...clientReq,
|
|
127
|
-
isRemoteRequest: true,
|
|
128
|
-
testRule: true,
|
|
129
|
-
}
|
|
130
|
-
);
|
|
131
|
-
}
|
|
132
|
-
} catch (e) {
|
|
133
|
-
console.error(`${tableName}.${method}`, e);
|
|
134
|
-
tableSchemaErrors[tableName] ??= {};
|
|
135
|
-
tableSchemaErrors[tableName]![method] = {
|
|
136
|
-
error: "Internal publish error. Check server logs",
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
throw {
|
|
140
|
-
...getErrorAsObject(e),
|
|
141
|
-
publish_path: `publish.${tableName}.${method}: \n -> ${e}`,
|
|
142
|
-
};
|
|
143
134
|
}
|
|
135
|
+
} catch (e) {
|
|
136
|
+
console.error(`${tableName}.${method}`, e);
|
|
137
|
+
tableSchemaErrors[tableName] ??= {};
|
|
138
|
+
tableSchemaErrors[tableName]![method] = {
|
|
139
|
+
error: "Internal publish error. Check server logs",
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
throw {
|
|
143
|
+
...getErrorAsObject(e),
|
|
144
|
+
publish_path: `publish.${tableName}.${method}: \n -> ${e}`,
|
|
145
|
+
};
|
|
144
146
|
}
|
|
147
|
+
}
|
|
145
148
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
tableColumns = res;
|
|
163
|
-
}
|
|
149
|
+
if (method === "getInfo" || method === "getColumns") {
|
|
150
|
+
const tableRules = await this.getValidatedRequestRule(
|
|
151
|
+
{ tableName, command: method, clientReq },
|
|
152
|
+
clientInfo
|
|
153
|
+
);
|
|
154
|
+
const res = await (this.dbo[tableName] as TableHandler)[method](
|
|
155
|
+
undefined,
|
|
156
|
+
undefined,
|
|
157
|
+
undefined,
|
|
158
|
+
tableRules,
|
|
159
|
+
{ ...clientReq, isRemoteRequest: {} }
|
|
160
|
+
);
|
|
161
|
+
if (method === "getInfo") {
|
|
162
|
+
tableInfo = res as TableInfo;
|
|
163
|
+
} else {
|
|
164
|
+
tableColumns = res as DBSchemaTable["columns"];
|
|
164
165
|
}
|
|
165
166
|
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
}
|
|
167
|
+
}
|
|
168
|
+
})
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
if (tableInfo && tableColumns) {
|
|
172
|
+
tables.push({
|
|
173
|
+
name: tableName,
|
|
174
|
+
info: tableInfo,
|
|
175
|
+
columns: tableColumns,
|
|
176
|
+
});
|
|
176
177
|
}
|
|
177
178
|
})
|
|
178
179
|
);
|
package/lib/onSocketConnected.ts
CHANGED
|
@@ -17,7 +17,7 @@ export async function onSocketConnected(this: Prostgles, socket: PRGLIOSocket) {
|
|
|
17
17
|
try {
|
|
18
18
|
await this.opts.onLog?.({
|
|
19
19
|
type: "connect",
|
|
20
|
-
sid: this.authHandler?.
|
|
20
|
+
sid: this.authHandler?.getValidatedSid({ socket }),
|
|
21
21
|
socketId: socket.id,
|
|
22
22
|
connectedSocketIds: this.connectedSockets.map((s) => s.id),
|
|
23
23
|
});
|
|
@@ -30,7 +30,7 @@ export async function onSocketConnected(this: Prostgles, socket: PRGLIOSocket) {
|
|
|
30
30
|
if (onUseOrSocketConnected) {
|
|
31
31
|
if (!authHandler) throw "authHandler missing";
|
|
32
32
|
const errorInfo = await onUseOrSocketConnected(
|
|
33
|
-
authHandler.
|
|
33
|
+
authHandler.getValidatedSid({ socket }),
|
|
34
34
|
getClientRequestIPsInfo({ socket }),
|
|
35
35
|
{ socket }
|
|
36
36
|
);
|
|
@@ -91,7 +91,7 @@ export async function onSocketConnected(this: Prostgles, socket: PRGLIOSocket) {
|
|
|
91
91
|
this.dboBuilder.queryStreamer.onDisconnect(socket.id);
|
|
92
92
|
void this.opts.onLog?.({
|
|
93
93
|
type: "disconnect",
|
|
94
|
-
sid: this.authHandler?.
|
|
94
|
+
sid: this.authHandler?.getValidatedSid({ socket }),
|
|
95
95
|
socketId: socket.id,
|
|
96
96
|
connectedSocketIds: this.connectedSockets.map((s) => s.id),
|
|
97
97
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prostgles-server",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.271",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"pg": "^8.11.5",
|
|
58
58
|
"pg-cursor": "^2.11.0",
|
|
59
59
|
"pg-promise": "^11.9.1",
|
|
60
|
-
"prostgles-types": "^4.0.
|
|
60
|
+
"prostgles-types": "^4.0.166"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@eslint/js": "^9.22.0",
|