prostgles-server 4.2.289 → 4.2.291

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 (51) hide show
  1. package/dist/Auth/AuthHandler.d.ts +12 -6
  2. package/dist/Auth/AuthHandler.d.ts.map +1 -1
  3. package/dist/Auth/AuthHandler.js +18 -3
  4. package/dist/Auth/AuthHandler.js.map +1 -1
  5. package/dist/Auth/AuthTypes.d.ts +3 -13
  6. package/dist/Auth/AuthTypes.d.ts.map +1 -1
  7. package/dist/Auth/endpoints/setCatchAllRequestHandler.d.ts.map +1 -1
  8. package/dist/Auth/endpoints/setCatchAllRequestHandler.js +17 -9
  9. package/dist/Auth/endpoints/setCatchAllRequestHandler.js.map +1 -1
  10. package/dist/Auth/setupAuthRoutes.d.ts.map +1 -1
  11. package/dist/Auth/setupAuthRoutes.js +2 -26
  12. package/dist/Auth/setupAuthRoutes.js.map +1 -1
  13. package/dist/Auth/utils/handleGetUser.d.ts.map +1 -1
  14. package/dist/Auth/utils/handleGetUser.js +6 -2
  15. package/dist/Auth/utils/handleGetUser.js.map +1 -1
  16. package/dist/Auth/utils/removeExpressRoute.d.ts.map +1 -1
  17. package/dist/Auth/utils/removeExpressRoute.js +25 -12
  18. package/dist/Auth/utils/removeExpressRoute.js.map +1 -1
  19. package/dist/Auth/utils/setCookieAndGoToReturnURLIFSet.d.ts +1 -0
  20. package/dist/Auth/utils/setCookieAndGoToReturnURLIFSet.d.ts.map +1 -1
  21. package/dist/Auth/utils/setCookieAndGoToReturnURLIFSet.js +22 -4
  22. package/dist/Auth/utils/setCookieAndGoToReturnURLIFSet.js.map +1 -1
  23. package/dist/FileManager/FileManager.d.ts +1 -2
  24. package/dist/FileManager/FileManager.d.ts.map +1 -1
  25. package/dist/FileManager/FileManager.js +4 -5
  26. package/dist/FileManager/FileManager.js.map +1 -1
  27. package/dist/FileManager/initFileManager.js +2 -2
  28. package/dist/FileManager/initFileManager.js.map +1 -1
  29. package/dist/ProstglesTypes.d.ts +1 -1
  30. package/dist/ProstglesTypes.d.ts.map +1 -1
  31. package/dist/RestApi.d.ts +3 -2
  32. package/dist/RestApi.d.ts.map +1 -1
  33. package/dist/RestApi.js +12 -5
  34. package/dist/RestApi.js.map +1 -1
  35. package/lib/Auth/AuthHandler.ts +20 -6
  36. package/lib/Auth/AuthTypes.ts +4 -18
  37. package/lib/Auth/endpoints/setCatchAllRequestHandler.ts +17 -13
  38. package/lib/Auth/setupAuthRoutes.ts +2 -29
  39. package/lib/Auth/utils/handleGetUser.ts +7 -2
  40. package/lib/Auth/utils/removeExpressRoute.ts +30 -16
  41. package/lib/Auth/utils/setCookieAndGoToReturnURLIFSet.ts +23 -3
  42. package/lib/FileManager/FileManager.ts +4 -5
  43. package/lib/FileManager/initFileManager.ts +2 -2
  44. package/lib/ProstglesTypes.ts +1 -1
  45. package/lib/RestApi.ts +14 -7
  46. package/package.json +1 -1
  47. package/dist/Auth/utils/getUserOrError.d.ts +0 -10
  48. package/dist/Auth/utils/getUserOrError.d.ts.map +0 -1
  49. package/dist/Auth/utils/getUserOrError.js +0 -48
  50. package/dist/Auth/utils/getUserOrError.js.map +0 -1
  51. package/lib/Auth/utils/getUserOrError.ts +0 -56
@@ -162,12 +162,12 @@ export async function initFileManager(this: FileManager, prg: Prostgles) {
162
162
  /**
163
163
  * 4. Serve media through express
164
164
  */
165
- const { fileServeRoute = `/${fileTableName}`, expressApp: app } = fileTable;
165
+ const { fileServePath: fileServeRoute = `/${fileTableName}`, expressApp: app } = fileTable;
166
166
 
167
167
  if (fileServeRoute.endsWith("/")) {
168
168
  throw `fileServeRoute must not end with a '/'`;
169
169
  }
170
- this.fileRoute = fileServeRoute;
170
+ this.path = fileServeRoute;
171
171
 
172
172
  app.get(this.fileRouteExpress, async (req, res) => {
173
173
  const mediaTableHandler = this.dbo[fileTableName] as unknown as TableHandler | undefined;
@@ -42,7 +42,7 @@ export type FileTableConfig = {
42
42
  /**
43
43
  * GET path used in serving media. defaults to /${tableName}
44
44
  */
45
- fileServeRoute?: string;
45
+ fileServePath?: string;
46
46
 
47
47
  /**
48
48
  * If defined the the files will not be deleted immediately
package/lib/RestApi.ts CHANGED
@@ -1,11 +1,12 @@
1
1
  import * as bodyParser from "body-parser";
2
2
  import { Express } from "express";
3
- import { HTTP_FAIL_CODES } from "./Auth/AuthHandler";
3
+ import { HTTP_FAIL_CODES, removeExpressRoute } from "./Auth/AuthHandler";
4
4
  import { ExpressReq, ExpressRes } from "./Auth/AuthTypes";
5
5
  import { getSerializedClientErrorFromPGError } from "./DboBuilder/DboBuilder";
6
6
  import { Prostgles } from "./Prostgles";
7
7
  import { runClientMethod, runClientRequest, runClientSqlRequest } from "./runClientRequest";
8
8
  import { VoidFunction } from "./SchemaWatch/SchemaWatch";
9
+ import { isDefined } from "prostgles-types";
9
10
  const jsonParser = bodyParser.json();
10
11
 
11
12
  export type ExpressApp = {
@@ -37,7 +38,7 @@ export type RestApiConfig = {
37
38
  /**
38
39
  * Defaults to "/api"
39
40
  */
40
- routePrefix: string;
41
+ path?: string;
41
42
  };
42
43
 
43
44
  export class RestApi {
@@ -49,13 +50,18 @@ export class RestApi {
49
50
  schema: string;
50
51
  };
51
52
  expressApp: Express;
52
- constructor({ expressApp, routePrefix, prostgles }: RestApiConfig & { prostgles: Prostgles }) {
53
+ path = "/api";
54
+ constructor({ expressApp, path, prostgles }: RestApiConfig & { prostgles: Prostgles }) {
55
+ if (isDefined(path) && !path.trim()) {
56
+ throw new Error("path cannot be empty");
57
+ }
58
+ this.path = path || "/api";
53
59
  this.prostgles = prostgles;
54
60
  this.routes = {
55
- db: `${routePrefix}/db/:tableName/:command`,
56
- sql: `${routePrefix}/db/sql`,
57
- methods: `${routePrefix}/methods/:method`,
58
- schema: `${routePrefix}/schema`,
61
+ db: `${path}/db/:tableName/:command`,
62
+ sql: `${path}/db/sql`,
63
+ methods: `${path}/methods/:method`,
64
+ schema: `${path}/schema`,
59
65
  };
60
66
  this.expressApp = expressApp;
61
67
  expressApp.post(this.routes.db, jsonParser, this.onPostTableCommand);
@@ -68,6 +74,7 @@ export class RestApi {
68
74
  this.expressApp.removeListener(this.routes.db, this.onPostTableCommand);
69
75
  this.expressApp.removeListener(this.routes.sql, this.onPostSql);
70
76
  this.expressApp.removeListener(this.routes.methods, this.onPostMethod);
77
+ removeExpressRoute(this.expressApp, [this.path]);
71
78
  };
72
79
  onPostMethod = async (req: ExpressReq, res: ExpressRes) => {
73
80
  const { method = "" } = req.params;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prostgles-server",
3
- "version": "4.2.289",
3
+ "version": "4.2.291",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,10 +0,0 @@
1
- import type { AuthHandler } from "../AuthHandler";
2
- import { AuthClientRequest } from "../AuthTypes";
3
- import { type GetUserOrRedirected } from "./handleGetUser";
4
- /**
5
- * Used by:
6
- * - setCatchAllRequestHandler
7
- * - loginSignupConfig.use
8
- */
9
- export declare function getUserOrError(this: AuthHandler, clientReq: AuthClientRequest): Promise<GetUserOrRedirected>;
10
- //# sourceMappingURL=getUserOrError.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getUserOrError.d.ts","sourceRoot":"","sources":["../../../lib/Auth/utils/getUserOrError.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAqB,MAAM,cAAc,CAAC;AAEpE,OAAO,EAAe,KAAK,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAGxE;;;;GAIG;AACH,wBAAsB,cAAc,CAClC,IAAI,EAAE,WAAW,EACjB,SAAS,EAAE,iBAAiB,GAC3B,OAAO,CAAC,mBAAmB,CAAC,CAuC9B"}
@@ -1,48 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getUserOrError = void 0;
4
- /**
5
- * Used by:
6
- * - setCatchAllRequestHandler
7
- * - loginSignupConfig.use
8
- */
9
- async function getUserOrError(clientReq) {
10
- // const sid = this.getValidatedSid(clientReq);
11
- // if (!sid) return { sid };
12
- try {
13
- // const userOrErrorCode = await throttledAuthCall(async () => {
14
- // return this.opts.getUser(
15
- // this.validateSid(sid),
16
- // this.dbo as DBOFullyTyped,
17
- // this.db,
18
- // getClientRequestIPsInfo(clientReq),
19
- // clientReq
20
- // );
21
- // }, 50);
22
- // if (isAuthError(userOrErrorCode)) {
23
- // const error: AuthResponse.AuthFailure | undefined =
24
- // typeof userOrErrorCode === "string" ?
25
- // { success: false, code: userOrErrorCode }
26
- // : userOrErrorCode;
27
- // return {
28
- // sid,
29
- // error,
30
- // };
31
- // }
32
- // if (sid && userOrErrorCode?.user) {
33
- // return { sid, ...userOrErrorCode };
34
- // }
35
- // return {
36
- // sid,
37
- // };
38
- return this.handleGetUser(clientReq);
39
- }
40
- catch (_err) {
41
- return {
42
- sid: this.getValidatedSid(clientReq),
43
- error: { success: false, code: "server-error" },
44
- };
45
- }
46
- }
47
- exports.getUserOrError = getUserOrError;
48
- //# sourceMappingURL=getUserOrError.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getUserOrError.js","sourceRoot":"","sources":["../../../lib/Auth/utils/getUserOrError.ts"],"names":[],"mappings":";;;AAQA;;;;GAIG;AACI,KAAK,UAAU,cAAc,CAElC,SAA4B;IAE5B,+CAA+C;IAC/C,4BAA4B;IAE5B,IAAI,CAAC;QACH,gEAAgE;QAChE,8BAA8B;QAC9B,6BAA6B;QAC7B,iCAAiC;QACjC,eAAe;QACf,0CAA0C;QAC1C,gBAAgB;QAChB,OAAO;QACP,UAAU;QAEV,sCAAsC;QACtC,wDAAwD;QACxD,4CAA4C;QAC5C,kDAAkD;QAClD,yBAAyB;QAEzB,aAAa;QACb,WAAW;QACX,aAAa;QACb,OAAO;QACP,IAAI;QACJ,sCAAsC;QACtC,wCAAwC;QACxC,IAAI;QACJ,WAAW;QACX,SAAS;QACT,KAAK;QACL,OAAO,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;IACvC,CAAC;IAAC,OAAO,IAAI,EAAE,CAAC;QACd,OAAO;YACL,GAAG,EAAE,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC;YACpC,KAAK,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,cAAc,EAAE;SAChD,CAAC;IACJ,CAAC;AACH,CAAC;AA1CD,wCA0CC"}
@@ -1,56 +0,0 @@
1
- import { AuthResponse } from "prostgles-types";
2
- import { DBOFullyTyped } from "../../DBSchemaBuilder";
3
- import type { AuthHandler } from "../AuthHandler";
4
- import { AuthClientRequest, AuthResultWithSID } from "../AuthTypes";
5
- import { getClientRequestIPsInfo } from "../utils/getClientRequestIPsInfo";
6
- import { isAuthError, type GetUserOrRedirected } from "./handleGetUser";
7
- import { throttledAuthCall } from "./throttledReject";
8
-
9
- /**
10
- * Used by:
11
- * - setCatchAllRequestHandler
12
- * - loginSignupConfig.use
13
- */
14
- export async function getUserOrError(
15
- this: AuthHandler,
16
- clientReq: AuthClientRequest
17
- ): Promise<GetUserOrRedirected> {
18
- // const sid = this.getValidatedSid(clientReq);
19
- // if (!sid) return { sid };
20
-
21
- try {
22
- // const userOrErrorCode = await throttledAuthCall(async () => {
23
- // return this.opts.getUser(
24
- // this.validateSid(sid),
25
- // this.dbo as DBOFullyTyped,
26
- // this.db,
27
- // getClientRequestIPsInfo(clientReq),
28
- // clientReq
29
- // );
30
- // }, 50);
31
-
32
- // if (isAuthError(userOrErrorCode)) {
33
- // const error: AuthResponse.AuthFailure | undefined =
34
- // typeof userOrErrorCode === "string" ?
35
- // { success: false, code: userOrErrorCode }
36
- // : userOrErrorCode;
37
-
38
- // return {
39
- // sid,
40
- // error,
41
- // };
42
- // }
43
- // if (sid && userOrErrorCode?.user) {
44
- // return { sid, ...userOrErrorCode };
45
- // }
46
- // return {
47
- // sid,
48
- // };
49
- return this.handleGetUser(clientReq);
50
- } catch (_err) {
51
- return {
52
- sid: this.getValidatedSid(clientReq),
53
- error: { success: false, code: "server-error" },
54
- };
55
- }
56
- }