contensis-cli 1.0.0-beta.62 → 1.0.0-beta.64
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/commands/create.js +15 -0
- package/dist/commands/create.js.map +2 -2
- package/dist/commands/get.js +11 -0
- package/dist/commands/get.js.map +2 -2
- package/dist/commands/list.js +16 -1
- package/dist/commands/list.js.map +2 -2
- package/dist/commands/remove.js +11 -0
- package/dist/commands/remove.js.map +2 -2
- package/dist/commands/set.js +98 -12
- package/dist/commands/set.js.map +2 -2
- package/dist/localisation/en-GB.js +18 -1
- package/dist/localisation/en-GB.js.map +2 -2
- package/dist/services/ContensisCliService.js +182 -4
- package/dist/services/ContensisCliService.js.map +2 -2
- package/dist/shell.js +14 -5
- package/dist/shell.js.map +2 -2
- package/dist/util/index.js +3 -0
- package/dist/util/index.js.map +2 -2
- package/dist/util/logger.js +12 -14
- package/dist/util/logger.js.map +3 -3
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +2 -2
- package/src/commands/create.ts +24 -0
- package/src/commands/get.ts +17 -0
- package/src/commands/list.ts +21 -0
- package/src/commands/remove.ts +16 -0
- package/src/commands/set.ts +134 -10
- package/src/localisation/en-GB.ts +23 -1
- package/src/services/ContensisCliService.ts +230 -7
- package/src/shell.ts +14 -5
- package/src/util/index.ts +3 -0
- package/src/util/logger.ts +26 -14
- package/src/version.ts +1 -1
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
Model,
|
|
22
22
|
MigrateModelsResult,
|
|
23
23
|
} from 'migratortron';
|
|
24
|
-
import { Entry } from 'contensis-management-api/lib/models';
|
|
24
|
+
import { Entry, Role } from 'contensis-management-api/lib/models';
|
|
25
25
|
|
|
26
26
|
import { csvFormatter } from '~/util/csv.formatter';
|
|
27
27
|
import { xmlFormatter } from '~/util/xml.formatter';
|
|
@@ -754,14 +754,19 @@ class ContensisCli {
|
|
|
754
754
|
|
|
755
755
|
// print the key details to console
|
|
756
756
|
console.log(
|
|
757
|
-
` - ${key.name}${
|
|
758
|
-
|
|
759
|
-
|
|
757
|
+
` - ${chalk.bold(key.name)} [${key.dateModified
|
|
758
|
+
.toString()
|
|
759
|
+
.substring(0, 10)} ${key.modifiedBy}]`
|
|
760
760
|
);
|
|
761
|
-
|
|
762
|
-
|
|
761
|
+
if (key.description)
|
|
762
|
+
console.log(` ${log.infoText(key.description)}`);
|
|
763
|
+
console.log(` ${chalk.bold.grey`id`}: ${key.id}`);
|
|
764
|
+
console.log(
|
|
765
|
+
` ${chalk.bold.grey`sharedSecret`}: ${key.sharedSecret}`
|
|
766
|
+
);
|
|
767
|
+
console.log('');
|
|
768
|
+
log.help(messages.keys.tip());
|
|
763
769
|
}
|
|
764
|
-
console.log('');
|
|
765
770
|
|
|
766
771
|
if (err) {
|
|
767
772
|
log.error(messages.keys.failedCreate(currentEnv, name), err);
|
|
@@ -785,6 +790,224 @@ class ContensisCli {
|
|
|
785
790
|
}
|
|
786
791
|
};
|
|
787
792
|
|
|
793
|
+
PrintRoles = async () => {
|
|
794
|
+
const { currentEnv, log, messages } = this;
|
|
795
|
+
const contensis = await this.ConnectContensis();
|
|
796
|
+
|
|
797
|
+
if (contensis) {
|
|
798
|
+
// Retrieve roles list for env
|
|
799
|
+
const [rolesErr, roles] = await to(contensis.roles.GetRoles());
|
|
800
|
+
|
|
801
|
+
if (Array.isArray(roles)) {
|
|
802
|
+
log.success(messages.roles.list(currentEnv));
|
|
803
|
+
this.HandleFormattingAndOutput(roles, () => {
|
|
804
|
+
// print the roles to console
|
|
805
|
+
for (const {
|
|
806
|
+
id,
|
|
807
|
+
name,
|
|
808
|
+
description,
|
|
809
|
+
enabled,
|
|
810
|
+
assignments,
|
|
811
|
+
permissions,
|
|
812
|
+
} of roles) {
|
|
813
|
+
const color = enabled ? (s: string) => s : log.infoText;
|
|
814
|
+
|
|
815
|
+
console.log(color(` - ${chalk.bold(name)} ${log.infoText(id)}`));
|
|
816
|
+
if (description) console.log(log.infoText(` ${description}`));
|
|
817
|
+
if (enabled === false)
|
|
818
|
+
console.log(` ${chalk.bold.grey('enabled')}: false`);
|
|
819
|
+
if (assignments.groups?.length)
|
|
820
|
+
console.log(
|
|
821
|
+
` ${chalk.bold.grey('groups')}: ${assignments.groups.join(
|
|
822
|
+
', '
|
|
823
|
+
)}`
|
|
824
|
+
);
|
|
825
|
+
if (assignments.users?.length)
|
|
826
|
+
console.log(
|
|
827
|
+
` ${chalk.bold.grey('users')}: ${assignments.users.join(
|
|
828
|
+
', '
|
|
829
|
+
)}`
|
|
830
|
+
);
|
|
831
|
+
if (assignments.apiKeys?.length)
|
|
832
|
+
console.log(
|
|
833
|
+
` ${chalk.bold.grey('keys')}: ${assignments.apiKeys.join(
|
|
834
|
+
', '
|
|
835
|
+
)}`
|
|
836
|
+
);
|
|
837
|
+
|
|
838
|
+
if (permissions.entries?.length) {
|
|
839
|
+
console.log(` ${chalk.bold.grey('entries')}:`);
|
|
840
|
+
for (const p of permissions.entries)
|
|
841
|
+
console.log(
|
|
842
|
+
` ${p.id}: ${log.infoText(
|
|
843
|
+
p.actions.length > 2
|
|
844
|
+
? p.actions.length
|
|
845
|
+
: p.actions.join(', ')
|
|
846
|
+
)}`
|
|
847
|
+
);
|
|
848
|
+
}
|
|
849
|
+
if (permissions.contentTypes?.length)
|
|
850
|
+
console.log(
|
|
851
|
+
` ${chalk.bold.grey(
|
|
852
|
+
'contentTypes'
|
|
853
|
+
)}: ${permissions.contentTypes
|
|
854
|
+
.map(
|
|
855
|
+
p =>
|
|
856
|
+
`${p.id} [${p.actions.join(',')}] ${p.languages.join(
|
|
857
|
+
' '
|
|
858
|
+
)}`
|
|
859
|
+
)
|
|
860
|
+
.join(', ')}`
|
|
861
|
+
);
|
|
862
|
+
}
|
|
863
|
+
});
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
if (rolesErr) {
|
|
867
|
+
log.error(messages.roles.noList(currentEnv));
|
|
868
|
+
log.error(jsonFormatter(rolesErr));
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
};
|
|
872
|
+
|
|
873
|
+
PrintRole = async (roleNameOrId: string) => {
|
|
874
|
+
const { currentEnv, log, messages } = this;
|
|
875
|
+
const contensis = await this.ConnectContensis();
|
|
876
|
+
|
|
877
|
+
if (contensis) {
|
|
878
|
+
// Retrieve roles list for env
|
|
879
|
+
const [rolesErr, roles] = await to(contensis.roles.GetRoles());
|
|
880
|
+
|
|
881
|
+
if (Array.isArray(roles)) {
|
|
882
|
+
log.success(messages.roles.list(currentEnv));
|
|
883
|
+
|
|
884
|
+
const role =
|
|
885
|
+
roles.find(
|
|
886
|
+
r =>
|
|
887
|
+
r.id === roleNameOrId ||
|
|
888
|
+
r.name.toLowerCase() === roleNameOrId.toLowerCase()
|
|
889
|
+
) ||
|
|
890
|
+
roles.find(r =>
|
|
891
|
+
r.name.toLowerCase().includes(roleNameOrId.toLowerCase())
|
|
892
|
+
);
|
|
893
|
+
|
|
894
|
+
if (role) this.HandleFormattingAndOutput(role, log.object);
|
|
895
|
+
else log.error(messages.roles.failedGet(currentEnv, roleNameOrId));
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
if (rolesErr) {
|
|
899
|
+
log.error(messages.roles.noList(currentEnv));
|
|
900
|
+
log.error(jsonFormatter(rolesErr));
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
};
|
|
904
|
+
|
|
905
|
+
CreateRole = async (role: Partial<Role>) => {
|
|
906
|
+
const { currentEnv, log, messages } = this;
|
|
907
|
+
const contensis = await this.ConnectContensis();
|
|
908
|
+
|
|
909
|
+
if (contensis) {
|
|
910
|
+
const [err, created] = await contensis.roles.CreateRole(role as Role);
|
|
911
|
+
|
|
912
|
+
if (created) {
|
|
913
|
+
log.success(
|
|
914
|
+
messages.roles.created(currentEnv, role.id || role.name || '')
|
|
915
|
+
);
|
|
916
|
+
|
|
917
|
+
this.HandleFormattingAndOutput(created, log.object);
|
|
918
|
+
|
|
919
|
+
log.help(messages.roles.tip());
|
|
920
|
+
return role.id;
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
if (err) {
|
|
924
|
+
log.error(
|
|
925
|
+
messages.roles.failedCreate(currentEnv, role.id || role.name || ''),
|
|
926
|
+
err
|
|
927
|
+
);
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
};
|
|
931
|
+
|
|
932
|
+
UpdateRole = async (roleNameOrId: string, role: Partial<Role>) => {
|
|
933
|
+
const { currentEnv, log, messages } = this;
|
|
934
|
+
const contensis = await this.ConnectContensis();
|
|
935
|
+
|
|
936
|
+
if (contensis) {
|
|
937
|
+
// Retrieve roles list for env
|
|
938
|
+
const [rolesErr, roles] = await to(contensis.roles.GetRoles());
|
|
939
|
+
|
|
940
|
+
if (Array.isArray(roles)) {
|
|
941
|
+
log.success(messages.roles.list(currentEnv));
|
|
942
|
+
|
|
943
|
+
const existingRole = roles.find(
|
|
944
|
+
r =>
|
|
945
|
+
r.id === roleNameOrId ||
|
|
946
|
+
r.name.toLowerCase() === roleNameOrId.toLowerCase()
|
|
947
|
+
);
|
|
948
|
+
if (existingRole) {
|
|
949
|
+
log.info(messages.roles.setPayload());
|
|
950
|
+
log.object(role);
|
|
951
|
+
log.raw(``);
|
|
952
|
+
const [updateErr, updated] = await contensis.roles.UpdateRole(
|
|
953
|
+
existingRole.id,
|
|
954
|
+
role
|
|
955
|
+
);
|
|
956
|
+
if (updateErr)
|
|
957
|
+
log.error(messages.roles.failedSet(currentEnv, roleNameOrId));
|
|
958
|
+
else {
|
|
959
|
+
log.success(messages.roles.set());
|
|
960
|
+
|
|
961
|
+
this.HandleFormattingAndOutput(updated, log.object);
|
|
962
|
+
}
|
|
963
|
+
} else {
|
|
964
|
+
// Role does not exist
|
|
965
|
+
log.error(messages.roles.failedGet(currentEnv, roleNameOrId));
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
if (rolesErr) {
|
|
970
|
+
log.error(messages.roles.noList(currentEnv));
|
|
971
|
+
log.error(jsonFormatter(rolesErr));
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
};
|
|
975
|
+
|
|
976
|
+
RemoveRole = async (roleNameOrId: string) => {
|
|
977
|
+
const { currentEnv, log, messages } = this;
|
|
978
|
+
const contensis = await this.ConnectContensis();
|
|
979
|
+
|
|
980
|
+
if (contensis) {
|
|
981
|
+
// Retrieve roles list for env
|
|
982
|
+
const [rolesErr, roles] = await to(contensis.roles.GetRoles());
|
|
983
|
+
|
|
984
|
+
if (Array.isArray(roles)) {
|
|
985
|
+
log.success(messages.roles.list(currentEnv));
|
|
986
|
+
|
|
987
|
+
const existingRole = roles.find(
|
|
988
|
+
r =>
|
|
989
|
+
r.id === roleNameOrId ||
|
|
990
|
+
r.name.toLowerCase() === roleNameOrId.toLowerCase()
|
|
991
|
+
);
|
|
992
|
+
if (existingRole) {
|
|
993
|
+
const [deleteErr] = await contensis.roles.RemoveRole(existingRole.id);
|
|
994
|
+
|
|
995
|
+
if (deleteErr)
|
|
996
|
+
log.error(messages.roles.failedRemove(currentEnv, roleNameOrId));
|
|
997
|
+
else log.success(messages.roles.removed(currentEnv, roleNameOrId));
|
|
998
|
+
} else {
|
|
999
|
+
// Role does not exist
|
|
1000
|
+
log.error(messages.roles.failedGet(currentEnv, roleNameOrId));
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
if (rolesErr) {
|
|
1005
|
+
log.error(messages.roles.noList(currentEnv));
|
|
1006
|
+
log.error(jsonFormatter(rolesErr));
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
};
|
|
1010
|
+
|
|
788
1011
|
CreateProject = async (project: Project) => {
|
|
789
1012
|
const { currentEnv, log, messages } = this;
|
|
790
1013
|
const contensis = await this.ConnectContensis();
|
package/src/shell.ts
CHANGED
|
@@ -135,7 +135,9 @@ class ContensisShell {
|
|
|
135
135
|
availableCommands.push('login', 'list projects', 'set project');
|
|
136
136
|
if (userId)
|
|
137
137
|
availableCommands.push(
|
|
138
|
+
'create key',
|
|
138
139
|
'create project',
|
|
140
|
+
'create role',
|
|
139
141
|
'diff models',
|
|
140
142
|
'get block',
|
|
141
143
|
'get block logs',
|
|
@@ -144,6 +146,7 @@ class ContensisShell {
|
|
|
144
146
|
'get entries',
|
|
145
147
|
'get model',
|
|
146
148
|
'get project',
|
|
149
|
+
'get role',
|
|
147
150
|
'get version',
|
|
148
151
|
'import contenttypes',
|
|
149
152
|
'import components',
|
|
@@ -152,18 +155,24 @@ class ContensisShell {
|
|
|
152
155
|
'list blocks',
|
|
153
156
|
'list contenttypes',
|
|
154
157
|
'list components',
|
|
155
|
-
'list models',
|
|
156
158
|
'list keys',
|
|
159
|
+
'list models',
|
|
160
|
+
'list roles',
|
|
157
161
|
'list webhooks',
|
|
158
|
-
'create key',
|
|
159
162
|
'push block',
|
|
160
163
|
'release block',
|
|
164
|
+
'remove components',
|
|
165
|
+
'remove contenttypes',
|
|
161
166
|
'remove key',
|
|
162
167
|
'remove entries',
|
|
163
|
-
'remove
|
|
164
|
-
'remove components',
|
|
168
|
+
'remove role',
|
|
165
169
|
'set project name',
|
|
166
|
-
'set project description'
|
|
170
|
+
'set project description',
|
|
171
|
+
'set role name',
|
|
172
|
+
'set role description',
|
|
173
|
+
'set role assignments',
|
|
174
|
+
'set role enabled',
|
|
175
|
+
'set role permissions'
|
|
167
176
|
);
|
|
168
177
|
|
|
169
178
|
const prompt = inquirer.createPromptModule();
|
package/src/util/index.ts
CHANGED
|
@@ -27,6 +27,9 @@ export const tryStringify = (obj: any) => {
|
|
|
27
27
|
}
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
+
export const isSysError = (error: any): error is Error =>
|
|
31
|
+
error?.message !== undefined && error.stack;
|
|
32
|
+
|
|
30
33
|
export const isUuid = (str: string) => {
|
|
31
34
|
// Regular expression to check if string is a valid UUID
|
|
32
35
|
const regexExp =
|
package/src/util/logger.ts
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
import chalk from 'chalk';
|
|
3
3
|
import dateFormat from 'dateformat';
|
|
4
4
|
import deepCleaner from 'deep-cleaner';
|
|
5
|
-
import ProgressBar from 'progress';
|
|
6
|
-
import { tryStringify } from '.';
|
|
5
|
+
// import ProgressBar from 'progress';
|
|
6
|
+
import { isSysError, tryStringify } from '.';
|
|
7
7
|
|
|
8
8
|
type LogMethod = (content: string) => void;
|
|
9
9
|
type LogErrorMethod = (content: string, err?: any, newline?: string) => void;
|
|
@@ -40,7 +40,11 @@ export class Logger {
|
|
|
40
40
|
static error: LogErrorMethod = (content, err, newline = '\n') => {
|
|
41
41
|
const message = `${Logger.getPrefix()} ${Logger.errorText(
|
|
42
42
|
`${Logger.isUserTerminal ? '❌' : '[ERROR]'} ${content}${
|
|
43
|
-
err
|
|
43
|
+
err
|
|
44
|
+
? `\n\n${
|
|
45
|
+
isSysError(err) ? err.toString() : JSON.stringify(err, null, 2)
|
|
46
|
+
}`
|
|
47
|
+
: ''
|
|
44
48
|
}`
|
|
45
49
|
)}${newline}`;
|
|
46
50
|
if (progress.active) progress.current.interrupt(message);
|
|
@@ -92,7 +96,7 @@ export class Logger {
|
|
|
92
96
|
Logger.raw(` ${Logger.infoText(`-------------------------------------`)}`);
|
|
93
97
|
|
|
94
98
|
static object: LogJsonMethod = content => {
|
|
95
|
-
for (const [key, value] of Object.entries(content)) {
|
|
99
|
+
for (const [key, value] of Object.entries(content || {})) {
|
|
96
100
|
if (value && typeof value === 'object') {
|
|
97
101
|
Logger.raw(` ${chalk.bold.grey(key)}:`);
|
|
98
102
|
if (key === 'fields' && Array.isArray(value)) {
|
|
@@ -178,14 +182,20 @@ export class Logger {
|
|
|
178
182
|
else Logger.objectRecurse(item, depth + 1, `${indent} `);
|
|
179
183
|
} else Logger.raw(`${indent}${item}`);
|
|
180
184
|
}
|
|
181
|
-
} else
|
|
185
|
+
} else {
|
|
186
|
+
let pos = 0;
|
|
182
187
|
for (const [key, value] of Object.entries(content)) {
|
|
183
188
|
if (Array.isArray(value)) {
|
|
189
|
+
const thisIndent =
|
|
190
|
+
pos++ === 0
|
|
191
|
+
? `${indent.substring(0, indent.length - 2)}- `
|
|
192
|
+
: indent;
|
|
193
|
+
if (value.length) Logger.raw(`${thisIndent}${chalk.bold.grey(key)}:`);
|
|
184
194
|
for (const item of value) {
|
|
185
195
|
if (item && typeof item === 'object') {
|
|
186
196
|
if (Array.isArray(item) && depth > 3)
|
|
187
197
|
Logger.raw(chalk.grey(`${indent} [${item.join(', ')}]`));
|
|
188
|
-
else Logger.objectRecurse(item, depth + 1, `${indent}`);
|
|
198
|
+
else Logger.objectRecurse(item, depth + 1, `${indent} `);
|
|
189
199
|
} else {
|
|
190
200
|
Logger.raw(`${indent} ${item}`);
|
|
191
201
|
}
|
|
@@ -199,6 +209,7 @@ export class Logger {
|
|
|
199
209
|
Logger.raw(`${indent}${chalk.bold.grey(key)}: ${value}`);
|
|
200
210
|
}
|
|
201
211
|
}
|
|
212
|
+
}
|
|
202
213
|
};
|
|
203
214
|
static raw: LogMethod = (content: string) => {
|
|
204
215
|
if (progress.active) progress.current.interrupt(content);
|
|
@@ -222,13 +233,14 @@ export const logError: LogErrorFunc = (
|
|
|
222
233
|
};
|
|
223
234
|
|
|
224
235
|
export const progress = {
|
|
236
|
+
current: { interrupt: (x: string) => {} },
|
|
225
237
|
active: false,
|
|
226
|
-
done: () => new ProgressBar('', 0),
|
|
227
|
-
colours: { green: '\u001b[42m \u001b[0m', red: '\u001b[41m \u001b[0m' },
|
|
228
|
-
current: new ProgressBar(`:bar`, {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
}),
|
|
238
|
+
// done: () => new ProgressBar('', 0),
|
|
239
|
+
// colours: { green: '\u001b[42m \u001b[0m', red: '\u001b[41m \u001b[0m' },
|
|
240
|
+
// current: new ProgressBar(`:bar`, {
|
|
241
|
+
// complete: '=',
|
|
242
|
+
// incomplete: ' ',
|
|
243
|
+
// width: 20,
|
|
244
|
+
// total: 100,
|
|
245
|
+
// }),
|
|
234
246
|
};
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const LIB_VERSION = "1.0.0-beta.
|
|
1
|
+
export const LIB_VERSION = "1.0.0-beta.64";
|