soul-cli 0.7.6 → 0.7.8

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/.env.sample CHANGED
@@ -6,8 +6,8 @@ CORS_ORIGIN_WHITELIST=http://localhost:3000,http://127.0.0.1:3000
6
6
  AUTH=false
7
7
 
8
8
  RATE_LIMIT_ENABLED=false
9
- RATE_LIMIT_WINDOW_MS=1000
10
- RATE_LIMIT_MAX_REQUESTS=10
9
+ RATE_LIMIT_WINDOW=1000
10
+ RATE_LIMIT_MAX=10
11
11
 
12
12
  DB=foobar.db
13
13
 
package/README.md CHANGED
@@ -34,16 +34,17 @@ Options:
34
34
  -p, --port Port to listen on [number]
35
35
  -r, --rate-limit-enabled Enable rate limiting [boolean]
36
36
  -c, --cors CORS whitelist origins [string]
37
+ --env, --envpath Path to load .env file [string]
37
38
  -a, --auth Enable authentication and authorization [boolean]
38
39
 
39
- -iuu, --initialuserusername Initial user username [string]
40
- -iup, --initialuserpassword Initial user password [string]
40
+ --iuu, --initialuserusername Initial user username [string]
41
+ --iup, --initialuserpassword Initial user password [string]
41
42
 
42
- -ts, --tokensecret Token Secret [string]
43
- -atet, --accesstokenexpirationtime Access Token Expiration Time (Default: 5H) [string]
44
- -rtet, --refreshtokenexpirationtime Refresh Token Expiration Time (Default: 1D) [string]
45
- -S, --studio Start Soul Studio in parallel
46
- --help Show help
43
+ --ts, --tokensecret Token Secret [string]
44
+ --atet, --accesstokenexpirationtime Access Token Expiration Time (Default: 5H) [string]
45
+ --rtet, --refreshtokenexpirationtime Refresh Token Expiration Time (Default: 1D) [string]
46
+ -S, --studio Start Soul Studio in parallel
47
+ --help Show help
47
48
 
48
49
  ```
49
50
 
@@ -63,7 +64,7 @@ Run the Soul command with the necessary parameters:
63
64
 
64
65
  ```
65
66
 
66
- soul --d foobar.db -a -ts <your_jwt_secret_value> -atet=4H -rtet=3D -iuu=john -iup=<your_password>
67
+ soul -d foobar.db -a --ts=<your_jwt_secret_value> --atet=4H --rtet=3D --iuu=john --iup=<your_password>
67
68
 
68
69
  ```
69
70
 
@@ -72,32 +73,46 @@ Note: When configuring your JWT Secret, it is recommended to use a long string v
72
73
  In this example:
73
74
 
74
75
  The `-a` flag instructs Soul to run in auth mode.
75
- The `-ts` flag allows you to pass a JWT secret value for the `access and refresh tokens` generation and verification. Replace <your_jwt_secret_value> with your desired secret value.
76
- The `-atet` flag sets the JWT expiration time for the access token. In this case, it is set to four hours (4H), meaning the token will expire after 4 hours.
77
- The `-rtet` flag sets the JWT expiration time for the refresh token. In this case, it is set to three days (3D), meaning the token will expire after 3 days.
78
- The `-iuu` flag is used to pass a username for the initial user
79
- The `-iup` flag is used to pass a password for the initial user
76
+ The `--ts` flag allows you to pass a JWT secret value for the `access and refresh tokens` generation and verification. Replace <your_jwt_secret_value> with your desired secret value.
77
+ The `--atet` flag sets the JWT expiration time for the access token. In this case, it is set to four hours (4H), meaning the token will expire after 4 hours.
78
+ The `--rtet` flag sets the JWT expiration time for the refresh token. In this case, it is set to three days (3D), meaning the token will expire after 3 days.
79
+ The `--iuu` flag is used to pass a username for the initial user
80
+ The `--iup` flag is used to pass a password for the initial user
80
81
 
81
- Here are some example values for the `-atet` and `rtet` flags
82
+ Here are some example values for the `atet` and `rtet` flags
82
83
 
83
84
  - 60M: Represents a duration of 60 minutes.
84
85
  - 5H: Represents a duration of 5 hours.
85
86
  - 1D: Represents a duration of 1 day.
86
87
 
87
- NOTE: It is crucial to securely store a copy of the `-ts`(`Token Secret`) value used in Soul. Once you pass this values, make sure to keep a backup because you will need it every time you restart Soul. Losing this secret values can result in a situation where all of your users are blocked from accessing Soul.
88
+ NOTE: It is crucial to securely store a copy of the `--ts`(`Token Secret`) value used in Soul. Once you pass this values, make sure to keep a backup because you will need it every time you restart Soul. Losing this secret values can result in a situation where all of your users are blocked from accessing Soul.
88
89
 
89
90
  ### 3. Updating Super Users
90
91
 
91
92
  To modify a superuser information in a database, you can utilize the `updatesuperuser` command. This command allows you to change a superuser's `password` or upgrade/downgrade a normal user to a `superuser`. Below is an example of how to use it:
92
93
 
93
94
  ```
94
- soul --d foobar.db updatesuperuser --id=1 password=<new_password_for_the_user> // Update the password for the superuser with ID 1
95
+ soul -d foobar.db updatesuperuser --id=1 password=<new_password_for_the_user> // Update the password for the superuser with ID 1
95
96
 
96
- soul --d foobar.db updatesuperuser --id=1 --is_superuser=true // Upgrade the user with ID 1 to a superuser
97
+ soul -d foobar.db updatesuperuser --id=1 --is_superuser=true // Upgrade the user with ID 1 to a superuser
97
98
 
98
- soul --d foobar.db updatesuperuser --id=1 --is_superuser=false // Revoke the superuser role from the superuser with ID 1
99
+ soul -d foobar.db updatesuperuser --id=1 --is_superuser=false // Revoke the superuser role from the superuser with ID 1
99
100
  ```
100
101
 
102
+ ### Passing Custom Path for .env File
103
+
104
+ There might be cases where you want to pass a custom path for your `.env` file. For this, you can use the `--env` flag when running the `soul` command, providing the absolute file path of your `.env` file.
105
+
106
+ ```shell
107
+ soul -d foobar.db --env=/Users/Documents/Projects/React-Project/.env
108
+ ```
109
+
110
+ NOTE:
111
+
112
+ - You should pass an absolute file path of the .env file.
113
+ - Relative paths are not allowed.
114
+ - Don't forget to include the .env file in the specified path.
115
+
101
116
  ## Documentation
102
117
 
103
118
  API documentation is available while the project is running at [http://localhost:8000/api/docs](http://localhost:8000/api/docs)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "soul-cli",
3
- "version": "0.7.6",
3
+ "version": "0.7.8",
4
4
  "description": "A SQLite REST and Realtime server",
5
5
  "main": "src/server.js",
6
6
  "bin": {
package/src/cli.js CHANGED
@@ -46,32 +46,34 @@ if (process.env.NO_CLI !== 'true') {
46
46
  type: 'string',
47
47
  demandOption: false,
48
48
  })
49
+ .options('env', {
50
+ alias: 'envpath',
51
+ describe: 'Environment variable file path to load',
52
+ type: 'string',
53
+ demandOption: false,
54
+ })
49
55
  .options('a', {
50
56
  alias: 'auth',
51
57
  describe: 'Enable authentication and authorization',
52
58
  type: 'boolean',
53
- default: false,
54
59
  demandOption: false,
55
60
  })
56
61
  .options('ts', {
57
62
  alias: 'tokensecret',
58
63
  describe: 'JWT secret for the access and refresh tokens',
59
64
  type: 'string',
60
- default: null,
61
65
  demandOption: false,
62
66
  })
63
67
  .options('atet', {
64
68
  alias: 'accesstokenexpirationtime',
65
69
  describe: 'JWT expiration time for access token',
66
70
  type: 'string',
67
- default: '5H',
68
71
  demandOption: false,
69
72
  })
70
73
  .options('rtet', {
71
74
  alias: 'refreshtokenexpirationtime',
72
75
  describe: 'JWT expiration time for refresh token',
73
76
  type: 'string',
74
- default: '3D',
75
77
  demandOption: false,
76
78
  })
77
79
  .options('iuu', {
@@ -6,7 +6,7 @@ const { yargs } = require('../cli');
6
6
 
7
7
  const { argv } = yargs;
8
8
 
9
- dotenv.config({ path: path.join(__dirname, '../../.env') });
9
+ dotenv.config({ path: argv.envpath || path.join(__dirname, '../../.env') });
10
10
 
11
11
  const envVarsSchema = Joi.object()
12
12
  .keys({
@@ -20,7 +20,7 @@ const envVarsSchema = Joi.object()
20
20
  VERBOSE: Joi.string().valid('console', null).default(null),
21
21
 
22
22
  CORS_ORIGIN_WHITELIST: Joi.string().default('*'),
23
- AUTH: Joi.boolean().default(false),
23
+ AUTH: Joi.boolean(),
24
24
 
25
25
  RATE_LIMIT_ENABLED: Joi.boolean().default(false),
26
26
  RATE_LIMIT_WINDOW_MS: Joi.number().positive().default(1000),
@@ -33,9 +33,9 @@ const envVarsSchema = Joi.object()
33
33
  INITIAL_USER_USERNAME: Joi.string(),
34
34
  INITIAL_USER_PASSWORD: Joi.string(),
35
35
 
36
- TOKEN_SECRET: Joi.string().default(null),
37
- ACCESS_TOKEN_EXPIRATION_TIME: Joi.string().default('5H'),
38
- REFRESH_TOKEN_EXPIRATION_TIME: Joi.string().default('3D'),
36
+ TOKEN_SECRET: Joi.string(),
37
+ ACCESS_TOKEN_EXPIRATION_TIME: Joi.string(),
38
+ REFRESH_TOKEN_EXPIRATION_TIME: Joi.string(),
39
39
  })
40
40
  .unknown();
41
41
 
@@ -113,12 +113,16 @@ module.exports = {
113
113
  envVars.CORS_ORIGIN_WHITELIST?.split(',') || ['*'],
114
114
  },
115
115
 
116
- auth: argv.auth || envVars.AUTH,
117
- tokenSecret: argv.tokensecret || envVars.TOKEN_SECRET,
116
+ auth: argv.auth || envVars.AUTH || false,
117
+ tokenSecret: argv.tokensecret || envVars.TOKEN_SECRET || null,
118
118
  accessTokenExpirationTime:
119
- argv.accesstokenexpirationtime || envVars.ACCESS_TOKEN_EXPIRATION_TIME,
119
+ argv.accesstokenexpirationtime ||
120
+ envVars.ACCESS_TOKEN_EXPIRATION_TIME ||
121
+ '5H',
120
122
  refreshTokenExpirationTime:
121
- argv.refreshtokenexpirationtime || envVars.REFRESH_TOKEN_EXPIRATION_TIME,
123
+ argv.refreshtokenexpirationtime ||
124
+ envVars.REFRESH_TOKEN_EXPIRATION_TIME ||
125
+ '3D',
122
126
 
123
127
  initialUserUsername:
124
128
  argv.initialuserusername || envVars.INITIAL_USER_USERNAME,
@@ -13,4 +13,12 @@ const isUsernameTaken = (username) => {
13
13
  return users.length > 0;
14
14
  };
15
15
 
16
- module.exports = { isUsernameTaken };
16
+ const checkAuthConfigs = ({ auth, tokenSecret }) => {
17
+ if (auth && !tokenSecret) {
18
+ throw new Error(
19
+ 'You need to provide a token secret either from the CLI or from your environment variables',
20
+ );
21
+ }
22
+ };
23
+
24
+ module.exports = { isUsernameTaken, checkAuthConfigs };
@@ -1,5 +1,6 @@
1
1
  const users = require('./user');
2
2
  const token = require('./token');
3
3
  const tables = require('./tables');
4
+ const { checkAuthConfigs } = require('./common');
4
5
 
5
- module.exports = { ...users, ...token, ...tables };
6
+ module.exports = { ...users, ...token, ...tables, checkAuthConfigs };
package/src/index.js CHANGED
@@ -23,11 +23,11 @@ const {
23
23
  createDefaultTables,
24
24
  createInitialUser,
25
25
  removeRevokedRefreshTokens,
26
+ checkAuthConfigs,
26
27
  } = require('./controllers/auth');
27
28
 
28
29
  const { runCLICommands } = require('./commands');
29
30
  const { authConstants } = require('./constants');
30
-
31
31
  const app = express();
32
32
  app.get('/health', (req, res) => {
33
33
  res.send('OK');
@@ -85,6 +85,9 @@ if (config.rateLimit.enabled) {
85
85
  app.use(limiter);
86
86
  }
87
87
 
88
+ // If Auth mode is activated but if the tokenSecret value is undefined then throw an error
89
+ checkAuthConfigs({ auth: config.auth, tokenSecret: config.tokenSecret });
90
+
88
91
  // If Auth mode is activated then create auth tables in the DB & create a super user if there are no users in the DB
89
92
  if (config.auth) {
90
93
  createDefaultTables();