@saltcorn/server 0.9.5-beta.7 → 0.9.5-beta.9

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/errors.js CHANGED
@@ -37,6 +37,7 @@ module.exports =
37
37
  const createCrash = severity <= 3;
38
38
  //console.error(err.stack);
39
39
  if (!(devmode && log_sql) && createCrash) await Crash.create(err, req);
40
+ else console.error(err);
40
41
 
41
42
  if (req.xhr) {
42
43
  res
package/load_plugins.js CHANGED
@@ -25,14 +25,29 @@ const loadPlugin = async (plugin, force) => {
25
25
  typeof plugin.configuration === "string"
26
26
  ? JSON.parse(plugin.configuration)
27
27
  : plugin.configuration;
28
- // register plugin
29
- getState().registerPlugin(
30
- res.plugin_module.plugin_name || plugin.name,
31
- res.plugin_module,
32
- configuration,
33
- res.location,
34
- res.name
35
- );
28
+ try {
29
+ // register plugin
30
+ getState().registerPlugin(
31
+ res.plugin_module.plugin_name || plugin.name,
32
+ res.plugin_module,
33
+ configuration,
34
+ res.location,
35
+ res.name
36
+ );
37
+ } catch (error) {
38
+ if (force) {
39
+ // remove the install dir and try again
40
+ await loader.remove();
41
+ await loader.install(force);
42
+ getState().registerPlugin(
43
+ res.plugin_module.plugin_name || plugin.name,
44
+ res.plugin_module,
45
+ configuration,
46
+ res.location,
47
+ res.name
48
+ );
49
+ }
50
+ }
36
51
  if (res.plugin_module.onLoad) {
37
52
  try {
38
53
  await res.plugin_module.onLoad(plugin.configuration);
@@ -76,9 +91,15 @@ const loadAllPlugins = async (force) => {
76
91
  * @param plugin
77
92
  * @param force
78
93
  * @param noSignalOrDB
94
+ * @param __ translation function
79
95
  * @returns {Promise<void>}
80
96
  */
81
- const loadAndSaveNewPlugin = async (plugin, force, noSignalOrDB) => {
97
+ const loadAndSaveNewPlugin = async (
98
+ plugin,
99
+ force,
100
+ noSignalOrDB,
101
+ __ = (str) => str
102
+ ) => {
82
103
  const tenants_unsafe_plugins = getRootState().getConfig(
83
104
  "tenants_unsafe_plugins",
84
105
  false
@@ -104,8 +125,10 @@ const loadAndSaveNewPlugin = async (plugin, force, noSignalOrDB) => {
104
125
  return;
105
126
  }
106
127
  }
128
+ const msgs = [];
107
129
  const loader = new PluginInstaller(plugin);
108
- const { version, plugin_module, location } = await loader.install(force);
130
+ const { version, plugin_module, location, loadedWithReload } =
131
+ await loader.install(force);
109
132
 
110
133
  // install dependecies
111
134
  for (const loc of plugin_module.dependencies || []) {
@@ -118,13 +141,43 @@ const loadAndSaveNewPlugin = async (plugin, force, noSignalOrDB) => {
118
141
  );
119
142
  }
120
143
  }
121
- getState().registerPlugin(
122
- plugin_module.plugin_name || plugin.name,
123
- plugin_module,
124
- plugin.configuration,
125
- location,
126
- plugin.name
127
- );
144
+ let registeredWithReload = false;
145
+ try {
146
+ getState().registerPlugin(
147
+ plugin_module.plugin_name || plugin.name,
148
+ plugin_module,
149
+ plugin.configuration,
150
+ location,
151
+ plugin.name
152
+ );
153
+ } catch (error) {
154
+ if (force) {
155
+ getState().log(
156
+ 2,
157
+ `Error registering plugin ${plugin.name}. Removing and trying again.`
158
+ );
159
+ await loader.remove();
160
+ await loader.install(force);
161
+ getState().registerPlugin(
162
+ plugin_module.plugin_name || plugin.name,
163
+ plugin_module,
164
+ plugin.configuration,
165
+ location,
166
+ plugin.name
167
+ );
168
+ registeredWithReload = true;
169
+ } else {
170
+ throw error;
171
+ }
172
+ }
173
+ if (loadedWithReload || registeredWithReload) {
174
+ msgs.push(
175
+ __(
176
+ "The plugin was corrupted and had to be repaired. We recommend restarting your server.",
177
+ plugin.name
178
+ )
179
+ );
180
+ }
128
181
  if (plugin_module.onLoad) {
129
182
  try {
130
183
  await plugin_module.onLoad(plugin.configuration);
@@ -141,6 +194,7 @@ const loadAndSaveNewPlugin = async (plugin, force, noSignalOrDB) => {
141
194
  force: false, // okay ??
142
195
  });
143
196
  }
197
+ return msgs;
144
198
  };
145
199
 
146
200
  module.exports = {
package/locales/en.json CHANGED
@@ -1389,5 +1389,7 @@
1389
1389
  "not available": "not available",
1390
1390
  "pull": "pull",
1391
1391
  "refresh": "refresh",
1392
- "installed": "installed"
1393
- }
1392
+ "installed": "installed",
1393
+ "Include table history in backup": "Include table history in backup",
1394
+ "The plugin was corrupted and had to be repaired. We recommend restarting your server.": "The plugin was corrupted and had to be repaired. We recommend restarting your server."
1395
+ }
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "@saltcorn/server",
3
- "version": "0.9.5-beta.7",
3
+ "version": "0.9.5-beta.9",
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
9
  "@aws-sdk/client-s3": "^3.451.0",
10
- "@saltcorn/base-plugin": "0.9.5-beta.7",
11
- "@saltcorn/builder": "0.9.5-beta.7",
12
- "@saltcorn/data": "0.9.5-beta.7",
13
- "@saltcorn/admin-models": "0.9.5-beta.7",
14
- "@saltcorn/filemanager": "0.9.5-beta.7",
15
- "@saltcorn/markup": "0.9.5-beta.7",
16
- "@saltcorn/plugins-loader": "0.9.5-beta.7",
17
- "@saltcorn/sbadmin2": "0.9.5-beta.7",
10
+ "@saltcorn/base-plugin": "0.9.5-beta.9",
11
+ "@saltcorn/builder": "0.9.5-beta.9",
12
+ "@saltcorn/data": "0.9.5-beta.9",
13
+ "@saltcorn/admin-models": "0.9.5-beta.9",
14
+ "@saltcorn/filemanager": "0.9.5-beta.9",
15
+ "@saltcorn/markup": "0.9.5-beta.9",
16
+ "@saltcorn/plugins-loader": "0.9.5-beta.9",
17
+ "@saltcorn/sbadmin2": "0.9.5-beta.9",
18
18
  "@socket.io/cluster-adapter": "^0.2.1",
19
19
  "@socket.io/sticky": "^1.0.1",
20
20
  "adm-zip": "0.5.10",
@@ -549,10 +549,12 @@ function updateViewPreview() {
549
549
  },
550
550
 
551
551
  error: function (resp) {
552
- $("#viewcfg-preview-error").html(resp.responseText || resp.statusText);
552
+ $("#viewcfg-preview-error")
553
+ .show()
554
+ .html(resp.responseText || resp.statusText);
553
555
  },
554
556
  success: function (res) {
555
- $("#viewcfg-preview-error").html("");
557
+ $("#viewcfg-preview-error").hide().html("");
556
558
  $preview.css({ opacity: 1.0 });
557
559
 
558
560
  //disable functions preview migght try to call
package/routes/admin.js CHANGED
@@ -274,6 +274,8 @@ router.get(
274
274
  const aBackupFilePrefixForm = backupFilePrefixForm(req);
275
275
  aBackupFilePrefixForm.values.backup_file_prefix =
276
276
  getState().getConfig("backup_file_prefix");
277
+ aBackupFilePrefixForm.values.backup_history =
278
+ getState().getConfig("backup_history");
277
279
  //
278
280
  const backupForm = autoBackupForm(req);
279
281
  backupForm.values.auto_backup_frequency = getState().getConfig(
@@ -674,6 +676,13 @@ const backupFilePrefixForm = (req) =>
674
676
  sublabel: req.__("Backup file prefix"),
675
677
  default: "sc-backup-",
676
678
  },
679
+ {
680
+ type: "Bool",
681
+ label: req.__("History"),
682
+ name: "backup_history",
683
+ sublabel: req.__("Include table history in backup"),
684
+ default: true,
685
+ },
677
686
  ],
678
687
  });
679
688
 
@@ -547,7 +547,7 @@ const no_views_logged_in = async (req, res) => {
547
547
  * @returns {Promise<boolean>}
548
548
  */
549
549
  const get_config_response = async (role_id, res, req) => {
550
- const wrap = async (contents, homeCfg, title, description) => {
550
+ const wrap = async (contents, homeCfg, title, description, no_menu) => {
551
551
  if (contents.html_file) await sendHtmlFile(req, res, contents.html_file);
552
552
  else
553
553
  res.sendWrap(
@@ -555,6 +555,7 @@ const get_config_response = async (role_id, res, req) => {
555
555
  title: title || "",
556
556
  description: description || "",
557
557
  bodyClass: "page_" + db.sqlsanitize(homeCfg),
558
+ no_menu,
558
559
  },
559
560
  contents
560
561
  );
@@ -574,7 +575,8 @@ const get_config_response = async (role_id, res, req) => {
574
575
  await db_page.run(req.query, { res, req }),
575
576
  homeCfg,
576
577
  db_page.title,
577
- db_page.description
578
+ db_page.description,
579
+ db_page.attributes?.no_menu
578
580
  );
579
581
  else {
580
582
  const group = PageGroup.findOne({ name: homeCfg });
@@ -587,7 +589,8 @@ const get_config_response = async (role_id, res, req) => {
587
589
  await eligible.run(req.query, { res, req }),
588
590
  homeCfg,
589
591
  eligible.title,
590
- eligible.description
592
+ eligible.description,
593
+ eligible.attributes?.no_menu
591
594
  );
592
595
  } else wrap(req.__("%s has no eligible page", group.name), homeCfg);
593
596
  } else res.redirect(homeCfg);
package/routes/plugins.js CHANGED
@@ -1243,7 +1243,12 @@ router.post(
1243
1243
  res.redirect(`/plugins`);
1244
1244
  return;
1245
1245
  }
1246
- await load_plugins.loadAndSaveNewPlugin(plugin, forceReInstall);
1246
+ const msgs = await load_plugins.loadAndSaveNewPlugin(
1247
+ plugin,
1248
+ forceReInstall,
1249
+ undefined,
1250
+ req.__
1251
+ );
1247
1252
  const plugin_module = getState().plugins[name];
1248
1253
  await sleep(1000); // Allow other workers to load this plugin
1249
1254
  await getState().refresh_views();
@@ -1257,9 +1262,11 @@ router.post(
1257
1262
  plugin_db.name
1258
1263
  )
1259
1264
  );
1265
+ if (msgs?.length > 0) req.flash("warning", msgs.join("<br>"));
1260
1266
  res.redirect(`/plugins/configure/${plugin_db.name}`);
1261
1267
  } else {
1262
1268
  req.flash("success", req.__(`Module %s installed`, plugin.name));
1269
+ if (msgs?.length > 0) req.flash("warning", msgs.join("<br>"));
1263
1270
  res.redirect(`/plugins`);
1264
1271
  }
1265
1272
  })