acebase-server 1.17.0 → 1.18.1

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/README.md CHANGED
@@ -93,7 +93,7 @@ The following `authentication` settings are available:
93
93
 
94
94
  ### Setup authorization rules
95
95
 
96
- If you enabled authentication, you can also define access rules for your data. Using rules, you can allow or deny specific (or anonymous) users _read_ and/or _write_ access to your data. These rules are identical to those used by [Firebase](https://firebase.google.com/docs/database/security/), but reading current data in the db works a little differently. In addition, ".schema" rules allow for an easy and clean way to validate data being written, while ".validate" rules allow you to check existing data and use more advanced business logic. The rules are saved in a file called _rules.json_ in your database directory, but can be overridden and extended programmatically (see [Coding your rules](#coding-your-rules)). The default rules written to the file are determined by the `defaultAccessRule` authentication setting at the first server launch with `authentication` enabled.
96
+ If you enabled authentication, you can also define access rules for your data. Using rules, you can allow or deny specific (or anonymous) users _read_ and/or _write_ access to your data. These rules are similar to those used by [Firebase](https://firebase.google.com/docs/database/security/), but they are not identical. AceBase has easy ".schema" rules allow for an easy and clean way to validate data being written, while ".validate" rules allow you to check existing data and use more advanced business logic. The rules can be saved to the _rules.json_ file in your database directory, and can be overridden and extended programmatically from within your own code: ".validate" rules are coded in JavaScript (see [Coding your rules](#coding-your-rules)). The default rules written to the file are determined by the `defaultAccessRule` authentication setting at the first server launch with `authentication` enabled.
97
97
 
98
98
  The default _rules.json_ file content is based on the value of the `defaultAccessRule` setting, possible values are:
99
99
  * `"auth"`: Only allow authenticated users read/write access to the database
@@ -336,7 +336,7 @@ _(NEW v1.17.0+)_
336
336
  Instead of writing your rules into the `rules.json` file on your server, it is also possible to configure them in your code. Any rule you set with code will override or augment existing rules found in the `rules.json` file, so can use both. Coding your rules has a number of advantages:
337
337
  * You can use the same rule definitions and functions on multiple paths without copy/pasting
338
338
  * You can code them in your favorite editor
339
- * You can use running server values and cached data in your rules, such as `process.env` and vars like `maintanceMode`
339
+ * You can use running server values and cached data in your rules, such as `process.env` and vars like `maintenanceMode`
340
340
  * Rules become debuggable!
341
341
 
342
342
  To add a rule in your code, use the following syntax:
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env node
2
+
3
+ if (process.argv[2] === 'start') {
4
+ require('../dist/cjs/start');
5
+ }
6
+ else {
7
+ console.log(`[acebase-server CLI] unknown instruction. Did you mean "npx acebase-server start"?`);
8
+ }
@@ -1,57 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const acebase_1 = require("acebase");
4
- const server_1 = require("./server");
5
- const cluster = require("cluster");
6
- const numCPUs = 2; //os.cpus().length;
7
1
  /**
8
- * Node.js cluster example. You can use this as a reference how to create an AceBaseServer cluster using Node.js'
9
- * built-in cluster functionality.
10
2
  *
11
- * If you want to run a pm2 or cloud-based cluster instead, do NOT use this code.
12
- * To do that, see https://github.com/appy-one/acebase-ipc-server
3
+ * To run an AceBase server in a cluster and examples, please refer to this discussion:
4
+ * https://github.com/appy-one/acebase-server/discussions/83
13
5
  *
14
6
  */
15
- const dbname = 'default';
16
- const options = { /* default options */}; // Load from cluster.config.js!
17
- options.authentication = { enabled: false };
18
- options.https = { enabled: false };
19
- if (cluster.isMaster) {
20
- // Startup master
21
- console.log(`Starting database server cluster with ${numCPUs} workers`);
22
- const master = new acebase_1.AceBase(dbname, options);
23
- master.once('ready', () => {
24
- console.log(`Master database server started on process ${process.pid}`);
25
- });
26
- for (let i = 0; i < numCPUs; i++) {
27
- const worker = cluster.fork();
28
- worker.on('disconnect', () => {
29
- console.error(`worker ${worker.process.pid} disconnected`);
30
- });
31
- worker.on('message', (msg) => {
32
- if (msg === 'acebase-server-shutdown') {
33
- // We could handle shutdown message here to kill the worker safely, but we'll do it in the worker threads instead: see below
34
- // worker.kill();
35
- }
36
- });
37
- }
38
- cluster.on('exit', (worker, code, signal) => {
39
- console.error(`worker ${worker.process.pid} died`);
40
- });
41
- }
42
- else {
43
- console.log(`Worker ${process.pid} is running`);
44
- const server = new server_1.AceBaseServer(dbname, options);
45
- server.ready(() => {
46
- console.log(`Worker database server started on process ${process.pid}`);
47
- });
48
- // Handle shutdown event to exit the worker process safely
49
- server.on('shutdown', () => {
50
- process.exit();
51
- });
52
- // Other option:
53
- // process.on('acebase-server-shutdown', () => {
54
- // process.exit();
55
- // });
56
- }
57
7
  //# sourceMappingURL=cluster.js.map
@@ -22,6 +22,7 @@ const addRoute = (env) => {
22
22
  if (!access.allow) {
23
23
  return (0, error_1.sendUnauthorizedError)(res, access.code, access.message);
24
24
  }
25
+ // const options: { include?: string[]; exclude?: string[]; child_objects?: boolean } = {};
25
26
  const options = {};
26
27
  if (req.query.include) {
27
28
  options.include = req.query.include.split(',');
@@ -29,8 +30,8 @@ const addRoute = (env) => {
29
30
  if (req.query.exclude) {
30
31
  options.exclude = req.query.exclude.split(',');
31
32
  }
32
- if (typeof req.query.child_objects === 'boolean') {
33
- options.child_objects = req.query.child_objects;
33
+ if (['true', 'false'].includes(req.query.child_objects)) {
34
+ options.child_objects = req.query.child_objects === 'true';
34
35
  }
35
36
  if (path === '') {
36
37
  // If user has access to the root of database (NOT recommended for others than admin...)
@@ -17,8 +17,8 @@ const addRoute = (env) => {
17
17
  // defines a schema
18
18
  try {
19
19
  const data = req.body;
20
- const { path, schema } = data;
21
- yield env.db.schema.set(path, schema);
20
+ const { path, schema, warnOnly = false } = data;
21
+ yield env.db.schema.set(path, schema, warnOnly);
22
22
  res.contentType('application/json').send({ success: true });
23
23
  }
24
24
  catch (err) {
@@ -19,7 +19,7 @@ const addRoute = (env) => {
19
19
  info: {
20
20
  title: 'AceBase Server',
21
21
  description: 'AceBase Server API endpoint documentation and test environment. This documentation is available on the server because it is running in development mode. To disable this, set your NODE_ENV environment variable to production. Many endpoints require you to authenticate using Bearer authentication. Use the _/auth/{dbname}/signin_ endpoint to obtain an access token, then click the _Authorize_ button and paste your token into the input field. For more information about AceBase, see GitHub',
22
- version: '1.17.0',
22
+ version: '1.18.1',
23
23
  contact: {
24
24
  name: 'AceBase API Support',
25
25
  email: 'me@appy.one',
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.addRoute = void 0;
4
4
  const os = require("os");
5
- const SERVER_VERSION = '1.17.0'; // Loaded from package.json by npm scripts
5
+ const SERVER_VERSION = '1.18.1'; // Loaded from package.json by npm scripts
6
6
  const addRoute = (env) => {
7
7
  // Add info endpoint
8
8
  env.router.get(`/info/${env.db.name}`, (req, res) => {
@@ -78,13 +78,8 @@ class AceBaseServer extends acebase_core_1.SimpleEventEmitter {
78
78
  const dbOptions = {
79
79
  logLevel: this.config.logLevel,
80
80
  info: 'realtime database server',
81
- // NEW: Allow storage setting like AceBaseLocalSettings - could allow using other db backend (typed, but undocumented)
82
- storage: this.config.storage || {
83
- path: this.config.path,
84
- removeVoidProperties: true,
85
- },
81
+ storage: Object.assign({ path: this.config.path, removeVoidProperties: true, ipc: this.config.ipc }, this.config.storage),
86
82
  transactions: this.config.transactions,
87
- ipc: this.config.ipc,
88
83
  sponsor: this.config.sponsor,
89
84
  logColors: this.config.logColors,
90
85
  };
package/dist/cjs/start.js CHANGED
@@ -1,6 +1,49 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const server_1 = require("./server");
4
+ /*
5
+
6
+ Use environment variables or pass arguments to this script to start an AceBase server
7
+ instance from the command-line.
8
+
9
+ Command-line arguments format:
10
+ `npx acebase-server start DBNAME=mydb HOST=localhost PORT=3000`
11
+ You can use all variables mentioned below (without 'ACEBASE_' prefix)
12
+
13
+ All environment variables MUST be prefixed with 'ACEBASE_' (except for PORT if ACEBASE_PORT is not specified).
14
+ Currently available environment variables:
15
+
16
+ # File and network settings:
17
+ ACEBASE_DBNAME='mydb'
18
+ ACEBASE_DBPATH='.'
19
+ ACEBASE_HOST='localhost'
20
+ ACEBASE_PORT='3000'
21
+ ACEBASE_ROOT_PATH=''
22
+
23
+ # Transaction logging settings:
24
+ ACEBASE_TXLOG='true'
25
+ ACEBASE_TXDAYS='30'
26
+
27
+ # Auth settings:
28
+ ACEBASE_AUTH='true'
29
+ ACEBASE_AUTH_USER_SIGNUP='true'
30
+ ACEBASE_AUTH_DEFAULT_ACCESS_RULE='deny'
31
+ ACEBASE_AUTH_DEFAULT_ADMIN_PASSWORD=''
32
+ ACEBASE_AUTH_NEW_USER_RATE_LIMIT='0'
33
+ ACEBASE_AUTH_SEPARATE_DB='false'
34
+ ACEBASE_AUTH_TOKENS_EXPIRE='0'
35
+
36
+ # IPC configuration for single machine clusters
37
+ ACEBASE_IPC='socket'
38
+
39
+ # IPC configuration for multiple machine clusters (Make sure there is ONLY ONE 'master' instance)
40
+ ACEBASE_IPC_PORT='9163'
41
+ ACEBASE_IPC_HOST='ipc.example.com'
42
+ ACEBASE_IPC_ROLE='master'
43
+ ACEBASE_IPC_SSL='true'
44
+ ACEBASE_IPC_TOKEN='secret'
45
+
46
+ */
4
47
  // If one executes "node start.js [dbname=name] [host=ip] [port=nr]"
5
48
  function getVariable(name, defaultValue) {
6
49
  // Checks if an argument with the name was passed,
@@ -11,18 +54,23 @@ function getVariable(name, defaultValue) {
11
54
  if (arg) {
12
55
  return arg.split('=')[1];
13
56
  }
14
- if (typeof process.env[name] !== 'undefined') {
57
+ const envName = `ACEBASE_${name}`;
58
+ if (typeof process.env[envName] !== 'undefined') {
59
+ return process.env[envName];
60
+ }
61
+ if (name === 'PORT' && typeof process.env[name] !== 'undefined') {
15
62
  return process.env[name];
16
63
  }
17
64
  return defaultValue;
18
65
  }
19
- const path = getVariable('DBPATH', '.');
20
- const dbname = getVariable('DBNAME', 'default');
21
- const host = getVariable('HOST', 'localhost'); // '0.0.0.0'
22
- const port = +getVariable('PORT', 3000);
66
+ const options = {
67
+ host: getVariable('HOST', 'localhost'),
68
+ port: +getVariable('PORT', 3000),
69
+ path: getVariable('DBPATH', '.'),
70
+ rootPath: getVariable('ROOT_PATH', ''),
71
+ };
72
+ // Check if we should use a remote IPC server, let AceBase use a local IPC socket otherwise
23
73
  const ipcPort = +getVariable('IPC_PORT', 0);
24
- const rootPath = getVariable('ROOT_PATH', '');
25
- const options = { host, port, path, rootPath };
26
74
  if (ipcPort > 0) {
27
75
  const role = getVariable('IPC_ROLE');
28
76
  if (!['master', 'worker'].includes(role)) {
@@ -36,15 +84,33 @@ if (ipcPort > 0) {
36
84
  role,
37
85
  };
38
86
  }
39
- if (+getVariable('TXLOG', 0) === 1) {
87
+ else if (getVariable('IPC') === 'socket') {
88
+ // Use local IPC socket, will become default soon
89
+ options.ipc = 'socket';
90
+ }
91
+ // Check if transaction logging should be enabled (not enabled by default)
92
+ if (getVariable('TXLOG', 'false') === 'true' || +getVariable('TXLOG', 0) === 1) {
40
93
  options.transactions = {
41
94
  log: true,
42
95
  maxAge: +getVariable('TXDAYS', 30),
43
96
  };
44
97
  }
45
- if (+getVariable('AUTH', 1) === 0) {
98
+ // Check if authentication should be enabled (default)
99
+ if (getVariable('AUTH', 'true') === 'true' || +getVariable('AUTH', 1) === 1) {
100
+ options.authentication = {
101
+ enabled: true,
102
+ allowUserSignup: +getVariable('AUTH_USER_SIGNUP', 1) === 1,
103
+ defaultAccessRule: getVariable('AUTH_DEFAULT_ACCESS_RULE'),
104
+ defaultAdminPassword: getVariable('AUTH_DEFAULT_ADMIN_PASSWORD'),
105
+ newUserRateLimit: +getVariable('AUTH_NEW_USER_RATE_LIMIT', 0),
106
+ separateDb: getVariable('AUTH_SEPARATE_DB', false),
107
+ tokensExpire: +getVariable('AUTH_TOKENS_EXPIRE', 0), // No implemented yet
108
+ };
109
+ }
110
+ else {
46
111
  options.authentication = { enabled: false };
47
112
  }
113
+ const dbname = getVariable('DBNAME', 'default');
48
114
  const server = new server_1.AceBaseServer(dbname, options);
49
115
  server.once('ready', () => {
50
116
  var _a;
@@ -1,55 +1,7 @@
1
- import { AceBase } from 'acebase';
2
- import { AceBaseServer } from './server.js';
3
- import * as cluster from 'cluster';
4
- const numCPUs = 2; //os.cpus().length;
5
1
  /**
6
- * Node.js cluster example. You can use this as a reference how to create an AceBaseServer cluster using Node.js'
7
- * built-in cluster functionality.
8
2
  *
9
- * If you want to run a pm2 or cloud-based cluster instead, do NOT use this code.
10
- * To do that, see https://github.com/appy-one/acebase-ipc-server
3
+ * To run an AceBase server in a cluster and examples, please refer to this discussion:
4
+ * https://github.com/appy-one/acebase-server/discussions/83
11
5
  *
12
6
  */
13
- const dbname = 'default';
14
- const options = { /* default options */}; // Load from cluster.config.js!
15
- options.authentication = { enabled: false };
16
- options.https = { enabled: false };
17
- if (cluster.isMaster) {
18
- // Startup master
19
- console.log(`Starting database server cluster with ${numCPUs} workers`);
20
- const master = new AceBase(dbname, options);
21
- master.once('ready', () => {
22
- console.log(`Master database server started on process ${process.pid}`);
23
- });
24
- for (let i = 0; i < numCPUs; i++) {
25
- const worker = cluster.fork();
26
- worker.on('disconnect', () => {
27
- console.error(`worker ${worker.process.pid} disconnected`);
28
- });
29
- worker.on('message', (msg) => {
30
- if (msg === 'acebase-server-shutdown') {
31
- // We could handle shutdown message here to kill the worker safely, but we'll do it in the worker threads instead: see below
32
- // worker.kill();
33
- }
34
- });
35
- }
36
- cluster.on('exit', (worker, code, signal) => {
37
- console.error(`worker ${worker.process.pid} died`);
38
- });
39
- }
40
- else {
41
- console.log(`Worker ${process.pid} is running`);
42
- const server = new AceBaseServer(dbname, options);
43
- server.ready(() => {
44
- console.log(`Worker database server started on process ${process.pid}`);
45
- });
46
- // Handle shutdown event to exit the worker process safely
47
- server.on('shutdown', () => {
48
- process.exit();
49
- });
50
- // Other option:
51
- // process.on('acebase-server-shutdown', () => {
52
- // process.exit();
53
- // });
54
- }
55
7
  //# sourceMappingURL=cluster.js.map
@@ -9,6 +9,7 @@ export const addRoute = (env) => {
9
9
  if (!access.allow) {
10
10
  return sendUnauthorizedError(res, access.code, access.message);
11
11
  }
12
+ // const options: { include?: string[]; exclude?: string[]; child_objects?: boolean } = {};
12
13
  const options = {};
13
14
  if (req.query.include) {
14
15
  options.include = req.query.include.split(',');
@@ -16,8 +17,8 @@ export const addRoute = (env) => {
16
17
  if (req.query.exclude) {
17
18
  options.exclude = req.query.exclude.split(',');
18
19
  }
19
- if (typeof req.query.child_objects === 'boolean') {
20
- options.child_objects = req.query.child_objects;
20
+ if (['true', 'false'].includes(req.query.child_objects)) {
21
+ options.child_objects = req.query.child_objects === 'true';
21
22
  }
22
23
  if (path === '') {
23
24
  // If user has access to the root of database (NOT recommended for others than admin...)
@@ -5,8 +5,8 @@ export const addRoute = (env) => {
5
5
  // defines a schema
6
6
  try {
7
7
  const data = req.body;
8
- const { path, schema } = data;
9
- await env.db.schema.set(path, schema);
8
+ const { path, schema, warnOnly = false } = data;
9
+ await env.db.schema.set(path, schema, warnOnly);
10
10
  res.contentType('application/json').send({ success: true });
11
11
  }
12
12
  catch (err) {
@@ -14,7 +14,7 @@ export const addRoute = (env) => {
14
14
  info: {
15
15
  title: 'AceBase Server',
16
16
  description: 'AceBase Server API endpoint documentation and test environment. This documentation is available on the server because it is running in development mode. To disable this, set your NODE_ENV environment variable to production. Many endpoints require you to authenticate using Bearer authentication. Use the _/auth/{dbname}/signin_ endpoint to obtain an access token, then click the _Authorize_ button and paste your token into the input field. For more information about AceBase, see GitHub',
17
- version: '1.17.0',
17
+ version: '1.18.1',
18
18
  contact: {
19
19
  name: 'AceBase API Support',
20
20
  email: 'me@appy.one',
@@ -1,5 +1,5 @@
1
1
  import * as os from 'os';
2
- const SERVER_VERSION = '1.17.0'; // Loaded from package.json by npm scripts
2
+ const SERVER_VERSION = '1.18.1'; // Loaded from package.json by npm scripts
3
3
  export const addRoute = (env) => {
4
4
  // Add info endpoint
5
5
  env.router.get(`/info/${env.db.name}`, (req, res) => {
@@ -62,13 +62,13 @@ export class AceBaseServer extends SimpleEventEmitter {
62
62
  const dbOptions = {
63
63
  logLevel: this.config.logLevel,
64
64
  info: 'realtime database server',
65
- // NEW: Allow storage setting like AceBaseLocalSettings - could allow using other db backend (typed, but undocumented)
66
- storage: this.config.storage || {
65
+ storage: {
67
66
  path: this.config.path,
68
67
  removeVoidProperties: true,
68
+ ipc: this.config.ipc,
69
+ ...this.config.storage, // Allow overriding storage settings - allows using other db backends (typed, but undocumented)
69
70
  },
70
71
  transactions: this.config.transactions,
71
- ipc: this.config.ipc,
72
72
  sponsor: this.config.sponsor,
73
73
  logColors: this.config.logColors,
74
74
  };
package/dist/esm/start.js CHANGED
@@ -1,4 +1,47 @@
1
1
  import { AceBaseServer } from './server.js';
2
+ /*
3
+
4
+ Use environment variables or pass arguments to this script to start an AceBase server
5
+ instance from the command-line.
6
+
7
+ Command-line arguments format:
8
+ `npx acebase-server start DBNAME=mydb HOST=localhost PORT=3000`
9
+ You can use all variables mentioned below (without 'ACEBASE_' prefix)
10
+
11
+ All environment variables MUST be prefixed with 'ACEBASE_' (except for PORT if ACEBASE_PORT is not specified).
12
+ Currently available environment variables:
13
+
14
+ # File and network settings:
15
+ ACEBASE_DBNAME='mydb'
16
+ ACEBASE_DBPATH='.'
17
+ ACEBASE_HOST='localhost'
18
+ ACEBASE_PORT='3000'
19
+ ACEBASE_ROOT_PATH=''
20
+
21
+ # Transaction logging settings:
22
+ ACEBASE_TXLOG='true'
23
+ ACEBASE_TXDAYS='30'
24
+
25
+ # Auth settings:
26
+ ACEBASE_AUTH='true'
27
+ ACEBASE_AUTH_USER_SIGNUP='true'
28
+ ACEBASE_AUTH_DEFAULT_ACCESS_RULE='deny'
29
+ ACEBASE_AUTH_DEFAULT_ADMIN_PASSWORD=''
30
+ ACEBASE_AUTH_NEW_USER_RATE_LIMIT='0'
31
+ ACEBASE_AUTH_SEPARATE_DB='false'
32
+ ACEBASE_AUTH_TOKENS_EXPIRE='0'
33
+
34
+ # IPC configuration for single machine clusters
35
+ ACEBASE_IPC='socket'
36
+
37
+ # IPC configuration for multiple machine clusters (Make sure there is ONLY ONE 'master' instance)
38
+ ACEBASE_IPC_PORT='9163'
39
+ ACEBASE_IPC_HOST='ipc.example.com'
40
+ ACEBASE_IPC_ROLE='master'
41
+ ACEBASE_IPC_SSL='true'
42
+ ACEBASE_IPC_TOKEN='secret'
43
+
44
+ */
2
45
  // If one executes "node start.js [dbname=name] [host=ip] [port=nr]"
3
46
  function getVariable(name, defaultValue) {
4
47
  // Checks if an argument with the name was passed,
@@ -9,18 +52,23 @@ function getVariable(name, defaultValue) {
9
52
  if (arg) {
10
53
  return arg.split('=')[1];
11
54
  }
12
- if (typeof process.env[name] !== 'undefined') {
55
+ const envName = `ACEBASE_${name}`;
56
+ if (typeof process.env[envName] !== 'undefined') {
57
+ return process.env[envName];
58
+ }
59
+ if (name === 'PORT' && typeof process.env[name] !== 'undefined') {
13
60
  return process.env[name];
14
61
  }
15
62
  return defaultValue;
16
63
  }
17
- const path = getVariable('DBPATH', '.');
18
- const dbname = getVariable('DBNAME', 'default');
19
- const host = getVariable('HOST', 'localhost'); // '0.0.0.0'
20
- const port = +getVariable('PORT', 3000);
64
+ const options = {
65
+ host: getVariable('HOST', 'localhost'),
66
+ port: +getVariable('PORT', 3000),
67
+ path: getVariable('DBPATH', '.'),
68
+ rootPath: getVariable('ROOT_PATH', ''),
69
+ };
70
+ // Check if we should use a remote IPC server, let AceBase use a local IPC socket otherwise
21
71
  const ipcPort = +getVariable('IPC_PORT', 0);
22
- const rootPath = getVariable('ROOT_PATH', '');
23
- const options = { host, port, path, rootPath };
24
72
  if (ipcPort > 0) {
25
73
  const role = getVariable('IPC_ROLE');
26
74
  if (!['master', 'worker'].includes(role)) {
@@ -34,15 +82,33 @@ if (ipcPort > 0) {
34
82
  role,
35
83
  };
36
84
  }
37
- if (+getVariable('TXLOG', 0) === 1) {
85
+ else if (getVariable('IPC') === 'socket') {
86
+ // Use local IPC socket, will become default soon
87
+ options.ipc = 'socket';
88
+ }
89
+ // Check if transaction logging should be enabled (not enabled by default)
90
+ if (getVariable('TXLOG', 'false') === 'true' || +getVariable('TXLOG', 0) === 1) {
38
91
  options.transactions = {
39
92
  log: true,
40
93
  maxAge: +getVariable('TXDAYS', 30),
41
94
  };
42
95
  }
43
- if (+getVariable('AUTH', 1) === 0) {
96
+ // Check if authentication should be enabled (default)
97
+ if (getVariable('AUTH', 'true') === 'true' || +getVariable('AUTH', 1) === 1) {
98
+ options.authentication = {
99
+ enabled: true,
100
+ allowUserSignup: +getVariable('AUTH_USER_SIGNUP', 1) === 1,
101
+ defaultAccessRule: getVariable('AUTH_DEFAULT_ACCESS_RULE'),
102
+ defaultAdminPassword: getVariable('AUTH_DEFAULT_ADMIN_PASSWORD'),
103
+ newUserRateLimit: +getVariable('AUTH_NEW_USER_RATE_LIMIT', 0),
104
+ separateDb: getVariable('AUTH_SEPARATE_DB', false),
105
+ tokensExpire: +getVariable('AUTH_TOKENS_EXPIRE', 0), // No implemented yet
106
+ };
107
+ }
108
+ else {
44
109
  options.authentication = { enabled: false };
45
110
  }
111
+ const dbname = getVariable('DBNAME', 'default');
46
112
  const server = new AceBaseServer(dbname, options);
47
113
  server.once('ready', () => {
48
114
  server.debug.log(`AceBase server running`);
@@ -1,2 +1,7 @@
1
- export {};
1
+ /**
2
+ *
3
+ * To run an AceBase server in a cluster and examples, please refer to this discussion:
4
+ * https://github.com/appy-one/acebase-server/discussions/83
5
+ *
6
+ */
2
7
  //# sourceMappingURL=cluster.d.ts.map
@@ -3,7 +3,7 @@ import { RouteInitEnvironment, RouteRequest } from '../shared/env';
3
3
  export type RequestQuery = {
4
4
  include?: string;
5
5
  exclude?: string;
6
- child_objects?: boolean;
6
+ child_objects?: 'true' | 'false';
7
7
  };
8
8
  export type RequestBody = null;
9
9
  export type ResponseBody = Transport.SerializedValue & {
@@ -4,6 +4,7 @@ export type RequestBody = {
4
4
  action?: 'set';
5
5
  path: string;
6
6
  schema: string | Record<string, any>;
7
+ warnOnly?: boolean;
7
8
  };
8
9
  export type ResponseBody = {
9
10
  success: true;
@@ -152,7 +152,7 @@ export type AceBaseServerSettings = Partial<{
152
152
  /**
153
153
  * IPC settings for pm2 or cloud-based clusters. BETA stage, see https://github.com/appy-one/acebase-ipc-server
154
154
  */
155
- ipc: IPCClientSettings;
155
+ ipc: IPCClientSettings | 'socket';
156
156
  /**
157
157
  * Allows overriding of default storage settings used by the database. ALPHA stage
158
158
  */
@@ -186,7 +186,7 @@ export declare class AceBaseServerConfig {
186
186
  readonly auth: AceBaseServerAuthenticationSettings;
187
187
  readonly email: AceBaseServerEmailSettings;
188
188
  readonly transactions: AceBaseServerTransactionSettings;
189
- readonly ipc: IPCClientSettings;
189
+ readonly ipc: AceBaseServerSettings['ipc'];
190
190
  readonly storage?: AceBaseStorageSettings;
191
191
  readonly sponsor: boolean;
192
192
  readonly logColors: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "acebase-server",
3
- "version": "1.17.0",
3
+ "version": "1.18.1",
4
4
  "description": "AceBase realtime database server (webserver endpoint to allow remote connections)",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",
@@ -12,6 +12,9 @@
12
12
  "types": "./dist/types/index.d.ts"
13
13
  }
14
14
  },
15
+ "bin": {
16
+ "acebase-server": "./bin/acebase-server.js"
17
+ },
15
18
  "private": false,
16
19
  "repository": "github:appy-one/acebase-server",
17
20
  "scripts": {
@@ -61,8 +64,8 @@
61
64
  "author": "Ewout Stortenbeker <me@appy.one> (http://appy.one)",
62
65
  "license": "MIT",
63
66
  "dependencies": {
64
- "acebase": "^1.28.5",
65
- "acebase-core": "^1.26.2",
67
+ "acebase": "^1.29.0",
68
+ "acebase-core": "^1.27.1",
66
69
  "express": "^4.17.1",
67
70
  "socket.io": "^4.5.0",
68
71
  "swagger-jsdoc": "^6.1.0",
@@ -19,6 +19,24 @@
19
19
  schema:
20
20
  type: string
21
21
  example: collection/child/property
22
+ - name: include
23
+ in: query
24
+ description: comma-separated list of child properties to include
25
+ required: false
26
+ schema:
27
+ type: string
28
+ - name: exclude
29
+ in: query
30
+ description: comma-separated list of child properties to exclude
31
+ required: false
32
+ schema:
33
+ type: string
34
+ - name: child_objects
35
+ in: query
36
+ description: whether to include child objects
37
+ required: false
38
+ schema:
39
+ type: boolean
22
40
  responses:
23
41
  200:
24
42
  description: Returns the serialized value of the target path, and whether it exists in the database
@@ -32,6 +32,10 @@
32
32
  type: string
33
33
  description: When given, tests this schema definition against the passed value instead of ones defined in the database
34
34
  example: "{ name: string, stats?: { size: number, created: Date, modified: Date, deleted?: Date } }"
35
+ warnOnly:
36
+ type: boolean
37
+ description: whether to issue warnings for failing schema checks instead of denying writes. This allows you to add schemas to an existing database and testdrive them without enforcing them yet. Default is `false`
38
+ example: false
35
39
  required:
36
40
  - path
37
41
  - schema