mstate-cli 0.2.2 → 0.2.3
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/dist/index.js +17 -17
- package/package.json +1 -1
- package/src/common/constant.ts +4 -3
- package/src/common/enum.ts +3 -2
- package/src/handlers/company.handler.ts +73 -9
- package/src/index.ts +8 -4
package/package.json
CHANGED
package/src/common/constant.ts
CHANGED
@@ -7,9 +7,10 @@ export const CRED_FILE_PATH = path.join(
|
|
7
7
|
'.mstate_credentials',
|
8
8
|
);
|
9
9
|
|
10
|
-
export const MSTATE_DOMAIN: string = `https://mstate.ai/`;
|
10
|
+
// export const MSTATE_DOMAIN: string = `https://mstate.ai/`;
|
11
11
|
// export const MSTATE_DOMAIN: string = `http://localhost:5173/`;
|
12
|
+
export const MSTATE_DOMAIN: string = `https://dev.mstate.ai/`;
|
12
13
|
|
13
|
-
|
14
|
+
export const MSTATE_URL: string = 'https://dev.mstate.mobioffice.io/api';
|
14
15
|
// export const MSTATE_URL = 'http://localhost:3000/api';
|
15
|
-
export const MSTATE_URL = 'https://api.mstate.mobioffice.io/api';
|
16
|
+
// export const MSTATE_URL = 'https://api.mstate.mobioffice.io/api';
|
package/src/common/enum.ts
CHANGED
@@ -14,17 +14,20 @@ enum Key {
|
|
14
14
|
PERMISSIONS = 'permissions=',
|
15
15
|
SECRET_KEY = 'secret=',
|
16
16
|
USER_ID = 'user=',
|
17
|
-
|
17
|
+
NAME = 'name=',
|
18
|
+
EMAIL = 'email=',
|
19
|
+
PHONE = 'phone=',
|
20
|
+
COMPANY_ID = 'company=',
|
18
21
|
}
|
19
22
|
|
20
23
|
class CompanyHandler {
|
21
|
-
constructor() {
|
24
|
+
constructor() {}
|
22
25
|
|
23
26
|
async addToken() {
|
24
27
|
const args = process.argv;
|
25
28
|
|
26
29
|
const pString = getValueFromArgs(args, Key.PERMISSIONS).trim();
|
27
|
-
const permissions = pString.split(',').map(s => s.trim());
|
30
|
+
const permissions = pString.split(',').map((s) => s.trim());
|
28
31
|
const secretKey = getSecretKey();
|
29
32
|
const user = getValueFromArgs(args, Key.USER_ID);
|
30
33
|
const companyID = getValueFromArgs(args, Key.COMPANY_ID);
|
@@ -59,7 +62,7 @@ class CompanyHandler {
|
|
59
62
|
body: JSON.stringify({
|
60
63
|
user,
|
61
64
|
permissions,
|
62
|
-
company: companyID
|
65
|
+
company: companyID,
|
63
66
|
}),
|
64
67
|
});
|
65
68
|
|
@@ -72,14 +75,75 @@ class CompanyHandler {
|
|
72
75
|
} else {
|
73
76
|
customLog.success('Company updated successfully \n', response?.data);
|
74
77
|
}
|
78
|
+
}
|
79
|
+
|
80
|
+
async addUser() {
|
81
|
+
const args = process.argv;
|
82
|
+
|
83
|
+
const secretKey = getSecretKey();
|
84
|
+
const name = getValueFromArgs(args, Key.NAME);
|
85
|
+
const email = getValueFromArgs(args, Key.EMAIL);
|
86
|
+
const phone = getValueFromArgs(args, Key.PHONE);
|
87
|
+
const companyID = getValueFromArgs(args, Key.COMPANY_ID);
|
88
|
+
|
89
|
+
if (!secretKey) {
|
90
|
+
customLog.changeAndThrow(`Parameter secret is required`);
|
91
|
+
return;
|
92
|
+
}
|
93
|
+
|
94
|
+
if (!name) {
|
95
|
+
customLog.changeAndThrow(`Parameter name is required`);
|
96
|
+
return;
|
97
|
+
}
|
98
|
+
|
99
|
+
if (!email) {
|
100
|
+
customLog.changeAndThrow(`Parameter email is required`);
|
101
|
+
return;
|
102
|
+
}
|
103
|
+
|
104
|
+
if (!phone) {
|
105
|
+
customLog.changeAndThrow(`Parameter phone is required`);
|
106
|
+
return;
|
107
|
+
}
|
108
|
+
|
109
|
+
if (!companyID) {
|
110
|
+
customLog.changeAndThrow(`Parameter company is required`);
|
111
|
+
return;
|
112
|
+
}
|
113
|
+
|
114
|
+
const url = `${MSTATE_URL}/um/user`;
|
115
|
+
const responseJSON = await fetch(url, {
|
116
|
+
method: 'POST',
|
117
|
+
headers: {
|
118
|
+
'secret-key': secretKey,
|
119
|
+
'Content-Type': 'application/json',
|
120
|
+
},
|
121
|
+
body: JSON.stringify({
|
122
|
+
companyNickName: companyID,
|
123
|
+
name,
|
124
|
+
username: name,
|
125
|
+
email,
|
126
|
+
password: '123',
|
127
|
+
phone,
|
128
|
+
}),
|
129
|
+
});
|
75
130
|
|
131
|
+
const response = await responseJSON.json();
|
132
|
+
if (response?.errors) {
|
133
|
+
customLog.changeAndThrow(
|
134
|
+
'Invalid Parameters for Company: ',
|
135
|
+
...response?.errors,
|
136
|
+
);
|
137
|
+
} else {
|
138
|
+
customLog.success('User Updated successfully \n', response?.data);
|
139
|
+
}
|
76
140
|
}
|
77
141
|
|
78
142
|
async revokePermission() {
|
79
143
|
const args = process.argv;
|
80
144
|
|
81
145
|
const pString = getValueFromArgs(args, Key.PERMISSIONS);
|
82
|
-
const permissions = pString.split(',').map(s => s.trim());
|
146
|
+
const permissions = pString.split(',').map((s) => s.trim());
|
83
147
|
const secretKey = getSecretKey();
|
84
148
|
const user = getValueFromArgs(args, Key.USER_ID);
|
85
149
|
const companyID = getValueFromArgs(args, Key.COMPANY_ID);
|
@@ -142,7 +206,7 @@ class CompanyHandler {
|
|
142
206
|
|
143
207
|
const startServer = (port: number) => {
|
144
208
|
return app.listen(port, () => {
|
145
|
-
console.log(`
|
209
|
+
console.log(`Waiting for browser response...`);
|
146
210
|
});
|
147
211
|
};
|
148
212
|
|
@@ -186,9 +250,9 @@ class CompanyHandler {
|
|
186
250
|
.then(async () => {
|
187
251
|
await open(
|
188
252
|
MSTATE_DOMAIN +
|
189
|
-
|
190
|
-
|
191
|
-
|
253
|
+
`oauth?redirect=${encodeURIComponent(
|
254
|
+
'cli/mstate/login',
|
255
|
+
)}&open=${port}&scope=profile`,
|
192
256
|
);
|
193
257
|
})
|
194
258
|
.catch((err) => {
|
package/src/index.ts
CHANGED
@@ -28,7 +28,7 @@ const [action] = argv.slice(2);
|
|
28
28
|
);
|
29
29
|
break;
|
30
30
|
|
31
|
-
case CmdAction.
|
31
|
+
case CmdAction.PERMISSION:
|
32
32
|
if (hasFlag(argv, '-d')) await companyHandler.revokePermission();
|
33
33
|
else await companyHandler.addToken();
|
34
34
|
break;
|
@@ -37,9 +37,13 @@ const [action] = argv.slice(2);
|
|
37
37
|
companyHandler.handleUpdateSavedSecretKey();
|
38
38
|
break;
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
|
40
|
+
case CmdAction.USER:
|
41
|
+
await companyHandler.addUser();
|
42
|
+
break;
|
43
|
+
|
44
|
+
case CmdAction.DEV: // comment this case on production build
|
45
|
+
companyHandler.logToken();
|
46
|
+
break;
|
43
47
|
|
44
48
|
case CmdAction.LOGIN:
|
45
49
|
await companyHandler.handleLogin();
|