prostgles-server 4.2.326 → 4.2.328

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 (69) hide show
  1. package/dist/DboBuilder/TableHandler/DataValidator.d.ts +1 -9
  2. package/dist/DboBuilder/TableHandler/DataValidator.d.ts.map +1 -1
  3. package/dist/DboBuilder/TableHandler/DataValidator.js +35 -32
  4. package/dist/DboBuilder/TableHandler/DataValidator.js.map +1 -1
  5. package/dist/DboBuilder/TableHandler/insert/insert.d.ts.map +1 -1
  6. package/dist/DboBuilder/TableHandler/insert/insert.js +6 -7
  7. package/dist/DboBuilder/TableHandler/insert/insert.js.map +1 -1
  8. package/dist/DboBuilder/TableHandler/insert/insertNestedRecords.js +6 -6
  9. package/dist/DboBuilder/TableHandler/insert/insertNestedRecords.js.map +1 -1
  10. package/dist/FileManager/initFileManager.d.ts.map +1 -1
  11. package/dist/FileManager/initFileManager.js +1 -1
  12. package/dist/FileManager/initFileManager.js.map +1 -1
  13. package/dist/Prostgles.d.ts +1 -1
  14. package/dist/Prostgles.d.ts.map +1 -1
  15. package/dist/PublishParser/PublishParser.d.ts +3 -3
  16. package/dist/PublishParser/PublishParser.d.ts.map +1 -1
  17. package/dist/PublishParser/PublishParser.js +12 -6
  18. package/dist/PublishParser/PublishParser.js.map +1 -1
  19. package/dist/PublishParser/getSchemaFromPublish.d.ts +2 -2
  20. package/dist/PublishParser/getSchemaFromPublish.d.ts.map +1 -1
  21. package/dist/PublishParser/getSchemaFromPublish.js +3 -3
  22. package/dist/PublishParser/getSchemaFromPublish.js.map +1 -1
  23. package/dist/PublishParser/publishTypesAndUtils.d.ts +10 -1
  24. package/dist/PublishParser/publishTypesAndUtils.d.ts.map +1 -1
  25. package/dist/RestApi.d.ts.map +1 -1
  26. package/dist/RestApi.js +2 -2
  27. package/dist/RestApi.js.map +1 -1
  28. package/dist/TableConfig/getSchemaDiffQueries.d.ts +6 -0
  29. package/dist/TableConfig/getSchemaDiffQueries.d.ts.map +1 -1
  30. package/dist/TableConfig/getSchemaForTableConfig.d.ts +3 -0
  31. package/dist/TableConfig/getSchemaForTableConfig.d.ts.map +1 -1
  32. package/dist/TableConfig/getSchemaForTableConfig.js +4 -1
  33. package/dist/TableConfig/getSchemaForTableConfig.js.map +1 -1
  34. package/dist/WebsocketAPI/getClientHandlers.d.ts +2 -1
  35. package/dist/WebsocketAPI/getClientHandlers.d.ts.map +1 -1
  36. package/dist/WebsocketAPI/getClientHandlers.js +14 -8
  37. package/dist/WebsocketAPI/getClientHandlers.js.map +1 -1
  38. package/dist/WebsocketAPI/getClientSchema.d.ts +2 -1
  39. package/dist/WebsocketAPI/getClientSchema.d.ts.map +1 -1
  40. package/dist/WebsocketAPI/getClientSchema.js +4 -4
  41. package/dist/WebsocketAPI/getClientSchema.js.map +1 -1
  42. package/dist/WebsocketAPI/onSocketConnected.js +1 -1
  43. package/dist/WebsocketAPI/onSocketConnected.js.map +1 -1
  44. package/dist/WebsocketAPI/pushSocketSchema.js +1 -1
  45. package/dist/WebsocketAPI/pushSocketSchema.js.map +1 -1
  46. package/dist/initProstgles.d.ts +2 -2
  47. package/dist/initProstgles.d.ts.map +1 -1
  48. package/dist/initProstgles.js +1 -1
  49. package/dist/initProstgles.js.map +1 -1
  50. package/dist/runClientRequest.d.ts +2 -1
  51. package/dist/runClientRequest.d.ts.map +1 -1
  52. package/dist/runClientRequest.js +4 -4
  53. package/dist/runClientRequest.js.map +1 -1
  54. package/lib/DboBuilder/TableHandler/DataValidator.ts +37 -123
  55. package/lib/DboBuilder/TableHandler/insert/insert.ts +27 -33
  56. package/lib/DboBuilder/TableHandler/insert/insertNestedRecords.ts +7 -7
  57. package/lib/FileManager/initFileManager.ts +2 -1
  58. package/lib/PublishParser/PublishParser.ts +23 -9
  59. package/lib/PublishParser/getSchemaFromPublish.ts +7 -4
  60. package/lib/PublishParser/publishTypesAndUtils.ts +11 -1
  61. package/lib/RestApi.ts +3 -2
  62. package/lib/TableConfig/getSchemaForTableConfig.ts +7 -1
  63. package/lib/WebsocketAPI/getClientHandlers.ts +20 -9
  64. package/lib/WebsocketAPI/getClientSchema.ts +14 -7
  65. package/lib/WebsocketAPI/onSocketConnected.ts +1 -1
  66. package/lib/WebsocketAPI/pushSocketSchema.ts +1 -1
  67. package/lib/initProstgles.ts +7 -3
  68. package/lib/runClientRequest.ts +7 -5
  69. package/package.json +2 -2
@@ -1,11 +1,15 @@
1
1
  import { isObject, omitKeys, tryCatchV2, type ClientSchema } from "prostgles-types";
2
2
  import type { AuthClientRequest } from "../Auth/AuthTypes";
3
3
  import { Prostgles } from "../Prostgles";
4
- import type { PublishParser } from "../PublishParser/PublishParser";
4
+ import type { PermissionScope, PublishParser } from "../PublishParser/PublishParser";
5
5
  import { clientCanRunSqlRequest } from "../runClientRequest";
6
- const version = (require("../../package.json") as { version: string }).version;
6
+ import { version } from "../../package.json";
7
7
 
8
- export async function getClientSchema(this: Prostgles, clientReq: AuthClientRequest) {
8
+ export async function getClientSchema(
9
+ this: Prostgles,
10
+ clientReq: AuthClientRequest,
11
+ scope: PermissionScope | undefined
12
+ ) {
9
13
  const result = await tryCatchV2(async () => {
10
14
  const clientInfo =
11
15
  clientReq.socket ?
@@ -22,10 +26,13 @@ export async function getClientSchema(this: Prostgles, clientReq: AuthClientRequ
22
26
 
23
27
  try {
24
28
  if (!publishParser) throw "publishParser undefined";
25
- fullSchema = await publishParser.getSchemaFromPublish({
26
- ...clientInfo,
27
- userData,
28
- });
29
+ fullSchema = await publishParser.getSchemaFromPublish(
30
+ {
31
+ ...clientInfo,
32
+ userData,
33
+ },
34
+ scope
35
+ );
29
36
  } catch (e) {
30
37
  publishValidationError = e;
31
38
  console.error(`\nProstgles Publish validation failed (after socket connected):\n ->`, e);
@@ -105,7 +105,7 @@ export async function onSocketConnected(this: Prostgles, socket: PRGLIOSocket) {
105
105
  }
106
106
  ) => {
107
107
  runClientRequest
108
- .bind(this)(args, { socket })
108
+ .bind(this)(args, { socket }, undefined)
109
109
  .then((res) => {
110
110
  cb(null, res);
111
111
  })
@@ -5,7 +5,7 @@ import { runClientSqlRequest } from "../runClientRequest";
5
5
  import { makeSocketError } from "./onSocketConnected";
6
6
  export async function pushSocketSchema(this: Prostgles, socket: PRGLIOSocket) {
7
7
  try {
8
- const clientSchema = await this.getClientSchema({ socket });
8
+ const clientSchema = await this.getClientSchema({ socket }, undefined);
9
9
  socket.prostgles = clientSchema;
10
10
  if (clientSchema.rawSQL) {
11
11
  socket.removeAllListeners(CHANNELS.SQL);
@@ -7,7 +7,7 @@ import { DBEventsManager } from "./DBEventsManager";
7
7
  import { DBOFullyTyped } from "./DBSchemaBuilder";
8
8
  import { DBHandlerServer, Prostgles, getIsSuperUser } from "./Prostgles";
9
9
  import { ProstglesInitOptions } from "./ProstglesTypes";
10
- import { DbTableInfo, PublishParser } from "./PublishParser/PublishParser";
10
+ import { DbTableInfo, PublishParser, type PermissionScope } from "./PublishParser/PublishParser";
11
11
  import { SchemaWatch } from "./SchemaWatch/SchemaWatch";
12
12
  import { runSQLFile } from "./TableConfig/runSQLFile";
13
13
  import { sleep } from "./utils";
@@ -72,7 +72,10 @@ export type InitResult<S = void, SUser extends SessionUser = SessionUser> = {
72
72
  update: (newOpts: UpdateableOptions<S, SUser>) => Promise<void>;
73
73
  restart: () => Promise<InitResult<S, SUser>>;
74
74
  options: ProstglesInitOptions<S, SUser>;
75
- getClientDBHandlers: (clientReq: AuthClientRequest) => ReturnType<typeof getClientHandlers<S>>;
75
+ getClientDBHandlers: (
76
+ clientReq: AuthClientRequest,
77
+ scope: PermissionScope | undefined
78
+ ) => ReturnType<typeof getClientHandlers<S>>;
76
79
  };
77
80
 
78
81
  const clientOnlyUpdateKeys = ["auth"] as const satisfies (keyof UpdateableOptions)[];
@@ -270,7 +273,8 @@ export const initProstgles = async function (
270
273
  await sleep(1000);
271
274
  return true;
272
275
  },
273
- getClientDBHandlers: (clientReq: AuthClientRequest) => getClientHandlers(this, clientReq),
276
+ getClientDBHandlers: (clientReq: AuthClientRequest, scope: PermissionScope | undefined) =>
277
+ getClientHandlers(this, clientReq, scope),
274
278
  };
275
279
 
276
280
  return initResult;
@@ -12,7 +12,7 @@ import { TableHandler as TableHandlerServer } from "./DboBuilder/TableHandler/Ta
12
12
  import { parseFieldFilter } from "./DboBuilder/ViewHandler/parseFieldFilter";
13
13
  import { canRunSQL } from "./DboBuilder/runSQL";
14
14
  import { Prostgles } from "./Prostgles";
15
- import { ParsedTableRule } from "./PublishParser/publishTypesAndUtils";
15
+ import { ParsedTableRule, type PermissionScope } from "./PublishParser/publishTypesAndUtils";
16
16
 
17
17
  const TABLE_METHODS = {
18
18
  find: 1,
@@ -57,7 +57,8 @@ type TableMethodFunctionWithRulesAndLocalParams = (
57
57
  export const runClientRequest = async function (
58
58
  this: Prostgles,
59
59
  args: Args,
60
- clientReq: AuthClientRequest
60
+ clientReq: AuthClientRequest,
61
+ scope: PermissionScope | undefined
61
62
  ) {
62
63
  /* Channel name will only include client-sent params so we ignore table_rules enforced params */
63
64
  if (!this.publishParser || !this.dbo) {
@@ -82,7 +83,8 @@ export const runClientRequest = async function (
82
83
  }
83
84
  const validRules = await this.publishParser.getValidatedRequestRule(
84
85
  { tableName, command, clientReq },
85
- clientInfo
86
+ clientInfo,
87
+ scope
86
88
  );
87
89
 
88
90
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
@@ -151,8 +153,8 @@ export const clientCanRunSqlRequest = async function (
151
153
  throw "authHandler missing";
152
154
  }
153
155
  const publishParams = await this.publishParser?.getPublishParams(clientReq, undefined);
154
- const res = publishParams && (await this.opts.publishRawSQL?.(publishParams));
155
- return Boolean((res && typeof res === "boolean") || res === "*");
156
+ const allowedToRunSQL = publishParams && (await this.opts.publishRawSQL?.(publishParams));
157
+ return allowedToRunSQL === true || allowedToRunSQL === "*";
156
158
  };
157
159
 
158
160
  const allowed = await canRunSQL();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prostgles-server",
3
- "version": "4.2.326",
3
+ "version": "4.2.328",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -56,7 +56,7 @@
56
56
  "pg": "^8.15.6",
57
57
  "pg-cursor": "^2.14.6",
58
58
  "pg-promise": "^11.13.0",
59
- "prostgles-types": "^4.0.177"
59
+ "prostgles-types": "^4.0.178"
60
60
  },
61
61
  "devDependencies": {
62
62
  "@eslint/js": "^9.22.0",