contensis-cli 1.0.0-beta.6 → 1.0.0-beta.61
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 +760 -75
- package/dist/commands/connect.js +3 -3
- package/dist/commands/connect.js.map +2 -2
- package/dist/commands/create.js +30 -10
- package/dist/commands/create.js.map +2 -2
- package/dist/commands/diff.js +57 -0
- package/dist/commands/diff.js.map +7 -0
- package/dist/commands/get.js +61 -12
- package/dist/commands/get.js.map +2 -2
- package/dist/commands/globalOptions.js +22 -17
- package/dist/commands/globalOptions.js.map +2 -2
- package/dist/commands/import.js +46 -11
- package/dist/commands/import.js.map +2 -2
- package/dist/commands/index.js +9 -1
- package/dist/commands/index.js.map +2 -2
- package/dist/commands/list.js +19 -8
- package/dist/commands/list.js.map +2 -2
- package/dist/commands/login.js +3 -3
- package/dist/commands/login.js.map +2 -2
- package/dist/commands/push.js +8 -4
- package/dist/commands/push.js.map +2 -2
- package/dist/commands/release.js +47 -0
- package/dist/commands/release.js.map +7 -0
- package/dist/commands/remove.js +40 -8
- package/dist/commands/remove.js.map +2 -2
- package/dist/commands/set.js +53 -12
- package/dist/commands/set.js.map +2 -2
- package/dist/localisation/en-GB.js +100 -48
- package/dist/localisation/en-GB.js.map +2 -2
- package/dist/providers/CredentialProvider.js +36 -7
- package/dist/providers/CredentialProvider.js.map +3 -3
- package/dist/providers/SessionCacheProvider.js +21 -1
- package/dist/providers/SessionCacheProvider.js.map +2 -2
- package/dist/providers/file-provider.js +8 -4
- package/dist/providers/file-provider.js.map +3 -3
- package/dist/services/ContensisCliService.js +640 -375
- package/dist/services/ContensisCliService.js.map +3 -3
- package/dist/shell.js +27 -10
- package/dist/shell.js.map +3 -3
- package/dist/util/console.printer.js +171 -55
- package/dist/util/console.printer.js.map +2 -2
- package/dist/util/index.js +5 -2
- package/dist/util/index.js.map +3 -3
- package/dist/util/logger.js +47 -16
- package/dist/util/logger.js.map +2 -2
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +2 -2
- package/src/commands/connect.ts +3 -2
- package/src/commands/create.ts +37 -8
- package/src/commands/diff.ts +41 -0
- package/src/commands/get.ts +80 -5
- package/src/commands/globalOptions.ts +18 -17
- package/src/commands/import.ts +57 -7
- package/src/commands/index.ts +9 -1
- package/src/commands/list.ts +35 -9
- package/src/commands/login.ts +3 -2
- package/src/commands/push.ts +9 -2
- package/src/commands/release.ts +32 -0
- package/src/commands/remove.ts +50 -4
- package/src/commands/set.ts +65 -9
- package/src/localisation/en-GB.ts +146 -65
- package/src/providers/CredentialProvider.ts +39 -6
- package/src/providers/SessionCacheProvider.ts +29 -2
- package/src/providers/file-provider.ts +12 -4
- package/src/services/ContensisCliService.ts +789 -426
- package/src/shell.ts +31 -11
- package/src/util/console.printer.ts +240 -78
- package/src/util/index.ts +12 -6
- package/src/util/logger.ts +87 -18
- package/src/version.ts +1 -1
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { cliCommand } from '~/services/ContensisCliService';
|
|
3
|
+
|
|
4
|
+
export const makeReleaseCommand = () => {
|
|
5
|
+
const release = new Command()
|
|
6
|
+
.command('release')
|
|
7
|
+
.description('release command')
|
|
8
|
+
.addHelpText('after', `\n`)
|
|
9
|
+
.showHelpAfterError(true)
|
|
10
|
+
.exitOverride();
|
|
11
|
+
|
|
12
|
+
release
|
|
13
|
+
.command('block')
|
|
14
|
+
.description('release a block version')
|
|
15
|
+
.argument('<block-id>', 'the name of the block to release')
|
|
16
|
+
.argument('<version>', 'the block version to release')
|
|
17
|
+
.usage('<block-id> <version>')
|
|
18
|
+
.addHelpText(
|
|
19
|
+
'after',
|
|
20
|
+
`
|
|
21
|
+
Example call:
|
|
22
|
+
> release block contensis-app 3\n`
|
|
23
|
+
)
|
|
24
|
+
.action(async (blockId: string, version: string, opts) => {
|
|
25
|
+
await cliCommand(['release', 'block', blockId], opts).ReleaseBlock(
|
|
26
|
+
blockId,
|
|
27
|
+
version
|
|
28
|
+
);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
return release;
|
|
32
|
+
};
|
package/src/commands/remove.ts
CHANGED
|
@@ -1,27 +1,34 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
import { cliCommand } from '~/services/ContensisCliService';
|
|
3
3
|
import { shell } from '~/shell';
|
|
4
|
-
import {
|
|
4
|
+
import { Logger } from '~/util/logger';
|
|
5
|
+
import { commit, mapContensisOpts, zenql } from './globalOptions';
|
|
5
6
|
|
|
6
7
|
export const makeRemoveCommand = () => {
|
|
7
8
|
const remove = new Command()
|
|
8
9
|
.command('remove')
|
|
10
|
+
.description('remove command')
|
|
11
|
+
.addHelpText('after', `\n`)
|
|
9
12
|
.showHelpAfterError(true)
|
|
10
13
|
.exitOverride();
|
|
11
14
|
|
|
12
15
|
remove
|
|
13
16
|
.command('project')
|
|
17
|
+
.description('remove an entire project')
|
|
14
18
|
.argument('<projectId>', 'the project id to delete')
|
|
15
19
|
.usage('<projectId>')
|
|
20
|
+
.addHelpText('after', `\n`)
|
|
16
21
|
.action(async (projectId, opts) => {
|
|
17
22
|
const project = await cliCommand(
|
|
18
23
|
['remove', 'project', projectId],
|
|
19
24
|
opts
|
|
20
25
|
).SetProject(projectId);
|
|
21
|
-
if (project) await shell().
|
|
26
|
+
if (project) await shell().restart();
|
|
22
27
|
});
|
|
28
|
+
|
|
23
29
|
remove
|
|
24
30
|
.command('key')
|
|
31
|
+
.description('remove api key')
|
|
25
32
|
.argument('<id>', 'the id of the API key to delete')
|
|
26
33
|
.usage('<id>')
|
|
27
34
|
.addHelpText(
|
|
@@ -37,6 +44,7 @@ Example call:
|
|
|
37
44
|
|
|
38
45
|
remove
|
|
39
46
|
.command('components')
|
|
47
|
+
.description('delete components')
|
|
40
48
|
.argument('<id...>', 'the id(s) of the components to delete')
|
|
41
49
|
.addOption(commit)
|
|
42
50
|
.usage('<id> [--commit]')
|
|
@@ -49,13 +57,14 @@ Example call:
|
|
|
49
57
|
)
|
|
50
58
|
.action(async (id: string[], opts) => {
|
|
51
59
|
await cliCommand(
|
|
52
|
-
['remove', 'components', id.join('
|
|
60
|
+
['remove', 'components', id.join(' ')],
|
|
53
61
|
opts
|
|
54
62
|
).RemoveComponents(id, opts.commit);
|
|
55
63
|
});
|
|
56
64
|
|
|
57
65
|
remove
|
|
58
66
|
.command('contenttypes')
|
|
67
|
+
.description('delete content types')
|
|
59
68
|
.argument('<id...>', 'the id(s) of the content types to delete')
|
|
60
69
|
.addOption(commit)
|
|
61
70
|
.usage('<id> [--commit]')
|
|
@@ -68,10 +77,47 @@ Example call:
|
|
|
68
77
|
)
|
|
69
78
|
.action(async (id: string[], opts) => {
|
|
70
79
|
await cliCommand(
|
|
71
|
-
['remove', 'contenttypes', id.join('
|
|
80
|
+
['remove', 'contenttypes', id.join(' ')],
|
|
72
81
|
opts
|
|
73
82
|
).RemoveContentTypes(id, opts.commit);
|
|
74
83
|
});
|
|
75
84
|
|
|
85
|
+
const removeEntries = remove
|
|
86
|
+
.command('entries')
|
|
87
|
+
.description('delete entries')
|
|
88
|
+
.argument(
|
|
89
|
+
'[ids...]',
|
|
90
|
+
'the entry id(s) to delete ...or add *** if you wish to delete all entries in all content types'
|
|
91
|
+
)
|
|
92
|
+
.addOption(zenql)
|
|
93
|
+
.addOption(commit)
|
|
94
|
+
.addHelpText(
|
|
95
|
+
'after',
|
|
96
|
+
`
|
|
97
|
+
Example call:
|
|
98
|
+
> remove entries a1c25591-8c9b-50e2-96d8-f6c774fcf023 8df914cc-1da1-59d6-86e0-8ea4ebd99aaa
|
|
99
|
+
> remove entries --zenql "sys.contentTypeId = test"
|
|
100
|
+
`
|
|
101
|
+
)
|
|
102
|
+
.action(async (entryIds: string[], opts) => {
|
|
103
|
+
const removeAll = entryIds?.[0] === '***';
|
|
104
|
+
|
|
105
|
+
// Remove all asterisks from args
|
|
106
|
+
if (entryIds?.[0] && !entryIds[0].replace(/\*/g, '')) entryIds.pop();
|
|
107
|
+
|
|
108
|
+
const hasArgs = !!(entryIds?.length || opts.zenql || removeAll);
|
|
109
|
+
if (!hasArgs) {
|
|
110
|
+
Logger.help(
|
|
111
|
+
`Not enough arguments supplied\n\n${removeEntries.helpInformation()}`
|
|
112
|
+
);
|
|
113
|
+
} else {
|
|
114
|
+
await cliCommand(
|
|
115
|
+
['remove', 'entries', entryIds.join(' ')],
|
|
116
|
+
opts,
|
|
117
|
+
mapContensisOpts({ entryIds, ...opts })
|
|
118
|
+
).RemoveEntries(opts.commit);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
|
|
76
122
|
return remove;
|
|
77
123
|
};
|
package/src/commands/set.ts
CHANGED
|
@@ -5,35 +5,91 @@ import { shell } from '~/shell';
|
|
|
5
5
|
export const makeSetCommand = () => {
|
|
6
6
|
const set = new Command()
|
|
7
7
|
.command('set')
|
|
8
|
+
.description('set command')
|
|
9
|
+
.addHelpText('after', `\n`)
|
|
8
10
|
.showHelpAfterError(true)
|
|
9
11
|
.exitOverride();
|
|
10
|
-
|
|
12
|
+
|
|
13
|
+
const project = set
|
|
11
14
|
.command('project')
|
|
15
|
+
.description('set current working project')
|
|
12
16
|
.argument('<projectId>', 'the project id to work with')
|
|
13
17
|
.usage('<projectId>')
|
|
18
|
+
.addHelpText(
|
|
19
|
+
'after',
|
|
20
|
+
`
|
|
21
|
+
Example call:
|
|
22
|
+
> set project website\n`
|
|
23
|
+
)
|
|
14
24
|
.action(async projectId => {
|
|
15
|
-
const
|
|
25
|
+
const nextProjectId = cliCommand([
|
|
16
26
|
'set',
|
|
17
27
|
'project',
|
|
18
28
|
projectId,
|
|
19
29
|
]).SetProject(projectId);
|
|
20
|
-
if (
|
|
30
|
+
if (nextProjectId) await shell().restart();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
project
|
|
34
|
+
.command('name')
|
|
35
|
+
.description('update project name')
|
|
36
|
+
.argument('<"Project name">', 'update the current project name')
|
|
37
|
+
.usage('<"Project name">')
|
|
38
|
+
.addHelpText(
|
|
39
|
+
'after',
|
|
40
|
+
`
|
|
41
|
+
Example call:
|
|
42
|
+
> set project name "Project name"\n`
|
|
43
|
+
)
|
|
44
|
+
.action(async (name: string, opts) => {
|
|
45
|
+
const success = await cliCommand(
|
|
46
|
+
['set', 'project', 'name'],
|
|
47
|
+
opts
|
|
48
|
+
).UpdateProject({
|
|
49
|
+
name,
|
|
50
|
+
});
|
|
51
|
+
if (success) await shell().restart();
|
|
21
52
|
});
|
|
53
|
+
|
|
54
|
+
project
|
|
55
|
+
.command('description')
|
|
56
|
+
.description('update project description')
|
|
57
|
+
.argument(
|
|
58
|
+
'<"Project description">',
|
|
59
|
+
'update the current project description'
|
|
60
|
+
)
|
|
61
|
+
.usage('<"Project description">')
|
|
62
|
+
.addHelpText(
|
|
63
|
+
'after',
|
|
64
|
+
`
|
|
65
|
+
Example call:
|
|
66
|
+
> set project description "Description of project"\n`
|
|
67
|
+
)
|
|
68
|
+
.action(async (description: string, opts) => {
|
|
69
|
+
const success = await cliCommand(
|
|
70
|
+
['set', 'project', 'description'],
|
|
71
|
+
opts
|
|
72
|
+
).UpdateProject({
|
|
73
|
+
description,
|
|
74
|
+
});
|
|
75
|
+
if (success) await shell().restart();
|
|
76
|
+
});
|
|
77
|
+
|
|
22
78
|
set
|
|
23
79
|
.command('version')
|
|
80
|
+
.description('set content version')
|
|
24
81
|
.addArgument(
|
|
25
82
|
new Argument('<versionStatus>', 'content version status')
|
|
26
83
|
.choices(['latest', 'published'])
|
|
27
84
|
.default('latest')
|
|
28
85
|
)
|
|
29
86
|
.usage('<latest/published>')
|
|
87
|
+
.addHelpText('after', `\n`)
|
|
30
88
|
.action(async versionStatus => {
|
|
31
|
-
const success =
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
]).SetVersion(versionStatus);
|
|
36
|
-
if (success) await shell().start();
|
|
89
|
+
const success = cliCommand(['set', 'version', versionStatus]).SetVersion(
|
|
90
|
+
versionStatus
|
|
91
|
+
);
|
|
92
|
+
if (success) await shell().restart();
|
|
37
93
|
});
|
|
38
94
|
|
|
39
95
|
return set;
|
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
BlockRunningStatus,
|
|
3
|
+
MigrateModelsResult,
|
|
4
|
+
MigrateStatus,
|
|
5
|
+
} from 'migratortron';
|
|
2
6
|
import { Logger } from '~/util/logger';
|
|
3
7
|
|
|
4
8
|
export const LogMessages = {
|
|
5
9
|
app: {
|
|
6
10
|
contensis: () => 'Contensis',
|
|
7
11
|
quit: () => `Goodbye 👋\n`,
|
|
8
|
-
startup: () =>
|
|
9
|
-
|
|
12
|
+
startup: (version: string) =>
|
|
13
|
+
`v${version} © 2001-${new Date().getFullYear()} Zengenti 🇬🇧. \n - Creators of Contensis and purveyors of other fine software\n\n👋 Welcome to the contensis-cli\n`,
|
|
10
14
|
help: () =>
|
|
11
15
|
'Press [CTRL]+[C] or type "quit" to return to your system shell\nPress [TAB] for suggestions\n',
|
|
12
16
|
suggestions: () =>
|
|
@@ -73,8 +77,10 @@ export const LogMessages = {
|
|
|
73
77
|
'the shared secret to use when logging in with a client id',
|
|
74
78
|
},
|
|
75
79
|
},
|
|
76
|
-
passwordPrompt: (env
|
|
77
|
-
|
|
80
|
+
passwordPrompt: (env?: string, userId?: string) =>
|
|
81
|
+
userId
|
|
82
|
+
? `Enter password for ${userId}@${env}:`
|
|
83
|
+
: `Please enter a password`,
|
|
78
84
|
failed: (env: string, userId: string) =>
|
|
79
85
|
`Unable to login to ${env} as ${userId}`,
|
|
80
86
|
success: (env: string, userId: string) =>
|
|
@@ -87,49 +93,38 @@ export const LogMessages = {
|
|
|
87
93
|
projects: {
|
|
88
94
|
list: () => `Available projects:`,
|
|
89
95
|
noList: () => `Cannot retrieve projects list`,
|
|
90
|
-
set: (projectId: string) =>
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
`[${env}] ${commit ? `Deleted` : `Will delete`} content type "${id}"`,
|
|
105
|
-
failedRemove: (env: string, id: string) =>
|
|
106
|
-
`[${env}] Unable to delete content type "${id}"`,
|
|
107
|
-
},
|
|
108
|
-
components: {
|
|
109
|
-
list: (projectId: string) => `Components in "${projectId}":`,
|
|
110
|
-
noList: (projectId: string) =>
|
|
111
|
-
`[${projectId}] Cannot retrieve components list`,
|
|
112
|
-
get: (projectId: string, componentId: string) =>
|
|
113
|
-
`[${projectId}] Component "${componentId}"`,
|
|
114
|
-
failedGet: (projectId: string, componentId: string) =>
|
|
115
|
-
`[${projectId}] Unable to get component "${componentId}"`,
|
|
116
|
-
created: (projectId: string, componentId: string, status?: string) =>
|
|
117
|
-
`[${projectId}] Component ${status}d "${componentId}"`,
|
|
118
|
-
removed: (env: string, id: string, commit: boolean) =>
|
|
119
|
-
`[${env}] ${commit ? `Deleted` : `Will delete`} component "${id}"`,
|
|
120
|
-
failedRemove: (env: string, id: string) =>
|
|
121
|
-
`[${env}] Unable to delete component "${id}"`,
|
|
122
|
-
},
|
|
123
|
-
version: {
|
|
124
|
-
set: (env: string, versionStatus: string) =>
|
|
125
|
-
`[${env}] Content version status set to "${versionStatus}"`,
|
|
126
|
-
invalid: (versionStatus: string) =>
|
|
127
|
-
`Content version status "${versionStatus}" is not valid, allowed values are "published" or "latest".`,
|
|
128
|
-
noEnv: () =>
|
|
129
|
-
`No Contensis environment set, connect to your Contensis cloud instance using "contensis connect {cms alias}"`,
|
|
96
|
+
set: (projectId: string) =>
|
|
97
|
+
`Current project is set to ${Logger.highlightText(projectId)}`,
|
|
98
|
+
failedSet: (projectId: string) =>
|
|
99
|
+
`Project ${Logger.highlightText(projectId)} not found`,
|
|
100
|
+
tip: () =>
|
|
101
|
+
`You need to set your current working project with "set project {projectId}"`,
|
|
102
|
+
created: (env: string, id: string) =>
|
|
103
|
+
`[${env}] Created project ${Logger.highlightText(id)}`,
|
|
104
|
+
failedCreate: (env: string, id: string) =>
|
|
105
|
+
`[${env}] Unable to create project ${Logger.highlightText(id)}`,
|
|
106
|
+
updated: (env: string, id: string) =>
|
|
107
|
+
`[${env}] Updated project ${Logger.highlightText(id)}`,
|
|
108
|
+
failedUpdate: (env: string, id: string) =>
|
|
109
|
+
`[${env}] Unable to update project ${Logger.highlightText(id)}`,
|
|
130
110
|
},
|
|
131
|
-
|
|
132
|
-
|
|
111
|
+
migrate: {
|
|
112
|
+
models: {
|
|
113
|
+
result: (
|
|
114
|
+
status: keyof MigrateModelsResult['project']['contentTypes']
|
|
115
|
+
) => {
|
|
116
|
+
switch (status) {
|
|
117
|
+
case 'created':
|
|
118
|
+
case 'updated':
|
|
119
|
+
return Logger.successText;
|
|
120
|
+
case 'errors':
|
|
121
|
+
return Logger.errorText;
|
|
122
|
+
default:
|
|
123
|
+
return Logger.infoText;
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
status: (status: MigrateStatus) => {
|
|
133
128
|
switch (status) {
|
|
134
129
|
case 'no change':
|
|
135
130
|
return Logger.successText;
|
|
@@ -145,23 +140,78 @@ export const LogMessages = {
|
|
|
145
140
|
return Logger.infoText;
|
|
146
141
|
}
|
|
147
142
|
},
|
|
143
|
+
},
|
|
144
|
+
models: {
|
|
145
|
+
list: (projectId: string) =>
|
|
146
|
+
`Content models in ${Logger.highlightText(projectId)}:`,
|
|
147
|
+
noList: (projectId: string) =>
|
|
148
|
+
`[${projectId}] Cannot retrieve content models`,
|
|
149
|
+
get: (projectId: string, id: string) =>
|
|
150
|
+
`[${projectId}] Content models ${Logger.infoText(`[ ${id} ]`)}`,
|
|
151
|
+
failedGet: (projectId: string, id: string) =>
|
|
152
|
+
`[${projectId}] Unable to get content models ${Logger.highlightText(id)}`,
|
|
153
|
+
},
|
|
154
|
+
contenttypes: {
|
|
155
|
+
list: (projectId: string) =>
|
|
156
|
+
`Content types in ${Logger.highlightText(projectId)}:`,
|
|
157
|
+
get: (projectId: string, id: string) =>
|
|
158
|
+
`[${projectId}] Content type ${Logger.highlightText(id)}`,
|
|
159
|
+
failedGet: (projectId: string, id: string) =>
|
|
160
|
+
`[${projectId}] Unable to get content type ${Logger.highlightText(id)}`,
|
|
161
|
+
created: (projectId: string, id: string, status?: string) =>
|
|
162
|
+
`[${projectId}] Content type ${status}d ${Logger.highlightText(id)}`,
|
|
163
|
+
removed: (env: string, id: string, commit: boolean) =>
|
|
164
|
+
`[${env}] ${
|
|
165
|
+
commit ? `Deleted` : `Will delete`
|
|
166
|
+
} content type ${Logger.highlightText(id)}`,
|
|
167
|
+
failedRemove: (env: string, id: string) =>
|
|
168
|
+
`[${env}] Unable to delete content type ${Logger.highlightText(id)}`,
|
|
169
|
+
},
|
|
170
|
+
components: {
|
|
171
|
+
list: (projectId: string) =>
|
|
172
|
+
`Components in ${Logger.highlightText(projectId)}:`,
|
|
173
|
+
get: (projectId: string, id: string) =>
|
|
174
|
+
`[${projectId}] Component ${Logger.highlightText(id)}`,
|
|
175
|
+
failedGet: (projectId: string, id: string) =>
|
|
176
|
+
`[${projectId}] Unable to get component ${Logger.highlightText(id)}`,
|
|
177
|
+
created: (projectId: string, id: string, status?: string) =>
|
|
178
|
+
`[${projectId}] Component ${status}d ${Logger.highlightText(id)}`,
|
|
148
179
|
removed: (env: string, id: string, commit: boolean) =>
|
|
149
|
-
`[${env}] ${
|
|
180
|
+
`[${env}] ${
|
|
181
|
+
commit ? `Deleted` : `Will delete`
|
|
182
|
+
} component ${Logger.highlightText(id)}`,
|
|
150
183
|
failedRemove: (env: string, id: string) =>
|
|
151
|
-
`[${env}] Unable to delete
|
|
152
|
-
|
|
153
|
-
|
|
184
|
+
`[${env}] Unable to delete component ${Logger.highlightText(id)}`,
|
|
185
|
+
},
|
|
186
|
+
version: {
|
|
187
|
+
set: (env: string, versionStatus: string) =>
|
|
188
|
+
`[${env}] Content version status set to "${versionStatus}"`,
|
|
189
|
+
invalid: (versionStatus: string) =>
|
|
190
|
+
`Content version status "${versionStatus}" is not valid, allowed values are "published" or "latest".`,
|
|
191
|
+
noEnv: () =>
|
|
192
|
+
`No Contensis environment set, connect to your Contensis cloud instance using "contensis connect {cms alias}"`,
|
|
193
|
+
},
|
|
194
|
+
entries: {
|
|
195
|
+
imported: (env: string, commit: boolean, count: number) =>
|
|
196
|
+
`[${env}] ${commit ? `Imported` : `Will import`} ${count} entries`,
|
|
197
|
+
failedImport: (env: string) => `[${env}] Unable to import entries`,
|
|
198
|
+
removed: (env: string, commit: boolean) =>
|
|
199
|
+
`[${env}] ${commit ? `Deleted` : `Will delete`} entries`,
|
|
200
|
+
failedRemove: (env: string) => `[${env}] Unable to delete entries`,
|
|
201
|
+
notFound: (env: string) => `[${env}] Entries were not found`,
|
|
202
|
+
commitTip: () => `Add --commit flag to commit the previewed changes`,
|
|
154
203
|
},
|
|
155
204
|
keys: {
|
|
156
205
|
list: (env: string) => `[${env}] API keys:`,
|
|
157
206
|
noList: (env: string) => `[${env}] Cannot retrieve API`,
|
|
158
207
|
created: (env: string, name: string) =>
|
|
159
|
-
`[${env}] Created API key
|
|
208
|
+
`[${env}] Created API key ${Logger.highlightText(name)}`,
|
|
160
209
|
failedCreate: (env: string, name: string) =>
|
|
161
|
-
`[${env}] Unable to create API key
|
|
162
|
-
removed: (env: string, id: string) =>
|
|
210
|
+
`[${env}] Unable to create API key ${Logger.highlightText(name)}`,
|
|
211
|
+
removed: (env: string, id: string) =>
|
|
212
|
+
`[${env}] Deleted API key ${Logger.highlightText(id)}`,
|
|
163
213
|
failedRemove: (env: string, id: string) =>
|
|
164
|
-
`[${env}] Unable to delete API key
|
|
214
|
+
`[${env}] Unable to delete API key ${Logger.highlightText(id)}`,
|
|
165
215
|
},
|
|
166
216
|
blocks: {
|
|
167
217
|
runningStatus: (status: BlockRunningStatus | 'broken') => {
|
|
@@ -180,32 +230,63 @@ export const LogMessages = {
|
|
|
180
230
|
return Logger.infoText(status);
|
|
181
231
|
}
|
|
182
232
|
},
|
|
183
|
-
get: (env: string) =>
|
|
233
|
+
get: (id: string, env: string, projectId?: string) =>
|
|
234
|
+
`[${env}] Block ${id} in project ${projectId}:`,
|
|
184
235
|
list: (env: string, projectId?: string) =>
|
|
185
236
|
`[${env}] Blocks in project ${projectId}:`,
|
|
186
237
|
noList: (env: string, projectId?: string) =>
|
|
187
238
|
`[${env}] Cannot retrieve blocks in project ${projectId}`,
|
|
239
|
+
getLogs: (id: string, branch: string, env: string, projectId?: string) =>
|
|
240
|
+
`[${env}] Requesting logs from block ${Logger.highlightText(
|
|
241
|
+
id
|
|
242
|
+
)} in branch ${branch} in project ${projectId}`,
|
|
243
|
+
failedGetLogs: (id: string, env: string, projectId?: string) =>
|
|
244
|
+
`[${env}] Unable to fetch block logs for ${Logger.highlightText(
|
|
245
|
+
id
|
|
246
|
+
)} in project ${projectId}`,
|
|
188
247
|
tryPush: (id: string, branch: string, env: string, projectId?: string) =>
|
|
189
|
-
`[${env}] Request to push block
|
|
248
|
+
`[${env}] Request to push block ${Logger.highlightText(
|
|
249
|
+
id
|
|
250
|
+
)} in branch ${branch} in project ${projectId}`,
|
|
190
251
|
pushed: (id: string, branch: string, env: string, projectId?: string) =>
|
|
191
|
-
`[${env}] Pushed block
|
|
252
|
+
`[${env}] Pushed block ${Logger.highlightText(
|
|
253
|
+
id
|
|
254
|
+
)} in branch ${branch} in project ${projectId}`,
|
|
192
255
|
failedPush: (id: string, env: string, projectId?: string) =>
|
|
193
|
-
`[${env}] Unable to push block
|
|
256
|
+
`[${env}] Unable to push block ${Logger.highlightText(
|
|
257
|
+
id
|
|
258
|
+
)} in project ${projectId}`,
|
|
259
|
+
released: (id: string, env: string, projectId?: string) =>
|
|
260
|
+
`[${env}] Released block ${Logger.highlightText(
|
|
261
|
+
id
|
|
262
|
+
)} in project ${projectId}`,
|
|
263
|
+
failedRelease: (id: string, env: string, projectId?: string) =>
|
|
264
|
+
`[${env}] Unable to release block ${Logger.highlightText(
|
|
265
|
+
id
|
|
266
|
+
)} in project ${projectId}`,
|
|
194
267
|
deleted: (id: string, env: string, projectId?: string) =>
|
|
195
|
-
`[${env}] Deleted block
|
|
268
|
+
`[${env}] Deleted block ${Logger.highlightText(
|
|
269
|
+
id
|
|
270
|
+
)} in project ${projectId}`,
|
|
196
271
|
failedDelete: (id: string, env: string, projectId?: string) =>
|
|
197
|
-
`[${env}] Unable to delete block
|
|
272
|
+
`[${env}] Unable to delete block ${Logger.highlightText(
|
|
273
|
+
id
|
|
274
|
+
)} in project ${projectId}`,
|
|
198
275
|
},
|
|
199
276
|
webhooks: {
|
|
200
277
|
list: (env: string) => `[${env}] Webhook subscriptions:`,
|
|
201
278
|
noList: (env: string) => `[${env}] Cannot retrieve webhook subscriptions`,
|
|
202
279
|
created: (env: string, name: string) =>
|
|
203
|
-
`[${env}] Created Webhook subscription
|
|
280
|
+
`[${env}] Created Webhook subscription ${Logger.highlightText(name)}`,
|
|
204
281
|
failedCreate: (env: string, name: string) =>
|
|
205
|
-
`[${env}] Unable to create Webhook subscription
|
|
282
|
+
`[${env}] Unable to create Webhook subscription ${Logger.highlightText(
|
|
283
|
+
name
|
|
284
|
+
)}`,
|
|
206
285
|
deleted: (env: string, id: string) =>
|
|
207
|
-
`[${env}] Deleted Webhook subscription
|
|
286
|
+
`[${env}] Deleted Webhook subscription ${Logger.highlightText(id)}`,
|
|
208
287
|
failedDelete: (env: string, id: string) =>
|
|
209
|
-
`[${env}] Unable to delete Webhook subscription
|
|
288
|
+
`[${env}] Unable to delete Webhook subscription ${Logger.highlightText(
|
|
289
|
+
id
|
|
290
|
+
)}`,
|
|
210
291
|
},
|
|
211
292
|
};
|
|
@@ -10,6 +10,7 @@ interface Remarks {
|
|
|
10
10
|
|
|
11
11
|
class CredentialProvider {
|
|
12
12
|
private serviceId: string;
|
|
13
|
+
private keytar!: typeof keytar;
|
|
13
14
|
private userId: string = '';
|
|
14
15
|
private passwordFallback?: string;
|
|
15
16
|
|
|
@@ -29,9 +30,34 @@ class CredentialProvider {
|
|
|
29
30
|
this.passwordFallback = passwordFallback;
|
|
30
31
|
}
|
|
31
32
|
|
|
33
|
+
Import = async () => {
|
|
34
|
+
try {
|
|
35
|
+
this.keytar = (await import('keytar')).default;
|
|
36
|
+
} catch (ex) {
|
|
37
|
+
this.keytar = {
|
|
38
|
+
findCredentials: async () => {
|
|
39
|
+
throw ex;
|
|
40
|
+
},
|
|
41
|
+
getPassword: async () => {
|
|
42
|
+
throw ex;
|
|
43
|
+
},
|
|
44
|
+
findPassword: async () => {
|
|
45
|
+
throw ex;
|
|
46
|
+
},
|
|
47
|
+
setPassword: async () => {
|
|
48
|
+
throw ex;
|
|
49
|
+
},
|
|
50
|
+
deletePassword: async () => {
|
|
51
|
+
throw ex;
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
32
57
|
Init = async (): Promise<[Error, CredentialProvider]> => {
|
|
58
|
+
await this.Import();
|
|
33
59
|
const [err, stored] = (await to(
|
|
34
|
-
keytar.findCredentials(this.serviceId)
|
|
60
|
+
this.keytar.findCredentials(this.serviceId)
|
|
35
61
|
)) as [
|
|
36
62
|
Error,
|
|
37
63
|
{
|
|
@@ -40,8 +66,10 @@ class CredentialProvider {
|
|
|
40
66
|
}[]
|
|
41
67
|
];
|
|
42
68
|
if (err && this.passwordFallback) {
|
|
43
|
-
this.current = {
|
|
44
|
-
|
|
69
|
+
this.current = {
|
|
70
|
+
account: this.userId,
|
|
71
|
+
password: this.passwordFallback,
|
|
72
|
+
};
|
|
45
73
|
}
|
|
46
74
|
if (!err) {
|
|
47
75
|
this.remarks = { secure: true };
|
|
@@ -49,16 +77,21 @@ class CredentialProvider {
|
|
|
49
77
|
stored?.find(
|
|
50
78
|
u => u?.account?.toLowerCase() === this.userId.toLowerCase()
|
|
51
79
|
) || null;
|
|
80
|
+
|
|
81
|
+
if (!this.current && this.passwordFallback) {
|
|
82
|
+
await this.Save(this.passwordFallback);
|
|
83
|
+
return await this.Init();
|
|
84
|
+
}
|
|
52
85
|
}
|
|
53
86
|
return [err, this];
|
|
54
87
|
};
|
|
55
88
|
|
|
56
89
|
Save = async (password: string) => {
|
|
57
90
|
const [err] = await to(
|
|
58
|
-
keytar.setPassword(this.serviceId, this.userId, password)
|
|
91
|
+
this.keytar.setPassword(this.serviceId, this.userId, password)
|
|
59
92
|
);
|
|
60
93
|
|
|
61
|
-
if (!err) Logger.info(`${this.serviceId} - credentials saved`);
|
|
94
|
+
// if (!err) Logger.info(`${this.serviceId} - credentials saved`);
|
|
62
95
|
return err && !this.passwordFallback ? err : true;
|
|
63
96
|
};
|
|
64
97
|
|
|
@@ -68,7 +101,7 @@ class CredentialProvider {
|
|
|
68
101
|
return true;
|
|
69
102
|
} else {
|
|
70
103
|
const [err] = await to(
|
|
71
|
-
keytar.deletePassword(this.serviceId, this.userId)
|
|
104
|
+
this.keytar.deletePassword(this.serviceId, this.userId)
|
|
72
105
|
);
|
|
73
106
|
|
|
74
107
|
Logger.warning(`${this.serviceId} - invalid credentials removed`);
|
|
@@ -3,7 +3,8 @@ import path from 'path';
|
|
|
3
3
|
import clone from 'lodash/cloneDeep';
|
|
4
4
|
import mergeWith from 'lodash/mergeWith';
|
|
5
5
|
import unionBy from 'lodash/unionBy';
|
|
6
|
-
import {
|
|
6
|
+
import { appRootDir } from './file-provider';
|
|
7
|
+
import { isJson, tryParse } from '~/util';
|
|
7
8
|
import { Logger } from '~/util/logger';
|
|
8
9
|
|
|
9
10
|
class SessionCacheProvider {
|
|
@@ -11,7 +12,7 @@ class SessionCacheProvider {
|
|
|
11
12
|
private cache = {} as SessionCache;
|
|
12
13
|
|
|
13
14
|
constructor() {
|
|
14
|
-
this.localFilePath = path.join(
|
|
15
|
+
this.localFilePath = path.join(appRootDir, 'environments.json');
|
|
15
16
|
this.cache = {
|
|
16
17
|
currentTimestamp: new Date().toISOString(),
|
|
17
18
|
environments: {},
|
|
@@ -69,6 +70,32 @@ class SessionCacheProvider {
|
|
|
69
70
|
}
|
|
70
71
|
return this.Get();
|
|
71
72
|
};
|
|
73
|
+
|
|
74
|
+
UpdateEnv = (
|
|
75
|
+
updateContent: Partial<EnvironmentCache>,
|
|
76
|
+
env = this.cache.currentEnvironment,
|
|
77
|
+
setCurrentEnv = true
|
|
78
|
+
) => {
|
|
79
|
+
try {
|
|
80
|
+
const environment = this.cache.environments[env || ''];
|
|
81
|
+
|
|
82
|
+
this.cache.environments[env || ''] = {
|
|
83
|
+
...environment,
|
|
84
|
+
...updateContent,
|
|
85
|
+
};
|
|
86
|
+
this.Update({
|
|
87
|
+
currentEnvironment: setCurrentEnv ? env : this.cache.currentEnvironment,
|
|
88
|
+
environments: this.cache.environments,
|
|
89
|
+
});
|
|
90
|
+
} catch (ex: any) {
|
|
91
|
+
// Problem merging cache data for update
|
|
92
|
+
Logger.error(
|
|
93
|
+
`Problem updating environment "${env}" in environments.json`
|
|
94
|
+
);
|
|
95
|
+
Logger.error(ex);
|
|
96
|
+
}
|
|
97
|
+
return this.Get();
|
|
98
|
+
};
|
|
72
99
|
}
|
|
73
100
|
|
|
74
101
|
export default SessionCacheProvider;
|