prostgles-server 4.2.226 → 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.
Files changed (108) hide show
  1. package/.eslintrc.json +1 -0
  2. package/dist/Auth/AuthHandler.d.ts +3 -5
  3. package/dist/Auth/AuthHandler.d.ts.map +1 -1
  4. package/dist/Auth/AuthHandler.js +10 -14
  5. package/dist/Auth/AuthHandler.js.map +1 -1
  6. package/dist/Auth/AuthTypes.d.ts +37 -14
  7. package/dist/Auth/AuthTypes.d.ts.map +1 -1
  8. package/dist/Auth/endpoints/setCatchAllRequestHandler.d.ts.map +1 -1
  9. package/dist/Auth/endpoints/setCatchAllRequestHandler.js +4 -4
  10. package/dist/Auth/endpoints/setCatchAllRequestHandler.js.map +1 -1
  11. package/dist/Auth/endpoints/setLoginRequestHandler.d.ts +2 -1
  12. package/dist/Auth/endpoints/setLoginRequestHandler.d.ts.map +1 -1
  13. package/dist/Auth/endpoints/setLoginRequestHandler.js.map +1 -1
  14. package/dist/Auth/endpoints/setMagicLinkOrOTPRequestHandler.d.ts +5 -0
  15. package/dist/Auth/endpoints/setMagicLinkOrOTPRequestHandler.d.ts.map +1 -0
  16. package/dist/Auth/endpoints/setMagicLinkOrOTPRequestHandler.js +52 -0
  17. package/dist/Auth/endpoints/setMagicLinkOrOTPRequestHandler.js.map +1 -0
  18. package/dist/Auth/endpoints/setRegisterRequestHandler.d.ts +2 -2
  19. package/dist/Auth/endpoints/setRegisterRequestHandler.d.ts.map +1 -1
  20. package/dist/Auth/endpoints/setRegisterRequestHandler.js +2 -2
  21. package/dist/Auth/endpoints/setRegisterRequestHandler.js.map +1 -1
  22. package/dist/Auth/getClientAuth.d.ts.map +1 -1
  23. package/dist/Auth/getClientAuth.js +1 -1
  24. package/dist/Auth/getClientAuth.js.map +1 -1
  25. package/dist/Auth/setupAuthRoutes.d.ts.map +1 -1
  26. package/dist/Auth/setupAuthRoutes.js +5 -7
  27. package/dist/Auth/setupAuthRoutes.js.map +1 -1
  28. package/dist/DBSchemaBuilder.js +9 -9
  29. package/dist/DBSchemaBuilder.js.map +1 -1
  30. package/dist/DboBuilder/DboBuilder.d.ts +1 -1
  31. package/dist/DboBuilder/DboBuilder.js +1 -1
  32. package/dist/DboBuilder/DboBuilder.js.map +1 -1
  33. package/dist/DboBuilder/QueryStreamer.js +9 -9
  34. package/dist/DboBuilder/QueryStreamer.js.map +1 -1
  35. package/dist/DboBuilder/ViewHandler/find.js +1 -1
  36. package/dist/DboBuilder/ViewHandler/find.js.map +1 -1
  37. package/dist/FileManager/upload.d.ts.map +1 -1
  38. package/dist/FileManager/upload.js +1 -1
  39. package/dist/FileManager/upload.js.map +1 -1
  40. package/dist/FileManager/uploadStream.d.ts.map +1 -1
  41. package/dist/FileManager/uploadStream.js +1 -1
  42. package/dist/FileManager/uploadStream.js.map +1 -1
  43. package/dist/PostgresNotifListenManager.js +3 -3
  44. package/dist/PostgresNotifListenManager.js.map +1 -1
  45. package/dist/Prostgles.js +1 -1
  46. package/dist/Prostgles.js.map +1 -1
  47. package/dist/PubSubManager/PubSubManager.d.ts +1 -1
  48. package/dist/PubSubManager/PubSubManager.d.ts.map +1 -1
  49. package/dist/PubSubManager/PubSubManager.js +5 -5
  50. package/dist/PubSubManager/PubSubManager.js.map +1 -1
  51. package/dist/PubSubManager/addSub.js +3 -3
  52. package/dist/PubSubManager/addSub.js.map +1 -1
  53. package/dist/PubSubManager/addSync.js +5 -5
  54. package/dist/PubSubManager/addSync.js.map +1 -1
  55. package/dist/PubSubManager/notifListener.js +5 -5
  56. package/dist/PubSubManager/notifListener.js.map +1 -1
  57. package/dist/PubSubManager/pushSubData.js +1 -1
  58. package/dist/PubSubManager/pushSubData.js.map +1 -1
  59. package/dist/SchemaWatch/SchemaWatch.js +2 -2
  60. package/dist/SchemaWatch/SchemaWatch.js.map +1 -1
  61. package/dist/SyncReplication.js +2 -2
  62. package/dist/SyncReplication.js.map +1 -1
  63. package/dist/TableConfig/initTableConfig.js +4 -4
  64. package/dist/TableConfig/initTableConfig.js.map +1 -1
  65. package/dist/initProstgles.js +1 -1
  66. package/dist/initProstgles.js.map +1 -1
  67. package/dist/onSocketConnected.js +3 -3
  68. package/dist/onSocketConnected.js.map +1 -1
  69. package/dist/typeTests/dboTypeCheck.js +3 -3
  70. package/dist/typeTests/dboTypeCheck.js.map +1 -1
  71. package/lib/Auth/AuthHandler.ts +18 -19
  72. package/lib/Auth/AuthTypes.ts +42 -14
  73. package/lib/Auth/endpoints/setCatchAllRequestHandler.ts +5 -4
  74. package/lib/Auth/endpoints/setLoginRequestHandler.ts +3 -2
  75. package/lib/Auth/endpoints/setMagicLinkOrOTPRequestHandler.ts +78 -0
  76. package/lib/Auth/endpoints/setRegisterRequestHandler.ts +4 -4
  77. package/lib/Auth/getClientAuth.ts +6 -2
  78. package/lib/Auth/setupAuthRoutes.ts +7 -10
  79. package/lib/DBSchemaBuilder.ts +9 -9
  80. package/lib/DboBuilder/DboBuilder.ts +1 -1
  81. package/lib/DboBuilder/QueryStreamer.ts +9 -9
  82. package/lib/DboBuilder/ViewHandler/find.ts +1 -1
  83. package/lib/FileManager/upload.ts +3 -8
  84. package/lib/FileManager/uploadStream.ts +6 -8
  85. package/lib/PostgresNotifListenManager.ts +3 -3
  86. package/lib/Prostgles.ts +1 -1
  87. package/lib/PubSubManager/PubSubManager.ts +5 -5
  88. package/lib/PubSubManager/addSub.ts +3 -3
  89. package/lib/PubSubManager/addSync.ts +3 -3
  90. package/lib/PubSubManager/notifListener.ts +5 -5
  91. package/lib/PubSubManager/pushSubData.ts +1 -1
  92. package/lib/SchemaWatch/SchemaWatch.ts +2 -2
  93. package/lib/SyncReplication.ts +2 -2
  94. package/lib/TableConfig/initTableConfig.ts +4 -4
  95. package/lib/initProstgles.ts +1 -1
  96. package/lib/onSocketConnected.ts +3 -3
  97. package/lib/typeTests/dboTypeCheck.ts +11 -11
  98. package/package.json +2 -2
  99. package/dist/Auth/endpoints/setConfirmEmailRequestHandler.d.ts +0 -5
  100. package/dist/Auth/endpoints/setConfirmEmailRequestHandler.d.ts.map +0 -1
  101. package/dist/Auth/endpoints/setConfirmEmailRequestHandler.js +0 -52
  102. package/dist/Auth/endpoints/setConfirmEmailRequestHandler.js.map +0 -1
  103. package/dist/Auth/endpoints/setMagicLinkRequestHandler.d.ts +0 -5
  104. package/dist/Auth/endpoints/setMagicLinkRequestHandler.d.ts.map +0 -1
  105. package/dist/Auth/endpoints/setMagicLinkRequestHandler.js +0 -36
  106. package/dist/Auth/endpoints/setMagicLinkRequestHandler.js.map +0 -1
  107. package/lib/Auth/endpoints/setConfirmEmailRequestHandler.ts +0 -65
  108. package/lib/Auth/endpoints/setMagicLinkRequestHandler.ts +0 -48
@@ -41,11 +41,9 @@ export const AUTH_ROUTES_AND_PARAMS = {
41
41
  emailRegistration: "/register",
42
42
  returnUrlParamName: "returnURL",
43
43
  sidKeyName: "session_id",
44
- logoutGetPath: "/logout",
45
- magicLinksRoute: "/magic-link",
46
- magicLinksExpressRoute: "/magic-link/:id",
47
- confirmEmail: "/confirm-email",
48
- confirmEmailExpressRoute: "/confirm-email",
44
+ logout: "/logout",
45
+ magicLinks: "/magic-link",
46
+ magicLinksIdParam: "/magic-link/:id",
49
47
  catchAll: "*",
50
48
  } as const;
51
49
 
@@ -75,11 +73,16 @@ export class AuthHandler {
75
73
  };
76
74
 
77
75
  isUserRoute = (pathname: string) => {
78
- const { login, logoutGetPath, magicLinksRoute, loginWithProvider } = AUTH_ROUTES_AND_PARAMS;
76
+ const {
77
+ login,
78
+ logout: logoutRoute,
79
+ magicLinks: magicLinksRoute,
80
+ loginWithProvider,
81
+ } = AUTH_ROUTES_AND_PARAMS;
79
82
  const pubRoutes = [
80
83
  ...(this.opts.loginSignupConfig?.publicRoutes || []),
81
84
  login,
82
- logoutGetPath,
85
+ logoutRoute,
83
86
  magicLinksRoute,
84
87
  loginWithProvider,
85
88
  ].filter((publicRoute) => publicRoute);
@@ -179,26 +182,22 @@ export class AuthHandler {
179
182
  const app = this.opts.loginSignupConfig?.app;
180
183
  const {
181
184
  login,
182
- logoutGetPath,
183
- magicLinksExpressRoute,
185
+ logout,
186
+ magicLinksIdParam,
184
187
  catchAll,
185
188
  loginWithProvider,
186
- emailRegistration: emailSignup,
187
- magicLinksRoute,
188
- confirmEmail,
189
- confirmEmailExpressRoute,
189
+ emailRegistration,
190
+ magicLinks,
190
191
  } = AUTH_ROUTES_AND_PARAMS;
191
192
 
192
193
  removeExpressRoute(app, [
193
194
  login,
194
- logoutGetPath,
195
- magicLinksExpressRoute,
195
+ logout,
196
+ magicLinksIdParam,
196
197
  catchAll,
197
198
  loginWithProvider,
198
- emailSignup,
199
- magicLinksRoute,
200
- confirmEmail,
201
- confirmEmailExpressRoute,
199
+ emailRegistration,
200
+ magicLinks,
202
201
  ]);
203
202
  };
204
203
 
@@ -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 SignupWithEmailAndPassword = {
119
+ export type SignupWithEmail = {
120
120
  /**
121
121
  * Defaults to 8
122
122
  */
123
123
  minPasswordLength?: number;
124
124
 
125
125
  /**
126
- * Called when the user has registered
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
- * - WS AUTHGUARD - allows connected SPA client to check if on protected route and needs to reload to ne redirected to login
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,
@@ -341,6 +354,10 @@ export type LoginResponse =
341
354
  | AuthResponse.PasswordLoginFailure["code"]
342
355
  | AuthResponse.MagicLinkAuthFailure["code"];
343
356
 
357
+ export type MagicLinkOrOTPData =
358
+ | { type: "magic-link"; magicId: string }
359
+ | { type: "otp"; code: string; email: string };
360
+
344
361
  export type LoginParams =
345
362
  | ({
346
363
  type: "username";
@@ -386,20 +403,30 @@ export type LoginSignupConfig<S, SUser extends SessionUser> = {
386
403
  ) => Awaitable<void>;
387
404
 
388
405
  /**
389
- * If defined, will enable GET /magic-link/:id route.
390
- * Requests with valid magic link ids will be logged in and redirected to the returnUrl if set
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
391
412
  */
392
- onMagicLink?: (
393
- magicId: string,
413
+ onMagicLinkOrOTP?: (
414
+ data: MagicLinkOrOTPData,
394
415
  dbo: DBOFullyTyped<S>,
395
416
  db: DB,
396
417
  client: LoginClientInfo
397
418
  ) => Awaitable<
398
- | { session: BasicSession; response?: AuthResponse.MagicLinkAuthSuccess }
399
- | { session?: undefined; response: AuthResponse.MagicLinkAuthFailure }
419
+ | {
420
+ session: BasicSession | undefined;
421
+ response?: AuthResponse.AuthSuccess | AuthResponse.PasswordRegisterEmailConfirmationSuccess;
422
+ }
423
+ | {
424
+ session?: undefined;
425
+ response: AuthResponse.MagicLinkAuthFailure | AuthResponse.CodeVerificationFailure;
426
+ }
400
427
  >;
401
428
 
402
- signupWithEmailAndPassword?: SignupWithEmailAndPassword;
429
+ signupWithEmail?: SignupWithEmail;
403
430
 
404
431
  loginWithOAuth?: LoginWithOAuthConfig<S>;
405
432
 
@@ -410,7 +437,8 @@ export type LoginSignupConfig<S, SUser extends SessionUser> = {
410
437
  localLoginMode?: AuthSocketSchema["loginType"];
411
438
 
412
439
  /**
413
- * 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.
414
442
  */
415
443
  login: (
416
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 requestHandler: RequestHandler = async (req, res, next) => {
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.logoutGetPath, req.path)) {
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, requestHandler);
110
+ app.get(AUTH_ROUTES_AND_PARAMS.catchAll, requestHandlerCatchAll);
110
111
  }
@@ -3,14 +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 LoginResponseHandler = Response<
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
- >;
13
+ | AuthResponse.CodeVerificationFailure;
14
+ export type LoginResponseHandler = Response<LoginResponse>;
14
15
 
15
16
  export function setLoginRequestHandler(this: AuthHandler, app: e.Express) {
16
17
  app.post(AUTH_ROUTES_AND_PARAMS.login, async (req, res: LoginResponseHandler) => {
@@ -0,0 +1,78 @@
1
+ import e, { type Response } from "express";
2
+ import { DBOFullyTyped } from "../../DBSchemaBuilder";
3
+ import {
4
+ AUTH_ROUTES_AND_PARAMS,
5
+ AuthHandler,
6
+ getClientRequestIPsInfo,
7
+ HTTP_FAIL_CODES,
8
+ HTTP_SUCCESS_CODES,
9
+ } from "../AuthHandler";
10
+ import { ExpressReq, LoginSignupConfig, MagicLinkOrOTPData, SessionUser } from "../AuthTypes";
11
+ import { throttledAuthCall } from "../utils/throttledReject";
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
+ >;
20
+
21
+ export function setMagicLinkOrOTPRequestHandler(
22
+ this: AuthHandler,
23
+ onMagicLink: Required<LoginSignupConfig<void, SessionUser>>["onMagicLinkOrOTP"],
24
+ app: e.Express
25
+ ) {
26
+ const handler = async (
27
+ req: ExpressReq,
28
+ res: MagicLinkResponseHandler,
29
+ data: MagicLinkOrOTPData
30
+ ) => {
31
+ try {
32
+ const response = await throttledAuthCall(async () => {
33
+ return onMagicLink(
34
+ data,
35
+ this.dbo as DBOFullyTyped,
36
+ this.db,
37
+ getClientRequestIPsInfo({ httpReq: req })
38
+ );
39
+ });
40
+ if (!response.session) {
41
+ res
42
+ .status(response.response?.success ? HTTP_SUCCESS_CODES.OK : HTTP_FAIL_CODES.UNAUTHORIZED)
43
+ .json(response.response);
44
+ } else {
45
+ this.setCookieAndGoToReturnURLIFSet(response.session, { req, res });
46
+ }
47
+ } catch (_e) {
48
+ res
49
+ .status(HTTP_FAIL_CODES.BAD_REQUEST)
50
+ .json({ success: false, code: "something-went-wrong" });
51
+ }
52
+ };
53
+ app.get(AUTH_ROUTES_AND_PARAMS.magicLinksIdParam, (req, res: MagicLinkResponseHandler) => {
54
+ const { id } = req.params;
55
+
56
+ if (typeof id !== "string" || !id) {
57
+ res
58
+ .status(HTTP_FAIL_CODES.BAD_REQUEST)
59
+ .json({ success: false, code: "invalid-magic-link", message: "Invalid magic link" });
60
+ }
61
+ return handler(req, res, { type: "magic-link", magicId: id });
62
+ });
63
+ app.post(AUTH_ROUTES_AND_PARAMS.magicLinks, (req, res: MagicLinkResponseHandler) => {
64
+ const { code, email } = req.body;
65
+
66
+ if (typeof code !== "string" || !code) {
67
+ res
68
+ .status(HTTP_FAIL_CODES.BAD_REQUEST)
69
+ .json({ success: false, code: "invalid-otp-code", message: "Invalid or empty code" });
70
+ }
71
+ if (typeof email !== "string" || !email) {
72
+ res
73
+ .status(HTTP_FAIL_CODES.BAD_REQUEST)
74
+ .json({ success: false, code: "invalid-email", message: "Invalid or empty email" });
75
+ }
76
+ return handler(req, res, { type: "otp", code, email });
77
+ });
78
+ }
@@ -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 { SignupWithEmailAndPassword } from "../AuthTypes";
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 = async (
17
- { onRegister, minPasswordLength = 8 }: SignupWithEmailAndPassword,
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.confirmEmail}`);
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 { loginWithOAuth, signupWithEmailAndPassword, localLoginMode, login } =
68
- this.opts.loginSignupConfig ?? {};
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,14 +1,12 @@
1
- import e, { RequestHandler } from "express";
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
- import { setMagicLinkRequestHandler } from "./endpoints/setMagicLinkRequestHandler";
6
+ import { setMagicLinkOrOTPRequestHandler } from "./endpoints/setMagicLinkOrOTPRequestHandler";
8
7
  import { setOAuthRequestHandlers } from "./endpoints/setOAuthRequestHandlers";
9
8
  import { setRegisterRequestHandler } from "./endpoints/setRegisterRequestHandler";
10
9
  import { upsertNamedExpressMiddleware } from "./utils/upsertNamedExpressMiddleware";
11
- import { removeExpressRoute } from "../FileManager/FileManager";
12
10
 
13
11
  export async function setupAuthRoutes(this: AuthHandler) {
14
12
  const { loginSignupConfig } = this.opts;
@@ -23,10 +21,10 @@ export async function setupAuthRoutes(this: AuthHandler) {
23
21
  const {
24
22
  app,
25
23
  publicRoutes = [],
26
- onMagicLink,
24
+ onMagicLinkOrOTP,
27
25
  use,
28
26
  loginWithOAuth,
29
- signupWithEmailAndPassword,
27
+ signupWithEmail: signupWithEmailAndPassword,
30
28
  } = loginSignupConfig;
31
29
  if (publicRoutes.find((r) => typeof r !== "string" || !r)) {
32
30
  throw "Invalid or empty string provided within publicRoutes ";
@@ -34,7 +32,6 @@ export async function setupAuthRoutes(this: AuthHandler) {
34
32
 
35
33
  if (signupWithEmailAndPassword) {
36
34
  setRegisterRequestHandler(signupWithEmailAndPassword, app);
37
- setConfirmEmailRequestHandler.bind(this)(signupWithEmailAndPassword, app);
38
35
  }
39
36
 
40
37
  if (loginWithOAuth) {
@@ -43,7 +40,7 @@ export async function setupAuthRoutes(this: AuthHandler) {
43
40
 
44
41
  if (use) {
45
42
  const prostglesUseMiddleware: RequestHandler = (req, res, next) => {
46
- use({
43
+ void use({
47
44
  req,
48
45
  res,
49
46
  next,
@@ -62,8 +59,8 @@ export async function setupAuthRoutes(this: AuthHandler) {
62
59
  upsertNamedExpressMiddleware(app, prostglesUseMiddleware, "prostglesUseMiddleware");
63
60
  }
64
61
 
65
- if (onMagicLink) {
66
- setMagicLinkRequestHandler.bind(this)(onMagicLink, app);
62
+ if (onMagicLinkOrOTP) {
63
+ setMagicLinkOrOTPRequestHandler.bind(this)(onMagicLinkOrOTP, app);
67
64
  }
68
65
 
69
66
  setLoginRequestHandler.bind(this)(app);
@@ -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
  };
@@ -161,7 +161,7 @@ export class DboBuilder {
161
161
  };
162
162
 
163
163
  destroy() {
164
- this._pubSubManager?.destroy();
164
+ return this._pubSubManager?.destroy();
165
165
  }
166
166
 
167
167
  _joins?: Join[];
@@ -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 {
@@ -152,7 +152,7 @@ export const find = async function (
152
152
  });
153
153
  return result;
154
154
  } catch (e) {
155
- this._log({
155
+ await this._log({
156
156
  command,
157
157
  localParams,
158
158
  data: { filter, selectParams },
@@ -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
- onError?.(err);
22
- passThrough.end();
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 (error) {}
80
+ } catch {}
81
81
  }
82
82
  };
83
83
 
package/lib/Prostgles.ts CHANGED
@@ -392,7 +392,7 @@ export class Prostgles {
392
392
  if (this.connectedSockets.length) {
393
393
  this.connectedSockets.forEach((s) => {
394
394
  s.emit(CHANNELS.SCHEMA_CHANGED);
395
- this.pushSocketSchema(s);
395
+ void this.pushSocketSchema(s);
396
396
  });
397
397
  return;
398
398
  }