prostgles-server 2.0.344 → 3.0.0
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/AuthHandler.d.ts +45 -29
- package/dist/AuthHandler.d.ts.map +1 -1
- package/dist/AuthHandler.js +22 -8
- package/dist/AuthHandler.js.map +1 -1
- package/dist/DboBuilder/QueryBuilder/QueryBuilder.d.ts +1 -1
- package/dist/Prostgles.d.ts +12 -8
- package/dist/Prostgles.d.ts.map +1 -1
- package/dist/Prostgles.js +4 -2
- package/dist/Prostgles.js.map +1 -1
- package/dist/PublishParser.d.ts +11 -11
- package/dist/PublishParser.d.ts.map +1 -1
- package/dist/PublishParser.js.map +1 -1
- package/dist/TableConfig.d.ts +1 -0
- package/dist/TableConfig.d.ts.map +1 -1
- package/dist/TableConfig.js +14 -7
- package/dist/TableConfig.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/lib/AuthHandler.d.ts +45 -29
- package/lib/AuthHandler.d.ts.map +1 -1
- package/lib/AuthHandler.js +22 -8
- package/lib/AuthHandler.ts +68 -55
- package/lib/Prostgles.d.ts +12 -8
- package/lib/Prostgles.d.ts.map +1 -1
- package/lib/Prostgles.js +4 -2
- package/lib/Prostgles.ts +12 -10
- package/lib/PublishParser.d.ts +11 -11
- package/lib/PublishParser.d.ts.map +1 -1
- package/lib/PublishParser.ts +11 -12
- package/lib/TableConfig.d.ts +1 -0
- package/lib/TableConfig.d.ts.map +1 -1
- package/lib/TableConfig.js +14 -7
- package/lib/TableConfig.ts +16 -8
- package/lib/index.d.ts +2 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.ts +2 -1
- package/lib/validation.d.ts.map +1 -1
- package/lib/validation.js +0 -6
- package/package.json +1 -1
- package/tests/client/PID.txt +1 -1
- package/tests/server/index.js +3 -3
- package/tests/server/index.ts +3 -3
- package/tests/server/package-lock.json +1 -1
- package/tests/server/publishTypeCheck.d.ts.map +1 -1
- package/tests/server/publishTypeCheck.ts +0 -1
package/lib/AuthHandler.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Request, Response } from "express";
|
|
1
|
+
import { Express, NextFunction, Request, Response } from "express";
|
|
2
2
|
import { AnyObject, AuthGuardLocation, AuthGuardLocationResponse, CHANNELS, DBSchema } from "prostgles-types";
|
|
3
3
|
import { LocalParams, PRGLIOSocket } from "./DboBuilder";
|
|
4
4
|
import { DBOFullyTyped } from "./DBSchemaBuilder";
|
|
5
5
|
import { removeExpressRoute } from "./FileManager";
|
|
6
|
-
import { DB, DBHandlerServer, Prostgles } from "./Prostgles";
|
|
6
|
+
import { DB, DBHandlerServer, ExpressApp, Prostgles } from "./Prostgles";
|
|
7
7
|
type Awaitable<T> = T | Promise<T>;
|
|
8
8
|
type AuthSocketSchema = {
|
|
9
9
|
user?: AnyObject;
|
|
@@ -13,22 +13,8 @@ type AuthSocketSchema = {
|
|
|
13
13
|
pathGuard?: boolean;
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
-
type ExpressReq = Request
|
|
17
|
-
// {
|
|
18
|
-
// body?: AnyObject;
|
|
19
|
-
// query?: AnyObject;
|
|
20
|
-
// cookies?: AnyObject;
|
|
21
|
-
// params?: AnyObject;
|
|
22
|
-
// path: string;
|
|
23
|
-
// originalUrl: string;
|
|
24
|
-
// }
|
|
16
|
+
type ExpressReq = Request;
|
|
25
17
|
type ExpressRes = Response;
|
|
26
|
-
// {
|
|
27
|
-
// status: (code: number) => ({ json: (response: AnyObject) => any; });
|
|
28
|
-
// cookie: (name: string, value: string, options: AnyObject) => any;
|
|
29
|
-
// sendFile: (filepath: string) => void;
|
|
30
|
-
// redirect: (url: string) => void;
|
|
31
|
-
// }
|
|
32
18
|
|
|
33
19
|
export type BasicSession = {
|
|
34
20
|
|
|
@@ -41,8 +27,28 @@ export type BasicSession = {
|
|
|
41
27
|
/** On expired */
|
|
42
28
|
onExpiration: "redirect" | "show_error";
|
|
43
29
|
};
|
|
44
|
-
export type AuthClientRequest = { socket: any } | { httpReq: ExpressReq }
|
|
45
|
-
export type
|
|
30
|
+
export type AuthClientRequest = { socket: any } | { httpReq: ExpressReq };
|
|
31
|
+
export type SessionUser<ServerUser extends AnyObject = AnyObject, ClientUser extends AnyObject = AnyObject> = {
|
|
32
|
+
/**
|
|
33
|
+
* This user will be available in all serverside prostgles options
|
|
34
|
+
* */
|
|
35
|
+
user: ServerUser;
|
|
36
|
+
/**
|
|
37
|
+
* User data sent to the authenticated client
|
|
38
|
+
*/
|
|
39
|
+
clientUser: ClientUser;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export type AuthResult<SU = SessionUser> = SU & { sid: string; } | {
|
|
43
|
+
user?: undefined;
|
|
44
|
+
clientUser?: undefined;
|
|
45
|
+
sid?: string;
|
|
46
|
+
} | undefined
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
export type AuthRequestParams<S, SUser extends SessionUser> = { db: DB, dbo: DBOFullyTyped<S>; getUser: () => Promise<AuthResult<SUser>> }
|
|
50
|
+
|
|
51
|
+
export type Auth<S = void, SUser extends SessionUser = SessionUser> = {
|
|
46
52
|
/**
|
|
47
53
|
* Name of the cookie or socket hadnshake query param that represents the session id.
|
|
48
54
|
* Defaults to "session_id"
|
|
@@ -58,7 +64,7 @@ export type Auth<S = void> = {
|
|
|
58
64
|
/**
|
|
59
65
|
* Express app instance. If provided Prostgles will attempt to set sidKeyName to user cookie
|
|
60
66
|
*/
|
|
61
|
-
app:
|
|
67
|
+
app: Express;
|
|
62
68
|
|
|
63
69
|
/**
|
|
64
70
|
* Used in allowing logging in through express. Defaults to /login
|
|
@@ -76,22 +82,30 @@ export type Auth<S = void> = {
|
|
|
76
82
|
cookieOptions?: AnyObject;
|
|
77
83
|
|
|
78
84
|
/**
|
|
79
|
-
*
|
|
85
|
+
* False by default. If false and userRoutes are provided then the socket will request window.location.reload if the current url is on a user route.
|
|
86
|
+
*/
|
|
87
|
+
disableSocketAuthGuard?: boolean;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* If provided, any client requests to NOT these routes (or their subroutes) will be redirected to loginRoute (if logged in) and then redirected back to the initial route after logging in
|
|
91
|
+
* If logged in the user is allowed to access these routes
|
|
80
92
|
*/
|
|
81
93
|
publicRoutes?: string[];
|
|
82
94
|
|
|
83
95
|
/**
|
|
84
|
-
*
|
|
96
|
+
* Will attach a app.use listener and will expose getUser
|
|
97
|
+
* Used for blocking access
|
|
85
98
|
*/
|
|
86
|
-
|
|
99
|
+
use?: (args: { req: Express.Request, res: Express.Response, next: NextFunction } & AuthRequestParams<S, SUser>) => void | Promise<void>;
|
|
87
100
|
|
|
88
101
|
/**
|
|
89
102
|
* Will be called after a GET request is authorised
|
|
103
|
+
* This means that
|
|
90
104
|
*/
|
|
91
105
|
onGetRequestOK?: (
|
|
92
106
|
req: ExpressReq,
|
|
93
107
|
res: ExpressRes,
|
|
94
|
-
params:
|
|
108
|
+
params: AuthRequestParams<S, SUser>
|
|
95
109
|
) => any;
|
|
96
110
|
|
|
97
111
|
/**
|
|
@@ -114,19 +128,7 @@ export type Auth<S = void> = {
|
|
|
114
128
|
|
|
115
129
|
}
|
|
116
130
|
|
|
117
|
-
getUser: (sid: string | undefined, dbo: DBOFullyTyped<S>, db: DB, client: AuthClientRequest) => Awaitable<
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* User data used on server. Mainly used in http request auth
|
|
121
|
-
*/
|
|
122
|
-
user: AnyObject;
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* User data sent to client. Mainly used in socket request auth
|
|
126
|
-
*/
|
|
127
|
-
clientUser: AnyObject;
|
|
128
|
-
|
|
129
|
-
} | undefined>;
|
|
131
|
+
getUser: (sid: string | undefined, dbo: DBOFullyTyped<S>, db: DB, client: AuthClientRequest) => Awaitable<AuthResult<SUser>>;
|
|
130
132
|
|
|
131
133
|
register?: (params: AnyObject, dbo: DBOFullyTyped<S>, db: DB) => Awaitable<BasicSession> | BasicSession;
|
|
132
134
|
login?: (params: AnyObject, dbo: DBOFullyTyped<S>, db: DB) => Awaitable<BasicSession> | BasicSession;
|
|
@@ -140,12 +142,6 @@ export type Auth<S = void> = {
|
|
|
140
142
|
}
|
|
141
143
|
}
|
|
142
144
|
|
|
143
|
-
export type ClientInfo = {
|
|
144
|
-
user?: AnyObject;
|
|
145
|
-
clientUser?: AnyObject;
|
|
146
|
-
sid?: string;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
145
|
export default class AuthHandler {
|
|
150
146
|
protected opts?: Auth;
|
|
151
147
|
dbo: DBHandlerServer;
|
|
@@ -238,7 +234,7 @@ export default class AuthHandler {
|
|
|
238
234
|
}
|
|
239
235
|
}
|
|
240
236
|
|
|
241
|
-
getUser = async (clientReq: { httpReq: ExpressReq; }): Promise<
|
|
237
|
+
getUser = async (clientReq: { httpReq: ExpressReq; }): Promise<AuthResult> => {
|
|
242
238
|
if(!this.sidKeyName || !this.opts?.getUser) throw "sidKeyName or this.opts.getUser missing"
|
|
243
239
|
const sid = clientReq.httpReq?.cookies?.[this.sidKeyName];
|
|
244
240
|
if (!sid) return undefined;
|
|
@@ -272,14 +268,28 @@ export default class AuthHandler {
|
|
|
272
268
|
if (!getUser) throw "getUser missing from auth config";
|
|
273
269
|
|
|
274
270
|
if (expressConfig) {
|
|
275
|
-
const { app, publicRoutes = [], onGetRequestOK, magicLinks } = expressConfig;
|
|
271
|
+
const { app, publicRoutes = [], onGetRequestOK, magicLinks, use } = expressConfig;
|
|
276
272
|
if (publicRoutes.find(r => typeof r !== "string" || !r)) {
|
|
277
273
|
throw "Invalid or empty string provided within publicRoutes "
|
|
278
274
|
}
|
|
279
275
|
|
|
280
|
-
if
|
|
276
|
+
if(use){
|
|
277
|
+
app.use((req, res, next) => {
|
|
278
|
+
use({
|
|
279
|
+
req,
|
|
280
|
+
res,
|
|
281
|
+
next,
|
|
282
|
+
getUser: () => this.getUser({ httpReq: req }) as any,
|
|
283
|
+
dbo: this.dbo,
|
|
284
|
+
db: this.db,
|
|
285
|
+
})
|
|
286
|
+
})
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
if (magicLinks && this.routes.magicLinks) {
|
|
281
290
|
const { check } = magicLinks;
|
|
282
291
|
if (!check) throw "Check must be defined for magicLinks";
|
|
292
|
+
|
|
283
293
|
app.get(this.routes.magicLinks?.expressRoute, async (req: ExpressReq, res: ExpressRes) => {
|
|
284
294
|
const { id } = req.params ?? {};
|
|
285
295
|
|
|
@@ -304,7 +314,7 @@ export default class AuthHandler {
|
|
|
304
314
|
}
|
|
305
315
|
|
|
306
316
|
const loginRoute = this.routes?.login;
|
|
307
|
-
if (
|
|
317
|
+
if (loginRoute) {
|
|
308
318
|
|
|
309
319
|
|
|
310
320
|
app.post(loginRoute, async (req: ExpressReq, res: ExpressRes) => {
|
|
@@ -326,7 +336,7 @@ export default class AuthHandler {
|
|
|
326
336
|
|
|
327
337
|
});
|
|
328
338
|
|
|
329
|
-
if (
|
|
339
|
+
if (this.routes.logoutGetPath && this.opts.logout) {
|
|
330
340
|
app.get(this.routes.logoutGetPath, async (req: ExpressReq, res: ExpressRes) => {
|
|
331
341
|
const sid = this.validateSid(req?.cookies?.[sidKeyName]);
|
|
332
342
|
if (sid) {
|
|
@@ -343,7 +353,7 @@ export default class AuthHandler {
|
|
|
343
353
|
});
|
|
344
354
|
}
|
|
345
355
|
|
|
346
|
-
if (
|
|
356
|
+
if (Array.isArray(publicRoutes)) {
|
|
347
357
|
|
|
348
358
|
/* Redirect if not logged in and requesting non public content */
|
|
349
359
|
app.get(this.routes.catchAll, async (req: ExpressReq, res: ExpressRes) => {
|
|
@@ -357,7 +367,8 @@ export default class AuthHandler {
|
|
|
357
367
|
* Requesting a User route
|
|
358
368
|
*/
|
|
359
369
|
if (this.isUserRoute(req.path)) {
|
|
360
|
-
|
|
370
|
+
|
|
371
|
+
/* Check auth. Redirect to login if unauthorized */
|
|
361
372
|
const u = await getUser(clientReq);
|
|
362
373
|
if (!u) {
|
|
363
374
|
res.redirect(`${loginRoute}?returnURL=${encodeURIComponent(req.originalUrl)}`);
|
|
@@ -370,7 +381,7 @@ export default class AuthHandler {
|
|
|
370
381
|
res.redirect(returnURL);
|
|
371
382
|
return;
|
|
372
383
|
|
|
373
|
-
/** If Logged in and requesting login then redirect */
|
|
384
|
+
/** If Logged in and requesting login then redirect to main page */
|
|
374
385
|
} else if (this.matchesRoute(loginRoute, req.path) && (await getUser(clientReq))) {
|
|
375
386
|
|
|
376
387
|
res.redirect("/");
|
|
@@ -491,7 +502,7 @@ export default class AuthHandler {
|
|
|
491
502
|
}
|
|
492
503
|
}
|
|
493
504
|
|
|
494
|
-
async getClientInfo(localParams: Pick<LocalParams, "socket" | "httpReq">): Promise<
|
|
505
|
+
async getClientInfo(localParams: Pick<LocalParams, "socket" | "httpReq">): Promise<AuthResult> {
|
|
495
506
|
if (!this.opts) return {};
|
|
496
507
|
|
|
497
508
|
const getSession = this.opts.cacheSession?.getSession;
|
|
@@ -507,7 +518,9 @@ export default class AuthHandler {
|
|
|
507
518
|
user,
|
|
508
519
|
clientUser,
|
|
509
520
|
}
|
|
510
|
-
} else return {
|
|
521
|
+
} else return {
|
|
522
|
+
sid: session.sid
|
|
523
|
+
};
|
|
511
524
|
}
|
|
512
525
|
}
|
|
513
526
|
|
|
@@ -520,7 +533,7 @@ export default class AuthHandler {
|
|
|
520
533
|
const clientReq = localParams.httpReq? { httpReq: localParams.httpReq } : { socket: localParams.socket };
|
|
521
534
|
let user, clientUser;
|
|
522
535
|
if(sid){
|
|
523
|
-
const res = await getUser(sid, this.dbo as any, this.db, clientReq);
|
|
536
|
+
const res = await getUser(sid, this.dbo as any, this.db, clientReq) as any;
|
|
524
537
|
user = res?.user;
|
|
525
538
|
clientUser = res?.clientUser;
|
|
526
539
|
}
|
|
@@ -561,7 +574,7 @@ export default class AuthHandler {
|
|
|
561
574
|
return Boolean(session && !hasExpired);
|
|
562
575
|
}
|
|
563
576
|
|
|
564
|
-
makeSocketAuth = async (socket: PRGLIOSocket): Promise<{ auth: AuthSocketSchema; userData:
|
|
577
|
+
makeSocketAuth = async (socket: PRGLIOSocket): Promise<{ auth: AuthSocketSchema; userData: AuthResult; } | Record<string, never>> => {
|
|
565
578
|
if (!this.opts) return {};
|
|
566
579
|
|
|
567
580
|
let auth: Partial<Record<keyof Omit<AuthSocketSchema, "user">, boolean | undefined>> & { user?: AnyObject | undefined } = {};
|
package/lib/Prostgles.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import * as pgPromise from 'pg-promise';
|
|
3
3
|
import pg = require('pg-promise/typescript/pg-subset');
|
|
4
4
|
import FileManager, { ImageOptions, LocalConfig, S3Config } from "./FileManager";
|
|
5
|
-
import AuthHandler, { Auth } from "./AuthHandler";
|
|
5
|
+
import AuthHandler, { Auth, SessionUser, AuthRequestParams } from "./AuthHandler";
|
|
6
6
|
import TableConfigurator, { TableConfig } from "./TableConfig";
|
|
7
7
|
import { DboBuilder, DBHandlerServer, PRGLIOSocket } from "./DboBuilder";
|
|
8
8
|
export { DBHandlerServer };
|
|
@@ -116,14 +116,14 @@ export declare type FileTableConfig = {
|
|
|
116
116
|
};
|
|
117
117
|
imageOptions?: ImageOptions;
|
|
118
118
|
};
|
|
119
|
-
export declare type ProstglesInitOptions<S = void> = {
|
|
119
|
+
export declare type ProstglesInitOptions<S = void, SUser extends SessionUser = SessionUser> = {
|
|
120
120
|
dbConnection: DbConnection;
|
|
121
121
|
dbOptions?: DbConnectionOpts;
|
|
122
122
|
tsGeneratedTypesDir?: string;
|
|
123
123
|
io?: any;
|
|
124
|
-
publish?: Publish<S>;
|
|
125
|
-
publishMethods?: PublishMethods<S>;
|
|
126
|
-
publishRawSQL?(params: PublishParams<S>): ((boolean | "*") | Promise<(boolean | "*")>);
|
|
124
|
+
publish?: Publish<S, SUser>;
|
|
125
|
+
publishMethods?: PublishMethods<S, SUser>;
|
|
126
|
+
publishRawSQL?(params: PublishParams<S, SUser>): ((boolean | "*") | Promise<(boolean | "*")>);
|
|
127
127
|
joins?: Joins;
|
|
128
128
|
schema?: string;
|
|
129
129
|
sqlFilePath?: string;
|
|
@@ -133,9 +133,13 @@ export declare type ProstglesInitOptions<S = void> = {
|
|
|
133
133
|
/**
|
|
134
134
|
* Use for connection verification. Will disconnect socket on any errors
|
|
135
135
|
*/
|
|
136
|
-
onSocketConnect?: (
|
|
137
|
-
|
|
138
|
-
|
|
136
|
+
onSocketConnect?: (args: AuthRequestParams<S, SUser> & {
|
|
137
|
+
socket: PRGLIOSocket;
|
|
138
|
+
}) => void | Promise<void>;
|
|
139
|
+
onSocketDisconnect?: (args: AuthRequestParams<S, SUser> & {
|
|
140
|
+
socket: PRGLIOSocket;
|
|
141
|
+
}) => void | Promise<void>;
|
|
142
|
+
auth?: Auth<S, SUser>;
|
|
139
143
|
DEBUG_MODE?: boolean;
|
|
140
144
|
watchSchemaType?:
|
|
141
145
|
/**
|
package/lib/Prostgles.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Prostgles.d.ts","sourceRoot":"","sources":["Prostgles.ts"],"names":[],"mappings":";AAMA,OAAO,KAAK,SAAS,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,GAAG,QAAQ,iCAAiC,CAAC,CAAC;AACvD,OAAO,WAAW,EAAE,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAIjF,OAAO,WAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"Prostgles.d.ts","sourceRoot":"","sources":["Prostgles.ts"],"names":[],"mappings":";AAMA,OAAO,KAAK,SAAS,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,GAAG,QAAQ,iCAAiC,CAAC,CAAC;AACvD,OAAO,WAAW,EAAE,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAIjF,OAAO,WAAW,EAAE,EAAE,IAAI,EAAE,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AAM,OAAO,CAAC,OAAO,CAAC,CAAC;KACjC,CAAC;IA8II,UAAU,CAAC,QAAQ,EAAE,MAAM;IA0BjC,gBAAgB,EAAE,GAAG,EAAE,CAAM;IACvB,eAAe;IAgHrB,gBAAgB,WAAkB,GAAG,mBAwFpC;CACF;AAqCD,wBAAsB,WAAW,CAAC,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAE1D"}
|
package/lib/Prostgles.js
CHANGED
|
@@ -514,7 +514,8 @@ class Prostgles {
|
|
|
514
514
|
try {
|
|
515
515
|
if (this.opts.onSocketConnect) {
|
|
516
516
|
try {
|
|
517
|
-
await this.
|
|
517
|
+
const getUser = async () => { return await this.authHandler?.getClientInfo({ socket }); };
|
|
518
|
+
await this.opts.onSocketConnect({ socket, dbo: dbo, db, getUser });
|
|
518
519
|
}
|
|
519
520
|
catch (error) {
|
|
520
521
|
const connectionError = error instanceof Error ? error.message : typeof error === "string" ? error : JSON.stringify(error);
|
|
@@ -556,7 +557,8 @@ class Prostgles {
|
|
|
556
557
|
this.connectedSockets = this.connectedSockets.filter(s => s.id !== socket.id);
|
|
557
558
|
// subscriptions = subscriptions.filter(sub => sub.socket.id !== socket.id);
|
|
558
559
|
if (this.opts.onSocketDisconnect) {
|
|
559
|
-
this.
|
|
560
|
+
const getUser = async () => { return await this.authHandler?.getClientInfo({ socket }); };
|
|
561
|
+
this.opts.onSocketDisconnect({ socket, dbo: dbo, db, getUser });
|
|
560
562
|
}
|
|
561
563
|
;
|
|
562
564
|
});
|
package/lib/Prostgles.ts
CHANGED
|
@@ -10,7 +10,7 @@ import FileManager, { ImageOptions, LocalConfig, S3Config } from "./FileManager"
|
|
|
10
10
|
|
|
11
11
|
const pkgj = require('../package.json');
|
|
12
12
|
const version = pkgj.version;
|
|
13
|
-
import AuthHandler, {
|
|
13
|
+
import AuthHandler, { Auth, SessionUser, AuthRequestParams } from "./AuthHandler";
|
|
14
14
|
console.log("Add a basic auth mode where user and sessions table are created");
|
|
15
15
|
|
|
16
16
|
import TableConfigurator, { TableConfig } from "./TableConfig";
|
|
@@ -211,14 +211,14 @@ export type FileTableConfig = {
|
|
|
211
211
|
imageOptions?: ImageOptions
|
|
212
212
|
};
|
|
213
213
|
|
|
214
|
-
export type ProstglesInitOptions<S = void> = {
|
|
214
|
+
export type ProstglesInitOptions<S = void, SUser extends SessionUser = SessionUser> = {
|
|
215
215
|
dbConnection: DbConnection;
|
|
216
216
|
dbOptions?: DbConnectionOpts;
|
|
217
217
|
tsGeneratedTypesDir?: string;
|
|
218
218
|
io?: any;
|
|
219
|
-
publish?: Publish<S>;
|
|
220
|
-
publishMethods?: PublishMethods<S>;
|
|
221
|
-
publishRawSQL?(params: PublishParams<S>): ((boolean | "*") | Promise<(boolean | "*")>);
|
|
219
|
+
publish?: Publish<S, SUser>;
|
|
220
|
+
publishMethods?: PublishMethods<S, SUser>;
|
|
221
|
+
publishRawSQL?(params: PublishParams<S, SUser>): ((boolean | "*") | Promise<(boolean | "*")>);
|
|
222
222
|
joins?: Joins;
|
|
223
223
|
schema?: string;
|
|
224
224
|
sqlFilePath?: string;
|
|
@@ -228,9 +228,9 @@ export type ProstglesInitOptions<S = void> = {
|
|
|
228
228
|
/**
|
|
229
229
|
* Use for connection verification. Will disconnect socket on any errors
|
|
230
230
|
*/
|
|
231
|
-
onSocketConnect?: (
|
|
232
|
-
onSocketDisconnect?: (
|
|
233
|
-
auth?: Auth<S>;
|
|
231
|
+
onSocketConnect?: (args: AuthRequestParams<S, SUser> & { socket: PRGLIOSocket }) => void | Promise<void>;
|
|
232
|
+
onSocketDisconnect?: (args: AuthRequestParams<S, SUser> & { socket: PRGLIOSocket }) => void | Promise<void>;
|
|
233
|
+
auth?: Auth<S, SUser>;
|
|
234
234
|
DEBUG_MODE?: boolean;
|
|
235
235
|
watchSchemaType?:
|
|
236
236
|
|
|
@@ -701,7 +701,8 @@ export class Prostgles {
|
|
|
701
701
|
try {
|
|
702
702
|
if (this.opts.onSocketConnect) {
|
|
703
703
|
try {
|
|
704
|
-
await this.
|
|
704
|
+
const getUser = async () => { return await this.authHandler?.getClientInfo({ socket }); }
|
|
705
|
+
await this.opts.onSocketConnect({ socket, dbo: dbo as any, db, getUser });
|
|
705
706
|
} catch(error) {
|
|
706
707
|
const connectionError = error instanceof Error? error.message : typeof error === "string"? error : JSON.stringify(error);
|
|
707
708
|
socket.emit(CHANNELS.CONNECTION, { connectionError });
|
|
@@ -745,7 +746,8 @@ export class Prostgles {
|
|
|
745
746
|
this.connectedSockets = this.connectedSockets.filter(s => s.id !== socket.id);
|
|
746
747
|
// subscriptions = subscriptions.filter(sub => sub.socket.id !== socket.id);
|
|
747
748
|
if (this.opts.onSocketDisconnect) {
|
|
748
|
-
this.
|
|
749
|
+
const getUser = async () => { return await this.authHandler?.getClientInfo({ socket }); }
|
|
750
|
+
this.opts.onSocketDisconnect({ socket, dbo: dbo as any, db, getUser });
|
|
749
751
|
};
|
|
750
752
|
});
|
|
751
753
|
|
package/lib/PublishParser.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { AnyObject, TableSchemaForClient, DBSchemaTable, FullFilter } from "prostgles-types";
|
|
2
|
-
import {
|
|
2
|
+
import { AuthResult, SessionUser } from "./AuthHandler";
|
|
3
3
|
import { CommonTableRules, LocalParams, PRGLIOSocket, TableOrViewInfo, TableSchemaColumn } from "./DboBuilder";
|
|
4
4
|
import { Prostgles, DBHandlerServer, DB } from "./Prostgles";
|
|
5
5
|
import type { DBOFullyTyped, PublishFullyTyped } from "./DBSchemaBuilder";
|
|
6
6
|
export declare type Method = (...args: any) => (any | Promise<any>);
|
|
7
|
-
export declare type PublishMethods<S = void> = (params: PublishParams<S>) => {
|
|
7
|
+
export declare type PublishMethods<S = void, SUser extends SessionUser = SessionUser> = (params: PublishParams<S, SUser>) => {
|
|
8
8
|
[key: string]: Method;
|
|
9
9
|
} | Promise<{
|
|
10
10
|
[key: string]: Method;
|
|
@@ -230,11 +230,11 @@ export declare type ParsedPublishTable = {
|
|
|
230
230
|
subscribe?: SubscribeRule;
|
|
231
231
|
subscribeOne?: SubscribeRule;
|
|
232
232
|
};
|
|
233
|
-
export declare type PublishParams<S = void> = {
|
|
233
|
+
export declare type PublishParams<S = void, SUser extends SessionUser = SessionUser> = {
|
|
234
234
|
sid?: string;
|
|
235
235
|
dbo: DBOFullyTyped<S>;
|
|
236
236
|
db: DB;
|
|
237
|
-
user?:
|
|
237
|
+
user?: SUser["user"];
|
|
238
238
|
socket: PRGLIOSocket;
|
|
239
239
|
tables: {
|
|
240
240
|
name: string;
|
|
@@ -254,7 +254,7 @@ export declare type ParsedPublishTables = {
|
|
|
254
254
|
[table_name: string]: ParsedPublishTable;
|
|
255
255
|
};
|
|
256
256
|
export declare type PublishedResult<Schema = void> = PublishAllOrNothing | PublishFullyTyped<Schema>;
|
|
257
|
-
export declare type Publish<Schema = void> = PublishedResult<Schema> | ((params: PublishParams<Schema>) => Awaitable<PublishedResult<Schema>>);
|
|
257
|
+
export declare type Publish<Schema = void, SUser extends SessionUser = SessionUser> = PublishedResult<Schema> | ((params: PublishParams<Schema, SUser>) => Awaitable<PublishedResult<Schema>>);
|
|
258
258
|
export declare class PublishParser {
|
|
259
259
|
publish: any;
|
|
260
260
|
publishMethods?: any;
|
|
@@ -263,18 +263,18 @@ export declare class PublishParser {
|
|
|
263
263
|
db: DB;
|
|
264
264
|
prostgles: Prostgles;
|
|
265
265
|
constructor(publish: any, publishMethods: any, publishRawSQL: any, dbo: DBHandlerServer, db: DB, prostgles: Prostgles);
|
|
266
|
-
getPublishParams(localParams: LocalParams, clientInfo?:
|
|
267
|
-
getMethods(socket: any, userData?:
|
|
266
|
+
getPublishParams(localParams: LocalParams, clientInfo?: AuthResult): Promise<PublishParams>;
|
|
267
|
+
getMethods(socket: any, userData?: AuthResult): Promise<{}>;
|
|
268
268
|
/**
|
|
269
269
|
* Parses the first level of publish. (If false then nothing if * then all tables and views)
|
|
270
270
|
* @param socket
|
|
271
271
|
* @param user
|
|
272
272
|
*/
|
|
273
|
-
getPublish(localParams: LocalParams, clientInfo?:
|
|
273
|
+
getPublish(localParams: LocalParams, clientInfo?: AuthResult): Promise<PublishObject>;
|
|
274
274
|
getValidatedRequestRuleWusr({ tableName, command, localParams }: DboTableCommand): Promise<TableRule>;
|
|
275
|
-
getValidatedRequestRule({ tableName, command, localParams }: DboTableCommand, clientInfo?:
|
|
276
|
-
getTableRules({ tableName, localParams }: DboTable, clientInfo?:
|
|
277
|
-
getSchemaFromPublish(socket: any, userData?:
|
|
275
|
+
getValidatedRequestRule({ tableName, command, localParams }: DboTableCommand, clientInfo?: AuthResult): Promise<TableRule>;
|
|
276
|
+
getTableRules({ tableName, localParams }: DboTable, clientInfo?: AuthResult): Promise<ParsedPublishTable | undefined>;
|
|
277
|
+
getSchemaFromPublish(socket: any, userData?: AuthResult): Promise<{
|
|
278
278
|
schema: TableSchemaForClient;
|
|
279
279
|
tables: DBSchemaTable[];
|
|
280
280
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PublishParser.d.ts","sourceRoot":"","sources":["PublishParser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,SAAS,EAAO,oBAAoB,EAAE,aAAa,EAAwB,UAAU,EAAY,MAAM,iBAAiB,CAAC;AACzJ,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"PublishParser.d.ts","sourceRoot":"","sources":["PublishParser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,SAAS,EAAO,oBAAoB,EAAE,aAAa,EAAwB,UAAU,EAAY,MAAM,iBAAiB,CAAC;AACzJ,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAyB,WAAW,EAAE,YAAY,EAAgB,eAAe,EAAE,iBAAiB,EAAe,MAAM,cAAc,CAAC;AACjK,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,E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AAa,CAAC;IAe3F,UAAU,CAAC,MAAM,EAAE,GAAG,EAAE,QAAQ,CAAC,EAAE,UAAU;IAoBnD;;;;OAIG;IACG,UAAU,CAAC,WAAW,EAAE,WAAW,EAAE,UAAU,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,aAAa,CAAC;IAcrF,2BAA2B,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,WAAW,EAAE,EAAE,eAAe,GAAG,OAAO,CAAC,SAAS,CAAC;IAKrG,uBAAuB,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,WAAW,EAAE,EAAE,eAAe,EAAE,UAAU,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC;IAyC1H,aAAa,CAAC,EAAE,SAAS,EAAE,WAAW,EAAE,EAAE,QAAQ,EAAE,UAAU,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,kBAAkB,GAAG,SAAS,CAAC;IAiKrH,oBAAoB,CAAC,MAAM,EAAE,GAAG,EAAE,QAAQ,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC;QAAE,MAAM,EAAE,oBAAoB,CAAC;QAAC,MAAM,EAAE,aAAa,EAAE,CAAA;KAAE,CAAC;CA2GnI"}
|
package/lib/PublishParser.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { getKeys, RULE_METHODS, AnyObject, get, TableSchemaForClient, DBSchemaTable, MethodKey, TableInfo, FullFilter, isObject } from "prostgles-types";
|
|
2
|
-
import {
|
|
2
|
+
import { AuthResult, SessionUser } from "./AuthHandler";
|
|
3
3
|
import { CommonTableRules, Filter, isPlainObject, LocalParams, PRGLIOSocket, TableHandler, TableOrViewInfo, TableSchemaColumn, ViewHandler } from "./DboBuilder";
|
|
4
|
-
import type { TableHandler as TableHandlerFromTypes } from "prostgles-types";
|
|
5
4
|
import { Prostgles, DBHandlerServer, DB, TABLE_METHODS } from "./Prostgles";
|
|
6
5
|
import type { DBOFullyTyped, PublishFullyTyped } from "./DBSchemaBuilder";
|
|
7
6
|
export type Method = (...args: any) => (any | Promise<any>);
|
|
8
|
-
export type PublishMethods<S = void> = (params: PublishParams<S>) => { [key: string]: Method } | Promise<{ [key: string]: Method } | null>;
|
|
7
|
+
export type PublishMethods<S = void, SUser extends SessionUser = SessionUser> = (params: PublishParams<S, SUser>) => { [key: string]: Method } | Promise<{ [key: string]: Method } | null>;
|
|
9
8
|
|
|
10
9
|
export type Awaitable<T> = T | Promise<T>;
|
|
11
10
|
|
|
@@ -347,11 +346,11 @@ export type ParsedPublishTable = {
|
|
|
347
346
|
// export type Publish = {
|
|
348
347
|
// tablesOrViews: {[key:string]: TableRule | ViewRule | "*" }
|
|
349
348
|
// }
|
|
350
|
-
export type PublishParams<S = void> = {
|
|
349
|
+
export type PublishParams<S = void, SUser extends SessionUser = SessionUser> = {
|
|
351
350
|
sid?: string;
|
|
352
351
|
dbo: DBOFullyTyped<S>;
|
|
353
352
|
db: DB;
|
|
354
|
-
user?:
|
|
353
|
+
user?: SUser["user"];
|
|
355
354
|
socket: PRGLIOSocket;
|
|
356
355
|
tables: {
|
|
357
356
|
name: string;
|
|
@@ -368,7 +367,7 @@ export type ParsedPublishTables = {
|
|
|
368
367
|
[table_name: string]: ParsedPublishTable
|
|
369
368
|
};
|
|
370
369
|
export type PublishedResult<Schema = void> = PublishAllOrNothing | PublishFullyTyped<Schema>;
|
|
371
|
-
export type Publish<Schema = void> = PublishedResult<Schema> | ((params: PublishParams<Schema>) => Awaitable<PublishedResult<Schema>>);
|
|
370
|
+
export type Publish<Schema = void, SUser extends SessionUser = SessionUser> = PublishedResult<Schema> | ((params: PublishParams<Schema, SUser>) => Awaitable<PublishedResult<Schema>>);
|
|
372
371
|
|
|
373
372
|
export class PublishParser {
|
|
374
373
|
publish: any;
|
|
@@ -389,7 +388,7 @@ export class PublishParser {
|
|
|
389
388
|
if (!this.dbo || !this.publish) throw "INTERNAL ERROR: dbo and/or publish missing";
|
|
390
389
|
}
|
|
391
390
|
|
|
392
|
-
async getPublishParams(localParams: LocalParams, clientInfo?:
|
|
391
|
+
async getPublishParams(localParams: LocalParams, clientInfo?: AuthResult): Promise<PublishParams> {
|
|
393
392
|
if (!this.dbo) throw "dbo missing"
|
|
394
393
|
return {
|
|
395
394
|
...(clientInfo || await this.prostgles.authHandler?.getClientInfo(localParams)),
|
|
@@ -404,7 +403,7 @@ export class PublishParser {
|
|
|
404
403
|
}
|
|
405
404
|
}
|
|
406
405
|
|
|
407
|
-
async getMethods(socket: any, userData?:
|
|
406
|
+
async getMethods(socket: any, userData?: AuthResult) {
|
|
408
407
|
let methods = {};
|
|
409
408
|
|
|
410
409
|
const publishParams = await this.getPublishParams({ socket }, userData);
|
|
@@ -429,7 +428,7 @@ export class PublishParser {
|
|
|
429
428
|
* @param socket
|
|
430
429
|
* @param user
|
|
431
430
|
*/
|
|
432
|
-
async getPublish(localParams: LocalParams, clientInfo?:
|
|
431
|
+
async getPublish(localParams: LocalParams, clientInfo?: AuthResult): Promise<PublishObject> {
|
|
433
432
|
const publishParams = await this.getPublishParams(localParams, clientInfo)
|
|
434
433
|
let _publish = await applyParamsIfFunc(this.publish, publishParams);
|
|
435
434
|
|
|
@@ -448,7 +447,7 @@ export class PublishParser {
|
|
|
448
447
|
return await this.getValidatedRequestRule({ tableName, command, localParams }, clientInfo);
|
|
449
448
|
}
|
|
450
449
|
|
|
451
|
-
async getValidatedRequestRule({ tableName, command, localParams }: DboTableCommand, clientInfo?:
|
|
450
|
+
async getValidatedRequestRule({ tableName, command, localParams }: DboTableCommand, clientInfo?: AuthResult): Promise<TableRule> {
|
|
452
451
|
if (!this.dbo) throw "INTERNAL ERROR: dbo is missing";
|
|
453
452
|
|
|
454
453
|
if (!command || !tableName) throw "command OR tableName are missing";
|
|
@@ -489,7 +488,7 @@ export class PublishParser {
|
|
|
489
488
|
} else throw { stack: ["getValidatedRequestRule()"], message: `Invalid or disallowed command: ${tableName}.${command}` };
|
|
490
489
|
}
|
|
491
490
|
|
|
492
|
-
async getTableRules({ tableName, localParams }: DboTable, clientInfo?:
|
|
491
|
+
async getTableRules({ tableName, localParams }: DboTable, clientInfo?: AuthResult): Promise<ParsedPublishTable | undefined> {
|
|
493
492
|
|
|
494
493
|
try {
|
|
495
494
|
if (!localParams || !tableName) throw { stack: ["getTableRules()"], message: "publish OR socket OR dbo OR tableName are missing" };
|
|
@@ -650,7 +649,7 @@ export class PublishParser {
|
|
|
650
649
|
|
|
651
650
|
|
|
652
651
|
/* Prepares schema for client. Only allowed views and commands will be present */
|
|
653
|
-
async getSchemaFromPublish(socket: any, userData?:
|
|
652
|
+
async getSchemaFromPublish(socket: any, userData?: AuthResult): Promise<{ schema: TableSchemaForClient; tables: DBSchemaTable[] }> {
|
|
654
653
|
let schema: TableSchemaForClient = {};
|
|
655
654
|
let tables: DBSchemaTable[] = []
|
|
656
655
|
|
package/lib/TableConfig.d.ts
CHANGED
|
@@ -240,6 +240,7 @@ export default class TableConfigurator<LANG_IDS = {
|
|
|
240
240
|
}) => void;
|
|
241
241
|
getJoinInfo: (sourceTable: string, targetTable: string) => JoinInfo | undefined;
|
|
242
242
|
init(): Promise<void>;
|
|
243
|
+
log: (...args: any[]) => void;
|
|
243
244
|
}
|
|
244
245
|
export {};
|
|
245
246
|
//# sourceMappingURL=TableConfig.d.ts.map
|