prostgles-server 4.2.227 → 4.2.229
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 -23
- 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 +4 -4
- 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 -24
- 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 +6 -6
- 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/AuthHandler.ts
CHANGED
|
@@ -41,10 +41,9 @@ export const AUTH_ROUTES_AND_PARAMS = {
|
|
|
41
41
|
emailRegistration: "/register",
|
|
42
42
|
returnUrlParamName: "returnURL",
|
|
43
43
|
sidKeyName: "session_id",
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
confirmEmail: "/confirm-email",
|
|
44
|
+
logout: "/logout",
|
|
45
|
+
magicLinks: "/magic-link",
|
|
46
|
+
magicLinksIdParam: "/magic-link/:id",
|
|
48
47
|
catchAll: "*",
|
|
49
48
|
} as const;
|
|
50
49
|
|
|
@@ -74,11 +73,16 @@ export class AuthHandler {
|
|
|
74
73
|
};
|
|
75
74
|
|
|
76
75
|
isUserRoute = (pathname: string) => {
|
|
77
|
-
const {
|
|
76
|
+
const {
|
|
77
|
+
login,
|
|
78
|
+
logout: logoutRoute,
|
|
79
|
+
magicLinks: magicLinksRoute,
|
|
80
|
+
loginWithProvider,
|
|
81
|
+
} = AUTH_ROUTES_AND_PARAMS;
|
|
78
82
|
const pubRoutes = [
|
|
79
83
|
...(this.opts.loginSignupConfig?.publicRoutes || []),
|
|
80
84
|
login,
|
|
81
|
-
|
|
85
|
+
logoutRoute,
|
|
82
86
|
magicLinksRoute,
|
|
83
87
|
loginWithProvider,
|
|
84
88
|
].filter((publicRoute) => publicRoute);
|
|
@@ -178,24 +182,22 @@ export class AuthHandler {
|
|
|
178
182
|
const app = this.opts.loginSignupConfig?.app;
|
|
179
183
|
const {
|
|
180
184
|
login,
|
|
181
|
-
|
|
182
|
-
|
|
185
|
+
logout,
|
|
186
|
+
magicLinksIdParam,
|
|
183
187
|
catchAll,
|
|
184
188
|
loginWithProvider,
|
|
185
189
|
emailRegistration,
|
|
186
|
-
|
|
187
|
-
confirmEmail,
|
|
190
|
+
magicLinks,
|
|
188
191
|
} = AUTH_ROUTES_AND_PARAMS;
|
|
189
192
|
|
|
190
193
|
removeExpressRoute(app, [
|
|
191
194
|
login,
|
|
192
|
-
|
|
193
|
-
|
|
195
|
+
logout,
|
|
196
|
+
magicLinksIdParam,
|
|
194
197
|
catchAll,
|
|
195
198
|
loginWithProvider,
|
|
196
199
|
emailRegistration,
|
|
197
|
-
|
|
198
|
-
confirmEmail,
|
|
200
|
+
magicLinks,
|
|
199
201
|
]);
|
|
200
202
|
};
|
|
201
203
|
|
package/lib/Auth/AuthTypes.ts
CHANGED
|
@@ -113,41 +113,40 @@ 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>;
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Called after the user has clicked the URL to confirm their email address
|
|
141
|
-
*/
|
|
142
|
-
onEmailConfirmation: (data: {
|
|
143
|
-
email: string;
|
|
144
|
-
code: string;
|
|
145
|
-
clientInfo: LoginClientInfo;
|
|
146
|
-
req: ExpressReq;
|
|
147
|
-
}) => Awaitable<
|
|
148
|
-
| AuthResponse.PasswordRegisterEmailConfirmationFailure
|
|
149
|
-
| (AuthResponse.PasswordRegisterEmailConfirmationSuccess & { redirect_to?: string })
|
|
150
|
-
>;
|
|
151
150
|
};
|
|
152
151
|
|
|
153
152
|
export type AuthProviderUserData =
|
|
@@ -289,11 +288,12 @@ export type AuthConfig<S = void, SUser extends SessionUser = SessionUser> = {
|
|
|
289
288
|
sidKeyName?: string;
|
|
290
289
|
|
|
291
290
|
/**
|
|
291
|
+
* Required to allow self-managed or managed (by setting up loginSignupConfig) authentication.
|
|
292
292
|
* Used in:
|
|
293
|
-
* -
|
|
294
|
-
* - PublishParams - userData and/or sid (in testing) are passed to the publish function
|
|
293
|
+
* - publish - userData and/or sid (in testing) are passed to the publish function
|
|
295
294
|
* - auth.expressConfig.use - express middleware to get user data and
|
|
296
295
|
* undefined sid is allowed to enable public users
|
|
296
|
+
* - websocket authguard - allows connected SPA client to check if on protected route and needs to reload to ne redirected to login
|
|
297
297
|
*/
|
|
298
298
|
getUser: (
|
|
299
299
|
sid: string | undefined,
|
|
@@ -390,8 +390,12 @@ export type LoginSignupConfig<S, SUser extends SessionUser> = {
|
|
|
390
390
|
) => Awaitable<void>;
|
|
391
391
|
|
|
392
392
|
/**
|
|
393
|
-
* If defined, will enable
|
|
394
|
-
*
|
|
393
|
+
* If defined, will enable:
|
|
394
|
+
* - GET /magic-link/:id route.
|
|
395
|
+
* - POST /magic-link { email, code } route.
|
|
396
|
+
* Successfull requests that return a session will be logged in
|
|
397
|
+
* and redirected to the returnUrl if set.
|
|
398
|
+
* Otherwise just the response will be sent
|
|
395
399
|
*/
|
|
396
400
|
onMagicLinkOrOTP?: (
|
|
397
401
|
data: MagicLinkOrOTPData,
|
|
@@ -399,14 +403,17 @@ export type LoginSignupConfig<S, SUser extends SessionUser> = {
|
|
|
399
403
|
db: DB,
|
|
400
404
|
client: LoginClientInfo
|
|
401
405
|
) => Awaitable<
|
|
402
|
-
| {
|
|
406
|
+
| {
|
|
407
|
+
session: BasicSession | undefined;
|
|
408
|
+
response?: AuthResponse.AuthSuccess | AuthResponse.PasswordRegisterEmailConfirmationSuccess;
|
|
409
|
+
}
|
|
403
410
|
| {
|
|
404
411
|
session?: undefined;
|
|
405
412
|
response: AuthResponse.MagicLinkAuthFailure | AuthResponse.CodeVerificationFailure;
|
|
406
413
|
}
|
|
407
414
|
>;
|
|
408
415
|
|
|
409
|
-
|
|
416
|
+
signupWithEmail?: SignupWithEmail;
|
|
410
417
|
|
|
411
418
|
loginWithOAuth?: LoginWithOAuthConfig<S>;
|
|
412
419
|
|
|
@@ -417,7 +424,8 @@ export type LoginSignupConfig<S, SUser extends SessionUser> = {
|
|
|
417
424
|
localLoginMode?: AuthSocketSchema["loginType"];
|
|
418
425
|
|
|
419
426
|
/**
|
|
420
|
-
* If provided then the user will be able to login with a username and password
|
|
427
|
+
* If provided then the user will be able to login with a username and/or password
|
|
428
|
+
* through the POST /login route.
|
|
421
429
|
*/
|
|
422
430
|
login: (
|
|
423
431
|
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, requirePassword }: SignupWithEmail,
|
|
18
18
|
app: e.Express
|
|
19
19
|
) => {
|
|
20
20
|
const registerRequestHandler = async (req: Request, res: RegisterResponseHandler) => {
|
|
@@ -24,7 +24,7 @@ export const setRegisterRequestHandler = async (
|
|
|
24
24
|
.status(HTTP_FAIL_CODES.BAD_REQUEST)
|
|
25
25
|
.json({ success: false, code: "something-went-wrong", message: error });
|
|
26
26
|
}
|
|
27
|
-
const { username, password } = data;
|
|
27
|
+
const { username, password = "" } = data;
|
|
28
28
|
const sendResponse = (response: ReturnType) => {
|
|
29
29
|
if (response.success) {
|
|
30
30
|
res.json(response);
|
|
@@ -35,7 +35,7 @@ export const setRegisterRequestHandler = async (
|
|
|
35
35
|
if (!username) {
|
|
36
36
|
return sendResponse({ success: false, code: "username-missing" });
|
|
37
37
|
}
|
|
38
|
-
if (!password) {
|
|
38
|
+
if (!password && requirePassword) {
|
|
39
39
|
return sendResponse({ success: false, code: "password-missing" });
|
|
40
40
|
} else if (password.length < minPasswordLength) {
|
|
41
41
|
return sendResponse({
|
|
@@ -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