contensis-cli 1.0.0-beta.10 → 1.0.0-beta.100
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 +1146 -78
- package/cli.js +3 -0
- package/dist/commands/connect.js +3 -3
- package/dist/commands/connect.js.map +2 -2
- package/dist/commands/create.js +45 -10
- package/dist/commands/create.js.map +2 -2
- package/dist/commands/dev.js +71 -0
- package/dist/commands/dev.js.map +7 -0
- package/dist/commands/diff.js +57 -0
- package/dist/commands/diff.js.map +7 -0
- package/dist/commands/execute.js +103 -0
- package/dist/commands/execute.js.map +7 -0
- package/dist/commands/get.js +169 -32
- package/dist/commands/get.js.map +3 -3
- package/dist/commands/globalOptions.js +37 -12
- package/dist/commands/globalOptions.js.map +2 -2
- package/dist/commands/import.js +65 -12
- package/dist/commands/import.js.map +2 -2
- package/dist/commands/index.js +22 -2
- package/dist/commands/index.js.map +2 -2
- package/dist/commands/list.js +53 -10
- package/dist/commands/list.js.map +2 -2
- package/dist/commands/login.js +2 -2
- package/dist/commands/login.js.map +2 -2
- package/dist/commands/push.js +17 -13
- package/dist/commands/push.js.map +2 -2
- package/dist/commands/remove.js +51 -8
- package/dist/commands/remove.js.map +2 -2
- package/dist/commands/set.js +139 -12
- package/dist/commands/set.js.map +2 -2
- package/dist/index.js +1 -1
- package/dist/index.js.map +2 -2
- package/dist/localisation/en-GB.js +297 -49
- package/dist/localisation/en-GB.js.map +2 -2
- package/dist/mappers/ContensisCliService-to-RequestHanderSiteConfigYaml.js +56 -0
- package/dist/mappers/ContensisCliService-to-RequestHanderSiteConfigYaml.js.map +7 -0
- package/dist/mappers/DevInit-to-CIWorkflow.js +374 -0
- package/dist/mappers/DevInit-to-CIWorkflow.js.map +7 -0
- package/dist/mappers/DevInit-to-RolePermissions.js +56 -0
- package/dist/mappers/DevInit-to-RolePermissions.js.map +7 -0
- package/dist/mappers/DevRequests-to-RequestHanderSiteConfigYaml.js +56 -0
- package/dist/mappers/DevRequests-to-RequestHanderSiteConfigYaml.js.map +7 -0
- package/dist/models/CliService.d.js +17 -0
- package/dist/models/CliService.d.js.map +7 -0
- package/dist/models/DevService.d.js +17 -0
- package/dist/models/DevService.d.js.map +7 -0
- package/dist/providers/CredentialProvider.js +46 -14
- 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 +12 -6
- package/dist/providers/file-provider.js.map +3 -3
- package/dist/services/ContensisCliService.js +1211 -420
- package/dist/services/ContensisCliService.js.map +3 -3
- package/dist/services/ContensisDevService.js +368 -0
- package/dist/services/ContensisDevService.js.map +7 -0
- package/dist/services/ContensisRoleService.js +114 -0
- package/dist/services/ContensisRoleService.js.map +7 -0
- package/dist/shell.js +58 -18
- 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/diff.js +116 -0
- package/dist/util/diff.js.map +7 -0
- package/dist/util/dotenv.js +57 -0
- package/dist/util/dotenv.js.map +7 -0
- package/dist/util/find.js +31 -0
- package/dist/util/find.js.map +7 -0
- package/dist/util/git.js +128 -0
- package/dist/util/git.js.map +7 -0
- package/dist/util/index.js +8 -2
- package/dist/util/index.js.map +3 -3
- package/dist/util/logger.js +90 -29
- package/dist/util/logger.js.map +3 -3
- package/dist/util/os.js +42 -0
- package/dist/util/os.js.map +7 -0
- package/dist/util/timers.js +49 -0
- package/dist/util/timers.js.map +7 -0
- package/dist/util/yaml.js +45 -0
- package/dist/util/yaml.js.map +7 -0
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/esbuild.config.js +3 -1
- package/package.json +14 -3
- package/src/commands/connect.ts +3 -2
- package/src/commands/create.ts +61 -8
- package/src/commands/dev.ts +69 -0
- package/src/commands/diff.ts +41 -0
- package/src/commands/execute.ts +117 -0
- package/src/commands/get.ts +242 -28
- package/src/commands/globalOptions.ts +42 -12
- package/src/commands/import.ts +83 -8
- package/src/commands/index.ts +22 -1
- package/src/commands/list.ts +85 -11
- package/src/commands/login.ts +2 -1
- package/src/commands/push.ts +18 -11
- package/src/commands/remove.ts +66 -4
- package/src/commands/set.ts +189 -9
- package/src/index.ts +1 -4
- package/src/localisation/en-GB.ts +428 -66
- package/src/mappers/ContensisCliService-to-RequestHanderSiteConfigYaml.ts +44 -0
- package/src/mappers/DevInit-to-CIWorkflow.ts +526 -0
- package/src/mappers/DevInit-to-RolePermissions.ts +32 -0
- package/src/mappers/DevRequests-to-RequestHanderSiteConfigYaml.ts +44 -0
- package/src/models/CliService.d.ts +36 -0
- package/src/models/DevService.d.ts +40 -0
- package/src/models/JsModules.d.ts +2 -0
- package/src/providers/CredentialProvider.ts +51 -18
- package/src/providers/SessionCacheProvider.ts +29 -2
- package/src/providers/file-provider.ts +17 -6
- package/src/services/ContensisCliService.ts +1532 -508
- package/src/services/ContensisDevService.ts +434 -0
- package/src/services/ContensisRoleService.ts +108 -0
- package/src/shell.ts +68 -18
- package/src/util/console.printer.ts +240 -78
- package/src/util/diff.ts +124 -0
- package/src/util/dotenv.ts +37 -0
- package/src/util/find.ts +8 -0
- package/src/util/git.ts +131 -0
- package/src/util/index.ts +16 -7
- package/src/util/logger.ts +145 -31
- package/src/util/os.ts +12 -0
- package/src/util/timers.ts +24 -0
- package/src/util/yaml.ts +13 -0
- package/src/version.ts +1 -1
|
@@ -28,52 +28,77 @@ __export(ContensisCliService_exports, {
|
|
|
28
28
|
default: () => ContensisCliService_default
|
|
29
29
|
});
|
|
30
30
|
module.exports = __toCommonJS(ContensisCliService_exports);
|
|
31
|
+
var import_await_to_js = __toESM(require("await-to-js"));
|
|
32
|
+
var import_chalk = __toESM(require("chalk"));
|
|
31
33
|
var import_fs = __toESM(require("fs"));
|
|
32
|
-
var import_path = __toESM(require("path"));
|
|
33
|
-
var import_node_fetch = __toESM(require("node-fetch"));
|
|
34
34
|
var import_inquirer = __toESM(require("inquirer"));
|
|
35
|
-
var
|
|
36
|
-
var
|
|
37
|
-
var
|
|
35
|
+
var import_node_fetch = __toESM(require("node-fetch"));
|
|
36
|
+
var import_path = __toESM(require("path"));
|
|
37
|
+
var import_migratortron = require("migratortron");
|
|
38
38
|
var import_ContensisAuthService = __toESM(require("./ContensisAuthService"));
|
|
39
|
-
var import_CredentialProvider = __toESM(require("../providers/CredentialProvider"));
|
|
40
|
-
var import_logger = require("../util/logger");
|
|
41
39
|
var import_en_GB = require("../localisation/en-GB");
|
|
42
|
-
var
|
|
40
|
+
var import_file_provider = require("../providers/file-provider");
|
|
41
|
+
var import_SessionCacheProvider = __toESM(require("../providers/SessionCacheProvider"));
|
|
42
|
+
var import_CredentialProvider = __toESM(require("../providers/CredentialProvider"));
|
|
43
|
+
var import_util = require("../util");
|
|
44
|
+
var import_console = require("../util/console.printer");
|
|
43
45
|
var import_csv = require("../util/csv.formatter");
|
|
44
46
|
var import_xml = require("../util/xml.formatter");
|
|
45
47
|
var import_json = require("../util/json.formatter");
|
|
46
|
-
var
|
|
47
|
-
var
|
|
48
|
+
var import_diff = require("../util/diff");
|
|
49
|
+
var import_logger = require("../util/logger");
|
|
50
|
+
var import_timers = require("../util/timers");
|
|
51
|
+
var import_find = require("../util/find");
|
|
52
|
+
let insecurePasswordWarningShown = false;
|
|
48
53
|
class ContensisCli {
|
|
49
54
|
static quit = (error) => {
|
|
50
55
|
process.removeAllListeners("exit");
|
|
51
56
|
const exitCode = error ? 1 : 0;
|
|
52
|
-
console.info(`
|
|
53
|
-
Exiting contensis-cli with exit code: ${exitCode}
|
|
54
|
-
`);
|
|
55
57
|
process.exit(exitCode);
|
|
56
58
|
};
|
|
57
|
-
|
|
59
|
+
command;
|
|
60
|
+
format;
|
|
61
|
+
output;
|
|
62
|
+
session;
|
|
58
63
|
contensis;
|
|
59
64
|
contensisOpts;
|
|
60
|
-
contentTypes;
|
|
61
|
-
components;
|
|
62
|
-
currentEnv;
|
|
63
65
|
currentProject;
|
|
64
|
-
|
|
65
|
-
|
|
66
|
+
clientDetailsLocation;
|
|
67
|
+
clientId;
|
|
68
|
+
clientSecret;
|
|
69
|
+
sourceAlias;
|
|
66
70
|
targetEnv;
|
|
67
71
|
urls;
|
|
68
|
-
command;
|
|
69
|
-
format;
|
|
70
|
-
output;
|
|
71
72
|
log = import_logger.Logger;
|
|
72
73
|
messages = import_en_GB.LogMessages;
|
|
73
|
-
session;
|
|
74
74
|
verb;
|
|
75
75
|
noun;
|
|
76
76
|
thirdArg;
|
|
77
|
+
get cache() {
|
|
78
|
+
return this.session.Get();
|
|
79
|
+
}
|
|
80
|
+
get currentEnv() {
|
|
81
|
+
return this.cache.currentEnvironment || "";
|
|
82
|
+
}
|
|
83
|
+
set currentEnv(currentEnvironment) {
|
|
84
|
+
this.session.Update({ currentEnvironment });
|
|
85
|
+
}
|
|
86
|
+
get env() {
|
|
87
|
+
const currentEnvironment = this.currentEnv;
|
|
88
|
+
const environments = this.cache.environments || {};
|
|
89
|
+
if (!currentEnvironment)
|
|
90
|
+
return {};
|
|
91
|
+
else if (!!environments[currentEnvironment])
|
|
92
|
+
return environments[currentEnvironment];
|
|
93
|
+
else {
|
|
94
|
+
return {
|
|
95
|
+
history: [],
|
|
96
|
+
lastUserId: "",
|
|
97
|
+
projects: [],
|
|
98
|
+
versionStatus: "latest"
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
}
|
|
77
102
|
constructor(args, outputOpts, contensisOpts = {}) {
|
|
78
103
|
const [exe, script, verb = "", noun = "", ...restArgs] = args;
|
|
79
104
|
this.verb = verb == null ? void 0 : verb.toLowerCase();
|
|
@@ -81,24 +106,12 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
81
106
|
this.thirdArg = restArgs == null ? void 0 : restArgs[0];
|
|
82
107
|
const commandText = `${this.verb} ${this.noun} ${restArgs ? restArgs.join(" ") : ""}`.trim();
|
|
83
108
|
this.session = new import_SessionCacheProvider.default();
|
|
84
|
-
this.cache = this.session.Get();
|
|
85
109
|
this.contensisOpts = contensisOpts;
|
|
86
110
|
this.format = outputOpts == null ? void 0 : outputOpts.format;
|
|
87
111
|
this.output = (outputOpts == null ? void 0 : outputOpts.output) && import_path.default.join(process.cwd(), outputOpts.output);
|
|
88
|
-
const currentEnvironment = (outputOpts == null ? void 0 : outputOpts.alias) || this.
|
|
112
|
+
const currentEnvironment = (outputOpts == null ? void 0 : outputOpts.alias) || this.currentEnv;
|
|
89
113
|
const environments = this.cache.environments || {};
|
|
90
|
-
|
|
91
|
-
this.env = {};
|
|
92
|
-
else if (!!environments[currentEnvironment])
|
|
93
|
-
this.env = environments[currentEnvironment];
|
|
94
|
-
else {
|
|
95
|
-
this.env = {
|
|
96
|
-
history: [],
|
|
97
|
-
lastUserId: "",
|
|
98
|
-
projects: [],
|
|
99
|
-
versionStatus: "latest"
|
|
100
|
-
};
|
|
101
|
-
}
|
|
114
|
+
this.currentEnv = currentEnvironment;
|
|
102
115
|
const env = this.env;
|
|
103
116
|
if (outputOpts == null ? void 0 : outputOpts.projectId)
|
|
104
117
|
env.currentProject = outputOpts.projectId;
|
|
@@ -110,9 +123,8 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
110
123
|
env.lastUserId = outputOpts.clientId;
|
|
111
124
|
if (outputOpts == null ? void 0 : outputOpts.sharedSecret)
|
|
112
125
|
env.passwordFallback = outputOpts.sharedSecret;
|
|
113
|
-
this.currentEnv = currentEnvironment;
|
|
114
126
|
this.currentProject = (env == null ? void 0 : env.currentProject) || "null";
|
|
115
|
-
this.
|
|
127
|
+
this.sourceAlias = (outputOpts == null ? void 0 : outputOpts.sourceAlias) || currentEnvironment;
|
|
116
128
|
if (currentEnvironment) {
|
|
117
129
|
this.urls = (0, import_util.url)(currentEnvironment, (env == null ? void 0 : env.currentProject) || "website");
|
|
118
130
|
}
|
|
@@ -124,7 +136,7 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
124
136
|
if (currentEnvironment) {
|
|
125
137
|
env.history = [this.command];
|
|
126
138
|
if (commandText) {
|
|
127
|
-
environments[currentEnvironment] =
|
|
139
|
+
environments[currentEnvironment] = env;
|
|
128
140
|
this.session.Update({
|
|
129
141
|
currentEnvironment,
|
|
130
142
|
environments,
|
|
@@ -149,34 +161,20 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
149
161
|
};
|
|
150
162
|
Connect = async (environment) => {
|
|
151
163
|
var _a;
|
|
152
|
-
const {
|
|
164
|
+
const { log, messages, session } = this;
|
|
153
165
|
if (environment) {
|
|
154
|
-
const envCache = cache.environments[environment];
|
|
155
|
-
if (!envCache)
|
|
156
|
-
cache.environments[environment] = {
|
|
157
|
-
versionStatus: "published",
|
|
158
|
-
history: [],
|
|
159
|
-
lastUserId: "",
|
|
160
|
-
projects: [],
|
|
161
|
-
...!this.currentEnv ? this.env : {}
|
|
162
|
-
};
|
|
163
|
-
this.env = cache.environments[environment];
|
|
164
166
|
this.currentEnv = environment;
|
|
165
167
|
this.urls = (0, import_util.url)(environment, "website");
|
|
166
168
|
const [fetchErr, response] = await (0, import_await_to_js.default)((0, import_node_fetch.default)(this.urls.cms));
|
|
167
169
|
if (response && (response == null ? void 0 : response.status) < 400) {
|
|
168
170
|
log.success(messages.connect.connected(environment));
|
|
171
|
+
session.UpdateEnv(this.env, environment);
|
|
169
172
|
if ((_a = this.env) == null ? void 0 : _a.lastUserId) {
|
|
170
|
-
await this.ConnectContensis();
|
|
171
173
|
await this.PrintProjects();
|
|
172
174
|
} else {
|
|
173
175
|
log.warning(messages.projects.noList());
|
|
174
176
|
log.help(messages.connect.tip());
|
|
175
177
|
}
|
|
176
|
-
session.Update({
|
|
177
|
-
currentEnvironment: environment,
|
|
178
|
-
environments: cache.environments
|
|
179
|
-
});
|
|
180
178
|
} else {
|
|
181
179
|
log.error(
|
|
182
180
|
messages.connect.unreachable(this.urls.cms, (response == null ? void 0 : response.status) || 0)
|
|
@@ -188,93 +186,80 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
188
186
|
};
|
|
189
187
|
ConnectContensis = async ({ commit = false } = {}) => {
|
|
190
188
|
var _a, _b, _c;
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
189
|
+
if (!this.contensis) {
|
|
190
|
+
const { contensisOpts, currentEnv, env, log, messages } = this;
|
|
191
|
+
const userId = env == null ? void 0 : env.lastUserId;
|
|
192
|
+
const isGuidId = userId && (0, import_util.isUuid)(userId);
|
|
193
|
+
if (currentEnv && userId) {
|
|
194
|
+
const credentials = await this.GetCredentials(
|
|
197
195
|
userId,
|
|
198
|
-
|
|
199
|
-
},
|
|
200
|
-
env.passwordFallback
|
|
201
|
-
).Init();
|
|
202
|
-
if (credentialError && !credentials.current) {
|
|
203
|
-
log.error(credentialError);
|
|
204
|
-
return;
|
|
205
|
-
}
|
|
206
|
-
const cachedPassword = (_a = credentials == null ? void 0 : credentials.current) == null ? void 0 : _a.password;
|
|
207
|
-
if (cachedPassword) {
|
|
208
|
-
this.contensis = new import_migratortron.ContensisMigrationService(
|
|
209
|
-
{
|
|
210
|
-
...contensisOpts,
|
|
211
|
-
source: {
|
|
212
|
-
url: ((_b = this.urls) == null ? void 0 : _b.cms) || "",
|
|
213
|
-
username: !isGuidId ? userId : void 0,
|
|
214
|
-
password: !isGuidId ? cachedPassword : void 0,
|
|
215
|
-
clientId: isGuidId ? userId : void 0,
|
|
216
|
-
sharedSecret: isGuidId ? cachedPassword : void 0,
|
|
217
|
-
project: (env == null ? void 0 : env.currentProject) || "",
|
|
218
|
-
assetHostname: (_c = this.urls) == null ? void 0 : _c.previewWeb
|
|
219
|
-
},
|
|
220
|
-
concurrency: typeof contensisOpts.concurrency !== "undefined" ? contensisOpts.concurrency : 3,
|
|
221
|
-
outputProgress: true
|
|
222
|
-
},
|
|
223
|
-
!commit
|
|
196
|
+
env.passwordFallback
|
|
224
197
|
);
|
|
198
|
+
const cachedPassword = (_a = credentials == null ? void 0 : credentials.current) == null ? void 0 : _a.password;
|
|
199
|
+
if (cachedPassword) {
|
|
200
|
+
this.contensis = new import_migratortron.ContensisMigrationService(
|
|
201
|
+
{
|
|
202
|
+
...contensisOpts,
|
|
203
|
+
source: {
|
|
204
|
+
url: ((_b = this.urls) == null ? void 0 : _b.cms) || "",
|
|
205
|
+
username: !isGuidId ? userId : void 0,
|
|
206
|
+
password: !isGuidId ? cachedPassword : void 0,
|
|
207
|
+
clientId: isGuidId ? userId : void 0,
|
|
208
|
+
sharedSecret: isGuidId ? cachedPassword : void 0,
|
|
209
|
+
project: (env == null ? void 0 : env.currentProject) || "",
|
|
210
|
+
assetHostname: (_c = this.urls) == null ? void 0 : _c.previewWeb
|
|
211
|
+
},
|
|
212
|
+
concurrency: typeof contensisOpts.concurrency !== "undefined" ? contensisOpts.concurrency : 3,
|
|
213
|
+
outputProgress: true
|
|
214
|
+
},
|
|
215
|
+
!commit
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
} else {
|
|
219
|
+
if (!currentEnv)
|
|
220
|
+
log.help(messages.connect.help());
|
|
221
|
+
if (!userId)
|
|
222
|
+
log.help(messages.connect.tip());
|
|
225
223
|
}
|
|
226
|
-
} else {
|
|
227
|
-
if (!currentEnv)
|
|
228
|
-
log.help(messages.connect.help());
|
|
229
|
-
if (!userId)
|
|
230
|
-
log.help(messages.connect.tip());
|
|
231
224
|
}
|
|
225
|
+
return this.contensis;
|
|
232
226
|
};
|
|
233
227
|
ConnectContensisImport = async ({
|
|
234
|
-
commit,
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
fileDataType
|
|
228
|
+
commit = false,
|
|
229
|
+
fromFile,
|
|
230
|
+
importDataType
|
|
238
231
|
}) => {
|
|
239
232
|
var _a, _b, _c, _d, _e, _f;
|
|
240
|
-
const
|
|
233
|
+
const source = fromFile ? "file" : "contensis";
|
|
234
|
+
const fileData = fromFile ? (0, import_file_provider.readJsonFile)(fromFile) || [] : [];
|
|
235
|
+
if (typeof fileData === "string")
|
|
236
|
+
throw new Error(`Import file format must be of type JSON`);
|
|
237
|
+
const { contensisOpts, currentEnv, env, log, messages, sourceAlias } = this;
|
|
241
238
|
const environments = this.cache.environments || {};
|
|
242
|
-
const sourceEnvironment = environments[
|
|
239
|
+
const sourceEnvironment = environments[sourceAlias || ""] || {};
|
|
243
240
|
const sourceCms = "source" in contensisOpts && contensisOpts.source || {};
|
|
244
241
|
const sourceUserId = sourceCms.clientId || sourceCms.username || sourceEnvironment.lastUserId;
|
|
245
242
|
const sourceProjectId = sourceCms.project || sourceEnvironment.currentProject || "website";
|
|
246
243
|
const isSourceGuidId = sourceUserId && (0, import_util.isUuid)(sourceUserId);
|
|
247
|
-
const sourceUrls = (0, import_util.url)(
|
|
244
|
+
const sourceUrls = (0, import_util.url)(sourceAlias || "", sourceProjectId);
|
|
248
245
|
const sourcePassword = sourceCms.sharedSecret || sourceCms.password || sourceEnvironment.passwordFallback;
|
|
249
246
|
const targetUserId = env == null ? void 0 : env.lastUserId;
|
|
250
247
|
const isTargetGuidId = targetUserId && (0, import_util.isUuid)(targetUserId);
|
|
251
248
|
if (sourceUserId && currentEnv && targetUserId) {
|
|
252
|
-
const
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
).Init();
|
|
259
|
-
if (sourceCredentialError && !sourceCredentials.current) {
|
|
260
|
-
(0, import_logger.logError)(sourceCredentialError);
|
|
261
|
-
return;
|
|
262
|
-
}
|
|
249
|
+
const sourceCredentials = await this.GetCredentials(
|
|
250
|
+
sourceUserId,
|
|
251
|
+
sourcePassword,
|
|
252
|
+
sourceAlias,
|
|
253
|
+
false
|
|
254
|
+
);
|
|
263
255
|
const cachedSourcePassword = (_a = sourceCredentials == null ? void 0 : sourceCredentials.current) == null ? void 0 : _a.password;
|
|
264
|
-
const
|
|
265
|
-
|
|
266
|
-
userId: targetUserId,
|
|
267
|
-
alias: currentEnv
|
|
268
|
-
},
|
|
256
|
+
const targetCredentials = await this.GetCredentials(
|
|
257
|
+
targetUserId,
|
|
269
258
|
env.passwordFallback
|
|
270
|
-
)
|
|
271
|
-
if (targetCredentialError && !targetCredentials.current) {
|
|
272
|
-
log.error(targetCredentialError);
|
|
273
|
-
return;
|
|
274
|
-
}
|
|
259
|
+
);
|
|
275
260
|
const cachedTargetPassword = (_b = targetCredentials == null ? void 0 : targetCredentials.current) == null ? void 0 : _b.password;
|
|
276
261
|
if (cachedSourcePassword && cachedTargetPassword) {
|
|
277
|
-
if (source === "file" ||
|
|
262
|
+
if (source === "file" || importDataType === "user-input") {
|
|
278
263
|
this.contensis = new import_migratortron.ContensisMigrationService(
|
|
279
264
|
{
|
|
280
265
|
concurrency: 3,
|
|
@@ -289,12 +274,11 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
289
274
|
targetProjects: [env.currentProject || ""],
|
|
290
275
|
assetHostname: (_d = this.urls) == null ? void 0 : _d.previewWeb
|
|
291
276
|
},
|
|
292
|
-
...
|
|
277
|
+
...importDataType ? { [importDataType]: fileData } : {}
|
|
293
278
|
},
|
|
294
279
|
!commit
|
|
295
280
|
);
|
|
296
|
-
}
|
|
297
|
-
if (source === "contensis") {
|
|
281
|
+
} else if (source === "contensis") {
|
|
298
282
|
this.contensis = new import_migratortron.ContensisMigrationService(
|
|
299
283
|
{
|
|
300
284
|
concurrency: 3,
|
|
@@ -329,82 +313,104 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
329
313
|
if (!targetUserId)
|
|
330
314
|
log.help(messages.connect.tip());
|
|
331
315
|
}
|
|
316
|
+
return this.contensis;
|
|
317
|
+
};
|
|
318
|
+
GetCredentials = async (userId, password, currentEnv = this.currentEnv, saveCurrentEnv = true) => {
|
|
319
|
+
const { log, messages } = this;
|
|
320
|
+
if (userId) {
|
|
321
|
+
const [credentialError, credentials] = await new import_CredentialProvider.default(
|
|
322
|
+
{ userId, alias: currentEnv },
|
|
323
|
+
password
|
|
324
|
+
).Init();
|
|
325
|
+
if (credentialError && !credentials.current) {
|
|
326
|
+
log.error(credentialError);
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
if (credentials.remarks.secure !== true) {
|
|
330
|
+
if (!insecurePasswordWarningShown) {
|
|
331
|
+
log.warning(messages.login.insecurePassword());
|
|
332
|
+
insecurePasswordWarningShown = true;
|
|
333
|
+
}
|
|
334
|
+
} else {
|
|
335
|
+
const env = this.cache.environments[currentEnv];
|
|
336
|
+
env.passwordFallback = void 0;
|
|
337
|
+
this.session.UpdateEnv(env, currentEnv, saveCurrentEnv);
|
|
338
|
+
}
|
|
339
|
+
return credentials;
|
|
340
|
+
}
|
|
332
341
|
};
|
|
333
342
|
Login = async (userId, {
|
|
334
343
|
password = (0, import_util.isPassword)(this.env.passwordFallback),
|
|
335
344
|
promptPassword = true,
|
|
336
345
|
sharedSecret = (0, import_util.isSharedSecret)(this.env.passwordFallback),
|
|
337
|
-
silent = false
|
|
338
|
-
|
|
346
|
+
silent = false,
|
|
347
|
+
attempt = 1
|
|
348
|
+
} = {}) => {
|
|
339
349
|
var _a, _b, _c, _d;
|
|
340
|
-
let inputPassword = password;
|
|
350
|
+
let inputPassword = password || sharedSecret;
|
|
341
351
|
const { log, messages } = this;
|
|
342
352
|
if (userId) {
|
|
343
|
-
const {
|
|
353
|
+
const { currentEnv, env } = this;
|
|
344
354
|
if (currentEnv) {
|
|
345
|
-
const
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
return await this.Login(userId, { password, sharedSecret });
|
|
398
|
-
} else {
|
|
399
|
-
throw new Error(messages.login.failed(currentEnv, userId));
|
|
355
|
+
const credentials = await this.GetCredentials(userId, inputPassword);
|
|
356
|
+
if (credentials) {
|
|
357
|
+
const cachedPassword = (0, import_util.isPassword)((_a = credentials.current) == null ? void 0 : _a.password);
|
|
358
|
+
const cachedSecret = (0, import_util.isSharedSecret)((_b = credentials.current) == null ? void 0 : _b.password);
|
|
359
|
+
if (!cachedPassword && !cachedSecret && promptPassword) {
|
|
360
|
+
({ inputPassword } = await import_inquirer.default.prompt([
|
|
361
|
+
{
|
|
362
|
+
type: "password",
|
|
363
|
+
message: messages.login.passwordPrompt(currentEnv, userId),
|
|
364
|
+
name: "inputPassword",
|
|
365
|
+
mask: "*",
|
|
366
|
+
prefix: void 0
|
|
367
|
+
}
|
|
368
|
+
]));
|
|
369
|
+
}
|
|
370
|
+
if (inputPassword || cachedPassword || cachedSecret) {
|
|
371
|
+
const authService = new import_ContensisAuthService.default({
|
|
372
|
+
username: userId,
|
|
373
|
+
password: inputPassword || cachedPassword,
|
|
374
|
+
projectId: (env == null ? void 0 : env.currentProject) || "website",
|
|
375
|
+
rootUrl: ((_c = this.urls) == null ? void 0 : _c.cms) || "",
|
|
376
|
+
clientId: userId,
|
|
377
|
+
clientSecret: sharedSecret || cachedSecret
|
|
378
|
+
});
|
|
379
|
+
const [authError, bearerToken] = await (0, import_await_to_js.default)(
|
|
380
|
+
authService.BearerToken()
|
|
381
|
+
);
|
|
382
|
+
if (bearerToken) {
|
|
383
|
+
env.authToken = bearerToken;
|
|
384
|
+
env.lastUserId = userId;
|
|
385
|
+
env.passwordFallback = credentials.remarks.secure !== true ? (_d = credentials.current) == null ? void 0 : _d.password : void 0;
|
|
386
|
+
this.session.UpdateEnv(env);
|
|
387
|
+
if (inputPassword)
|
|
388
|
+
await credentials.Save(inputPassword);
|
|
389
|
+
if (sharedSecret)
|
|
390
|
+
await credentials.Save(sharedSecret);
|
|
391
|
+
if (!silent) {
|
|
392
|
+
import_logger.Logger.success(messages.login.success(currentEnv, userId));
|
|
393
|
+
await this.PrintProjects();
|
|
394
|
+
}
|
|
395
|
+
} else if (authError) {
|
|
396
|
+
import_logger.Logger.error(authError.toString());
|
|
397
|
+
env.authToken = "";
|
|
398
|
+
env.lastUserId = "";
|
|
399
|
+
env.passwordFallback = void 0;
|
|
400
|
+
this.session.UpdateEnv(env);
|
|
401
|
+
if ((cachedPassword || cachedSecret) && credentials.remarks.secure) {
|
|
402
|
+
await credentials.Delete();
|
|
403
|
+
return await this.Login(userId, { password, sharedSecret });
|
|
404
|
+
} else {
|
|
405
|
+
throw new Error(messages.login.failed(currentEnv, userId));
|
|
406
|
+
}
|
|
400
407
|
}
|
|
408
|
+
return env.authToken;
|
|
409
|
+
} else {
|
|
410
|
+
import_logger.Logger.error(messages.login.passwordPrompt());
|
|
411
|
+
if (attempt < 2)
|
|
412
|
+
return await this.Login(userId, { attempt: attempt + 1 });
|
|
401
413
|
}
|
|
402
|
-
this.session.Update({
|
|
403
|
-
environments: cache.environments
|
|
404
|
-
});
|
|
405
|
-
return env.authToken;
|
|
406
|
-
} else {
|
|
407
|
-
import_logger.Logger.error(messages.login.passwordPrompt(currentEnv, userId));
|
|
408
414
|
}
|
|
409
415
|
} else {
|
|
410
416
|
import_logger.Logger.error(messages.login.noEnv());
|
|
@@ -413,37 +419,80 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
413
419
|
import_logger.Logger.error(messages.login.noUserId());
|
|
414
420
|
}
|
|
415
421
|
};
|
|
422
|
+
PrintContensisVersion = async () => {
|
|
423
|
+
const { log, messages } = this;
|
|
424
|
+
const contensis = await this.ConnectContensis();
|
|
425
|
+
if (contensis) {
|
|
426
|
+
const [projectsErr, projects] = await (0, import_await_to_js.default)(
|
|
427
|
+
contensis.projects.GetSourceProjects()
|
|
428
|
+
);
|
|
429
|
+
if (Array.isArray(projects)) {
|
|
430
|
+
this.HandleFormattingAndOutput(
|
|
431
|
+
contensis.contensisVersion,
|
|
432
|
+
() => log.raw(log.highlightText(contensis.contensisVersion))
|
|
433
|
+
);
|
|
434
|
+
}
|
|
435
|
+
if (projectsErr) {
|
|
436
|
+
log.error(messages.projects.noList());
|
|
437
|
+
log.error(projectsErr.message);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
};
|
|
441
|
+
PrintBearerToken = async () => {
|
|
442
|
+
const { log, messages } = this;
|
|
443
|
+
const contensis = await this.ConnectContensis();
|
|
444
|
+
if (contensis) {
|
|
445
|
+
const [error, token] = await (0, import_await_to_js.default)(
|
|
446
|
+
contensis.content.sourceRepo.repo.BearerToken()
|
|
447
|
+
);
|
|
448
|
+
if (token) {
|
|
449
|
+
this.HandleFormattingAndOutput(
|
|
450
|
+
token,
|
|
451
|
+
() => log.raw(log.highlightText(token))
|
|
452
|
+
);
|
|
453
|
+
}
|
|
454
|
+
if (error) {
|
|
455
|
+
log.error(messages.projects.noList());
|
|
456
|
+
log.error(error.message);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
};
|
|
416
460
|
PrintProjects = async () => {
|
|
417
|
-
const {
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
if (this.contensis) {
|
|
461
|
+
const { currentProject, log, messages, session } = this;
|
|
462
|
+
const contensis = await this.ConnectContensis();
|
|
463
|
+
if (contensis) {
|
|
421
464
|
const [projectsErr, projects] = await (0, import_await_to_js.default)(
|
|
422
|
-
|
|
465
|
+
contensis.projects.GetSourceProjects()
|
|
423
466
|
);
|
|
424
467
|
if (Array.isArray(projects)) {
|
|
425
|
-
const currentVals = cache.environments[currentEnv] || {};
|
|
426
468
|
const nextCurrentProject = currentProject && currentProject !== "null" ? currentProject : projects.some((p) => p.id === "website") ? "website" : void 0;
|
|
427
|
-
|
|
428
|
-
...currentVals,
|
|
469
|
+
session.UpdateEnv({
|
|
429
470
|
projects: projects.map((p) => p.id),
|
|
430
471
|
currentProject: nextCurrentProject
|
|
431
|
-
};
|
|
472
|
+
});
|
|
432
473
|
log.success(messages.projects.list());
|
|
474
|
+
log.raw("");
|
|
433
475
|
this.HandleFormattingAndOutput(projects, () => {
|
|
434
|
-
for (const project of projects
|
|
476
|
+
for (const project of projects.sort(
|
|
477
|
+
(a, b) => a.id.localeCompare(b.id)
|
|
478
|
+
)) {
|
|
479
|
+
let color;
|
|
480
|
+
try {
|
|
481
|
+
color = import_chalk.default.keyword(project.color);
|
|
482
|
+
} catch (ex) {
|
|
483
|
+
color = import_chalk.default.white;
|
|
484
|
+
}
|
|
435
485
|
console.log(
|
|
436
|
-
|
|
486
|
+
`${nextCurrentProject === project.id ? `>> ${log.boldText(color(project.id))}` : ` ${color(project.id)}`} ${log.infoText(
|
|
487
|
+
`[${project.supportedLanguages.map(
|
|
488
|
+
(l) => l === project.primaryLanguage ? `*${log.boldText(l)}` : l
|
|
489
|
+
).join(" ")}]`
|
|
490
|
+
)}`
|
|
437
491
|
);
|
|
438
492
|
}
|
|
439
493
|
});
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
});
|
|
443
|
-
if (nextCurrentProject) {
|
|
444
|
-
this.env = cache.environments[currentEnv];
|
|
445
|
-
this.SetProject(nextCurrentProject);
|
|
446
|
-
}
|
|
494
|
+
if (!this.SetProject(nextCurrentProject))
|
|
495
|
+
log.warning(messages.projects.tip());
|
|
447
496
|
}
|
|
448
497
|
if (projectsErr) {
|
|
449
498
|
log.error(messages.projects.noList());
|
|
@@ -451,8 +500,28 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
451
500
|
}
|
|
452
501
|
}
|
|
453
502
|
};
|
|
454
|
-
|
|
455
|
-
const {
|
|
503
|
+
PrintProject = async (projectId = this.currentProject) => {
|
|
504
|
+
const { log, messages, session } = this;
|
|
505
|
+
const contensis = await this.ConnectContensis();
|
|
506
|
+
if (contensis) {
|
|
507
|
+
const [projectsErr, projects] = await (0, import_await_to_js.default)(
|
|
508
|
+
contensis.projects.GetSourceProjects()
|
|
509
|
+
);
|
|
510
|
+
const foundProject = projects == null ? void 0 : projects.find(
|
|
511
|
+
(p) => p.id.toLowerCase() === projectId.toLowerCase()
|
|
512
|
+
);
|
|
513
|
+
if (foundProject) {
|
|
514
|
+
log.raw("");
|
|
515
|
+
this.HandleFormattingAndOutput(foundProject, log.object);
|
|
516
|
+
}
|
|
517
|
+
if (projectsErr) {
|
|
518
|
+
log.error(messages.projects.noList());
|
|
519
|
+
log.error(projectsErr.message);
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
};
|
|
523
|
+
SetProject = (projectId = "website") => {
|
|
524
|
+
const { env, log, messages, session } = this;
|
|
456
525
|
let nextProjectId;
|
|
457
526
|
if ((env == null ? void 0 : env.projects.length) > 0 && (env == null ? void 0 : env.lastUserId)) {
|
|
458
527
|
nextProjectId = env.projects.find(
|
|
@@ -460,10 +529,9 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
460
529
|
);
|
|
461
530
|
if (nextProjectId) {
|
|
462
531
|
env.currentProject = nextProjectId;
|
|
463
|
-
session.
|
|
464
|
-
environments: cache.environments
|
|
465
|
-
});
|
|
532
|
+
session.UpdateEnv(env);
|
|
466
533
|
log.success(messages.projects.set(projectId));
|
|
534
|
+
log.raw("");
|
|
467
535
|
} else {
|
|
468
536
|
log.error(messages.projects.failedSet(projectId));
|
|
469
537
|
}
|
|
@@ -473,8 +541,8 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
473
541
|
}
|
|
474
542
|
return nextProjectId;
|
|
475
543
|
};
|
|
476
|
-
SetVersion =
|
|
477
|
-
const {
|
|
544
|
+
SetVersion = (versionStatus) => {
|
|
545
|
+
const { env, log, messages, session } = this;
|
|
478
546
|
if (!["latest", "published"].includes(versionStatus)) {
|
|
479
547
|
log.error(messages.version.invalid(versionStatus));
|
|
480
548
|
return false;
|
|
@@ -484,10 +552,7 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
484
552
|
return false;
|
|
485
553
|
}
|
|
486
554
|
if ((env == null ? void 0 : env.projects.length) > 0 && (env == null ? void 0 : env.lastUserId)) {
|
|
487
|
-
|
|
488
|
-
session.Update({
|
|
489
|
-
environments: cache.environments
|
|
490
|
-
});
|
|
555
|
+
session.UpdateEnv({ versionStatus });
|
|
491
556
|
log.success(messages.version.set(this.currentEnv, versionStatus));
|
|
492
557
|
return true;
|
|
493
558
|
} else {
|
|
@@ -496,26 +561,11 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
496
561
|
return false;
|
|
497
562
|
}
|
|
498
563
|
};
|
|
499
|
-
HydrateContensis = async () => {
|
|
500
|
-
const { log } = this;
|
|
501
|
-
if (!this.contensis)
|
|
502
|
-
await this.ConnectContensis();
|
|
503
|
-
if (this.contensis) {
|
|
504
|
-
const [contensisErr, models] = await (0, import_await_to_js.default)(
|
|
505
|
-
this.contensis.models.HydrateContensisRepositories()
|
|
506
|
-
);
|
|
507
|
-
if (contensisErr) {
|
|
508
|
-
log.error(contensisErr.message);
|
|
509
|
-
return contensisErr;
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
};
|
|
513
564
|
PrintApiKeys = async () => {
|
|
514
565
|
const { currentEnv, log, messages } = this;
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
const [keysErr, apiKeys] = await this.contensis.apiKeys.GetKeys();
|
|
566
|
+
const contensis = await this.ConnectContensis();
|
|
567
|
+
if (contensis) {
|
|
568
|
+
const [keysErr, apiKeys] = await contensis.apiKeys.GetKeys();
|
|
519
569
|
if (Array.isArray(apiKeys)) {
|
|
520
570
|
log.success(messages.keys.list(currentEnv));
|
|
521
571
|
this.HandleFormattingAndOutput(apiKeys, () => {
|
|
@@ -543,22 +593,23 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
543
593
|
};
|
|
544
594
|
CreateApiKey = async (name, description) => {
|
|
545
595
|
const { currentEnv, log, messages } = this;
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
const [err, key] = await this.contensis.apiKeys.CreateKey(
|
|
550
|
-
name,
|
|
551
|
-
description
|
|
552
|
-
);
|
|
596
|
+
const contensis = await this.ConnectContensis();
|
|
597
|
+
if (contensis) {
|
|
598
|
+
const [err, key] = await contensis.apiKeys.CreateKey(name, description);
|
|
553
599
|
if (key) {
|
|
554
600
|
log.success(messages.keys.created(currentEnv, name));
|
|
555
601
|
console.log(
|
|
556
|
-
` - ${
|
|
602
|
+
` - ${import_chalk.default.bold(key.name)} [${key.dateModified.toString().substring(0, 10)} ${key.modifiedBy}]`
|
|
603
|
+
);
|
|
604
|
+
if (key.description)
|
|
605
|
+
console.log(` ${log.infoText(key.description)}`);
|
|
606
|
+
console.log(` ${import_chalk.default.bold.grey`id`}: ${key.id}`);
|
|
607
|
+
console.log(
|
|
608
|
+
` ${import_chalk.default.bold.grey`sharedSecret`}: ${key.sharedSecret}`
|
|
557
609
|
);
|
|
558
|
-
console.log(
|
|
559
|
-
|
|
610
|
+
console.log("");
|
|
611
|
+
log.help(messages.keys.tip());
|
|
560
612
|
}
|
|
561
|
-
console.log("");
|
|
562
613
|
if (err) {
|
|
563
614
|
log.error(messages.keys.failedCreate(currentEnv, name), err);
|
|
564
615
|
}
|
|
@@ -566,10 +617,9 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
566
617
|
};
|
|
567
618
|
RemoveApiKey = async (id) => {
|
|
568
619
|
const { currentEnv, log, messages } = this;
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
const [err, key] = await this.contensis.apiKeys.RemoveKey(id);
|
|
620
|
+
const contensis = await this.ConnectContensis({ commit: true });
|
|
621
|
+
if (contensis) {
|
|
622
|
+
const [err, key] = await contensis.apiKeys.RemoveKey(id);
|
|
573
623
|
if (!err) {
|
|
574
624
|
log.success(messages.keys.removed(currentEnv, id));
|
|
575
625
|
console.log("");
|
|
@@ -578,25 +628,348 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
578
628
|
}
|
|
579
629
|
}
|
|
580
630
|
};
|
|
581
|
-
|
|
631
|
+
PrintRoles = async () => {
|
|
632
|
+
const { currentEnv, log, messages } = this;
|
|
633
|
+
const contensis = await this.ConnectContensis();
|
|
634
|
+
if (contensis) {
|
|
635
|
+
const [rolesErr, roles] = await (0, import_await_to_js.default)(contensis.roles.GetRoles());
|
|
636
|
+
if (Array.isArray(roles)) {
|
|
637
|
+
log.success(messages.roles.list(currentEnv));
|
|
638
|
+
if (!roles.length)
|
|
639
|
+
log.help(messages.roles.noneExist());
|
|
640
|
+
this.HandleFormattingAndOutput(roles, () => {
|
|
641
|
+
var _a, _b, _c, _d, _e;
|
|
642
|
+
for (const {
|
|
643
|
+
id,
|
|
644
|
+
name,
|
|
645
|
+
description,
|
|
646
|
+
enabled,
|
|
647
|
+
assignments,
|
|
648
|
+
permissions
|
|
649
|
+
} of roles) {
|
|
650
|
+
const color = enabled ? (s) => s : log.infoText;
|
|
651
|
+
console.log(color(` - ${import_chalk.default.bold(name)} ${log.infoText(id)}`));
|
|
652
|
+
if (description)
|
|
653
|
+
console.log(log.infoText(` ${description}`));
|
|
654
|
+
if (enabled === false)
|
|
655
|
+
console.log(` ${import_chalk.default.bold.grey("enabled")}: false`);
|
|
656
|
+
if ((_a = assignments.groups) == null ? void 0 : _a.length)
|
|
657
|
+
console.log(
|
|
658
|
+
` ${import_chalk.default.bold.grey("groups")}: ${assignments.groups.join(
|
|
659
|
+
", "
|
|
660
|
+
)}`
|
|
661
|
+
);
|
|
662
|
+
if ((_b = assignments.users) == null ? void 0 : _b.length)
|
|
663
|
+
console.log(
|
|
664
|
+
` ${import_chalk.default.bold.grey("users")}: ${assignments.users.join(
|
|
665
|
+
", "
|
|
666
|
+
)}`
|
|
667
|
+
);
|
|
668
|
+
if ((_c = assignments.apiKeys) == null ? void 0 : _c.length)
|
|
669
|
+
console.log(
|
|
670
|
+
` ${import_chalk.default.bold.grey("keys")}: ${assignments.apiKeys.join(
|
|
671
|
+
", "
|
|
672
|
+
)}`
|
|
673
|
+
);
|
|
674
|
+
if ((_d = permissions.entries) == null ? void 0 : _d.length) {
|
|
675
|
+
console.log(` ${import_chalk.default.bold.grey("entries")}:`);
|
|
676
|
+
for (const p of permissions.entries)
|
|
677
|
+
console.log(
|
|
678
|
+
` ${p.id}: ${log.infoText(
|
|
679
|
+
p.actions.length > 2 ? p.actions.length : p.actions.join(", ")
|
|
680
|
+
)}`
|
|
681
|
+
);
|
|
682
|
+
}
|
|
683
|
+
if ((_e = permissions.contentTypes) == null ? void 0 : _e.length)
|
|
684
|
+
console.log(
|
|
685
|
+
` ${import_chalk.default.bold.grey(
|
|
686
|
+
"contentTypes"
|
|
687
|
+
)}: ${permissions.contentTypes.map(
|
|
688
|
+
(p) => `${p.id} [${p.actions.join(",")}] ${p.languages.join(
|
|
689
|
+
" "
|
|
690
|
+
)}`
|
|
691
|
+
).join(", ")}`
|
|
692
|
+
);
|
|
693
|
+
}
|
|
694
|
+
});
|
|
695
|
+
}
|
|
696
|
+
if (rolesErr) {
|
|
697
|
+
log.error(messages.roles.noList(currentEnv));
|
|
698
|
+
log.error((0, import_json.jsonFormatter)(rolesErr));
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
};
|
|
702
|
+
PrintRole = async (roleNameOrId) => {
|
|
703
|
+
const { currentEnv, log, messages } = this;
|
|
704
|
+
const contensis = await this.ConnectContensis();
|
|
705
|
+
if (contensis) {
|
|
706
|
+
const [rolesErr, roles] = await (0, import_await_to_js.default)(contensis.roles.GetRoles());
|
|
707
|
+
if (Array.isArray(roles)) {
|
|
708
|
+
log.success(messages.roles.list(currentEnv));
|
|
709
|
+
const role = (0, import_find.findByIdOrName)(roles, roleNameOrId);
|
|
710
|
+
if (role)
|
|
711
|
+
this.HandleFormattingAndOutput(role, log.object);
|
|
712
|
+
else
|
|
713
|
+
log.error(messages.roles.failedGet(currentEnv, roleNameOrId));
|
|
714
|
+
}
|
|
715
|
+
if (rolesErr) {
|
|
716
|
+
log.error(messages.roles.noList(currentEnv));
|
|
717
|
+
log.error((0, import_json.jsonFormatter)(rolesErr));
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
};
|
|
721
|
+
CreateRole = async (role) => {
|
|
722
|
+
const { currentEnv, log, messages } = this;
|
|
723
|
+
const contensis = await this.ConnectContensis();
|
|
724
|
+
if (contensis) {
|
|
725
|
+
const [err, created] = await contensis.roles.CreateRole(role);
|
|
726
|
+
if (created) {
|
|
727
|
+
log.success(
|
|
728
|
+
messages.roles.created(currentEnv, role.id || role.name || "")
|
|
729
|
+
);
|
|
730
|
+
this.HandleFormattingAndOutput(created, log.object);
|
|
731
|
+
log.help(messages.roles.tip());
|
|
732
|
+
return role.id;
|
|
733
|
+
}
|
|
734
|
+
if (err) {
|
|
735
|
+
log.error(
|
|
736
|
+
messages.roles.failedCreate(currentEnv, role.id || role.name || ""),
|
|
737
|
+
err
|
|
738
|
+
);
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
};
|
|
742
|
+
UpdateRole = async (roleNameOrId, role) => {
|
|
743
|
+
const { currentEnv, log, messages } = this;
|
|
744
|
+
const contensis = await this.ConnectContensis();
|
|
745
|
+
if (contensis) {
|
|
746
|
+
const [rolesErr, roles] = await (0, import_await_to_js.default)(contensis.roles.GetRoles());
|
|
747
|
+
if (Array.isArray(roles)) {
|
|
748
|
+
log.success(messages.roles.list(currentEnv));
|
|
749
|
+
const existingRole = (0, import_find.findByIdOrName)(roles, roleNameOrId, true);
|
|
750
|
+
if (existingRole) {
|
|
751
|
+
log.info(messages.roles.setPayload());
|
|
752
|
+
log.object(role);
|
|
753
|
+
log.raw(``);
|
|
754
|
+
const [updateErr, updated] = await contensis.roles.UpdateRole(
|
|
755
|
+
existingRole.id,
|
|
756
|
+
role
|
|
757
|
+
);
|
|
758
|
+
if (updateErr)
|
|
759
|
+
log.error(messages.roles.failedSet(currentEnv, roleNameOrId));
|
|
760
|
+
else {
|
|
761
|
+
log.success(messages.roles.set());
|
|
762
|
+
this.HandleFormattingAndOutput(updated, log.object);
|
|
763
|
+
}
|
|
764
|
+
} else {
|
|
765
|
+
log.error(messages.roles.failedGet(currentEnv, roleNameOrId));
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
if (rolesErr) {
|
|
769
|
+
log.error(messages.roles.noList(currentEnv));
|
|
770
|
+
log.error((0, import_json.jsonFormatter)(rolesErr));
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
};
|
|
774
|
+
RemoveRole = async (roleNameOrId) => {
|
|
775
|
+
const { currentEnv, log, messages } = this;
|
|
776
|
+
const contensis = await this.ConnectContensis();
|
|
777
|
+
if (contensis) {
|
|
778
|
+
const [rolesErr, roles] = await (0, import_await_to_js.default)(contensis.roles.GetRoles());
|
|
779
|
+
if (Array.isArray(roles)) {
|
|
780
|
+
log.success(messages.roles.list(currentEnv));
|
|
781
|
+
const existingRole = (0, import_find.findByIdOrName)(roles, roleNameOrId, true);
|
|
782
|
+
if (existingRole) {
|
|
783
|
+
const [deleteErr] = await contensis.roles.RemoveRole(existingRole.id);
|
|
784
|
+
if (deleteErr)
|
|
785
|
+
log.error(messages.roles.failedRemove(currentEnv, roleNameOrId));
|
|
786
|
+
else
|
|
787
|
+
log.success(messages.roles.removed(currentEnv, roleNameOrId));
|
|
788
|
+
} else {
|
|
789
|
+
log.error(messages.roles.failedGet(currentEnv, roleNameOrId));
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
if (rolesErr) {
|
|
793
|
+
log.error(messages.roles.noList(currentEnv));
|
|
794
|
+
log.error((0, import_json.jsonFormatter)(rolesErr));
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
};
|
|
798
|
+
CreateProject = async (project) => {
|
|
799
|
+
const { currentEnv, log, messages } = this;
|
|
800
|
+
const contensis = await this.ConnectContensis();
|
|
801
|
+
if (contensis) {
|
|
802
|
+
const [err, created] = await contensis.projects.CreateProject(project);
|
|
803
|
+
if (created) {
|
|
804
|
+
log.success(messages.projects.created(currentEnv, project.id));
|
|
805
|
+
this.HandleFormattingAndOutput(created, () => {
|
|
806
|
+
this.SetProject(project.id);
|
|
807
|
+
this.PrintProjects();
|
|
808
|
+
});
|
|
809
|
+
return project.id;
|
|
810
|
+
}
|
|
811
|
+
if (err) {
|
|
812
|
+
log.error(messages.projects.failedCreate(currentEnv, project.id), err);
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
};
|
|
816
|
+
UpdateProject = async (project) => {
|
|
817
|
+
const { currentEnv, currentProject, log, messages } = this;
|
|
818
|
+
const contensis = await this.ConnectContensis();
|
|
819
|
+
if (contensis) {
|
|
820
|
+
const [err, updated] = await contensis.projects.UpdateProject({
|
|
821
|
+
id: currentProject,
|
|
822
|
+
...project
|
|
823
|
+
});
|
|
824
|
+
if (updated) {
|
|
825
|
+
log.success(messages.projects.updated(currentEnv, currentProject));
|
|
826
|
+
this.HandleFormattingAndOutput(updated, log.object);
|
|
827
|
+
return updated.id;
|
|
828
|
+
}
|
|
829
|
+
if (err) {
|
|
830
|
+
log.error(
|
|
831
|
+
messages.projects.failedUpdate(currentEnv, currentProject),
|
|
832
|
+
err
|
|
833
|
+
);
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
};
|
|
837
|
+
PrintContentModels = async (modelIds = []) => {
|
|
838
|
+
const { currentProject, log, messages } = this;
|
|
839
|
+
const contensis = await this.ConnectContensis();
|
|
840
|
+
if (contensis) {
|
|
841
|
+
const models = await contensis.models.contentModels();
|
|
842
|
+
const contentTypes = await contensis.models.contentTypes();
|
|
843
|
+
const components = await contensis.models.components();
|
|
844
|
+
const returnModels = (modelIds == null ? void 0 : modelIds.length) ? models == null ? void 0 : models.filter(
|
|
845
|
+
(m) => modelIds.some((id) => id.toLowerCase() === m.id.toLowerCase())
|
|
846
|
+
) : void 0;
|
|
847
|
+
const contentTypeIds = Array.from(
|
|
848
|
+
/* @__PURE__ */ new Set([
|
|
849
|
+
...(returnModels || models || []).map((m) => m.id),
|
|
850
|
+
...(returnModels || models || []).map((m) => {
|
|
851
|
+
var _a, _b;
|
|
852
|
+
return ((_b = (_a = m.dependencies) == null ? void 0 : _a.contentTypes) == null ? void 0 : _b.map((c) => c[0])) || [];
|
|
853
|
+
}).flat()
|
|
854
|
+
])
|
|
855
|
+
);
|
|
856
|
+
const componentIds = Array.from(
|
|
857
|
+
new Set(
|
|
858
|
+
(returnModels || models || []).map((m) => {
|
|
859
|
+
var _a, _b;
|
|
860
|
+
return ((_b = (_a = m.dependencies) == null ? void 0 : _a.components) == null ? void 0 : _b.map((c) => c[0])) || [];
|
|
861
|
+
}).flat()
|
|
862
|
+
)
|
|
863
|
+
);
|
|
864
|
+
const contentModelBackup = [
|
|
865
|
+
...contentTypes.filter(
|
|
866
|
+
(c) => contentTypeIds.map((i) => i.toLowerCase()).includes(c.id.toLowerCase())
|
|
867
|
+
),
|
|
868
|
+
...components.filter(
|
|
869
|
+
(c) => componentIds.map((i) => i.toLowerCase()).includes(c.id.toLowerCase())
|
|
870
|
+
)
|
|
871
|
+
];
|
|
872
|
+
if (Array.isArray(returnModels)) {
|
|
873
|
+
log.success(messages.models.list(currentProject));
|
|
874
|
+
this.HandleFormattingAndOutput(contentModelBackup, () => {
|
|
875
|
+
for (const model of returnModels) {
|
|
876
|
+
log.raw("");
|
|
877
|
+
log.object(model);
|
|
878
|
+
}
|
|
879
|
+
log.raw("");
|
|
880
|
+
});
|
|
881
|
+
} else {
|
|
882
|
+
log.success(
|
|
883
|
+
messages.models.get(currentProject, (models == null ? void 0 : models.length.toString()) || "0")
|
|
884
|
+
);
|
|
885
|
+
log.raw("");
|
|
886
|
+
if (models == null ? void 0 : models.length) {
|
|
887
|
+
this.HandleFormattingAndOutput(contentModelBackup, () => {
|
|
888
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
889
|
+
for (const model of models) {
|
|
890
|
+
const components2 = ((_a = model.components) == null ? void 0 : _a.length) || 0;
|
|
891
|
+
const contentTypes2 = ((_b = model.contentTypes) == null ? void 0 : _b.length) || 0;
|
|
892
|
+
const dependencies = (((_d = (_c = model.dependencies) == null ? void 0 : _c.components) == null ? void 0 : _d.length) || 0) + (((_f = (_e = model.dependencies) == null ? void 0 : _e.contentTypes) == null ? void 0 : _f.length) || 0);
|
|
893
|
+
const dependencyOf = (((_h = (_g = model.dependencyOf) == null ? void 0 : _g.components) == null ? void 0 : _h.length) || 0) + (((_j = (_i = model.dependencyOf) == null ? void 0 : _i.contentTypes) == null ? void 0 : _j.length) || 0);
|
|
894
|
+
const hasAny = components2 + contentTypes2 + dependencies + dependencyOf;
|
|
895
|
+
log.raw(
|
|
896
|
+
` - ${log.highlightText(log.boldText(model.id))} ${hasAny ? log.infoText(
|
|
897
|
+
`{ ${components2 ? `components: ${components2}, ` : ""}${contentTypes2 ? `contentTypes: ${contentTypes2}, ` : ""}${dependencies ? `references: ${dependencies}, ` : ""}${dependencyOf ? `required by: ${dependencyOf}` : ""} }`
|
|
898
|
+
) : ""}`
|
|
899
|
+
);
|
|
900
|
+
}
|
|
901
|
+
log.raw("");
|
|
902
|
+
});
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
};
|
|
907
|
+
ImportContentModels = async ({
|
|
908
|
+
commit,
|
|
909
|
+
fromFile
|
|
910
|
+
}) => {
|
|
582
911
|
const { currentProject, log, messages } = this;
|
|
583
|
-
|
|
584
|
-
if (
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
912
|
+
const fileData = fromFile ? (0, import_file_provider.readJsonFile)(fromFile) || [] : [];
|
|
913
|
+
if (typeof fileData === "string")
|
|
914
|
+
throw new Error(`Import file format must be of type JSON`);
|
|
915
|
+
const contensis = await this.ConnectContensisImport({
|
|
916
|
+
commit,
|
|
917
|
+
fromFile,
|
|
918
|
+
importDataType: "models"
|
|
919
|
+
});
|
|
920
|
+
if (contensis) {
|
|
921
|
+
log.line();
|
|
922
|
+
if (contensis.isPreview) {
|
|
923
|
+
console.log(log.successText(` -- IMPORT PREVIEW -- `));
|
|
924
|
+
} else {
|
|
925
|
+
console.log(log.warningText(` *** COMMITTING IMPORT *** `));
|
|
926
|
+
}
|
|
927
|
+
const [migrateErr, result] = await contensis.MigrateContentModels();
|
|
928
|
+
if (migrateErr)
|
|
929
|
+
(0, import_logger.logError)(migrateErr);
|
|
930
|
+
else
|
|
931
|
+
this.HandleFormattingAndOutput(result, () => {
|
|
932
|
+
if (!commit) {
|
|
933
|
+
log.raw(log.boldText(`
|
|
934
|
+
Content types:`));
|
|
935
|
+
if (!result.contentTypes)
|
|
936
|
+
log.info(`- None returned
|
|
937
|
+
`);
|
|
938
|
+
else
|
|
939
|
+
(0, import_console.printModelMigrationAnalysis)(this, result.contentTypes);
|
|
940
|
+
log.raw(log.boldText(`
|
|
941
|
+
Components:`));
|
|
942
|
+
if (!result.components)
|
|
943
|
+
log.info(`- None returned
|
|
944
|
+
`);
|
|
945
|
+
else
|
|
946
|
+
(0, import_console.printModelMigrationAnalysis)(this, result.components);
|
|
947
|
+
} else {
|
|
948
|
+
const migrateResult = result;
|
|
949
|
+
log.raw(log.boldText(`
|
|
950
|
+
Content types:`));
|
|
951
|
+
(0, import_console.printModelMigrationResult)(
|
|
952
|
+
this,
|
|
953
|
+
migrateResult[currentProject].contentTypes
|
|
954
|
+
);
|
|
955
|
+
log.raw(log.boldText(`
|
|
956
|
+
Components:`));
|
|
957
|
+
(0, import_console.printModelMigrationResult)(
|
|
958
|
+
this,
|
|
959
|
+
migrateResult[currentProject].components
|
|
960
|
+
);
|
|
961
|
+
}
|
|
962
|
+
});
|
|
591
963
|
} else {
|
|
592
|
-
log.warning(messages.
|
|
964
|
+
log.warning(messages.models.noList(currentProject));
|
|
965
|
+
log.help(messages.connect.tip());
|
|
593
966
|
}
|
|
594
967
|
};
|
|
595
968
|
PrintContentTypes = async () => {
|
|
596
969
|
const { currentProject, log, messages } = this;
|
|
597
|
-
await this.
|
|
598
|
-
if (
|
|
599
|
-
const
|
|
970
|
+
const contensis = await this.ConnectContensis();
|
|
971
|
+
if (contensis) {
|
|
972
|
+
const contentTypes = await contensis.models.contentTypes();
|
|
600
973
|
if (Array.isArray(contentTypes)) {
|
|
601
974
|
log.success(messages.contenttypes.list(currentProject));
|
|
602
975
|
this.HandleFormattingAndOutput(contentTypes, () => {
|
|
@@ -613,9 +986,9 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
613
986
|
};
|
|
614
987
|
PrintContentType = async (contentTypeId) => {
|
|
615
988
|
const { currentProject, log, messages } = this;
|
|
616
|
-
await this.
|
|
617
|
-
if (
|
|
618
|
-
const
|
|
989
|
+
const contensis = await this.ConnectContensis();
|
|
990
|
+
if (contensis) {
|
|
991
|
+
const contentTypes = await contensis.models.contentTypes();
|
|
619
992
|
if (Array.isArray(contentTypes)) {
|
|
620
993
|
const contentType = contentTypes.find(
|
|
621
994
|
(c) => c.id.toLowerCase() === contentTypeId.toLowerCase()
|
|
@@ -635,15 +1008,12 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
635
1008
|
};
|
|
636
1009
|
RemoveContentTypes = async (contentTypeIds, commit = false) => {
|
|
637
1010
|
const { currentProject, log, messages } = this;
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
const [err, result] = await this.contensis.DeleteContentTypes(
|
|
645
|
-
contentTypeIds
|
|
646
|
-
);
|
|
1011
|
+
const contensis = await this.ConnectContensisImport({
|
|
1012
|
+
commit,
|
|
1013
|
+
importDataType: "user-input"
|
|
1014
|
+
});
|
|
1015
|
+
if (contensis) {
|
|
1016
|
+
const [err, result] = await contensis.DeleteContentTypes(contentTypeIds);
|
|
647
1017
|
if (err) {
|
|
648
1018
|
log.error(
|
|
649
1019
|
messages.contenttypes.failedRemove(
|
|
@@ -657,7 +1027,7 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
657
1027
|
messages.contenttypes.removed(
|
|
658
1028
|
currentProject,
|
|
659
1029
|
contentTypeIds.join('", "'),
|
|
660
|
-
!
|
|
1030
|
+
!contensis.isPreview
|
|
661
1031
|
)
|
|
662
1032
|
);
|
|
663
1033
|
this.HandleFormattingAndOutput(
|
|
@@ -677,15 +1047,15 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
677
1047
|
throw new Error(`Import file format must be of type JSON`);
|
|
678
1048
|
if (!Array.isArray(fileData))
|
|
679
1049
|
fileData = [fileData];
|
|
680
|
-
await this.ConnectContensisImport({
|
|
1050
|
+
const contensis = await this.ConnectContensisImport({
|
|
681
1051
|
commit,
|
|
682
|
-
|
|
1052
|
+
importDataType: fromFile ? "user-input" : void 0
|
|
683
1053
|
});
|
|
684
|
-
if (
|
|
1054
|
+
if (contensis) {
|
|
685
1055
|
for (const contentType of fileData) {
|
|
686
1056
|
contentType.projectId = currentProject;
|
|
687
1057
|
delete contentType.uuid;
|
|
688
|
-
const [err, created, createStatus] = await
|
|
1058
|
+
const [err, created, createStatus] = await contensis.models.targetRepos[currentProject].repo.UpsertContentType(false, contentType);
|
|
689
1059
|
if (err)
|
|
690
1060
|
log.error(err.message, err);
|
|
691
1061
|
if (createStatus) {
|
|
@@ -702,11 +1072,54 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
702
1072
|
}
|
|
703
1073
|
}
|
|
704
1074
|
};
|
|
1075
|
+
DiffModels = async ({
|
|
1076
|
+
fromFile
|
|
1077
|
+
}, modelIds = []) => {
|
|
1078
|
+
const { log } = this;
|
|
1079
|
+
let fileData = fromFile ? (0, import_file_provider.readJsonFile)(fromFile) || [] : [];
|
|
1080
|
+
if (typeof fileData === "string")
|
|
1081
|
+
throw new Error(`Import file format must be of type JSON`);
|
|
1082
|
+
if (!Array.isArray(fileData))
|
|
1083
|
+
fileData = [fileData];
|
|
1084
|
+
const contensis = await this.ConnectContensisImport({
|
|
1085
|
+
fromFile,
|
|
1086
|
+
importDataType: "models"
|
|
1087
|
+
});
|
|
1088
|
+
if (contensis) {
|
|
1089
|
+
const [err, result] = await (0, import_await_to_js.default)(
|
|
1090
|
+
contensis.models.Diff(fileData.length ? fileData : modelIds)
|
|
1091
|
+
);
|
|
1092
|
+
if (err)
|
|
1093
|
+
log.error(err.message, err);
|
|
1094
|
+
if (result)
|
|
1095
|
+
this.HandleFormattingAndOutput(result, () => {
|
|
1096
|
+
var _a;
|
|
1097
|
+
log.success(
|
|
1098
|
+
`Queried models ${log.infoText(
|
|
1099
|
+
`"${(_a = result.query.modelIds) == null ? void 0 : _a.join(", ")}"`
|
|
1100
|
+
)}
|
|
1101
|
+
`
|
|
1102
|
+
);
|
|
1103
|
+
log.raw(log.boldText(`Content types:`));
|
|
1104
|
+
if (!result.contentTypes)
|
|
1105
|
+
log.info(`- None returned
|
|
1106
|
+
`);
|
|
1107
|
+
else
|
|
1108
|
+
(0, import_console.printModelMigrationAnalysis)(this, result.contentTypes);
|
|
1109
|
+
log.raw(log.boldText(`Components:`));
|
|
1110
|
+
if (!result.components)
|
|
1111
|
+
log.info(`- None returned
|
|
1112
|
+
`);
|
|
1113
|
+
else
|
|
1114
|
+
(0, import_console.printModelMigrationAnalysis)(this, result.components);
|
|
1115
|
+
});
|
|
1116
|
+
}
|
|
1117
|
+
};
|
|
705
1118
|
PrintComponents = async () => {
|
|
706
1119
|
const { currentProject, log, messages } = this;
|
|
707
|
-
await this.
|
|
708
|
-
if (
|
|
709
|
-
const
|
|
1120
|
+
const contensis = await this.ConnectContensis();
|
|
1121
|
+
if (contensis) {
|
|
1122
|
+
const components = await contensis.models.components();
|
|
710
1123
|
if (Array.isArray(components)) {
|
|
711
1124
|
log.success(messages.components.list(currentProject));
|
|
712
1125
|
this.HandleFormattingAndOutput(components, () => {
|
|
@@ -723,9 +1136,9 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
723
1136
|
};
|
|
724
1137
|
PrintComponent = async (componentId) => {
|
|
725
1138
|
const { currentProject, log, messages } = this;
|
|
726
|
-
await this.
|
|
727
|
-
if (
|
|
728
|
-
const
|
|
1139
|
+
const contensis = await this.ConnectContensis();
|
|
1140
|
+
if (contensis) {
|
|
1141
|
+
const components = await contensis.models.components();
|
|
729
1142
|
if (Array.isArray(components)) {
|
|
730
1143
|
const component = components.find(
|
|
731
1144
|
(c) => c.id.toLowerCase() === componentId.toLowerCase()
|
|
@@ -741,13 +1154,12 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
741
1154
|
};
|
|
742
1155
|
RemoveComponents = async (componentIds, commit = false) => {
|
|
743
1156
|
const { currentProject, log, messages } = this;
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
const [err, result] = await this.contensis.DeleteContentTypes(
|
|
1157
|
+
const contensis = await this.ConnectContensisImport({
|
|
1158
|
+
commit,
|
|
1159
|
+
importDataType: "user-input"
|
|
1160
|
+
});
|
|
1161
|
+
if (contensis) {
|
|
1162
|
+
const [err, result] = await contensis.DeleteContentTypes(
|
|
751
1163
|
void 0,
|
|
752
1164
|
componentIds
|
|
753
1165
|
);
|
|
@@ -764,7 +1176,7 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
764
1176
|
messages.components.removed(
|
|
765
1177
|
currentProject,
|
|
766
1178
|
componentIds.join('", "'),
|
|
767
|
-
!
|
|
1179
|
+
!contensis.isPreview
|
|
768
1180
|
)
|
|
769
1181
|
);
|
|
770
1182
|
this.HandleFormattingAndOutput(
|
|
@@ -784,15 +1196,15 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
784
1196
|
throw new Error(`Import file format must be of type JSON`);
|
|
785
1197
|
if (!Array.isArray(fileData))
|
|
786
1198
|
fileData = [fileData];
|
|
787
|
-
await this.ConnectContensisImport({
|
|
1199
|
+
const contensis = await this.ConnectContensisImport({
|
|
788
1200
|
commit,
|
|
789
|
-
|
|
1201
|
+
importDataType: fromFile ? "user-input" : void 0
|
|
790
1202
|
});
|
|
791
|
-
if (
|
|
1203
|
+
if (contensis) {
|
|
792
1204
|
for (const component of fileData) {
|
|
793
1205
|
component.projectId = currentProject;
|
|
794
1206
|
delete component.uuid;
|
|
795
|
-
const [err, created, createStatus] = await
|
|
1207
|
+
const [err, created, createStatus] = await contensis.models.targetRepos[currentProject].repo.UpsertComponent(false, component);
|
|
796
1208
|
if (err)
|
|
797
1209
|
log.error(err.message, err);
|
|
798
1210
|
if (createStatus) {
|
|
@@ -809,33 +1221,37 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
809
1221
|
}
|
|
810
1222
|
}
|
|
811
1223
|
};
|
|
812
|
-
|
|
813
|
-
var _a
|
|
814
|
-
const { currentEnv, log, messages } = this;
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
if (this.contensis.isPreview) {
|
|
1224
|
+
RemoveEntries = async (commit = false) => {
|
|
1225
|
+
var _a;
|
|
1226
|
+
const { currentEnv, currentProject, log, messages } = this;
|
|
1227
|
+
const contensis = await this.ConnectContensisImport({
|
|
1228
|
+
commit,
|
|
1229
|
+
importDataType: "user-input"
|
|
1230
|
+
});
|
|
1231
|
+
if (contensis) {
|
|
1232
|
+
if (contensis.isPreview) {
|
|
822
1233
|
console.log(log.successText(` -- PREVIEW -- `));
|
|
823
1234
|
} else {
|
|
824
1235
|
console.log(log.warningText(` *** COMMITTING DELETE *** `));
|
|
825
1236
|
}
|
|
826
|
-
const [err, result] = await
|
|
1237
|
+
const [err, result] = await contensis.DeleteEntries();
|
|
827
1238
|
if (result)
|
|
828
1239
|
this.HandleFormattingAndOutput(result, () => {
|
|
829
|
-
(0, import_console.printMigrateResult)(this, result, {
|
|
1240
|
+
(0, import_console.printMigrateResult)(this, result, {
|
|
1241
|
+
action: "delete",
|
|
1242
|
+
showAllEntries: true
|
|
1243
|
+
});
|
|
830
1244
|
});
|
|
831
|
-
if (!err && (!commit &&
|
|
832
|
-
log.success(messages.entries.removed(currentEnv,
|
|
833
|
-
if (!commit)
|
|
1245
|
+
if (!err && (!commit && result.entriesToMigrate[currentProject].totalCount || commit && ((_a = result.migrateResult) == null ? void 0 : _a.deleted))) {
|
|
1246
|
+
log.success(messages.entries.removed(currentEnv, commit));
|
|
1247
|
+
if (!commit) {
|
|
1248
|
+
log.raw(``);
|
|
834
1249
|
log.help(messages.entries.commitTip());
|
|
1250
|
+
}
|
|
835
1251
|
} else {
|
|
836
|
-
log.error(messages.entries.failedRemove(currentEnv
|
|
837
|
-
if (!
|
|
838
|
-
log.help(messages.entries.notFound(
|
|
1252
|
+
log.error(messages.entries.failedRemove(currentEnv), err);
|
|
1253
|
+
if (!result.entriesToMigrate[currentProject].totalCount)
|
|
1254
|
+
log.help(messages.entries.notFound(currentEnv));
|
|
839
1255
|
}
|
|
840
1256
|
}
|
|
841
1257
|
};
|
|
@@ -843,90 +1259,252 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
843
1259
|
withDependents = false
|
|
844
1260
|
}) => {
|
|
845
1261
|
const { currentProject, log, messages } = this;
|
|
846
|
-
await this.ConnectContensis();
|
|
847
|
-
if (
|
|
1262
|
+
const contensis = await this.ConnectContensis();
|
|
1263
|
+
if (contensis) {
|
|
848
1264
|
log.line();
|
|
849
|
-
const entries = await
|
|
1265
|
+
const entries = await contensis.GetEntries({ withDependents });
|
|
850
1266
|
this.HandleFormattingAndOutput(
|
|
851
1267
|
entries,
|
|
852
1268
|
() => {
|
|
853
|
-
var _a
|
|
1269
|
+
var _a;
|
|
854
1270
|
return (0, import_migratortron.logEntriesTable)(
|
|
855
1271
|
entries,
|
|
856
1272
|
currentProject,
|
|
857
|
-
(
|
|
1273
|
+
(_a = contensis.payload.query) == null ? void 0 : _a.fields
|
|
858
1274
|
);
|
|
859
1275
|
}
|
|
860
1276
|
);
|
|
861
1277
|
} else {
|
|
862
|
-
log.warning(messages.
|
|
1278
|
+
log.warning(messages.models.noList(currentProject));
|
|
863
1279
|
log.help(messages.connect.tip());
|
|
864
1280
|
}
|
|
865
1281
|
};
|
|
866
1282
|
ImportEntries = async ({
|
|
867
1283
|
commit,
|
|
868
|
-
fromFile
|
|
1284
|
+
fromFile,
|
|
1285
|
+
logOutput
|
|
869
1286
|
}) => {
|
|
1287
|
+
var _a, _b, _c, _d, _e;
|
|
1288
|
+
const { currentEnv, currentProject, log, messages } = this;
|
|
1289
|
+
const contensis = await this.ConnectContensisImport({
|
|
1290
|
+
commit,
|
|
1291
|
+
fromFile,
|
|
1292
|
+
importDataType: "entries"
|
|
1293
|
+
});
|
|
1294
|
+
if (contensis) {
|
|
1295
|
+
log.line();
|
|
1296
|
+
if (contensis.isPreview) {
|
|
1297
|
+
console.log(log.successText(` -- IMPORT PREVIEW -- `));
|
|
1298
|
+
} else {
|
|
1299
|
+
console.log(log.warningText(` *** COMMITTING IMPORT *** `));
|
|
1300
|
+
}
|
|
1301
|
+
const [err, result] = await contensis.MigrateEntries();
|
|
1302
|
+
if (err)
|
|
1303
|
+
(0, import_logger.logError)(err);
|
|
1304
|
+
else
|
|
1305
|
+
this.HandleFormattingAndOutput(result, () => {
|
|
1306
|
+
(0, import_console.printMigrateResult)(this, result, {
|
|
1307
|
+
showAllEntries: logOutput === "all",
|
|
1308
|
+
showChangedEntries: logOutput === "changes"
|
|
1309
|
+
});
|
|
1310
|
+
});
|
|
1311
|
+
if (!err && !((_a = result.errors) == null ? void 0 : _a.length) && (!commit && result.entriesToMigrate[currentProject].totalCount || commit && (((_b = result.migrateResult) == null ? void 0 : _b.created) || ((_c = result.migrateResult) == null ? void 0 : _c.updated)))) {
|
|
1312
|
+
log.success(
|
|
1313
|
+
messages.entries.imported(
|
|
1314
|
+
currentEnv,
|
|
1315
|
+
commit,
|
|
1316
|
+
commit ? (((_d = result.migrateResult) == null ? void 0 : _d.created) || 0) + (((_e = result.migrateResult) == null ? void 0 : _e.updated) || 0) : result.entriesToMigrate[currentProject].totalCount
|
|
1317
|
+
)
|
|
1318
|
+
);
|
|
1319
|
+
if (!commit) {
|
|
1320
|
+
log.raw(``);
|
|
1321
|
+
log.help(messages.entries.commitTip());
|
|
1322
|
+
}
|
|
1323
|
+
} else {
|
|
1324
|
+
log.error(messages.entries.failedImport(currentEnv), err);
|
|
1325
|
+
if (!result.entriesToMigrate[currentProject].totalCount)
|
|
1326
|
+
log.help(messages.entries.notFound(currentEnv));
|
|
1327
|
+
}
|
|
1328
|
+
} else {
|
|
1329
|
+
log.warning(messages.models.noList(currentProject));
|
|
1330
|
+
log.help(messages.connect.tip());
|
|
1331
|
+
}
|
|
1332
|
+
};
|
|
1333
|
+
GetNodes = async (rootPath, depth = 0) => {
|
|
870
1334
|
const { currentProject, log, messages } = this;
|
|
871
|
-
const
|
|
872
|
-
if (
|
|
873
|
-
|
|
874
|
-
|
|
1335
|
+
const contensis = await this.ConnectContensis();
|
|
1336
|
+
if (contensis) {
|
|
1337
|
+
log.line();
|
|
1338
|
+
const [err] = await (0, import_await_to_js.default)(
|
|
1339
|
+
contensis.content.sourceRepo.nodes.GetNodes(rootPath, depth)
|
|
1340
|
+
);
|
|
1341
|
+
if (err) {
|
|
1342
|
+
log.error(messages.nodes.failedGet(currentProject), err);
|
|
1343
|
+
return;
|
|
1344
|
+
}
|
|
1345
|
+
const root = contensis.content.sourceRepo.nodes.tree;
|
|
1346
|
+
log.success(messages.nodes.get(currentProject, rootPath, depth));
|
|
1347
|
+
const outputNode = (node, spaces) => `${node.entry ? log.highlightText("e") : log.infoText("-")}${node.isCanonical ? log.highlightText("c") : log.infoText("-")}${node.includeInMenu ? log.highlightText("m") : log.infoText("-")}${spaces}${node.isCanonical ? log.boldText(`/${node.slug}`) : `/${node.slug}`}${node.entry ? ` ${log.helpText(node.entry.sys.contentTypeId)}` : ""}${node.childCount ? ` +${node.childCount}` : ``} ${log.infoText(node.displayName)}`;
|
|
1348
|
+
this.HandleFormattingAndOutput(root, () => {
|
|
1349
|
+
log.object({ ...root, children: void 0 });
|
|
1350
|
+
log.raw("");
|
|
1351
|
+
log.info(
|
|
1352
|
+
`${log.highlightText("e")} = has entry; ${log.highlightText(
|
|
1353
|
+
"c"
|
|
1354
|
+
)} = canonical; ${log.highlightText("m")} = include in menu`
|
|
1355
|
+
);
|
|
1356
|
+
log.line();
|
|
1357
|
+
const outputChildren = (root2, depth2 = 2) => {
|
|
1358
|
+
let str = "";
|
|
1359
|
+
for (const node of root2 == null ? void 0 : root2.children) {
|
|
1360
|
+
str += `${outputNode(node, Array(depth2 + 1).join(" "))}
|
|
1361
|
+
`;
|
|
1362
|
+
if ("children" in node)
|
|
1363
|
+
str += outputChildren(node, depth2 + 1);
|
|
1364
|
+
}
|
|
1365
|
+
return str;
|
|
1366
|
+
};
|
|
1367
|
+
const children = outputChildren(root);
|
|
1368
|
+
log.limits(
|
|
1369
|
+
`${outputNode(root, " ")}${children ? `
|
|
1370
|
+
${children}` : ""}`,
|
|
1371
|
+
100
|
|
1372
|
+
);
|
|
1373
|
+
});
|
|
1374
|
+
} else {
|
|
1375
|
+
log.warning(messages.models.noList(currentProject));
|
|
1376
|
+
log.help(messages.connect.tip());
|
|
1377
|
+
}
|
|
1378
|
+
};
|
|
1379
|
+
ImportNodes = async ({
|
|
1380
|
+
commit,
|
|
1381
|
+
fromFile,
|
|
1382
|
+
logOutput
|
|
1383
|
+
}) => {
|
|
1384
|
+
var _a, _b, _c;
|
|
1385
|
+
const { currentEnv, currentProject, log, messages } = this;
|
|
1386
|
+
const contensis = await this.ConnectContensisImport({
|
|
875
1387
|
commit,
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
fileDataType: "entries"
|
|
1388
|
+
fromFile,
|
|
1389
|
+
importDataType: "nodes"
|
|
879
1390
|
});
|
|
880
|
-
if (
|
|
1391
|
+
if (contensis) {
|
|
881
1392
|
log.line();
|
|
882
|
-
if (
|
|
1393
|
+
if (contensis.isPreview) {
|
|
883
1394
|
console.log(log.successText(` -- IMPORT PREVIEW -- `));
|
|
884
1395
|
} else {
|
|
885
1396
|
console.log(log.warningText(` *** COMMITTING IMPORT *** `));
|
|
886
1397
|
}
|
|
887
|
-
const [
|
|
888
|
-
if (
|
|
889
|
-
(0, import_logger.logError)(
|
|
1398
|
+
const [err, result] = await contensis.MigrateNodes();
|
|
1399
|
+
if (err)
|
|
1400
|
+
(0, import_logger.logError)(err);
|
|
890
1401
|
else
|
|
891
|
-
this.HandleFormattingAndOutput(
|
|
892
|
-
(0, import_console.printMigrateResult)(this,
|
|
1402
|
+
this.HandleFormattingAndOutput(result, () => {
|
|
1403
|
+
(0, import_console.printMigrateResult)(this, result, {
|
|
1404
|
+
showAllEntries: logOutput === "all",
|
|
1405
|
+
showChangedEntries: logOutput === "changes"
|
|
1406
|
+
});
|
|
893
1407
|
});
|
|
1408
|
+
const nodesTotalCount = result == null ? void 0 : result.nodesToMigrate[currentProject].totalCount;
|
|
1409
|
+
const nodesCreated = ((_a = result == null ? void 0 : result.nodesResult) == null ? void 0 : _a["created"]) || 0;
|
|
1410
|
+
const nodesUpdated = ((_b = result == null ? void 0 : result.nodesResult) == null ? void 0 : _b["updated"]) || 0;
|
|
1411
|
+
const noChange = result.nodesToMigrate[currentProject]["no change"] !== 0;
|
|
1412
|
+
if (!err && !((_c = result.errors) == null ? void 0 : _c.length) && (!commit && nodesTotalCount || commit && (nodesCreated || nodesUpdated))) {
|
|
1413
|
+
let totalCount;
|
|
1414
|
+
if (commit) {
|
|
1415
|
+
let created = typeof nodesCreated === "number" ? nodesCreated : 0;
|
|
1416
|
+
let updated = typeof nodesUpdated === "number" ? nodesUpdated : 0;
|
|
1417
|
+
totalCount = created + updated;
|
|
1418
|
+
} else {
|
|
1419
|
+
totalCount = typeof nodesTotalCount === "number" ? nodesTotalCount : 0;
|
|
1420
|
+
}
|
|
1421
|
+
log.success(messages.nodes.imported(currentEnv, commit, totalCount));
|
|
1422
|
+
if (!commit) {
|
|
1423
|
+
log.raw(``);
|
|
1424
|
+
log.help(messages.nodes.commitTip());
|
|
1425
|
+
}
|
|
1426
|
+
} else {
|
|
1427
|
+
if (noChange) {
|
|
1428
|
+
log.help(messages.nodes.noChange(currentEnv), err);
|
|
1429
|
+
} else {
|
|
1430
|
+
log.error(messages.nodes.failedImport(currentEnv), err);
|
|
1431
|
+
if (!nodesTotalCount)
|
|
1432
|
+
log.help(messages.nodes.notFound(currentEnv));
|
|
1433
|
+
}
|
|
1434
|
+
}
|
|
894
1435
|
} else {
|
|
895
|
-
log.warning(messages.
|
|
1436
|
+
log.warning(messages.models.noList(currentProject));
|
|
896
1437
|
log.help(messages.connect.tip());
|
|
897
1438
|
}
|
|
898
1439
|
};
|
|
899
|
-
PrintWebhookSubscriptions = async (
|
|
1440
|
+
PrintWebhookSubscriptions = async (subscriptionIdsOrNames) => {
|
|
900
1441
|
const { currentEnv, log, messages } = this;
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
const
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
}
|
|
910
|
-
) : Array.isArray(subscriptionIds) ? webhooks.filter((w) => subscriptionIds == null ? void 0 : subscriptionIds.some((id) => id === w.id)) : webhooks;
|
|
911
|
-
if (Array.isArray(filteredResults)) {
|
|
912
|
-
this.HandleFormattingAndOutput(filteredResults, () => {
|
|
913
|
-
log.success(messages.webhooks.list(currentEnv));
|
|
914
|
-
for (const {
|
|
915
|
-
id,
|
|
916
|
-
description,
|
|
917
|
-
method,
|
|
918
|
-
name: name2,
|
|
919
|
-
version,
|
|
920
|
-
url: url2
|
|
921
|
-
} of filteredResults) {
|
|
922
|
-
console.log(
|
|
923
|
-
` - ${name2}${description ? ` (${description})` : ""} [${version.modified.toString().substring(0, 10)} ${version.modifiedBy}]`
|
|
924
|
-
);
|
|
925
|
-
console.log(` ${id}`);
|
|
926
|
-
console.log(` [${method}] ${url2}`);
|
|
1442
|
+
const contensis = await this.ConnectContensis();
|
|
1443
|
+
if (contensis) {
|
|
1444
|
+
const [webhooksErr, webhooks] = await contensis.subscriptions.webhooks.GetSubscriptions();
|
|
1445
|
+
const filteredResults = (subscriptionIdsOrNames == null ? void 0 : subscriptionIdsOrNames.length) ? webhooks == null ? void 0 : webhooks.filter(
|
|
1446
|
+
(w) => (subscriptionIdsOrNames == null ? void 0 : subscriptionIdsOrNames.some(
|
|
1447
|
+
(idname) => {
|
|
1448
|
+
var _a;
|
|
1449
|
+
return (_a = w.name) == null ? void 0 : _a.toLowerCase().includes(idname.toLowerCase());
|
|
927
1450
|
}
|
|
928
|
-
|
|
929
|
-
|
|
1451
|
+
)) || (subscriptionIdsOrNames == null ? void 0 : subscriptionIdsOrNames.some(
|
|
1452
|
+
(id) => id.toLowerCase() === w.id.toLowerCase()
|
|
1453
|
+
))
|
|
1454
|
+
) : webhooks;
|
|
1455
|
+
if (Array.isArray(filteredResults)) {
|
|
1456
|
+
log.success(messages.webhooks.list(currentEnv));
|
|
1457
|
+
if (!(webhooks == null ? void 0 : webhooks.length))
|
|
1458
|
+
log.warning(messages.webhooks.noneExist());
|
|
1459
|
+
else {
|
|
1460
|
+
this.HandleFormattingAndOutput(filteredResults, () => {
|
|
1461
|
+
for (const {
|
|
1462
|
+
id,
|
|
1463
|
+
description,
|
|
1464
|
+
method,
|
|
1465
|
+
name,
|
|
1466
|
+
version,
|
|
1467
|
+
url: url2,
|
|
1468
|
+
enabled,
|
|
1469
|
+
topics,
|
|
1470
|
+
templates,
|
|
1471
|
+
headers
|
|
1472
|
+
} of filteredResults) {
|
|
1473
|
+
console.log(
|
|
1474
|
+
log.infoText(
|
|
1475
|
+
` ${import_chalk.default.bold.white`- ${name}`} ${id} [${(version.modified || version.created).toString().substring(0, 10)} ${version.modifiedBy || version.createdBy}]`
|
|
1476
|
+
)
|
|
1477
|
+
);
|
|
1478
|
+
if (description)
|
|
1479
|
+
console.log(log.infoText` ${description}`);
|
|
1480
|
+
console.log(` ${log.infoText`[${method}]`} ${url2}`);
|
|
1481
|
+
if (headers && Object.keys(headers).length) {
|
|
1482
|
+
console.log(` ${log.infoText`headers`}:`);
|
|
1483
|
+
for (const [key, { value, secret }] of Object.entries(headers))
|
|
1484
|
+
console.log(
|
|
1485
|
+
` ${import_chalk.default.bold.gray(key)}: ${secret ? "\u{1F910}" : value}`
|
|
1486
|
+
);
|
|
1487
|
+
}
|
|
1488
|
+
if (topics == null ? void 0 : topics.length)
|
|
1489
|
+
if ((topics == null ? void 0 : topics.length) === 1)
|
|
1490
|
+
console.log(
|
|
1491
|
+
` ${log.infoText`topics`}: ${topics.map((t) => JSON.stringify(t)).join(" ").replaceAll('"', "").replaceAll(",", " ").replaceAll("{", "").replaceAll("}", "")}`
|
|
1492
|
+
);
|
|
1493
|
+
else {
|
|
1494
|
+
console.log(` ${log.infoText`topics`}:`);
|
|
1495
|
+
log.objectRecurse(topics, 1, " ");
|
|
1496
|
+
}
|
|
1497
|
+
if (templates && Object.keys(templates).length)
|
|
1498
|
+
console.log(
|
|
1499
|
+
` ${log.infoText`templates`}: ${Object.keys(
|
|
1500
|
+
templates
|
|
1501
|
+
).join(" ")}`
|
|
1502
|
+
);
|
|
1503
|
+
if (enabled === false)
|
|
1504
|
+
console.log(` ${log.infoText`enabled`}: ${enabled}`);
|
|
1505
|
+
}
|
|
1506
|
+
});
|
|
1507
|
+
}
|
|
930
1508
|
}
|
|
931
1509
|
if (webhooksErr) {
|
|
932
1510
|
log.error(messages.webhooks.noList(currentEnv));
|
|
@@ -935,14 +1513,13 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
935
1513
|
}
|
|
936
1514
|
};
|
|
937
1515
|
PrintBlocks = async () => {
|
|
938
|
-
const { currentEnv, log, messages } = this;
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
const [err, blocks] = await this.contensis.blocks.GetBlocks();
|
|
1516
|
+
const { currentEnv, env, log, messages } = this;
|
|
1517
|
+
const contensis = await this.ConnectContensis();
|
|
1518
|
+
if (contensis) {
|
|
1519
|
+
const [err, blocks] = await contensis.blocks.GetBlocks();
|
|
943
1520
|
if (Array.isArray(blocks)) {
|
|
944
1521
|
this.HandleFormattingAndOutput(blocks, () => {
|
|
945
|
-
log.success(messages.blocks.list(currentEnv));
|
|
1522
|
+
log.success(messages.blocks.list(currentEnv, env.currentProject));
|
|
946
1523
|
for (const {
|
|
947
1524
|
id,
|
|
948
1525
|
description,
|
|
@@ -960,6 +1537,7 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
960
1537
|
);
|
|
961
1538
|
}
|
|
962
1539
|
});
|
|
1540
|
+
return blocks;
|
|
963
1541
|
}
|
|
964
1542
|
if (err) {
|
|
965
1543
|
log.error(messages.blocks.noList(currentEnv));
|
|
@@ -969,10 +1547,9 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
969
1547
|
};
|
|
970
1548
|
PrintBlockVersions = async (blockId, branch, version) => {
|
|
971
1549
|
const { currentEnv, env, log, messages } = this;
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
const [err, blocks] = await this.contensis.blocks.GetBlockVersions(
|
|
1550
|
+
const contensis = await this.ConnectContensis();
|
|
1551
|
+
if (contensis) {
|
|
1552
|
+
const [err, blocks] = await contensis.blocks.GetBlockVersions(
|
|
976
1553
|
blockId,
|
|
977
1554
|
branch,
|
|
978
1555
|
version
|
|
@@ -980,7 +1557,7 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
980
1557
|
if (blocks) {
|
|
981
1558
|
this.HandleFormattingAndOutput(blocks, () => {
|
|
982
1559
|
log.success(
|
|
983
|
-
messages.blocks.get(
|
|
1560
|
+
messages.blocks.get(blockId, currentEnv, env.currentProject)
|
|
984
1561
|
);
|
|
985
1562
|
for (const block of blocks)
|
|
986
1563
|
(0, import_console.printBlockVersion)(
|
|
@@ -994,6 +1571,7 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
994
1571
|
} : void 0
|
|
995
1572
|
);
|
|
996
1573
|
});
|
|
1574
|
+
return blocks;
|
|
997
1575
|
}
|
|
998
1576
|
if (err) {
|
|
999
1577
|
log.error(messages.blocks.noList(currentEnv, env.currentProject));
|
|
@@ -1003,17 +1581,18 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
1003
1581
|
};
|
|
1004
1582
|
PushBlock = async (block) => {
|
|
1005
1583
|
const { currentEnv, env, log, messages } = this;
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1584
|
+
log.info(
|
|
1585
|
+
messages.blocks.tryPush(
|
|
1586
|
+
block.id,
|
|
1587
|
+
block.source.branch,
|
|
1588
|
+
currentEnv,
|
|
1589
|
+
env.currentProject
|
|
1590
|
+
)
|
|
1011
1591
|
);
|
|
1012
1592
|
console.log((0, import_json.jsonFormatter)(block));
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
const [err, blockVersion] = await this.contensis.blocks.PushBlockVersion(
|
|
1593
|
+
const contensis = await this.ConnectContensis();
|
|
1594
|
+
if (contensis) {
|
|
1595
|
+
const [err, blockVersion] = await contensis.blocks.PushBlockVersion(
|
|
1017
1596
|
block
|
|
1018
1597
|
);
|
|
1019
1598
|
if (!err) {
|
|
@@ -1025,7 +1604,6 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
1025
1604
|
env.currentProject
|
|
1026
1605
|
)
|
|
1027
1606
|
);
|
|
1028
|
-
console.log((0, import_json.jsonFormatter)(blockVersion));
|
|
1029
1607
|
}
|
|
1030
1608
|
if (blockVersion) {
|
|
1031
1609
|
this.HandleFormattingAndOutput(blockVersion, () => {
|
|
@@ -1036,70 +1614,283 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
1036
1614
|
throw new Error(
|
|
1037
1615
|
messages.blocks.failedPush(block.id, currentEnv, env.currentProject)
|
|
1038
1616
|
);
|
|
1617
|
+
} else {
|
|
1618
|
+
throw new Error(
|
|
1619
|
+
messages.blocks.failedPush(block.id, currentEnv, env.currentProject)
|
|
1620
|
+
);
|
|
1039
1621
|
}
|
|
1040
1622
|
};
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
if (
|
|
1046
|
-
|
|
1623
|
+
GetLatestBlockVersion = async (blockId, branch = "default") => {
|
|
1624
|
+
var _a;
|
|
1625
|
+
const { contensis, log, messages } = this;
|
|
1626
|
+
const [getErr, blockVersions] = await (contensis == null ? void 0 : contensis.blocks.GetBlockVersions(blockId, branch)) || [];
|
|
1627
|
+
if (getErr) {
|
|
1628
|
+
return [getErr, void 0];
|
|
1629
|
+
}
|
|
1630
|
+
let blockVersionNo = "latest";
|
|
1631
|
+
try {
|
|
1632
|
+
blockVersionNo = `${(_a = blockVersions == null ? void 0 : blockVersions[0]) == null ? void 0 : _a.version.versionNo}`;
|
|
1633
|
+
if (!Number.isNaN(blockVersionNo) && Number(blockVersionNo) > 0)
|
|
1634
|
+
return [null, blockVersionNo];
|
|
1635
|
+
else
|
|
1636
|
+
throw new Error(`'${blockVersionNo}' is not a valid version number`);
|
|
1637
|
+
} catch (parseVersionEx) {
|
|
1638
|
+
log.info(
|
|
1639
|
+
`Request for blockId: ${blockId}, branch: ${branch}, version: latest`
|
|
1640
|
+
);
|
|
1641
|
+
log.info(
|
|
1642
|
+
`Get block versions response was: ${(0, import_util.tryStringify)(blockVersions)}`
|
|
1643
|
+
);
|
|
1644
|
+
log.error(messages.blocks.failedParsingVersion());
|
|
1645
|
+
return [parseVersionEx, void 0];
|
|
1646
|
+
}
|
|
1647
|
+
};
|
|
1648
|
+
ExecuteBlockAction = async (action, blockId, version = "latest") => {
|
|
1649
|
+
const { currentEnv, env, log, messages } = this;
|
|
1650
|
+
const contensis = await this.ConnectContensis();
|
|
1651
|
+
if (contensis) {
|
|
1652
|
+
let actionOnBlockVersion = version;
|
|
1653
|
+
if (action === "release" && version === "latest") {
|
|
1654
|
+
const [getErr, blockVersion2] = await this.GetLatestBlockVersion(
|
|
1655
|
+
blockId
|
|
1656
|
+
);
|
|
1657
|
+
if (getErr) {
|
|
1658
|
+
throw new Error(
|
|
1659
|
+
`${messages.blocks.noList(
|
|
1660
|
+
currentEnv,
|
|
1661
|
+
env.currentProject
|
|
1662
|
+
)} (${getErr})`
|
|
1663
|
+
);
|
|
1664
|
+
} else if (blockVersion2) {
|
|
1665
|
+
actionOnBlockVersion = blockVersion2;
|
|
1666
|
+
}
|
|
1667
|
+
}
|
|
1668
|
+
const [err, blockVersion] = await contensis.blocks.BlockAction(
|
|
1669
|
+
blockId,
|
|
1670
|
+
action,
|
|
1671
|
+
actionOnBlockVersion
|
|
1672
|
+
);
|
|
1673
|
+
if (blockVersion) {
|
|
1674
|
+
this.HandleFormattingAndOutput(blockVersion, () => {
|
|
1675
|
+
log.success(
|
|
1676
|
+
messages.blocks.actionComplete(
|
|
1677
|
+
action,
|
|
1678
|
+
blockId,
|
|
1679
|
+
currentEnv,
|
|
1680
|
+
env.currentProject
|
|
1681
|
+
)
|
|
1682
|
+
);
|
|
1683
|
+
(0, import_console.printBlockVersion)(this, blockVersion);
|
|
1684
|
+
});
|
|
1685
|
+
}
|
|
1686
|
+
if (err) {
|
|
1687
|
+
log.error((0, import_json.jsonFormatter)(err));
|
|
1688
|
+
throw new Error(
|
|
1689
|
+
messages.blocks.actionFailed(
|
|
1690
|
+
action,
|
|
1691
|
+
blockId,
|
|
1692
|
+
currentEnv,
|
|
1693
|
+
env.currentProject
|
|
1694
|
+
)
|
|
1695
|
+
);
|
|
1696
|
+
}
|
|
1697
|
+
}
|
|
1698
|
+
};
|
|
1699
|
+
PrintBlockLogs = async (blockId, branch, version, dataCenter, follow = false) => {
|
|
1700
|
+
const { currentEnv, env, log, messages } = this;
|
|
1701
|
+
const contensis = await this.ConnectContensis();
|
|
1702
|
+
if (contensis) {
|
|
1703
|
+
log.success(
|
|
1704
|
+
messages.blocks.getLogs(blockId, branch, currentEnv, env.currentProject)
|
|
1705
|
+
);
|
|
1706
|
+
const [err, blockLogs] = await contensis.blocks.GetBlockLogs({
|
|
1047
1707
|
blockId,
|
|
1048
1708
|
branchId: branch,
|
|
1049
1709
|
version,
|
|
1050
1710
|
dataCenter
|
|
1051
1711
|
});
|
|
1052
|
-
if (
|
|
1053
|
-
|
|
1054
|
-
|
|
1712
|
+
if (err) {
|
|
1713
|
+
log.error(
|
|
1714
|
+
messages.blocks.failedGetLogs(blockId, currentEnv, env.currentProject)
|
|
1715
|
+
);
|
|
1716
|
+
log.error((0, import_json.jsonFormatter)(err));
|
|
1717
|
+
} else if (blockLogs) {
|
|
1718
|
+
const removeTrailingNewline = (logs) => logs.endsWith("\n") ? logs.slice(0, logs.length - 1) : logs;
|
|
1719
|
+
const renderLogs = removeTrailingNewline(blockLogs);
|
|
1720
|
+
this.HandleFormattingAndOutput(renderLogs, () => {
|
|
1055
1721
|
console.log(
|
|
1056
|
-
` - ${blockId} ${branch} ${Number(version) ? `v${version}` : version} [${dataCenter}]`
|
|
1722
|
+
` - ${blockId} ${branch} ${Number(version) ? `v${version}` : version} ${dataCenter ? `[${dataCenter}]` : ""}`
|
|
1057
1723
|
);
|
|
1058
1724
|
log.line();
|
|
1059
|
-
console.log(log.infoText(
|
|
1060
|
-
|
|
1725
|
+
console.log(log.infoText(renderLogs));
|
|
1726
|
+
});
|
|
1727
|
+
let following = follow;
|
|
1728
|
+
let alreadyShown = blockLogs;
|
|
1729
|
+
let needsNewLine = false;
|
|
1730
|
+
let counter = 0;
|
|
1731
|
+
const listeners = process.listeners("SIGINT");
|
|
1732
|
+
process.removeAllListeners("SIGINT");
|
|
1733
|
+
process.on("SIGINT", () => {
|
|
1734
|
+
import_logger.Logger.warning(
|
|
1735
|
+
messages.blocks.stopFollow(blockId, currentEnv, env.currentProject)
|
|
1736
|
+
);
|
|
1737
|
+
stopFollowing();
|
|
1738
|
+
});
|
|
1739
|
+
let delay = (0, import_timers.promiseDelay)(5 * 1e3, null);
|
|
1740
|
+
const stopFollowing = () => {
|
|
1741
|
+
following = false;
|
|
1742
|
+
delay.cancel();
|
|
1743
|
+
process.removeAllListeners("SIGINT");
|
|
1744
|
+
for (const listener of listeners)
|
|
1745
|
+
process.addListener("SIGINT", listener);
|
|
1746
|
+
};
|
|
1747
|
+
while (following) {
|
|
1748
|
+
if (counter++ > 300) {
|
|
1749
|
+
import_logger.Logger.warning(
|
|
1750
|
+
messages.blocks.timeoutFollow(
|
|
1751
|
+
blockId,
|
|
1752
|
+
currentEnv,
|
|
1753
|
+
env.currentProject
|
|
1754
|
+
)
|
|
1755
|
+
);
|
|
1756
|
+
stopFollowing();
|
|
1757
|
+
}
|
|
1758
|
+
await delay.wait();
|
|
1759
|
+
const [lastErr, lastLogs] = following ? await contensis.blocks.GetBlockLogs({
|
|
1760
|
+
blockId,
|
|
1761
|
+
branchId: branch,
|
|
1762
|
+
version,
|
|
1763
|
+
dataCenter
|
|
1764
|
+
}) : [null, null];
|
|
1765
|
+
if (lastLogs) {
|
|
1766
|
+
const difference = (0, import_diff.diffLogStrings)(lastLogs, alreadyShown);
|
|
1767
|
+
if (difference) {
|
|
1768
|
+
if (needsNewLine) {
|
|
1769
|
+
console.log("");
|
|
1770
|
+
}
|
|
1771
|
+
const render = removeTrailingNewline(difference);
|
|
1772
|
+
console.log(log.infoText(render));
|
|
1773
|
+
alreadyShown += `${render}
|
|
1774
|
+
`;
|
|
1775
|
+
needsNewLine = false;
|
|
1776
|
+
} else {
|
|
1777
|
+
process.stdout.write(".");
|
|
1778
|
+
needsNewLine = true;
|
|
1779
|
+
}
|
|
1780
|
+
} else if (lastErr) {
|
|
1781
|
+
process.stdout.write("x");
|
|
1782
|
+
needsNewLine = true;
|
|
1783
|
+
}
|
|
1784
|
+
}
|
|
1785
|
+
}
|
|
1786
|
+
}
|
|
1787
|
+
};
|
|
1788
|
+
PrintProxies = async (proxyId) => {
|
|
1789
|
+
const { currentEnv, env, log, messages } = this;
|
|
1790
|
+
const contensis = await this.ConnectContensis();
|
|
1791
|
+
if (contensis) {
|
|
1792
|
+
const [err, proxies] = await contensis.proxies.GetProxies(
|
|
1793
|
+
proxyId
|
|
1794
|
+
);
|
|
1795
|
+
if (Array.isArray(proxies)) {
|
|
1796
|
+
this.HandleFormattingAndOutput(proxies, () => {
|
|
1797
|
+
log.success(messages.proxies.list(currentEnv, env.currentProject));
|
|
1798
|
+
for (const { id, name, description, endpoints, version } of proxies) {
|
|
1799
|
+
console.log(
|
|
1800
|
+
` - ${name} [${version.versionNo}] ${id} ${log.infoText`${description}`}`
|
|
1801
|
+
);
|
|
1802
|
+
for (const [language, endpoint] of Object.entries(
|
|
1803
|
+
endpoints
|
|
1804
|
+
))
|
|
1805
|
+
console.log(
|
|
1806
|
+
` - ${log.infoText`language: ${language}
|
|
1807
|
+
server: ${endpoint.server}
|
|
1808
|
+
headers.host: ${endpoint.headers.host}
|
|
1809
|
+
ssl: ${endpoint.ssl}`}`
|
|
1810
|
+
);
|
|
1811
|
+
}
|
|
1061
1812
|
});
|
|
1062
1813
|
}
|
|
1063
1814
|
if (err) {
|
|
1064
|
-
log.error(messages.
|
|
1815
|
+
log.error(messages.proxies.noList(currentEnv, env.currentProject));
|
|
1816
|
+
log.error((0, import_json.jsonFormatter)(err));
|
|
1817
|
+
}
|
|
1818
|
+
}
|
|
1819
|
+
};
|
|
1820
|
+
PrintRenderers = async (rendererId) => {
|
|
1821
|
+
const { currentEnv, env, log, messages } = this;
|
|
1822
|
+
const contensis = await this.ConnectContensis();
|
|
1823
|
+
if (contensis) {
|
|
1824
|
+
const [err, renderers] = await contensis.renderers.GetRenderers(
|
|
1825
|
+
rendererId
|
|
1826
|
+
);
|
|
1827
|
+
if (Array.isArray(renderers)) {
|
|
1828
|
+
this.HandleFormattingAndOutput(renderers, () => {
|
|
1829
|
+
log.success(messages.renderers.list(currentEnv, env.currentProject));
|
|
1830
|
+
for (const {
|
|
1831
|
+
id,
|
|
1832
|
+
description,
|
|
1833
|
+
assignedContentTypes,
|
|
1834
|
+
rules,
|
|
1835
|
+
version
|
|
1836
|
+
} of renderers) {
|
|
1837
|
+
console.log(
|
|
1838
|
+
` - ${id} [${version.versionNo}] ${log.infoText`${description}`}`
|
|
1839
|
+
);
|
|
1840
|
+
if (assignedContentTypes == null ? void 0 : assignedContentTypes.length)
|
|
1841
|
+
console.log(
|
|
1842
|
+
log.infoText` assignedContentTypes: ${assignedContentTypes.join(
|
|
1843
|
+
", "
|
|
1844
|
+
)}`
|
|
1845
|
+
);
|
|
1846
|
+
for (const rule of rules)
|
|
1847
|
+
if (rule.return)
|
|
1848
|
+
console.log(
|
|
1849
|
+
log.infoText` ${rule.return.endpointId ? "endpointId" : "blockId"}: ${rule.return.endpointId || rule.return.blockId}`
|
|
1850
|
+
);
|
|
1851
|
+
}
|
|
1852
|
+
});
|
|
1853
|
+
}
|
|
1854
|
+
if (err) {
|
|
1855
|
+
log.error(messages.renderers.noList(currentEnv, env.currentProject));
|
|
1065
1856
|
log.error((0, import_json.jsonFormatter)(err));
|
|
1066
1857
|
}
|
|
1067
1858
|
}
|
|
1068
1859
|
};
|
|
1069
1860
|
HandleFormattingAndOutput = (obj, logFn) => {
|
|
1070
1861
|
const { format, log, messages, output } = this;
|
|
1862
|
+
if (!format) {
|
|
1863
|
+
logFn(obj);
|
|
1864
|
+
} else if (format === "csv") {
|
|
1865
|
+
log.raw("");
|
|
1866
|
+
log.raw(log.infoText((0, import_csv.csvFormatter)(obj)));
|
|
1867
|
+
} else if (format === "xml") {
|
|
1868
|
+
log.raw("");
|
|
1869
|
+
log.raw(log.infoText((0, import_xml.xmlFormatter)(obj)));
|
|
1870
|
+
} else if (format === "json") {
|
|
1871
|
+
log.raw("");
|
|
1872
|
+
log.raw(log.infoText((0, import_json.jsonFormatter)(obj)));
|
|
1873
|
+
}
|
|
1874
|
+
log.raw("");
|
|
1071
1875
|
if (output) {
|
|
1072
1876
|
let writeString = "";
|
|
1877
|
+
const isText = !(0, import_util.tryParse)(obj) && typeof obj === "string";
|
|
1073
1878
|
if (format === "csv") {
|
|
1074
1879
|
writeString = (0, import_csv.csvFormatter)(obj);
|
|
1075
1880
|
} else if (format === "xml") {
|
|
1076
1881
|
writeString = (0, import_xml.xmlFormatter)(obj);
|
|
1077
1882
|
} else
|
|
1078
|
-
writeString = (0, import_json.jsonFormatter)(obj);
|
|
1883
|
+
writeString = isText ? obj : (0, import_json.jsonFormatter)(obj);
|
|
1079
1884
|
if (writeString) {
|
|
1080
1885
|
import_fs.default.writeFileSync(output, writeString);
|
|
1081
|
-
log.success(messages.app.fileOutput(format, output));
|
|
1886
|
+
log.success(messages.app.fileOutput(isText ? "text" : format, output));
|
|
1082
1887
|
} else {
|
|
1083
1888
|
log.info(messages.app.noFileOutput());
|
|
1084
1889
|
}
|
|
1085
|
-
} else {
|
|
1086
|
-
if (!format) {
|
|
1087
|
-
logFn(obj);
|
|
1088
|
-
} else if (format === "csv") {
|
|
1089
|
-
log.raw("");
|
|
1090
|
-
log.raw(log.infoText((0, import_csv.csvFormatter)(obj)));
|
|
1091
|
-
} else if (format === "xml") {
|
|
1092
|
-
log.raw("");
|
|
1093
|
-
log.raw(log.infoText((0, import_xml.xmlFormatter)(obj)));
|
|
1094
|
-
} else if (format === "json") {
|
|
1095
|
-
log.raw("");
|
|
1096
|
-
log.raw(log.infoText((0, import_json.jsonFormatter)(obj)));
|
|
1097
|
-
}
|
|
1098
|
-
log.raw("");
|
|
1099
1890
|
}
|
|
1100
1891
|
};
|
|
1101
1892
|
}
|
|
1102
|
-
const cliCommand = (commandArgs, outputOpts
|
|
1893
|
+
const cliCommand = (commandArgs, outputOpts, contensisOpts = {}) => {
|
|
1103
1894
|
return new ContensisCli(["", "", ...commandArgs], outputOpts, contensisOpts);
|
|
1104
1895
|
};
|
|
1105
1896
|
var ContensisCliService_default = ContensisCli;
|