prostgles-server 4.2.227 → 4.2.228
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/.eslintrc.json +1 -0
- package/dist/Auth/AuthHandler.d.ts +3 -4
- package/dist/Auth/AuthHandler.d.ts.map +1 -1
- package/dist/Auth/AuthHandler.js +9 -11
- package/dist/Auth/AuthHandler.js.map +1 -1
- package/dist/Auth/AuthTypes.d.ts +27 -12
- package/dist/Auth/AuthTypes.d.ts.map +1 -1
- package/dist/Auth/endpoints/setCatchAllRequestHandler.d.ts.map +1 -1
- package/dist/Auth/endpoints/setCatchAllRequestHandler.js +4 -4
- package/dist/Auth/endpoints/setCatchAllRequestHandler.js.map +1 -1
- package/dist/Auth/endpoints/setLoginRequestHandler.d.ts +2 -1
- package/dist/Auth/endpoints/setLoginRequestHandler.d.ts.map +1 -1
- package/dist/Auth/endpoints/setMagicLinkOrOTPRequestHandler.d.ts.map +1 -1
- package/dist/Auth/endpoints/setMagicLinkOrOTPRequestHandler.js +8 -6
- package/dist/Auth/endpoints/setMagicLinkOrOTPRequestHandler.js.map +1 -1
- package/dist/Auth/endpoints/setRegisterRequestHandler.d.ts +2 -2
- package/dist/Auth/endpoints/setRegisterRequestHandler.d.ts.map +1 -1
- package/dist/Auth/endpoints/setRegisterRequestHandler.js +2 -2
- package/dist/Auth/endpoints/setRegisterRequestHandler.js.map +1 -1
- package/dist/Auth/getClientAuth.d.ts.map +1 -1
- package/dist/Auth/getClientAuth.js +1 -1
- package/dist/Auth/getClientAuth.js.map +1 -1
- package/dist/Auth/setupAuthRoutes.d.ts.map +1 -1
- package/dist/Auth/setupAuthRoutes.js +2 -4
- package/dist/Auth/setupAuthRoutes.js.map +1 -1
- package/dist/DBSchemaBuilder.js +9 -9
- package/dist/DBSchemaBuilder.js.map +1 -1
- package/dist/DboBuilder/DboBuilder.d.ts +1 -1
- package/dist/DboBuilder/DboBuilder.js +1 -1
- package/dist/DboBuilder/DboBuilder.js.map +1 -1
- package/dist/DboBuilder/QueryStreamer.js +9 -9
- package/dist/DboBuilder/QueryStreamer.js.map +1 -1
- package/dist/DboBuilder/ViewHandler/find.js +1 -1
- package/dist/DboBuilder/ViewHandler/find.js.map +1 -1
- package/dist/FileManager/upload.d.ts.map +1 -1
- package/dist/FileManager/upload.js +1 -1
- package/dist/FileManager/upload.js.map +1 -1
- package/dist/FileManager/uploadStream.d.ts.map +1 -1
- package/dist/FileManager/uploadStream.js +1 -1
- package/dist/FileManager/uploadStream.js.map +1 -1
- package/dist/PostgresNotifListenManager.js +3 -3
- package/dist/PostgresNotifListenManager.js.map +1 -1
- package/dist/Prostgles.js +1 -1
- package/dist/Prostgles.js.map +1 -1
- package/dist/PubSubManager/PubSubManager.d.ts +1 -1
- package/dist/PubSubManager/PubSubManager.d.ts.map +1 -1
- package/dist/PubSubManager/PubSubManager.js +5 -5
- package/dist/PubSubManager/PubSubManager.js.map +1 -1
- package/dist/PubSubManager/addSub.js +3 -3
- package/dist/PubSubManager/addSub.js.map +1 -1
- package/dist/PubSubManager/addSync.js +5 -5
- package/dist/PubSubManager/addSync.js.map +1 -1
- package/dist/PubSubManager/notifListener.js +5 -5
- package/dist/PubSubManager/notifListener.js.map +1 -1
- package/dist/PubSubManager/pushSubData.js +1 -1
- package/dist/PubSubManager/pushSubData.js.map +1 -1
- package/dist/SchemaWatch/SchemaWatch.js +2 -2
- package/dist/SchemaWatch/SchemaWatch.js.map +1 -1
- package/dist/SyncReplication.js +2 -2
- package/dist/SyncReplication.js.map +1 -1
- package/dist/TableConfig/initTableConfig.js +4 -4
- package/dist/TableConfig/initTableConfig.js.map +1 -1
- package/dist/initProstgles.js +1 -1
- package/dist/initProstgles.js.map +1 -1
- package/dist/onSocketConnected.js +3 -3
- package/dist/onSocketConnected.js.map +1 -1
- package/dist/typeTests/dboTypeCheck.js +3 -3
- package/dist/typeTests/dboTypeCheck.js.map +1 -1
- package/lib/Auth/AuthHandler.ts +16 -14
- package/lib/Auth/AuthTypes.ts +32 -11
- package/lib/Auth/endpoints/setCatchAllRequestHandler.ts +5 -4
- package/lib/Auth/endpoints/setLoginRequestHandler.ts +3 -3
- package/lib/Auth/endpoints/setMagicLinkOrOTPRequestHandler.ts +23 -9
- package/lib/Auth/endpoints/setRegisterRequestHandler.ts +4 -4
- package/lib/Auth/getClientAuth.ts +6 -2
- package/lib/Auth/setupAuthRoutes.ts +3 -5
- package/lib/DBSchemaBuilder.ts +9 -9
- package/lib/DboBuilder/DboBuilder.ts +1 -1
- package/lib/DboBuilder/QueryStreamer.ts +9 -9
- package/lib/DboBuilder/ViewHandler/find.ts +1 -1
- package/lib/FileManager/upload.ts +3 -8
- package/lib/FileManager/uploadStream.ts +6 -8
- package/lib/PostgresNotifListenManager.ts +3 -3
- package/lib/Prostgles.ts +1 -1
- package/lib/PubSubManager/PubSubManager.ts +5 -5
- package/lib/PubSubManager/addSub.ts +3 -3
- package/lib/PubSubManager/addSync.ts +3 -3
- package/lib/PubSubManager/notifListener.ts +5 -5
- package/lib/PubSubManager/pushSubData.ts +1 -1
- package/lib/SchemaWatch/SchemaWatch.ts +2 -2
- package/lib/SyncReplication.ts +2 -2
- package/lib/TableConfig/initTableConfig.ts +4 -4
- package/lib/initProstgles.ts +1 -1
- package/lib/onSocketConnected.ts +3 -3
- package/lib/typeTests/dboTypeCheck.ts +11 -11
- package/package.json +2 -2
- package/dist/Auth/endpoints/setConfirmEmailRequestHandler.d.ts +0 -5
- package/dist/Auth/endpoints/setConfirmEmailRequestHandler.d.ts.map +0 -1
- package/dist/Auth/endpoints/setConfirmEmailRequestHandler.js +0 -52
- package/dist/Auth/endpoints/setConfirmEmailRequestHandler.js.map +0 -1
- package/lib/Auth/endpoints/setConfirmEmailRequestHandler.ts +0 -65
package/lib/Auth/AuthTypes.ts
CHANGED
|
@@ -113,25 +113,37 @@ type PasswordRegisterResponse =
|
|
|
113
113
|
| AuthResponse.PasswordRegisterSuccess;
|
|
114
114
|
|
|
115
115
|
/**
|
|
116
|
-
* Users have to provide an email and a password.
|
|
116
|
+
* Users have to provide an email and optionally a password.
|
|
117
117
|
* Account should be activated after email confirmation
|
|
118
118
|
*/
|
|
119
|
-
export type
|
|
119
|
+
export type SignupWithEmail = {
|
|
120
120
|
/**
|
|
121
121
|
* Defaults to 8
|
|
122
122
|
*/
|
|
123
123
|
minPasswordLength?: number;
|
|
124
124
|
|
|
125
125
|
/**
|
|
126
|
-
*
|
|
126
|
+
* If true, the user will have to provide a password
|
|
127
|
+
*/
|
|
128
|
+
requirePassword?: boolean;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Called when the user has registered.
|
|
127
132
|
*/
|
|
128
133
|
onRegister: (data: {
|
|
129
134
|
email: string;
|
|
135
|
+
|
|
130
136
|
/**
|
|
131
|
-
* Password after validation
|
|
137
|
+
* Password after validation.
|
|
138
|
+
* Will be empty if requirePassword is false
|
|
132
139
|
*/
|
|
133
140
|
password: string;
|
|
134
141
|
clientInfo: LoginClientInfo;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Returns a URL that the user can click or enter the verification code to confirm their email address.
|
|
145
|
+
* Will point to /magic-link/:email:code by default
|
|
146
|
+
*/
|
|
135
147
|
getConfirmationUrl: (data: { code: string; websiteUrl: string }) => string;
|
|
136
148
|
req: ExpressReq;
|
|
137
149
|
}) => Awaitable<PasswordRegisterResponse>;
|
|
@@ -289,11 +301,12 @@ export type AuthConfig<S = void, SUser extends SessionUser = SessionUser> = {
|
|
|
289
301
|
sidKeyName?: string;
|
|
290
302
|
|
|
291
303
|
/**
|
|
304
|
+
* Required to allow self-managed or managed (by setting up loginSignupConfig) authentication.
|
|
292
305
|
* Used in:
|
|
293
|
-
* -
|
|
294
|
-
* - PublishParams - userData and/or sid (in testing) are passed to the publish function
|
|
306
|
+
* - publish - userData and/or sid (in testing) are passed to the publish function
|
|
295
307
|
* - auth.expressConfig.use - express middleware to get user data and
|
|
296
308
|
* undefined sid is allowed to enable public users
|
|
309
|
+
* - websocket authguard - allows connected SPA client to check if on protected route and needs to reload to ne redirected to login
|
|
297
310
|
*/
|
|
298
311
|
getUser: (
|
|
299
312
|
sid: string | undefined,
|
|
@@ -390,8 +403,12 @@ export type LoginSignupConfig<S, SUser extends SessionUser> = {
|
|
|
390
403
|
) => Awaitable<void>;
|
|
391
404
|
|
|
392
405
|
/**
|
|
393
|
-
* If defined, will enable
|
|
394
|
-
*
|
|
406
|
+
* If defined, will enable:
|
|
407
|
+
* - GET /magic-link/:id route.
|
|
408
|
+
* - POST /magic-link { email, code } route.
|
|
409
|
+
* Successfull requests that return a session will be logged in
|
|
410
|
+
* and redirected to the returnUrl if set.
|
|
411
|
+
* Otherwise just the response will be sent
|
|
395
412
|
*/
|
|
396
413
|
onMagicLinkOrOTP?: (
|
|
397
414
|
data: MagicLinkOrOTPData,
|
|
@@ -399,14 +416,17 @@ export type LoginSignupConfig<S, SUser extends SessionUser> = {
|
|
|
399
416
|
db: DB,
|
|
400
417
|
client: LoginClientInfo
|
|
401
418
|
) => Awaitable<
|
|
402
|
-
| {
|
|
419
|
+
| {
|
|
420
|
+
session: BasicSession | undefined;
|
|
421
|
+
response?: AuthResponse.AuthSuccess | AuthResponse.PasswordRegisterEmailConfirmationSuccess;
|
|
422
|
+
}
|
|
403
423
|
| {
|
|
404
424
|
session?: undefined;
|
|
405
425
|
response: AuthResponse.MagicLinkAuthFailure | AuthResponse.CodeVerificationFailure;
|
|
406
426
|
}
|
|
407
427
|
>;
|
|
408
428
|
|
|
409
|
-
|
|
429
|
+
signupWithEmail?: SignupWithEmail;
|
|
410
430
|
|
|
411
431
|
loginWithOAuth?: LoginWithOAuthConfig<S>;
|
|
412
432
|
|
|
@@ -417,7 +437,8 @@ export type LoginSignupConfig<S, SUser extends SessionUser> = {
|
|
|
417
437
|
localLoginMode?: AuthSocketSchema["loginType"];
|
|
418
438
|
|
|
419
439
|
/**
|
|
420
|
-
* If provided then the user will be able to login with a username and password
|
|
440
|
+
* If provided then the user will be able to login with a username and/or password
|
|
441
|
+
* through the POST /login route.
|
|
421
442
|
*/
|
|
422
443
|
login: (
|
|
423
444
|
params: LoginParams,
|
|
@@ -24,7 +24,7 @@ export function setCatchAllRequestHandler(this: AuthHandler, app: e.Express) {
|
|
|
24
24
|
res.redirect("/");
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
const
|
|
27
|
+
const requestHandlerCatchAll: RequestHandler = async (req, res, next) => {
|
|
28
28
|
const { onGetRequestOK } = this.opts.loginSignupConfig ?? {};
|
|
29
29
|
const clientReq: AuthClientRequest = { httpReq: req, res };
|
|
30
30
|
const getUser = async () => {
|
|
@@ -47,7 +47,7 @@ export function setCatchAllRequestHandler(this: AuthHandler, app: e.Express) {
|
|
|
47
47
|
try {
|
|
48
48
|
const returnURL = getReturnUrl(req);
|
|
49
49
|
|
|
50
|
-
if (matchesRoute(AUTH_ROUTES_AND_PARAMS.
|
|
50
|
+
if (matchesRoute(AUTH_ROUTES_AND_PARAMS.logout, req.path) && req.method === "POST") {
|
|
51
51
|
await onLogout(req, res);
|
|
52
52
|
return;
|
|
53
53
|
}
|
|
@@ -56,6 +56,7 @@ export function setCatchAllRequestHandler(this: AuthHandler, app: e.Express) {
|
|
|
56
56
|
next();
|
|
57
57
|
return;
|
|
58
58
|
}
|
|
59
|
+
|
|
59
60
|
/**
|
|
60
61
|
* Requesting a User route
|
|
61
62
|
*/
|
|
@@ -87,7 +88,7 @@ export function setCatchAllRequestHandler(this: AuthHandler, app: e.Express) {
|
|
|
87
88
|
}
|
|
88
89
|
}
|
|
89
90
|
|
|
90
|
-
onGetRequestOK?.(req, res, {
|
|
91
|
+
await onGetRequestOK?.(req, res, {
|
|
91
92
|
getUser,
|
|
92
93
|
dbo: this.dbo as DBOFullyTyped,
|
|
93
94
|
db: this.db,
|
|
@@ -106,5 +107,5 @@ export function setCatchAllRequestHandler(this: AuthHandler, app: e.Express) {
|
|
|
106
107
|
}
|
|
107
108
|
};
|
|
108
109
|
|
|
109
|
-
app.get(AUTH_ROUTES_AND_PARAMS.catchAll,
|
|
110
|
+
app.get(AUTH_ROUTES_AND_PARAMS.catchAll, requestHandlerCatchAll);
|
|
110
111
|
}
|
|
@@ -3,15 +3,15 @@ import { AuthRequest, AuthResponse, isDefined, isObject } from "prostgles-types"
|
|
|
3
3
|
import { AUTH_ROUTES_AND_PARAMS, AuthHandler, HTTP_FAIL_CODES } from "../AuthHandler";
|
|
4
4
|
import { LoginParams } from "../AuthTypes";
|
|
5
5
|
|
|
6
|
-
export type
|
|
6
|
+
export type LoginResponse =
|
|
7
7
|
| AuthResponse.OAuthRegisterSuccess
|
|
8
8
|
| AuthResponse.OAuthRegisterFailure
|
|
9
9
|
| AuthResponse.PasswordLoginSuccess
|
|
10
10
|
| AuthResponse.PasswordLoginFailure
|
|
11
11
|
| AuthResponse.MagicLinkAuthFailure
|
|
12
12
|
| AuthResponse.MagicLinkAuthSuccess
|
|
13
|
-
| AuthResponse.CodeVerificationFailure
|
|
14
|
-
>;
|
|
13
|
+
| AuthResponse.CodeVerificationFailure;
|
|
14
|
+
export type LoginResponseHandler = Response<LoginResponse>;
|
|
15
15
|
|
|
16
16
|
export function setLoginRequestHandler(this: AuthHandler, app: e.Express) {
|
|
17
17
|
app.post(AUTH_ROUTES_AND_PARAMS.login, async (req, res: LoginResponseHandler) => {
|
|
@@ -1,21 +1,33 @@
|
|
|
1
|
-
import e from "express";
|
|
1
|
+
import e, { type Response } from "express";
|
|
2
2
|
import { DBOFullyTyped } from "../../DBSchemaBuilder";
|
|
3
3
|
import {
|
|
4
4
|
AUTH_ROUTES_AND_PARAMS,
|
|
5
5
|
AuthHandler,
|
|
6
6
|
getClientRequestIPsInfo,
|
|
7
7
|
HTTP_FAIL_CODES,
|
|
8
|
+
HTTP_SUCCESS_CODES,
|
|
8
9
|
} from "../AuthHandler";
|
|
9
10
|
import { ExpressReq, LoginSignupConfig, MagicLinkOrOTPData, SessionUser } from "../AuthTypes";
|
|
10
11
|
import { throttledAuthCall } from "../utils/throttledReject";
|
|
11
|
-
import {
|
|
12
|
+
import { LoginResponse } from "./setLoginRequestHandler";
|
|
13
|
+
import { AuthResponse } from "prostgles-types";
|
|
14
|
+
|
|
15
|
+
type MagicLinkResponseHandler = Response<
|
|
16
|
+
| LoginResponse
|
|
17
|
+
| AuthResponse.PasswordRegisterEmailConfirmationSuccess
|
|
18
|
+
| AuthResponse.PasswordRegisterEmailConfirmationFailure
|
|
19
|
+
>;
|
|
12
20
|
|
|
13
21
|
export function setMagicLinkOrOTPRequestHandler(
|
|
14
22
|
this: AuthHandler,
|
|
15
23
|
onMagicLink: Required<LoginSignupConfig<void, SessionUser>>["onMagicLinkOrOTP"],
|
|
16
24
|
app: e.Express
|
|
17
25
|
) {
|
|
18
|
-
const handler = async (
|
|
26
|
+
const handler = async (
|
|
27
|
+
req: ExpressReq,
|
|
28
|
+
res: MagicLinkResponseHandler,
|
|
29
|
+
data: MagicLinkOrOTPData
|
|
30
|
+
) => {
|
|
19
31
|
try {
|
|
20
32
|
const response = await throttledAuthCall(async () => {
|
|
21
33
|
return onMagicLink(
|
|
@@ -26,17 +38,19 @@ export function setMagicLinkOrOTPRequestHandler(
|
|
|
26
38
|
);
|
|
27
39
|
});
|
|
28
40
|
if (!response.session) {
|
|
29
|
-
res
|
|
41
|
+
res
|
|
42
|
+
.status(response.response?.success ? HTTP_SUCCESS_CODES.OK : HTTP_FAIL_CODES.UNAUTHORIZED)
|
|
43
|
+
.json(response.response);
|
|
30
44
|
} else {
|
|
31
45
|
this.setCookieAndGoToReturnURLIFSet(response.session, { req, res });
|
|
32
46
|
}
|
|
33
47
|
} catch (_e) {
|
|
34
48
|
res
|
|
35
|
-
.status(HTTP_FAIL_CODES.
|
|
49
|
+
.status(HTTP_FAIL_CODES.BAD_REQUEST)
|
|
36
50
|
.json({ success: false, code: "something-went-wrong" });
|
|
37
51
|
}
|
|
38
52
|
};
|
|
39
|
-
app.get(AUTH_ROUTES_AND_PARAMS.
|
|
53
|
+
app.get(AUTH_ROUTES_AND_PARAMS.magicLinksIdParam, (req, res: MagicLinkResponseHandler) => {
|
|
40
54
|
const { id } = req.params;
|
|
41
55
|
|
|
42
56
|
if (typeof id !== "string" || !id) {
|
|
@@ -46,18 +60,18 @@ export function setMagicLinkOrOTPRequestHandler(
|
|
|
46
60
|
}
|
|
47
61
|
return handler(req, res, { type: "magic-link", magicId: id });
|
|
48
62
|
});
|
|
49
|
-
app.post(AUTH_ROUTES_AND_PARAMS.
|
|
63
|
+
app.post(AUTH_ROUTES_AND_PARAMS.magicLinks, (req, res: MagicLinkResponseHandler) => {
|
|
50
64
|
const { code, email } = req.body;
|
|
51
65
|
|
|
52
66
|
if (typeof code !== "string" || !code) {
|
|
53
67
|
res
|
|
54
68
|
.status(HTTP_FAIL_CODES.BAD_REQUEST)
|
|
55
|
-
.json({ success: false, code: "invalid-otp-code", message: "Invalid code" });
|
|
69
|
+
.json({ success: false, code: "invalid-otp-code", message: "Invalid or empty code" });
|
|
56
70
|
}
|
|
57
71
|
if (typeof email !== "string" || !email) {
|
|
58
72
|
res
|
|
59
73
|
.status(HTTP_FAIL_CODES.BAD_REQUEST)
|
|
60
|
-
.json({ success: false, code: "
|
|
74
|
+
.json({ success: false, code: "invalid-email", message: "Invalid or empty email" });
|
|
61
75
|
}
|
|
62
76
|
return handler(req, res, { type: "otp", code, email });
|
|
63
77
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import e, { Request, Response } from "express";
|
|
2
2
|
import { AuthResponse } from "prostgles-types";
|
|
3
3
|
import { AUTH_ROUTES_AND_PARAMS, HTTP_FAIL_CODES } from "../AuthHandler";
|
|
4
|
-
import type {
|
|
4
|
+
import type { SignupWithEmail } from "../AuthTypes";
|
|
5
5
|
import { getClientRequestIPsInfo } from "../utils/getClientRequestIPsInfo";
|
|
6
6
|
import { parseLoginData } from "./setLoginRequestHandler";
|
|
7
7
|
|
|
@@ -13,8 +13,8 @@ type ReturnType =
|
|
|
13
13
|
|
|
14
14
|
type RegisterResponseHandler = Response<ReturnType>;
|
|
15
15
|
|
|
16
|
-
export const setRegisterRequestHandler =
|
|
17
|
-
{ onRegister, minPasswordLength = 8 }:
|
|
16
|
+
export const setRegisterRequestHandler = (
|
|
17
|
+
{ onRegister, minPasswordLength = 8 }: SignupWithEmail,
|
|
18
18
|
app: e.Express
|
|
19
19
|
) => {
|
|
20
20
|
const registerRequestHandler = async (req: Request, res: RegisterResponseHandler) => {
|
|
@@ -50,7 +50,7 @@ export const setRegisterRequestHandler = async (
|
|
|
50
50
|
email: username,
|
|
51
51
|
password,
|
|
52
52
|
getConfirmationUrl: ({ code, websiteUrl }) => {
|
|
53
|
-
const confirmationUrl = new URL(`${websiteUrl}${AUTH_ROUTES_AND_PARAMS.
|
|
53
|
+
const confirmationUrl = new URL(`${websiteUrl}${AUTH_ROUTES_AND_PARAMS.magicLinks}`);
|
|
54
54
|
confirmationUrl.searchParams.set("email", username);
|
|
55
55
|
confirmationUrl.searchParams.set("code", code);
|
|
56
56
|
return confirmationUrl.toString();
|
|
@@ -64,8 +64,12 @@ export async function getClientAuth(
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
const userData = await this.getSidAndUserFromRequest(clientReq);
|
|
67
|
-
const {
|
|
68
|
-
|
|
67
|
+
const {
|
|
68
|
+
loginWithOAuth,
|
|
69
|
+
signupWithEmail: signupWithEmailAndPassword,
|
|
70
|
+
localLoginMode,
|
|
71
|
+
login,
|
|
72
|
+
} = this.opts.loginSignupConfig ?? {};
|
|
69
73
|
|
|
70
74
|
const auth: AuthSocketSchema = {
|
|
71
75
|
providers: getOAuthProviders(loginWithOAuth),
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { RequestHandler } from "express";
|
|
2
2
|
import { DBOFullyTyped } from "../DBSchemaBuilder";
|
|
3
3
|
import { AuthHandler, HTTP_FAIL_CODES } from "./AuthHandler";
|
|
4
4
|
import { setCatchAllRequestHandler } from "./endpoints/setCatchAllRequestHandler";
|
|
5
|
-
import { setConfirmEmailRequestHandler } from "./endpoints/setConfirmEmailRequestHandler";
|
|
6
5
|
import { setLoginRequestHandler } from "./endpoints/setLoginRequestHandler";
|
|
7
6
|
import { setMagicLinkOrOTPRequestHandler } from "./endpoints/setMagicLinkOrOTPRequestHandler";
|
|
8
7
|
import { setOAuthRequestHandlers } from "./endpoints/setOAuthRequestHandlers";
|
|
@@ -25,7 +24,7 @@ export async function setupAuthRoutes(this: AuthHandler) {
|
|
|
25
24
|
onMagicLinkOrOTP,
|
|
26
25
|
use,
|
|
27
26
|
loginWithOAuth,
|
|
28
|
-
signupWithEmailAndPassword,
|
|
27
|
+
signupWithEmail: signupWithEmailAndPassword,
|
|
29
28
|
} = loginSignupConfig;
|
|
30
29
|
if (publicRoutes.find((r) => typeof r !== "string" || !r)) {
|
|
31
30
|
throw "Invalid or empty string provided within publicRoutes ";
|
|
@@ -33,7 +32,6 @@ export async function setupAuthRoutes(this: AuthHandler) {
|
|
|
33
32
|
|
|
34
33
|
if (signupWithEmailAndPassword) {
|
|
35
34
|
setRegisterRequestHandler(signupWithEmailAndPassword, app);
|
|
36
|
-
setConfirmEmailRequestHandler.bind(this)(signupWithEmailAndPassword, app);
|
|
37
35
|
}
|
|
38
36
|
|
|
39
37
|
if (loginWithOAuth) {
|
|
@@ -42,7 +40,7 @@ export async function setupAuthRoutes(this: AuthHandler) {
|
|
|
42
40
|
|
|
43
41
|
if (use) {
|
|
44
42
|
const prostglesUseMiddleware: RequestHandler = (req, res, next) => {
|
|
45
|
-
use({
|
|
43
|
+
void use({
|
|
46
44
|
req,
|
|
47
45
|
res,
|
|
48
46
|
next,
|
package/lib/DBSchemaBuilder.ts
CHANGED
|
@@ -148,7 +148,7 @@ export type PublishFullyTyped<Schema = void> =
|
|
|
148
148
|
ddb.dwad?.delete;
|
|
149
149
|
|
|
150
150
|
//@ts-ignore
|
|
151
|
-
prostgles({
|
|
151
|
+
void prostgles({
|
|
152
152
|
dbConnection: 1 as any,
|
|
153
153
|
publish: async (params) => {
|
|
154
154
|
const _rows = await params.dbo.dwadwa?.find?.({});
|
|
@@ -157,9 +157,9 @@ export type PublishFullyTyped<Schema = void> =
|
|
|
157
157
|
},
|
|
158
158
|
transactions: true,
|
|
159
159
|
onReady: ({ dbo }) => {
|
|
160
|
-
dbo.tdwa?.find!();
|
|
161
|
-
dbo.tx((t) => {
|
|
162
|
-
t.dwa?.find!();
|
|
160
|
+
void dbo.tdwa?.find!();
|
|
161
|
+
void dbo.tx((t) => {
|
|
162
|
+
void t.dwa?.find!();
|
|
163
163
|
});
|
|
164
164
|
},
|
|
165
165
|
});
|
|
@@ -192,13 +192,13 @@ export type PublishFullyTyped<Schema = void> =
|
|
|
192
192
|
const _test: DBSchema = c;
|
|
193
193
|
const dbt: DBOFullyTyped<S> = 1 as any;
|
|
194
194
|
|
|
195
|
-
dbt.tx!((t) => {
|
|
196
|
-
t.tbl1.delete();
|
|
195
|
+
void dbt.tx!((t) => {
|
|
196
|
+
void t.tbl1.delete();
|
|
197
197
|
});
|
|
198
198
|
|
|
199
199
|
const db: DBHandlerServer = 1 as any;
|
|
200
|
-
db.tx!((t) => {
|
|
201
|
-
t.wadwa?.find!();
|
|
200
|
+
void db.tx!((t) => {
|
|
201
|
+
void t.wadwa?.find!();
|
|
202
202
|
});
|
|
203
203
|
|
|
204
204
|
const _publish = (): PublishFullyTyped<S> => {
|
|
@@ -244,7 +244,7 @@ export type PublishFullyTyped<Schema = void> =
|
|
|
244
244
|
|
|
245
245
|
const p: PublishParams<undefined> = 1 as any;
|
|
246
246
|
|
|
247
|
-
p.dbo.dwadaw?.find?.();
|
|
247
|
+
void p.dbo.dwadaw?.find?.();
|
|
248
248
|
|
|
249
249
|
return res;
|
|
250
250
|
};
|
|
@@ -55,18 +55,18 @@ export class QueryStreamer {
|
|
|
55
55
|
this.db = dboBuilder.db;
|
|
56
56
|
const setAdminClient = () => {
|
|
57
57
|
this.adminClient = this.getConnection(undefined, { keepAlive: true });
|
|
58
|
-
this.adminClient.connect();
|
|
58
|
+
return this.adminClient.connect();
|
|
59
59
|
};
|
|
60
60
|
this.adminClient = this.getConnection(
|
|
61
61
|
(error) => {
|
|
62
62
|
if (error.message?.includes("database") && error.message?.includes("does not exist"))
|
|
63
63
|
return;
|
|
64
64
|
console.log("Admin client error. Reconnecting...", error);
|
|
65
|
-
setAdminClient();
|
|
65
|
+
void setAdminClient();
|
|
66
66
|
},
|
|
67
67
|
{ keepAlive: true }
|
|
68
68
|
);
|
|
69
|
-
this.adminClient.connect();
|
|
69
|
+
void this.adminClient.connect();
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
getConnection = (onError: ((err: any) => void) | undefined, extraOptions?: pg.ClientConfig) => {
|
|
@@ -84,7 +84,7 @@ export class QueryStreamer {
|
|
|
84
84
|
Object.values(socketQueries).forEach(({ client, stop }) => {
|
|
85
85
|
stop?.();
|
|
86
86
|
/** end does not stop active query?! */
|
|
87
|
-
client?.end();
|
|
87
|
+
void client?.end();
|
|
88
88
|
});
|
|
89
89
|
delete this.socketQueries[socketId];
|
|
90
90
|
};
|
|
@@ -165,7 +165,7 @@ export class QueryStreamer {
|
|
|
165
165
|
client ??
|
|
166
166
|
this.getConnection((err) => {
|
|
167
167
|
socketQuery.onError(err);
|
|
168
|
-
currentClient.end();
|
|
168
|
+
void currentClient.end();
|
|
169
169
|
});
|
|
170
170
|
this.socketQueries[socketId]![id]!.client = currentClient;
|
|
171
171
|
try {
|
|
@@ -188,7 +188,7 @@ export class QueryStreamer {
|
|
|
188
188
|
this.socketQueries[socketId]![id]!.cursor = cursor;
|
|
189
189
|
let streamLimitReached = false;
|
|
190
190
|
let reachedEnd = false;
|
|
191
|
-
(async () => {
|
|
191
|
+
void (async () => {
|
|
192
192
|
try {
|
|
193
193
|
let rowChunk: any[] = [];
|
|
194
194
|
let rowsSent = 0;
|
|
@@ -216,9 +216,9 @@ export class QueryStreamer {
|
|
|
216
216
|
|
|
217
217
|
if (!query.options?.persistStreamConnection) {
|
|
218
218
|
delete this.socketQueries[socketId]?.[id];
|
|
219
|
-
currentClient.end();
|
|
219
|
+
void currentClient.end();
|
|
220
220
|
}
|
|
221
|
-
cursor.close();
|
|
221
|
+
void cursor.close();
|
|
222
222
|
} catch (error: any) {
|
|
223
223
|
streamState = "errored";
|
|
224
224
|
if (error.message === "cannot insert multiple commands into a prepared statement") {
|
|
@@ -258,7 +258,7 @@ export class QueryStreamer {
|
|
|
258
258
|
if (!queryClient) return;
|
|
259
259
|
if (opts?.terminate) {
|
|
260
260
|
setTimeout(() => {
|
|
261
|
-
queryClient.end();
|
|
261
|
+
void queryClient.end();
|
|
262
262
|
}, 4e3);
|
|
263
263
|
}
|
|
264
264
|
try {
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
FileManager,
|
|
3
|
-
LocalConfig,
|
|
4
|
-
OnProgress,
|
|
5
|
-
UploadedItem,
|
|
6
|
-
} from "./FileManager";
|
|
1
|
+
import { FileManager, LocalConfig, OnProgress, UploadedItem } from "./FileManager";
|
|
7
2
|
import * as stream from "stream";
|
|
8
3
|
import * as fs from "fs";
|
|
9
4
|
|
|
@@ -12,7 +7,7 @@ export async function upload(
|
|
|
12
7
|
file: Buffer | string | stream.PassThrough,
|
|
13
8
|
name: string,
|
|
14
9
|
mime: string,
|
|
15
|
-
onProgress?: OnProgress
|
|
10
|
+
onProgress?: OnProgress
|
|
16
11
|
): Promise<UploadedItem> {
|
|
17
12
|
return new Promise(async (resolve, reject) => {
|
|
18
13
|
if (!file) {
|
|
@@ -43,7 +38,7 @@ export async function upload(
|
|
|
43
38
|
}
|
|
44
39
|
} else {
|
|
45
40
|
let content_length = 0;
|
|
46
|
-
this.cloudClient.upload({
|
|
41
|
+
void this.cloudClient.upload({
|
|
47
42
|
fileName: name,
|
|
48
43
|
contentType: mime,
|
|
49
44
|
file,
|
|
@@ -10,18 +10,16 @@ export function uploadStream(
|
|
|
10
10
|
onProgress?: OnProgress,
|
|
11
11
|
onError?: (error: any) => void,
|
|
12
12
|
onEnd?: (item: UploadedItem) => void,
|
|
13
|
-
expectedSizeBytes?: number
|
|
13
|
+
expectedSizeBytes?: number
|
|
14
14
|
) {
|
|
15
15
|
const passThrough = new stream.PassThrough();
|
|
16
16
|
|
|
17
17
|
if (!this.cloudClient && "localFolderPath" in this.config) {
|
|
18
18
|
try {
|
|
19
|
-
this.checkFreeSpace(this.config.localFolderPath, expectedSizeBytes).catch(
|
|
20
|
-
(err)
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
},
|
|
24
|
-
);
|
|
19
|
+
this.checkFreeSpace(this.config.localFolderPath, expectedSizeBytes).catch((err) => {
|
|
20
|
+
onError?.(err);
|
|
21
|
+
passThrough.end();
|
|
22
|
+
});
|
|
25
23
|
const url = this.getLocalFileUrl(name);
|
|
26
24
|
fs.mkdirSync(this.config.localFolderPath, { recursive: true });
|
|
27
25
|
const filePath = path.resolve(`${this.config.localFolderPath}/${name}`);
|
|
@@ -71,7 +69,7 @@ export function uploadStream(
|
|
|
71
69
|
onError?.(err);
|
|
72
70
|
}
|
|
73
71
|
} else {
|
|
74
|
-
this.upload(passThrough, name, mime, onProgress).then(onEnd).catch(onError);
|
|
72
|
+
void this.upload(passThrough, name, mime, onProgress).then(onEnd).catch(onError);
|
|
75
73
|
}
|
|
76
74
|
|
|
77
75
|
return passThrough;
|
|
@@ -44,7 +44,7 @@ export class PostgresNotifListenManager {
|
|
|
44
44
|
this.notifListener = notifListener;
|
|
45
45
|
this.db_channel_name = db_channel_name;
|
|
46
46
|
|
|
47
|
-
if (!noInit) this.init();
|
|
47
|
+
if (!noInit) void this.init();
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
async init(): Promise<PostgresNotifListenManager> {
|
|
@@ -68,7 +68,7 @@ export class PostgresNotifListenManager {
|
|
|
68
68
|
destroy = async () => {
|
|
69
69
|
this.destroyed = true;
|
|
70
70
|
await this.stopListening();
|
|
71
|
-
this.connection?.done();
|
|
71
|
+
await this.connection?.done();
|
|
72
72
|
this.connection = undefined;
|
|
73
73
|
};
|
|
74
74
|
|
|
@@ -77,7 +77,7 @@ export class PostgresNotifListenManager {
|
|
|
77
77
|
try {
|
|
78
78
|
await this.connection?.none("UNLISTEN $1~", [this.db_channel_name]);
|
|
79
79
|
await this.client?.query("UNLISTEN $1~", [this.db_channel_name]);
|
|
80
|
-
} catch
|
|
80
|
+
} catch {}
|
|
81
81
|
}
|
|
82
82
|
};
|
|
83
83
|
|
package/lib/Prostgles.ts
CHANGED
|
@@ -194,7 +194,7 @@ export class PubSubManager {
|
|
|
194
194
|
private constructor(dboBuilder: DboBuilder) {
|
|
195
195
|
this.dboBuilder = dboBuilder;
|
|
196
196
|
|
|
197
|
-
this._log({
|
|
197
|
+
void this._log({
|
|
198
198
|
type: "syncOrSub",
|
|
199
199
|
command: "postgresNotifListenManager.create",
|
|
200
200
|
duration: 0,
|
|
@@ -207,13 +207,13 @@ export class PubSubManager {
|
|
|
207
207
|
appCheck?: ReturnType<typeof setInterval>;
|
|
208
208
|
|
|
209
209
|
destroyed = false;
|
|
210
|
-
destroy = () => {
|
|
210
|
+
destroy = async () => {
|
|
211
211
|
this.destroyed = true;
|
|
212
212
|
if (this.appCheck) {
|
|
213
213
|
clearInterval(this.appCheck);
|
|
214
214
|
}
|
|
215
|
-
this.postgresNotifListenManager?.destroy();
|
|
216
|
-
this._log({
|
|
215
|
+
await this.postgresNotifListenManager?.destroy();
|
|
216
|
+
await this._log({
|
|
217
217
|
type: "syncOrSub",
|
|
218
218
|
command: "postgresNotifListenManager.destroy",
|
|
219
219
|
duration: 0,
|
|
@@ -393,7 +393,7 @@ export class PubSubManager {
|
|
|
393
393
|
|
|
394
394
|
delete this.sockets[socket.id];
|
|
395
395
|
|
|
396
|
-
this._log({
|
|
396
|
+
void this._log({
|
|
397
397
|
type: "sync",
|
|
398
398
|
command: "upsertSocket.disconnect",
|
|
399
399
|
tableName: "",
|
|
@@ -111,7 +111,7 @@ export async function addSub(
|
|
|
111
111
|
* Socket clients are not affected as they need to confirm they are ready to receive data
|
|
112
112
|
*/
|
|
113
113
|
result.sendFirstData = () => {
|
|
114
|
-
this.pushSubData(newSub);
|
|
114
|
+
void this.pushSubData(newSub);
|
|
115
115
|
};
|
|
116
116
|
} else if (socket) {
|
|
117
117
|
const removeListeners = () => {
|
|
@@ -122,7 +122,7 @@ export async function addSub(
|
|
|
122
122
|
removeListeners();
|
|
123
123
|
|
|
124
124
|
socket.once(result.channelNameReady, () => {
|
|
125
|
-
this.pushSubData(newSub);
|
|
125
|
+
void this.pushSubData(newSub);
|
|
126
126
|
});
|
|
127
127
|
socket.once(result.channelNameUnsubscribe, (_data: any, cb: BasicCallback) => {
|
|
128
128
|
const res = "ok";
|
|
@@ -130,7 +130,7 @@ export async function addSub(
|
|
|
130
130
|
const isMatch = s.socket?.id === socket.id && s.channel_name === channel_name;
|
|
131
131
|
return !isMatch;
|
|
132
132
|
});
|
|
133
|
-
this._log({
|
|
133
|
+
void this._log({
|
|
134
134
|
type: "syncOrSub",
|
|
135
135
|
command: "unsubscribe",
|
|
136
136
|
channel_name,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { find, tryCatchV2 } from "prostgles-types
|
|
1
|
+
import { find, tryCatchV2 } from "prostgles-types";
|
|
2
2
|
import {
|
|
3
3
|
AddSyncParams,
|
|
4
4
|
BasicCallback,
|
|
@@ -69,7 +69,7 @@ export async function addSync(
|
|
|
69
69
|
const unsyncChn = channelName + "unsync";
|
|
70
70
|
socket.removeAllListeners(unsyncChn);
|
|
71
71
|
socket.once(unsyncChn, (_data: any, cb: BasicCallback) => {
|
|
72
|
-
this._log({
|
|
72
|
+
void this._log({
|
|
73
73
|
type: "sync",
|
|
74
74
|
command: "unsync",
|
|
75
75
|
socketId: socket.id,
|
|
@@ -113,7 +113,7 @@ export async function addSync(
|
|
|
113
113
|
*/
|
|
114
114
|
|
|
115
115
|
if (data.onSyncRequest) {
|
|
116
|
-
this.syncData(newSync, data.onSyncRequest, "client");
|
|
116
|
+
void this.syncData(newSync, data.onSyncRequest, "client");
|
|
117
117
|
} else {
|
|
118
118
|
console.error("Unexpected sync request data from client: ", data);
|
|
119
119
|
}
|