contensis-cli 1.0.0-beta.63 → 1.0.0-beta.64
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/create.js +15 -0
- package/dist/commands/create.js.map +2 -2
- package/dist/commands/remove.js +11 -0
- package/dist/commands/remove.js.map +2 -2
- package/dist/commands/set.js +41 -13
- package/dist/commands/set.js.map +2 -2
- package/dist/localisation/en-GB.js +10 -2
- package/dist/localisation/en-GB.js.map +2 -2
- package/dist/services/ContensisCliService.js +73 -8
- package/dist/services/ContensisCliService.js.map +2 -2
- package/dist/shell.js +7 -3
- package/dist/shell.js.map +2 -2
- package/dist/util/index.js +3 -0
- package/dist/util/index.js.map +2 -2
- package/dist/util/logger.js +11 -13
- package/dist/util/logger.js.map +3 -3
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +2 -2
- package/src/commands/create.ts +24 -0
- package/src/commands/remove.ts +16 -0
- package/src/commands/set.ts +55 -13
- package/src/localisation/en-GB.ts +10 -2
- package/src/services/ContensisCliService.ts +91 -12
- package/src/shell.ts +7 -3
- package/src/util/index.ts +3 -0
- package/src/util/logger.ts +25 -13
- package/src/version.ts +1 -1
package/dist/util/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/util/index.ts"],
|
|
4
|
-
"sourcesContent": ["import mergeWith from 'lodash/mergeWith';\nimport { Logger } from './logger';\nimport { LogMessages as enGB } from '../localisation/en-GB.js';\n\nexport const isSharedSecret = (str = '') =>\n str.length > 80 && str.split('-').length === 3 ? str : undefined;\n\nexport const isPassword = (str = '') =>\n !isSharedSecret(str) ? str : undefined;\n\nexport const tryParse = (str: string) => {\n try {\n return typeof str === 'object' ? str : JSON.parse(str);\n } catch (e) {\n return false;\n }\n};\n\nexport const isJson = (str: string) =>\n typeof str === 'object' || !!tryParse(str);\n\nexport const tryStringify = (obj: any) => {\n try {\n return typeof obj === 'object' ? JSON.stringify(obj) : obj;\n } catch (e) {\n return obj;\n }\n};\n\nexport const isUuid = (str: string) => {\n // Regular expression to check if string is a valid UUID\n const regexExp =\n /^[0-9a-fA-F]{8}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{12}$/gi;\n\n return regexExp.test(str);\n};\n\nexport const url = (alias: string, project: string) => {\n const projectAndAlias =\n project && project.toLowerCase() !== 'website'\n ? `${project.toLowerCase()}-${alias}`\n : alias;\n return {\n api: `https://api-${alias}.cloud.contensis.com`,\n cms: `https://cms-${alias}.cloud.contensis.com`,\n liveWeb: `https://live-${projectAndAlias}.cloud.contensis.com`,\n previewWeb: `https://preview-${projectAndAlias}.cloud.contensis.com`,\n iisWeb: `https://iis-live-${projectAndAlias}.cloud.contensis.com`,\n iisPreviewWeb: `https://iis-preview-${projectAndAlias}.cloud.contensis.com`,\n };\n};\n\nexport const Logging = async (language = 'en-GB') => {\n const defaultMessages = enGB;\n // const { LogMessages: defaultMessages } = await import(\n // `../localisation/en-GB.js`\n // );\n let localisedMessages = defaultMessages;\n\n if (language === 'en-GB') {\n // Using a variable import e.g. `import(`../localisation/${language}.js`);`\n // does not play well with packaged executables\n // So we have to hard code the import for each language individually\n }\n return {\n messages: mergeWith(\n localisedMessages,\n defaultMessages,\n (v, s) => v || s\n ) as typeof defaultMessages,\n Log: Logger,\n };\n};\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAsB;AACtB,oBAAuB;AACvB,mBAAoC;AAE7B,MAAM,iBAAiB,CAAC,MAAM,OACnC,IAAI,SAAS,MAAM,IAAI,MAAM,GAAG,EAAE,WAAW,IAAI,MAAM;AAElD,MAAM,aAAa,CAAC,MAAM,OAC/B,CAAC,eAAe,GAAG,IAAI,MAAM;AAExB,MAAM,WAAW,CAAC,QAAgB;AACvC,MAAI;AACF,WAAO,OAAO,QAAQ,WAAW,MAAM,KAAK,MAAM,GAAG;AAAA,EACvD,SAAS,GAAP;AACA,WAAO;AAAA,EACT;AACF;AAEO,MAAM,SAAS,CAAC,QACrB,OAAO,QAAQ,YAAY,CAAC,CAAC,SAAS,GAAG;AAEpC,MAAM,eAAe,CAAC,QAAa;AACxC,MAAI;AACF,WAAO,OAAO,QAAQ,WAAW,KAAK,UAAU,GAAG,IAAI;AAAA,EACzD,SAAS,GAAP;AACA,WAAO;AAAA,EACT;AACF;AAEO,MAAM,SAAS,CAAC,QAAgB;AAErC,QAAM,WACJ;AAEF,SAAO,SAAS,KAAK,GAAG;AAC1B;AAEO,MAAM,MAAM,CAAC,OAAe,YAAoB;AACrD,QAAM,kBACJ,WAAW,QAAQ,YAAY,MAAM,YACjC,GAAG,QAAQ,YAAY,KAAK,UAC5B;AACN,SAAO;AAAA,IACL,KAAK,eAAe;AAAA,IACpB,KAAK,eAAe;AAAA,IACpB,SAAS,gBAAgB;AAAA,IACzB,YAAY,mBAAmB;AAAA,IAC/B,QAAQ,oBAAoB;AAAA,IAC5B,eAAe,uBAAuB;AAAA,EACxC;AACF;AAEO,MAAM,UAAU,OAAO,WAAW,YAAY;AACnD,QAAM,kBAAkB,aAAAA;AAIxB,MAAI,oBAAoB;AAExB,MAAI,aAAa,SAAS;AAAA,EAI1B;AACA,SAAO;AAAA,IACL,cAAU,iBAAAC;AAAA,MACR;AAAA,MACA;AAAA,MACA,CAAC,GAAG,MAAM,KAAK;AAAA,IACjB;AAAA,IACA,KAAK;AAAA,EACP;AACF;",
|
|
4
|
+
"sourcesContent": ["import mergeWith from 'lodash/mergeWith';\nimport { Logger } from './logger';\nimport { LogMessages as enGB } from '../localisation/en-GB.js';\n\nexport const isSharedSecret = (str = '') =>\n str.length > 80 && str.split('-').length === 3 ? str : undefined;\n\nexport const isPassword = (str = '') =>\n !isSharedSecret(str) ? str : undefined;\n\nexport const tryParse = (str: string) => {\n try {\n return typeof str === 'object' ? str : JSON.parse(str);\n } catch (e) {\n return false;\n }\n};\n\nexport const isJson = (str: string) =>\n typeof str === 'object' || !!tryParse(str);\n\nexport const tryStringify = (obj: any) => {\n try {\n return typeof obj === 'object' ? JSON.stringify(obj) : obj;\n } catch (e) {\n return obj;\n }\n};\n\nexport const isSysError = (error: any): error is Error =>\n error?.message !== undefined && error.stack;\n\nexport const isUuid = (str: string) => {\n // Regular expression to check if string is a valid UUID\n const regexExp =\n /^[0-9a-fA-F]{8}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{12}$/gi;\n\n return regexExp.test(str);\n};\n\nexport const url = (alias: string, project: string) => {\n const projectAndAlias =\n project && project.toLowerCase() !== 'website'\n ? `${project.toLowerCase()}-${alias}`\n : alias;\n return {\n api: `https://api-${alias}.cloud.contensis.com`,\n cms: `https://cms-${alias}.cloud.contensis.com`,\n liveWeb: `https://live-${projectAndAlias}.cloud.contensis.com`,\n previewWeb: `https://preview-${projectAndAlias}.cloud.contensis.com`,\n iisWeb: `https://iis-live-${projectAndAlias}.cloud.contensis.com`,\n iisPreviewWeb: `https://iis-preview-${projectAndAlias}.cloud.contensis.com`,\n };\n};\n\nexport const Logging = async (language = 'en-GB') => {\n const defaultMessages = enGB;\n // const { LogMessages: defaultMessages } = await import(\n // `../localisation/en-GB.js`\n // );\n let localisedMessages = defaultMessages;\n\n if (language === 'en-GB') {\n // Using a variable import e.g. `import(`../localisation/${language}.js`);`\n // does not play well with packaged executables\n // So we have to hard code the import for each language individually\n }\n return {\n messages: mergeWith(\n localisedMessages,\n defaultMessages,\n (v, s) => v || s\n ) as typeof defaultMessages,\n Log: Logger,\n };\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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MACA,CAAC,GAAG,MAAM,KAAK;AAAA,IACjB;AAAA,IACA,KAAK;AAAA,EACP;AACF;",
|
|
6
6
|
"names": ["enGB", "mergeWith"]
|
|
7
7
|
}
|
package/dist/util/logger.js
CHANGED
|
@@ -32,7 +32,6 @@ module.exports = __toCommonJS(logger_exports);
|
|
|
32
32
|
var import_chalk = __toESM(require("chalk"));
|
|
33
33
|
var import_dateformat = __toESM(require("dateformat"));
|
|
34
34
|
var import_deep_cleaner = __toESM(require("deep-cleaner"));
|
|
35
|
-
var import_progress = __toESM(require("progress"));
|
|
36
35
|
var import__ = require(".");
|
|
37
36
|
class Logger {
|
|
38
37
|
static isUserTerminal = !!process.stdout.columns;
|
|
@@ -57,7 +56,7 @@ class Logger {
|
|
|
57
56
|
const message = `${Logger.getPrefix()} ${Logger.errorText(
|
|
58
57
|
`${Logger.isUserTerminal ? "\u274C" : "[ERROR]"} ${content}${err ? `
|
|
59
58
|
|
|
60
|
-
${JSON.stringify(err, null, 2)}` : ""}`
|
|
59
|
+
${(0, import__.isSysError)(err) ? err.toString() : JSON.stringify(err, null, 2)}` : ""}`
|
|
61
60
|
)}${newline}`;
|
|
62
61
|
if (progress.active)
|
|
63
62
|
progress.current.interrupt(message);
|
|
@@ -156,15 +155,19 @@ ${Logger.standardText(content)}`;
|
|
|
156
155
|
} else
|
|
157
156
|
Logger.raw(`${indent}${item}`);
|
|
158
157
|
}
|
|
159
|
-
} else
|
|
158
|
+
} else {
|
|
159
|
+
let pos = 0;
|
|
160
160
|
for (const [key, value] of Object.entries(content)) {
|
|
161
161
|
if (Array.isArray(value)) {
|
|
162
|
+
const thisIndent = pos++ === 0 ? `${indent.substring(0, indent.length - 2)}- ` : indent;
|
|
163
|
+
if (value.length)
|
|
164
|
+
Logger.raw(`${thisIndent}${import_chalk.default.bold.grey(key)}:`);
|
|
162
165
|
for (const item of value) {
|
|
163
166
|
if (item && typeof item === "object") {
|
|
164
167
|
if (Array.isArray(item) && depth > 3)
|
|
165
168
|
Logger.raw(import_chalk.default.grey(`${indent} [${item.join(", ")}]`));
|
|
166
169
|
else
|
|
167
|
-
Logger.objectRecurse(item, depth + 1, `${indent}`);
|
|
170
|
+
Logger.objectRecurse(item, depth + 1, `${indent} `);
|
|
168
171
|
} else {
|
|
169
172
|
Logger.raw(`${indent} ${item}`);
|
|
170
173
|
}
|
|
@@ -176,6 +179,7 @@ ${Logger.standardText(content)}`;
|
|
|
176
179
|
Logger.raw(`${indent}${import_chalk.default.bold.grey(key)}: ${value}`);
|
|
177
180
|
}
|
|
178
181
|
}
|
|
182
|
+
}
|
|
179
183
|
};
|
|
180
184
|
static raw = (content) => {
|
|
181
185
|
if (progress.active)
|
|
@@ -196,15 +200,9 @@ const logError = (err = new Error("Undefined error"), msg, level = "error") => {
|
|
|
196
200
|
return null;
|
|
197
201
|
};
|
|
198
202
|
const progress = {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
current: new import_progress.default(`:bar`, {
|
|
203
|
-
complete: "=",
|
|
204
|
-
incomplete: " ",
|
|
205
|
-
width: 20,
|
|
206
|
-
total: 100
|
|
207
|
-
})
|
|
203
|
+
current: { interrupt: (x) => {
|
|
204
|
+
} },
|
|
205
|
+
active: false
|
|
208
206
|
};
|
|
209
207
|
// Annotate the CommonJS export names for ESM import in node:
|
|
210
208
|
0 && (module.exports = {
|
package/dist/util/logger.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/util/logger.ts"],
|
|
4
|
-
"sourcesContent": ["/* eslint-disable no-console */\nimport chalk from 'chalk';\nimport dateFormat from 'dateformat';\nimport deepCleaner from 'deep-cleaner';\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAkB;AAClB,wBAAuB;AACvB,0BAAwB;
|
|
6
|
-
"names": ["dateFormat", "chalk", "deepCleaner"
|
|
4
|
+
"sourcesContent": ["/* eslint-disable no-console */\nimport chalk from 'chalk';\nimport dateFormat from 'dateformat';\nimport deepCleaner from 'deep-cleaner';\n// import ProgressBar from 'progress';\nimport { isSysError, tryStringify } from '.';\n\ntype LogMethod = (content: string) => void;\ntype LogErrorMethod = (content: string, err?: any, newline?: string) => void;\ntype LogJsonMethod = (content: any, depth?: number, indent?: string) => void;\ntype LogJsonDepthMethod = (content: any, depth: number) => void;\ntype LogArrayMethod = (contentArray: string[]) => void;\ntype LogErrorFunc = (\n err: any,\n msg?: string,\n level?: 'error' | 'critical'\n) => void;\n\nexport class Logger {\n static isUserTerminal = !!process.stdout.columns;\n static getPrefix = () => {\n return Logger.isUserTerminal\n ? Logger.infoText(`[cli]`)\n : `[${dateFormat(new Date(), 'dd/mm HH:MM:ss')}]`;\n };\n static errorText = chalk.bold.red;\n static warningText = chalk.keyword('orange');\n static successText = chalk.keyword('green');\n static helpText = chalk.blue;\n static highlightText = chalk.yellow;\n static infoText = chalk.keyword('grey');\n static standardText = chalk.keyword('white');\n static boldText = chalk.bold;\n static critical: LogMethod = content => {\n const message = `${Logger.getPrefix()} ${Logger.errorText(\n '[CRITICAL]'\n )} ${content}`;\n console.log(message);\n };\n static error: LogErrorMethod = (content, err, newline = '\\n') => {\n const message = `${Logger.getPrefix()} ${Logger.errorText(\n `${Logger.isUserTerminal ? '\u274C' : '[ERROR]'} ${content}${\n err\n ? `\\n\\n${\n isSysError(err) ? err.toString() : JSON.stringify(err, null, 2)\n }`\n : ''\n }`\n )}${newline}`;\n if (progress.active) progress.current.interrupt(message);\n else console.log(message);\n };\n static warning: LogMethod = content => {\n // if (process.env.DEBUG === 'true') {\n const message = `${Logger.getPrefix()} ${Logger.warningText(\n `${Logger.isUserTerminal ? '\u26A0\uFE0F ' : '[WARN]'} ${content}`\n )}\\n`;\n if (progress.active) progress.current.interrupt(message);\n else console.log(message);\n // }\n };\n static success: LogMethod = content => {\n const message = `${Logger.getPrefix()} ${Logger.successText(\n `${Logger.isUserTerminal ? '\u2705' : '[OK]'} ${content}`\n )}`;\n if (progress.active) progress.current.interrupt(message);\n else console.log(message);\n };\n static info: LogMethod = content => {\n const message = `${Logger.getPrefix()} ${\n Logger.isUserTerminal ? chalk.bgCyan(' \u2139 ') : '[INFO]'\n } ${Logger.infoText(content)}`;\n if (progress.active) progress.current.interrupt(message);\n else console.log(message);\n };\n static help: LogMethod = content => {\n const message = `${Logger.getPrefix()} ${chalk.blue(\n `${Logger.isUserTerminal ? '\u23E9' : '[HELP]'} ${content}`\n )}\\n`;\n if (progress.active) progress.current.interrupt(message);\n else console.log(message);\n };\n static standard: LogMethod = content => {\n const message = `${Logger.getPrefix()} ${\n Logger.isUserTerminal ? '\u25FB\uFE0F' : '[STD]'\n } \\n${Logger.standardText(content)}`;\n if (progress.active) progress.current.interrupt(message);\n else console.log(message);\n progress.current.interrupt(message);\n };\n static json: LogJsonDepthMethod = (content, depth = 9) =>\n console.dir(deepCleaner(content), { colors: true, depth });\n static mixed: LogArrayMethod = contentArray =>\n console.log(`${Logger.getPrefix()} ${contentArray.join(' ')}`);\n static line = () =>\n Logger.raw(` ${Logger.infoText(`-------------------------------------`)}`);\n\n static object: LogJsonMethod = content => {\n for (const [key, value] of Object.entries(content || {})) {\n if (value && typeof value === 'object') {\n Logger.raw(` ${chalk.bold.grey(key)}:`);\n if (key === 'fields' && Array.isArray(value)) {\n for (const field of value || []) {\n Logger.raw(\n ` ${chalk.bold(field.id)}${\n field.id === content.entryTitleField\n ? '**'\n : field.validations.minCount?.value ||\n typeof field.validations.required?.message !== 'undefined'\n ? '*'\n : ''\n }: ${chalk.grey(\n `${field.dataType}${\n field.dataFormat\n ? `<${\n Array.isArray(\n field.validations.allowedFieldTypes?.fields\n )\n ? `composer[${field.validations.allowedFieldTypes.fields\n .map((f: any) => f.id)\n .join(' | ')}]`\n : field.dataFormat\n }${\n field.dataFormat === 'entry'\n ? `, ${field.validations.allowedContentTypes.contentTypes.join(\n ' | '\n )}`\n : ''\n }>`\n : ''\n }${\n field.validations.maxLength?.value\n ? `(${field.validations.maxLength.value})`\n : ''\n }`\n )}`\n );\n }\n } else if (key === 'groups' && Array.isArray(value)) {\n for (const group of value || []) {\n const description =\n Object.keys(group.description).length &&\n Object.values(group.description)?.[0];\n Logger.raw(\n ` ${chalk.bold(group.id)}${\n description\n ? `: ${chalk.grey(Object.values(group.description)?.[0])}`\n : ''\n }`\n );\n }\n } else {\n Logger.objectRecurse(value, 3, ' ');\n // for (const [innerkey, innervalue] of Object.entries(value)) {\n // if (innervalue && typeof innervalue === 'object') {\n // Logger.raw(` ${chalk.bold.grey(innerkey)}:`);\n // console.table(innervalue);\n // } else if (\n // typeof innervalue !== 'undefined' &&\n // innervalue !== null\n // ) {\n // Logger.raw(` ${chalk.bold.grey(innerkey)}: ${innervalue}`);\n // }\n // }\n }\n } else if (typeof value !== 'undefined' && value !== null) {\n const valueText =\n key === 'id' && typeof value === 'string'\n ? Logger.highlightText(value)\n : value;\n Logger.raw(` ${chalk.bold.grey(key)}: ${valueText}`);\n }\n }\n };\n\n static objectRecurse: LogJsonMethod = (content, depth = 3, indent = '') => {\n if (Array.isArray(content)) {\n for (const item of content) {\n if (item && typeof item === 'object') {\n if (Array.isArray(item) && depth > 3)\n Logger.raw(chalk.grey(`${indent} [${item.join(', ')}]`));\n else Logger.objectRecurse(item, depth + 1, `${indent} `);\n } else Logger.raw(`${indent}${item}`);\n }\n } else {\n let pos = 0;\n for (const [key, value] of Object.entries(content)) {\n if (Array.isArray(value)) {\n const thisIndent =\n pos++ === 0\n ? `${indent.substring(0, indent.length - 2)}- `\n : indent;\n if (value.length) Logger.raw(`${thisIndent}${chalk.bold.grey(key)}:`);\n for (const item of value) {\n if (item && typeof item === 'object') {\n if (Array.isArray(item) && depth > 3)\n Logger.raw(chalk.grey(`${indent} [${item.join(', ')}]`));\n else Logger.objectRecurse(item, depth + 1, `${indent} `);\n } else {\n Logger.raw(`${indent} ${item}`);\n }\n }\n } else if (value && typeof value === 'object') {\n Logger.raw(`${indent}${chalk.bold.grey(key)}:`);\n\n Logger.objectRecurse(value, depth + 1, `${indent} `);\n // console.table(value);\n } else if (typeof value !== 'undefined' && value !== null) {\n Logger.raw(`${indent}${chalk.bold.grey(key)}: ${value}`);\n }\n }\n }\n };\n static raw: LogMethod = (content: string) => {\n if (progress.active) progress.current.interrupt(content);\n else console.log(content);\n };\n}\n\nexport const logError: LogErrorFunc = (\n err = new Error('Undefined error'),\n msg,\n level = 'error'\n) => {\n Logger[level](msg || err.message || err?.data?.message || err.Message);\n (Array.isArray(err) ? err : [err]).map((error: AppError) => {\n if ('stack' in error) Logger.raw(` ${Logger.infoText(error.stack)}`);\n if ('data' in error)\n Logger.raw(` ${Logger.infoText(tryStringify(error.data))}`);\n });\n //Logger.line();\n return null;\n};\n\nexport const progress = {\n current: { interrupt: (x: string) => {} },\n active: false,\n // done: () => new ProgressBar('', 0),\n // colours: { green: '\\u001b[42m \\u001b[0m', red: '\\u001b[41m \\u001b[0m' },\n // current: new ProgressBar(`:bar`, {\n // complete: '=',\n // incomplete: ' ',\n // width: 20,\n // total: 100,\n // }),\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAkB;AAClB,wBAAuB;AACvB,0BAAwB;AAExB,eAAyC;AAalC,MAAM,OAAO;AAAA,EAClB,OAAO,iBAAiB,CAAC,CAAC,QAAQ,OAAO;AAAA,EACzC,OAAO,YAAY,MAAM;AACvB,WAAO,OAAO,iBACV,OAAO,SAAS,OAAO,IACvB,QAAI,kBAAAA,SAAW,IAAI,KAAK,GAAG,gBAAgB;AAAA,EACjD;AAAA,EACA,OAAO,YAAY,aAAAC,QAAM,KAAK;AAAA,EAC9B,OAAO,cAAc,aAAAA,QAAM,QAAQ,QAAQ;AAAA,EAC3C,OAAO,cAAc,aAAAA,QAAM,QAAQ,OAAO;AAAA,EAC1C,OAA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c,OAAO,QAAQ,GAAG,GAAG,UAAU;AAAA,QAEtD,WAAW,OAAO,UAAU,eAAe,UAAU,MAAM;AACzD,iBAAO,IAAI,GAAG,SAAS,aAAAA,QAAM,KAAK,KAAK,GAAG,MAAM,OAAO;AAAA,QACzD;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA,EACA,OAAO,MAAiB,CAAC,YAAoB;AAC3C,QAAI,SAAS;AAAQ,eAAS,QAAQ,UAAU,OAAO;AAAA;AAClD,cAAQ,IAAI,OAAO;AAAA,EAC1B;AACF;AAEO,MAAM,WAAyB,CACpC,MAAM,IAAI,MAAM,iBAAiB,GACjC,KACA,QAAQ,YACL;AA/NL;AAgOE,SAAO,OAAO,OAAO,IAAI,aAAW,gCAAK,SAAL,mBAAW,YAAW,IAAI,OAAO;AACrE,GAAC,MAAM,QAAQ,GAAG,IAAI,MAAM,CAAC,GAAG,GAAG,IAAI,CAAC,UAAoB;AAC1D,QAAI,WAAW;AAAO,aAAO,IAAI,KAAK,OAAO,SAAS,MAAM,KAAK,GAAG;AACpE,QAAI,UAAU;AACZ,aAAO,IAAI,KAAK,OAAO,aAAS,uBAAa,MAAM,IAAI,CAAC,GAAG;AAAA,EAC/D,CAAC;AAED,SAAO;AACT;AAEO,MAAM,WAAW;AAAA,EACtB,SAAS,EAAE,WAAW,CAAC,MAAc;AAAA,EAAC,EAAE;AAAA,EACxC,QAAQ;AASV;",
|
|
6
|
+
"names": ["dateFormat", "chalk", "deepCleaner"]
|
|
7
7
|
}
|
package/dist/version.js
CHANGED
|
@@ -21,7 +21,7 @@ __export(version_exports, {
|
|
|
21
21
|
LIB_VERSION: () => LIB_VERSION
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(version_exports);
|
|
24
|
-
const LIB_VERSION = "1.0.0-beta.
|
|
24
|
+
const LIB_VERSION = "1.0.0-beta.64";
|
|
25
25
|
// Annotate the CommonJS export names for ESM import in node:
|
|
26
26
|
0 && (module.exports = {
|
|
27
27
|
LIB_VERSION
|
package/dist/version.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/version.ts"],
|
|
4
|
-
"sourcesContent": ["export const LIB_VERSION = \"1.0.0-beta.
|
|
4
|
+
"sourcesContent": ["export const LIB_VERSION = \"1.0.0-beta.64\";\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,MAAM,cAAc;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "contensis-cli",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.64",
|
|
4
4
|
"description": "A fully featured Contensis command line interface with a shell UI provides simple and intuitive ways to manage or profile your content in any NodeJS terminal.",
|
|
5
5
|
"repository": "https://github.com/contensis/node-cli",
|
|
6
6
|
"homepage": "https://github.com/contensis/node-cli/tree/main/packages/contensis-cli#readme",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"jsonpath-mapper": "^1.1.0",
|
|
36
36
|
"keytar": "^7.9.0",
|
|
37
37
|
"lodash": "^4.17.21",
|
|
38
|
-
"migratortron": "^1.0.0-beta.
|
|
38
|
+
"migratortron": "^1.0.0-beta.26",
|
|
39
39
|
"node-fetch": "^2.6.7",
|
|
40
40
|
"patch-package": "^6.4.7",
|
|
41
41
|
"xml2js": "^0.4.23"
|
package/src/commands/create.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { Command } from 'commander';
|
|
|
2
2
|
import { Project } from 'contensis-core-api';
|
|
3
3
|
import { cliCommand } from '~/services/ContensisCliService';
|
|
4
4
|
import { shell } from '~/shell';
|
|
5
|
+
import { isUuid } from '~/util';
|
|
5
6
|
|
|
6
7
|
export const makeCreateCommand = () => {
|
|
7
8
|
const create = new Command()
|
|
@@ -47,6 +48,7 @@ export const makeCreateCommand = () => {
|
|
|
47
48
|
if (project) await shell().restart();
|
|
48
49
|
}
|
|
49
50
|
);
|
|
51
|
+
|
|
50
52
|
create
|
|
51
53
|
.command('key')
|
|
52
54
|
.description('create a new api key')
|
|
@@ -66,5 +68,27 @@ Example call:
|
|
|
66
68
|
);
|
|
67
69
|
});
|
|
68
70
|
|
|
71
|
+
create
|
|
72
|
+
.command('role')
|
|
73
|
+
.description('create a new role')
|
|
74
|
+
.argument('<"Role name">', 'the name of the role to create')
|
|
75
|
+
.argument('["Role description">', 'the description of the role')
|
|
76
|
+
.option('--disabled', 'do not enable the created role', false)
|
|
77
|
+
.addHelpText(
|
|
78
|
+
'after',
|
|
79
|
+
`
|
|
80
|
+
Example call:
|
|
81
|
+
> create role "My role" "This role is for testing" --disabled \n`
|
|
82
|
+
)
|
|
83
|
+
.action(async (roleName: string, description: string, opts) => {
|
|
84
|
+
await cliCommand(['create', 'role', roleName], opts).CreateRole({
|
|
85
|
+
name: roleName,
|
|
86
|
+
description,
|
|
87
|
+
enabled: !opts.disabled,
|
|
88
|
+
assignments: { apiKeys: [], groups: [], users: [] },
|
|
89
|
+
permissions: { contentTypes: [], entries: [] },
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
69
93
|
return create;
|
|
70
94
|
};
|
package/src/commands/remove.ts
CHANGED
|
@@ -42,6 +42,22 @@ Example call:
|
|
|
42
42
|
await cliCommand(['remove', 'key', id], opts).RemoveApiKey(id);
|
|
43
43
|
});
|
|
44
44
|
|
|
45
|
+
remove
|
|
46
|
+
.command('role')
|
|
47
|
+
.description('remove a role')
|
|
48
|
+
.argument('<"Role name" or id>', 'the existing role name or id to delete')
|
|
49
|
+
.addHelpText(
|
|
50
|
+
'after',
|
|
51
|
+
`
|
|
52
|
+
Example call:
|
|
53
|
+
> remove role "My role"\n`
|
|
54
|
+
)
|
|
55
|
+
.action(async (roleNameOrId: string, opts) => {
|
|
56
|
+
await cliCommand(['remove', 'role', roleNameOrId], opts).RemoveRole(
|
|
57
|
+
roleNameOrId
|
|
58
|
+
);
|
|
59
|
+
});
|
|
60
|
+
|
|
45
61
|
remove
|
|
46
62
|
.command('components')
|
|
47
63
|
.description('delete components')
|
package/src/commands/set.ts
CHANGED
|
@@ -68,6 +68,7 @@ Example call:
|
|
|
68
68
|
});
|
|
69
69
|
|
|
70
70
|
const role = set.command('role').description('update a role');
|
|
71
|
+
|
|
71
72
|
role
|
|
72
73
|
.command('name')
|
|
73
74
|
.description('update role name')
|
|
@@ -86,9 +87,52 @@ Example call:
|
|
|
86
87
|
});
|
|
87
88
|
});
|
|
88
89
|
|
|
90
|
+
role
|
|
91
|
+
.command('description')
|
|
92
|
+
.description('update role description')
|
|
93
|
+
.argument('<"Role name" or id>', 'the existing role name or id to update')
|
|
94
|
+
.argument('<"New description">', 'the new description for the role')
|
|
95
|
+
.usage('<"Role name"> <"New description">')
|
|
96
|
+
.addHelpText(
|
|
97
|
+
'after',
|
|
98
|
+
`
|
|
99
|
+
Example call:
|
|
100
|
+
> set role description "Existing role" "New role description"\n`
|
|
101
|
+
)
|
|
102
|
+
.action(async (roleNameOrId: string, description: string, opts) => {
|
|
103
|
+
await cliCommand(['set', 'role', 'description'], opts).UpdateRole(
|
|
104
|
+
roleNameOrId,
|
|
105
|
+
{
|
|
106
|
+
description,
|
|
107
|
+
}
|
|
108
|
+
);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
role
|
|
112
|
+
.command('enabled')
|
|
113
|
+
.description('enable or disable a role')
|
|
114
|
+
.argument('<"Role name" or id>', 'the existing role name or id to update')
|
|
115
|
+
.usage('<"Role name"> --disabled')
|
|
116
|
+
.option('--disabled', 'disable the role', false)
|
|
117
|
+
.addHelpText(
|
|
118
|
+
'after',
|
|
119
|
+
`
|
|
120
|
+
Example call:
|
|
121
|
+
> set role enabled "Existing role"\n
|
|
122
|
+
> set role enabled "Other role" --disabled\n`
|
|
123
|
+
)
|
|
124
|
+
.action(async (roleNameOrId: string, opts) => {
|
|
125
|
+
await cliCommand(
|
|
126
|
+
['set', 'role', opts.disabled ? 'disabled' : 'enabled'],
|
|
127
|
+
opts
|
|
128
|
+
).UpdateRole(roleNameOrId, {
|
|
129
|
+
enabled: !opts.disabled,
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
|
|
89
133
|
role
|
|
90
134
|
.command('assignments')
|
|
91
|
-
.description('
|
|
135
|
+
.description('assign users, groups or keys to a role')
|
|
92
136
|
.argument('<"Role name" or id>', 'the role name or id to update')
|
|
93
137
|
.option(
|
|
94
138
|
'-users --assign-users [assign-users...]',
|
|
@@ -120,21 +164,19 @@ Example call:
|
|
|
120
164
|
|
|
121
165
|
role
|
|
122
166
|
.command('permissions')
|
|
123
|
-
.description('
|
|
167
|
+
.description('add entry permissions to a role')
|
|
124
168
|
.argument('<"Role name" or id>', 'the role name or id to update')
|
|
125
169
|
.option(
|
|
126
|
-
'-
|
|
127
|
-
'
|
|
170
|
+
'-contenttypes, --content-type-ids [content-type-id...]',
|
|
171
|
+
'any content type ids to add permissions for'
|
|
128
172
|
)
|
|
129
173
|
.option(
|
|
130
|
-
'
|
|
131
|
-
'the entry actions to add to the role permissions'
|
|
132
|
-
'*'
|
|
174
|
+
'--entry-actions [entry-actions...]',
|
|
175
|
+
'the entry actions to add to the role permissions'
|
|
133
176
|
)
|
|
134
177
|
.option(
|
|
135
|
-
'
|
|
136
|
-
'the entry languages to add to the role permissions'
|
|
137
|
-
'*'
|
|
178
|
+
'--entry-languages [entry-languages...]',
|
|
179
|
+
'the entry languages to add to the role permissions'
|
|
138
180
|
)
|
|
139
181
|
.addHelpText(
|
|
140
182
|
'after',
|
|
@@ -147,10 +189,10 @@ Example call:
|
|
|
147
189
|
roleNameOrId,
|
|
148
190
|
{
|
|
149
191
|
permissions: {
|
|
150
|
-
entries: opts.
|
|
192
|
+
entries: opts.contentTypeIds?.map((id: string) => ({
|
|
151
193
|
id,
|
|
152
|
-
actions: opts.entryActions,
|
|
153
|
-
languages: opts.entryLanguages,
|
|
194
|
+
actions: opts.entryActions || [],
|
|
195
|
+
languages: opts.entryLanguages || [],
|
|
154
196
|
})),
|
|
155
197
|
},
|
|
156
198
|
}
|
|
@@ -206,6 +206,8 @@ export const LogMessages = {
|
|
|
206
206
|
noList: (env: string) => `[${env}] Cannot retrieve API keys`,
|
|
207
207
|
created: (env: string, name: string) =>
|
|
208
208
|
`[${env}] Created API key ${Logger.highlightText(name)}`,
|
|
209
|
+
tip: () =>
|
|
210
|
+
`Assign your new key to a role with "set role assignments", or create a new role with "create role"`,
|
|
209
211
|
failedCreate: (env: string, name: string) =>
|
|
210
212
|
`[${env}] Unable to create API key ${Logger.highlightText(name)}`,
|
|
211
213
|
removed: (env: string, id: string) =>
|
|
@@ -214,16 +216,22 @@ export const LogMessages = {
|
|
|
214
216
|
`[${env}] Unable to delete API key ${Logger.highlightText(id)}`,
|
|
215
217
|
},
|
|
216
218
|
roles: {
|
|
217
|
-
list: (env: string) => `[${env}] Retrieved roles
|
|
219
|
+
list: (env: string) => `[${env}] Retrieved roles`,
|
|
218
220
|
noList: (env: string) => `[${env}] Cannot retrieve roles`,
|
|
219
221
|
failedGet: (env: string, name: string) =>
|
|
220
222
|
`[${env}] Unable to find role ${Logger.highlightText(name)}`,
|
|
221
223
|
created: (env: string, name: string) =>
|
|
222
224
|
`[${env}] Created role ${Logger.highlightText(name)}`,
|
|
225
|
+
tip: () =>
|
|
226
|
+
`Give access to your role with "set role assignments", allow your role to do things with "set role permissions"`,
|
|
223
227
|
failedCreate: (env: string, name: string) =>
|
|
224
228
|
`[${env}] Unable to create role ${Logger.highlightText(name)}`,
|
|
229
|
+
setPayload: () => `Updating role with details\n`,
|
|
230
|
+
set: () => `Succesfully updated role\n`,
|
|
231
|
+
failedSet: (env: string, name: string) =>
|
|
232
|
+
`[${env}] Unable to update role ${Logger.highlightText(name)}`,
|
|
225
233
|
removed: (env: string, id: string) =>
|
|
226
|
-
`[${env}] Deleted role ${Logger.highlightText(id)}`,
|
|
234
|
+
`[${env}] Deleted role ${Logger.highlightText(id)}\n`,
|
|
227
235
|
failedRemove: (env: string, id: string) =>
|
|
228
236
|
`[${env}] Unable to delete role ${Logger.highlightText(id)}`,
|
|
229
237
|
},
|
|
@@ -754,14 +754,19 @@ class ContensisCli {
|
|
|
754
754
|
|
|
755
755
|
// print the key details to console
|
|
756
756
|
console.log(
|
|
757
|
-
` - ${key.name}${
|
|
758
|
-
|
|
759
|
-
|
|
757
|
+
` - ${chalk.bold(key.name)} [${key.dateModified
|
|
758
|
+
.toString()
|
|
759
|
+
.substring(0, 10)} ${key.modifiedBy}]`
|
|
760
760
|
);
|
|
761
|
-
|
|
762
|
-
|
|
761
|
+
if (key.description)
|
|
762
|
+
console.log(` ${log.infoText(key.description)}`);
|
|
763
|
+
console.log(` ${chalk.bold.grey`id`}: ${key.id}`);
|
|
764
|
+
console.log(
|
|
765
|
+
` ${chalk.bold.grey`sharedSecret`}: ${key.sharedSecret}`
|
|
766
|
+
);
|
|
767
|
+
console.log('');
|
|
768
|
+
log.help(messages.keys.tip());
|
|
763
769
|
}
|
|
764
|
-
console.log('');
|
|
765
770
|
|
|
766
771
|
if (err) {
|
|
767
772
|
log.error(messages.keys.failedCreate(currentEnv, name), err);
|
|
@@ -807,9 +812,10 @@ class ContensisCli {
|
|
|
807
812
|
} of roles) {
|
|
808
813
|
const color = enabled ? (s: string) => s : log.infoText;
|
|
809
814
|
|
|
810
|
-
console.log(color(` - ${name} ${log.infoText(id)}`));
|
|
815
|
+
console.log(color(` - ${chalk.bold(name)} ${log.infoText(id)}`));
|
|
811
816
|
if (description) console.log(log.infoText(` ${description}`));
|
|
812
|
-
|
|
817
|
+
if (enabled === false)
|
|
818
|
+
console.log(` ${chalk.bold.grey('enabled')}: false`);
|
|
813
819
|
if (assignments.groups?.length)
|
|
814
820
|
console.log(
|
|
815
821
|
` ${chalk.bold.grey('groups')}: ${assignments.groups.join(
|
|
@@ -896,6 +902,33 @@ class ContensisCli {
|
|
|
896
902
|
}
|
|
897
903
|
};
|
|
898
904
|
|
|
905
|
+
CreateRole = async (role: Partial<Role>) => {
|
|
906
|
+
const { currentEnv, log, messages } = this;
|
|
907
|
+
const contensis = await this.ConnectContensis();
|
|
908
|
+
|
|
909
|
+
if (contensis) {
|
|
910
|
+
const [err, created] = await contensis.roles.CreateRole(role as Role);
|
|
911
|
+
|
|
912
|
+
if (created) {
|
|
913
|
+
log.success(
|
|
914
|
+
messages.roles.created(currentEnv, role.id || role.name || '')
|
|
915
|
+
);
|
|
916
|
+
|
|
917
|
+
this.HandleFormattingAndOutput(created, log.object);
|
|
918
|
+
|
|
919
|
+
log.help(messages.roles.tip());
|
|
920
|
+
return role.id;
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
if (err) {
|
|
924
|
+
log.error(
|
|
925
|
+
messages.roles.failedCreate(currentEnv, role.id || role.name || ''),
|
|
926
|
+
err
|
|
927
|
+
);
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
};
|
|
931
|
+
|
|
899
932
|
UpdateRole = async (roleNameOrId: string, role: Partial<Role>) => {
|
|
900
933
|
const { currentEnv, log, messages } = this;
|
|
901
934
|
const contensis = await this.ConnectContensis();
|
|
@@ -913,13 +946,59 @@ class ContensisCli {
|
|
|
913
946
|
r.name.toLowerCase() === roleNameOrId.toLowerCase()
|
|
914
947
|
);
|
|
915
948
|
if (existingRole) {
|
|
916
|
-
|
|
949
|
+
log.info(messages.roles.setPayload());
|
|
950
|
+
log.object(role);
|
|
951
|
+
log.raw(``);
|
|
952
|
+
const [updateErr, updated] = await contensis.roles.UpdateRole(
|
|
953
|
+
existingRole.id,
|
|
954
|
+
role
|
|
955
|
+
);
|
|
956
|
+
if (updateErr)
|
|
957
|
+
log.error(messages.roles.failedSet(currentEnv, roleNameOrId));
|
|
958
|
+
else {
|
|
959
|
+
log.success(messages.roles.set());
|
|
960
|
+
|
|
961
|
+
this.HandleFormattingAndOutput(updated, log.object);
|
|
962
|
+
}
|
|
963
|
+
} else {
|
|
964
|
+
// Role does not exist
|
|
965
|
+
log.error(messages.roles.failedGet(currentEnv, roleNameOrId));
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
if (rolesErr) {
|
|
970
|
+
log.error(messages.roles.noList(currentEnv));
|
|
971
|
+
log.error(jsonFormatter(rolesErr));
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
};
|
|
975
|
+
|
|
976
|
+
RemoveRole = async (roleNameOrId: string) => {
|
|
977
|
+
const { currentEnv, log, messages } = this;
|
|
978
|
+
const contensis = await this.ConnectContensis();
|
|
979
|
+
|
|
980
|
+
if (contensis) {
|
|
981
|
+
// Retrieve roles list for env
|
|
982
|
+
const [rolesErr, roles] = await to(contensis.roles.GetRoles());
|
|
983
|
+
|
|
984
|
+
if (Array.isArray(roles)) {
|
|
985
|
+
log.success(messages.roles.list(currentEnv));
|
|
986
|
+
|
|
987
|
+
const existingRole = roles.find(
|
|
988
|
+
r =>
|
|
989
|
+
r.id === roleNameOrId ||
|
|
990
|
+
r.name.toLowerCase() === roleNameOrId.toLowerCase()
|
|
991
|
+
);
|
|
992
|
+
if (existingRole) {
|
|
993
|
+
const [deleteErr] = await contensis.roles.RemoveRole(existingRole.id);
|
|
917
994
|
|
|
918
|
-
|
|
995
|
+
if (deleteErr)
|
|
996
|
+
log.error(messages.roles.failedRemove(currentEnv, roleNameOrId));
|
|
997
|
+
else log.success(messages.roles.removed(currentEnv, roleNameOrId));
|
|
919
998
|
} else {
|
|
920
|
-
//Role not exist
|
|
999
|
+
// Role does not exist
|
|
1000
|
+
log.error(messages.roles.failedGet(currentEnv, roleNameOrId));
|
|
921
1001
|
}
|
|
922
|
-
this.HandleFormattingAndOutput(role, log.object);
|
|
923
1002
|
}
|
|
924
1003
|
|
|
925
1004
|
if (rolesErr) {
|
package/src/shell.ts
CHANGED
|
@@ -135,6 +135,7 @@ class ContensisShell {
|
|
|
135
135
|
availableCommands.push('login', 'list projects', 'set project');
|
|
136
136
|
if (userId)
|
|
137
137
|
availableCommands.push(
|
|
138
|
+
'create key',
|
|
138
139
|
'create project',
|
|
139
140
|
'create role',
|
|
140
141
|
'diff models',
|
|
@@ -158,16 +159,19 @@ class ContensisShell {
|
|
|
158
159
|
'list models',
|
|
159
160
|
'list roles',
|
|
160
161
|
'list webhooks',
|
|
161
|
-
'create key',
|
|
162
162
|
'push block',
|
|
163
163
|
'release block',
|
|
164
|
+
'remove components',
|
|
165
|
+
'remove contenttypes',
|
|
164
166
|
'remove key',
|
|
165
167
|
'remove entries',
|
|
166
|
-
'remove
|
|
167
|
-
'remove components',
|
|
168
|
+
'remove role',
|
|
168
169
|
'set project name',
|
|
169
170
|
'set project description',
|
|
171
|
+
'set role name',
|
|
172
|
+
'set role description',
|
|
170
173
|
'set role assignments',
|
|
174
|
+
'set role enabled',
|
|
171
175
|
'set role permissions'
|
|
172
176
|
);
|
|
173
177
|
|
package/src/util/index.ts
CHANGED
|
@@ -27,6 +27,9 @@ export const tryStringify = (obj: any) => {
|
|
|
27
27
|
}
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
+
export const isSysError = (error: any): error is Error =>
|
|
31
|
+
error?.message !== undefined && error.stack;
|
|
32
|
+
|
|
30
33
|
export const isUuid = (str: string) => {
|
|
31
34
|
// Regular expression to check if string is a valid UUID
|
|
32
35
|
const regexExp =
|