dbdocs 0.6.3 → 0.6.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.
- package/README.md +14 -0
- package/bin/run +0 -0
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
- package/src/commands/rename.js +88 -0
- package/src/user_data.json +1 -1
- package/src/validators/userName.js +6 -0
package/README.md
CHANGED
|
@@ -35,6 +35,7 @@ USAGE
|
|
|
35
35
|
* [`dbdocs ls`](#dbdocs-ls)
|
|
36
36
|
* [`dbdocs password`](#dbdocs-password)
|
|
37
37
|
* [`dbdocs remove [PROJECT_NAME]`](#dbdocs-remove-project_name)
|
|
38
|
+
* [`dbdocs rename`](#dbdocs-rename)
|
|
38
39
|
* [`dbdocs token`](#dbdocs-token)
|
|
39
40
|
* [`dbdocs validate [FILEPATH]`](#dbdocs-validate-filepath)
|
|
40
41
|
|
|
@@ -130,6 +131,19 @@ USAGE
|
|
|
130
131
|
ARGUMENTS
|
|
131
132
|
PROJECT_NAME name of the project which you want to remove
|
|
132
133
|
```
|
|
134
|
+
|
|
135
|
+
## `dbdocs rename`
|
|
136
|
+
|
|
137
|
+
change your username
|
|
138
|
+
|
|
139
|
+
```
|
|
140
|
+
USAGE
|
|
141
|
+
$ dbdocs rename
|
|
142
|
+
|
|
143
|
+
DESCRIPTION
|
|
144
|
+
change your username and your default organization name
|
|
145
|
+
```
|
|
146
|
+
|
|
133
147
|
## `dbdocs token`
|
|
134
148
|
|
|
135
149
|
generate or revoke your authentication token
|
package/bin/run
CHANGED
|
File without changes
|
package/oclif.manifest.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"0.6.
|
|
1
|
+
{"version":"0.6.4","commands":{"build":{"id":"build","description":"build docs","pluginName":"dbdocs","pluginType":"core","aliases":[],"flags":{"project":{"name":"project","type":"option","description":"project name"},"password":{"name":"password","type":"option","char":"p","description":"password for project"}},"args":[{"name":"filepath","description":"dbml file path"}]},"login":{"id":"login","description":"login to dbdocs\nlogin with your dbdocs credentials\n","pluginName":"dbdocs","pluginType":"core","aliases":[],"flags":{},"args":[]},"logout":{"id":"logout","description":"logout\nclears local login credentials\n","pluginName":"dbdocs","pluginType":"core","aliases":[],"flags":{},"args":[]},"ls":{"id":"ls","description":"list projects","pluginName":"dbdocs","pluginType":"core","aliases":[],"flags":{},"args":[]},"password":{"id":"password","description":"set password for your project or remove password","pluginName":"dbdocs","pluginType":"core","aliases":[],"flags":{"project":{"name":"project","type":"option","char":"p","description":"project name","helpValue":"project name"},"set":{"name":"set","type":"option","char":"s","description":"password for your project","helpValue":"password"},"remove":{"name":"remove","type":"boolean","char":"r","description":"remove password from your project","allowNo":false}},"args":[]},"remove":{"id":"remove","description":"remove docs","pluginName":"dbdocs","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"project_name","description":"name of the project which you want to remove"}]},"rename":{"id":"rename","description":"change your username","pluginName":"dbdocs","pluginType":"core","aliases":[],"flags":{},"args":[]},"token":{"id":"token","description":"generate or revoke your authentication token","pluginName":"dbdocs","pluginType":"core","aliases":[],"flags":{"generate":{"name":"generate","type":"boolean","char":"g","description":"generate authentication token","allowNo":false},"revoke":{"name":"revoke","type":"boolean","char":"r","description":"revoke authentication token","allowNo":false}},"args":[]},"validate":{"id":"validate","description":"validate docs content","pluginName":"dbdocs","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"filepath","description":"dbml file path"}]}}}
|
package/package.json
CHANGED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
const { Command } = require('@oclif/command');
|
|
2
|
+
const inquirer = require('inquirer');
|
|
3
|
+
const axios = require('axios');
|
|
4
|
+
const ora = require('ora');
|
|
5
|
+
const { vars } = require('../vars');
|
|
6
|
+
const { isValidUserName } = require('../validators/userName');
|
|
7
|
+
const verifyToken = require('../utils/verifyToken');
|
|
8
|
+
|
|
9
|
+
async function enterUserName () {
|
|
10
|
+
const answer = await inquirer.prompt([
|
|
11
|
+
{
|
|
12
|
+
message: 'Please input your new username: ',
|
|
13
|
+
name: 'newUserName',
|
|
14
|
+
},
|
|
15
|
+
]);
|
|
16
|
+
return answer.newUserName;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async function validateAndUpdateUserName (spinner, authConfig, command) {
|
|
20
|
+
let newUserName = await enterUserName();
|
|
21
|
+
|
|
22
|
+
while (!isValidUserName(newUserName)) {
|
|
23
|
+
spinner.warn('Invalid username! Username can only contain alphabets, numbers, "-" or "_" and can not be blanked!');
|
|
24
|
+
newUserName = await enterUserName();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
const { data: { user, hasRevokedToken } } = await axios.put(`${vars.apiUrl}/account/rename`, { newUserName }, authConfig);
|
|
29
|
+
return { user, hasRevokedToken };
|
|
30
|
+
} catch (err) {
|
|
31
|
+
const { error } = err.response.data;
|
|
32
|
+
const warningNames = ['UserNameNotChange', 'UserNameExisted'];
|
|
33
|
+
if (warningNames.includes(error.name)) {
|
|
34
|
+
spinner.warn(error.message);
|
|
35
|
+
} else {
|
|
36
|
+
command.error(error.message);
|
|
37
|
+
}
|
|
38
|
+
return { user: null, hasRevokedToken: null };
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
class RenameCommand extends Command {
|
|
43
|
+
async run () {
|
|
44
|
+
const spinner = ora({});
|
|
45
|
+
try {
|
|
46
|
+
const authConfig = await verifyToken();
|
|
47
|
+
|
|
48
|
+
this.warn('After renaming, your authentication token (if exists) will be revoked. Please re-generate a new one!');
|
|
49
|
+
this.warn('You may need to re-login your account on the dbdocs web app for the best user experience.');
|
|
50
|
+
|
|
51
|
+
let { user, hasRevokedToken } = await validateAndUpdateUserName(spinner, authConfig, this);
|
|
52
|
+
while (!user) {
|
|
53
|
+
({ user, hasRevokedToken } = await validateAndUpdateUserName(spinner, authConfig, this));
|
|
54
|
+
}
|
|
55
|
+
if (hasRevokedToken) {
|
|
56
|
+
spinner.succeed('Rename successfully and your access token has been revoked, please generate a new one!');
|
|
57
|
+
} else {
|
|
58
|
+
spinner.succeed('Rename successfully!');
|
|
59
|
+
}
|
|
60
|
+
} catch (err) {
|
|
61
|
+
if (spinner.isSpinning) {
|
|
62
|
+
spinner.fail();
|
|
63
|
+
}
|
|
64
|
+
let message = err.message || 'Something wrong :( Please try again.';
|
|
65
|
+
if (err.response) {
|
|
66
|
+
const { error } = err.response.data;
|
|
67
|
+
switch (error.name) {
|
|
68
|
+
case 'TokenExpiredError':
|
|
69
|
+
message = 'Your token has expired. Please login again.';
|
|
70
|
+
break;
|
|
71
|
+
|
|
72
|
+
case 'InvalidAuthToken':
|
|
73
|
+
message = 'Invalid token. Please login again.';
|
|
74
|
+
break;
|
|
75
|
+
|
|
76
|
+
default:
|
|
77
|
+
message = error.message;
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
this.error(message);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
RenameCommand.description = 'change your username';
|
|
87
|
+
|
|
88
|
+
module.exports = RenameCommand;
|
package/src/user_data.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"BUILD_COUNT":
|
|
1
|
+
{"BUILD_COUNT":1}
|