@saltcorn/server 0.9.1-beta.2 → 0.9.1-beta.4

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.
@@ -9,4 +9,23 @@ If you make a GET request, the query string values
9
9
  are accessible as a JSON object using the `row` variable (e.g. in a `run_js_code`).
10
10
 
11
11
  If you return a value from the action, it will be available in the `data`
12
- subfield of the JSON body in the HTTP response
12
+ subfield of the JSON body in the HTTP response
13
+
14
+ ### Redirection as response
15
+
16
+ Normally API call will return a JSON object with a true/false success field
17
+ and the response from the action, if any, in the data field. You may instead
18
+ require the API call to redirect to a different URL. You can do this in two
19
+ different ways.
20
+
21
+ **Static redirect**: if you set the `scgotourl` HTTP header, the response will
22
+ redirect to this URL.
23
+
24
+ **Dynamic redirect**: The redirect URL can also come from the action. If this
25
+ returns an object with the `goto` field (e.g.
26
+ `return {goto: "https://myapp.com/view/ShowTheThing?id"+newid}`)
27
+ that is normally returned in the JSON post body so it can be processed by client code.
28
+ You can instead request that this is processed server-side, by (a) setting a
29
+ `_process_result` field to true in the row data, i.e. JSON body in POST and query
30
+ string in GET or (b) setting the `scprocessresults` HTTP header. This will cause the
31
+ API call to return an HTTP redirect with the `goto` value.
@@ -33,6 +33,9 @@ must be enclosed in quotes (single, double or
33
33
  [backtick](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals))). 
34
34
  You can also as the value use a more complex JavaScript expression.
35
35
 
36
+ For examples of how you can use these values for greater than/less than,
37
+ or-conditions or case insensitivity, see [here](https://saltcorn.github.io/saltcorn/classes/_saltcorn_data.models.Table-1.html#md:querying-table-rows).
38
+
36
39
  You can refer to the logged in user using the variable name user.
37
40
  This is an object and you must use the dot to access user fields,
38
41
  e.g. user.id for the logged in users id. A very common scenario
@@ -60,3 +63,9 @@ in this case the table {{srcTable.name}}:
60
63
 
61
64
  {{# } }}
62
65
 
66
+ The state values from the query string can also be accessed, by preceeding the
67
+ variable name by a dollar sign (in pages and Show views). For instance if your URL ends in `?id=45&foo=1`,
68
+ you can access the value of `foo` (here 1) as `$foo`. In Filter views, there is no
69
+ underlying row and the purpose of the view is fundamentally to manipulate the state
70
+ so the state in extra state formulae is accessed without dollar sign; in the
71
+ previous example `foo` instead of `$foo`.
package/package.json CHANGED
@@ -1,28 +1,29 @@
1
1
  {
2
2
  "name": "@saltcorn/server",
3
- "version": "0.9.1-beta.2",
3
+ "version": "0.9.1-beta.4",
4
4
  "description": "Server app for Saltcorn, open-source no-code platform",
5
5
  "homepage": "https://saltcorn.com",
6
6
  "main": "index.js",
7
7
  "license": "MIT",
8
8
  "dependencies": {
9
- "@saltcorn/base-plugin": "0.9.1-beta.2",
10
- "@saltcorn/builder": "0.9.1-beta.2",
11
- "@saltcorn/data": "0.9.1-beta.2",
12
- "@saltcorn/admin-models": "0.9.1-beta.2",
13
- "@saltcorn/filemanager": "0.9.1-beta.2",
14
- "@saltcorn/markup": "0.9.1-beta.2",
15
- "@saltcorn/sbadmin2": "0.9.1-beta.2",
9
+ "@aws-sdk/client-s3": "^3.451.0",
10
+ "@saltcorn/base-plugin": "0.9.1-beta.4",
11
+ "@saltcorn/builder": "0.9.1-beta.4",
12
+ "@saltcorn/data": "0.9.1-beta.4",
13
+ "@saltcorn/admin-models": "0.9.1-beta.4",
14
+ "@saltcorn/filemanager": "0.9.1-beta.4",
15
+ "@saltcorn/markup": "0.9.1-beta.4",
16
+ "@saltcorn/sbadmin2": "0.9.1-beta.4",
16
17
  "@socket.io/cluster-adapter": "^0.2.1",
17
18
  "@socket.io/sticky": "^1.0.1",
18
19
  "adm-zip": "0.5.10",
19
- "aws-sdk": "^2.1386.0",
20
20
  "connect-flash": "^0.1.1",
21
21
  "connect-pg-simple": "^6.1.0",
22
22
  "content-disposition": "^0.5.3",
23
23
  "contractis": "^0.1.0",
24
24
  "cookie-parser": "^1.4.4",
25
25
  "cookie-session": "^1.4.0",
26
+ "cors": "2.8.5",
26
27
  "csurf": "^1.11.0",
27
28
  "csv-stringify": "^5.5.0",
28
29
  "express": "^4.17.1",
@@ -32,7 +33,6 @@
32
33
  "express-session": "^1.17.1",
33
34
  "greenlock": "^4.0.4",
34
35
  "greenlock-express": "^4.0.3",
35
- "underscore": "1.13.6",
36
36
  "helmet": "^3.23.3",
37
37
  "i18n": "^0.15.1",
38
38
  "imapflow": "1.0.123",
@@ -41,7 +41,7 @@
41
41
  "markdown-it": "^13.0.2",
42
42
  "moment": "^2.29.4",
43
43
  "multer": "1.4.5-lts.1",
44
- "multer-s3": "^2.10.0",
44
+ "multer-s3": "^3.0.1",
45
45
  "node-fetch": "2.6.9",
46
46
  "node-watch": "^0.7.2",
47
47
  "notp": "2.0.3",
@@ -59,8 +59,8 @@
59
59
  "systeminformation": "^5.21.7",
60
60
  "thirty-two": "1.0.2",
61
61
  "tmp-promise": "^3.0.2",
62
- "uuid": "^8.2.0",
63
- "cors": "2.8.5"
62
+ "underscore": "1.13.6",
63
+ "uuid": "^8.2.0"
64
64
  },
65
65
  "optionalDependencies": {
66
66
  "connect-sqlite3": "^0.9.11",
package/routes/api.js CHANGED
@@ -358,14 +358,22 @@ router.all(
358
358
  if (accessAllowed(req, user, trigger)) {
359
359
  try {
360
360
  const action = getState().actions[trigger.action];
361
+ const row = req.method === "GET" ? req.query : req.body;
361
362
  const resp = await action.run({
362
363
  configuration: trigger.configuration,
363
364
  body: req.body,
364
- row: req.method === "GET" ? req.query : req.body,
365
+ row,
365
366
  req,
366
367
  user: user || req.user,
367
368
  });
368
- res.json({ success: true, data: resp });
369
+ if (
370
+ (row._process_result || req.headers?.scprocessresults) &&
371
+ resp?.goto
372
+ )
373
+ res.redirect(resp.goto);
374
+ else if (req.headers?.scgotourl)
375
+ res.redirect(req.headers?.scgotourl);
376
+ else res.json({ success: true, data: resp });
369
377
  } catch (e) {
370
378
  Crash.create(e, req);
371
379
  res.status(400).json({ success: false, error: e.message });
package/s3storage.js CHANGED
@@ -1,5 +1,4 @@
1
- require("aws-sdk/lib/maintenance_mode_message").suppress = true;
2
- const aws = require("aws-sdk");
1
+ const { S3 } = require("@aws-sdk/client-s3");
3
2
  const multer = require("multer");
4
3
  const multerS3 = require("multer-s3");
5
4
  const { getState } = require("@saltcorn/data/db/state");
@@ -8,9 +7,11 @@ const { v4: uuidv4 } = require("uuid");
8
7
  const contentDisposition = require("content-disposition");
9
8
  const fs = require("fs");
10
9
  function createS3Client() {
11
- return new aws.S3({
12
- secretAccessKey: getState().getConfig("storage_s3_access_secret"),
13
- accessKeyId: getState().getConfig("storage_s3_access_key"),
10
+ return new S3({
11
+ credentials: {
12
+ secretAccessKey: getState().getConfig("storage_s3_access_secret"),
13
+ accessKeyId: getState().getConfig("storage_s3_access_key"),
14
+ },
14
15
  region: getState().getConfig("storage_s3_region"),
15
16
  endpoint: getState().getConfig("storage_s3_endpoint"),
16
17
  });