@extrahorizon/exh-cli 1.12.0-dev-143-312ba3f → 1.12.0-dev-145-36d98c7
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/build/commands/data/schemas/delete.js +2 -14
- package/build/commands/data/schemas/init.js +2 -30
- package/build/commands/data/schemas/list.js +2 -15
- package/build/commands/data/schemas/sync.d.ts +3 -5
- package/build/commands/data/schemas/sync.js +4 -40
- package/build/commands/data/schemas/verify.js +6 -51
- package/build/commands/login.js +2 -22
- package/build/commands/sync.d.ts +1 -1
- package/build/commands/sync.js +5 -47
- package/build/commands/whoami.js +3 -10
- package/build/services/auth.d.ts +2 -0
- package/build/services/auth.js +40 -0
- package/build/services/schemas/index.d.ts +5 -0
- package/build/services/schemas/index.js +43 -0
- package/build/services/schemas/init.d.ts +1 -0
- package/build/services/schemas/init.js +37 -0
- package/build/services/schemas/sync.d.ts +3 -0
- package/build/services/schemas/sync.js +44 -0
- package/build/{commands/data → services}/schemas/util/syncSchema.js +1 -1
- package/build/services/schemas/verify.d.ts +1 -0
- package/build/services/schemas/verify.js +56 -0
- package/build/services/sync.d.ts +10 -0
- package/build/services/sync.js +53 -0
- package/package.json +1 -1
- /package/build/{commands/data → services}/schemas/sync/statusHelpers.d.ts +0 -0
- /package/build/{commands/data → services}/schemas/sync/statusHelpers.js +0 -0
- /package/build/{commands/data → services}/schemas/util/listFilesInDir.d.ts +0 -0
- /package/build/{commands/data → services}/schemas/util/listFilesInDir.js +0 -0
- /package/build/{commands/data → services}/schemas/util/readJson.d.ts +0 -0
- /package/build/{commands/data → services}/schemas/util/readJson.js +0 -0
- /package/build/{commands/data → services}/schemas/util/schemaverify.d.ts +0 -0
- /package/build/{commands/data → services}/schemas/util/schemaverify.js +0 -0
- /package/build/{commands/data → services}/schemas/util/stripUnsupportedDescriptionFields.d.ts +0 -0
- /package/build/{commands/data → services}/schemas/util/stripUnsupportedDescriptionFields.js +0 -0
- /package/build/{commands/data → services}/schemas/util/syncSchema.d.ts +0 -0
- /package/build/{commands/data → services}/schemas/util/tests/listFilesInDir.test.d.ts +0 -0
- /package/build/{commands/data → services}/schemas/util/tests/listFilesInDir.test.js +0 -0
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.handler = exports.builder = exports.desc = exports.command = void 0;
|
|
4
|
-
const chalk = require("chalk");
|
|
5
4
|
const util_1 = require("../../../helpers/util");
|
|
6
|
-
const
|
|
5
|
+
const schemaService = require("../../../services/schemas");
|
|
7
6
|
exports.command = 'delete';
|
|
8
7
|
exports.desc = 'Delete a schema';
|
|
9
8
|
const builder = (yargs) => (0, util_1.epilogue)(yargs).option('id', {
|
|
@@ -13,17 +12,6 @@ const builder = (yargs) => (0, util_1.epilogue)(yargs).option('id', {
|
|
|
13
12
|
});
|
|
14
13
|
exports.builder = builder;
|
|
15
14
|
const handler = async ({ id }) => {
|
|
16
|
-
|
|
17
|
-
if (disableResponse.affectedRecords !== 1) {
|
|
18
|
-
console.log(chalk.red('Failed to delete schema', id));
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
const deleteResponse = await schemaRepository.remove(id);
|
|
22
|
-
if (deleteResponse.affectedRecords) {
|
|
23
|
-
console.log(chalk.green('Successfully deleted schema', id));
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
console.log(chalk.red('Failed to delete schema', id));
|
|
27
|
-
}
|
|
15
|
+
await schemaService.remove(id);
|
|
28
16
|
};
|
|
29
17
|
exports.handler = handler;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.handler = exports.builder = exports.desc = exports.command = void 0;
|
|
4
|
-
const promises_1 = require("fs/promises");
|
|
5
|
-
const osPath = require("path");
|
|
6
4
|
const util_1 = require("../../../helpers/util");
|
|
5
|
+
const schemaService = require("../../../services/schemas");
|
|
7
6
|
exports.command = 'init <name>';
|
|
8
7
|
exports.desc = 'Create a basic schema configuration file';
|
|
9
8
|
const builder = (yargs) => (0, util_1.epilogue)(yargs)
|
|
@@ -21,33 +20,6 @@ const builder = (yargs) => (0, util_1.epilogue)(yargs)
|
|
|
21
20
|
});
|
|
22
21
|
exports.builder = builder;
|
|
23
22
|
const handler = async function init({ name, path }) {
|
|
24
|
-
await (
|
|
25
|
-
const filePath = osPath.join(path, `${name}.json`);
|
|
26
|
-
await (0, promises_1.writeFile)(filePath, JSON.stringify(createSchema(name), null, 2));
|
|
27
|
-
console.log(`✅ Successfully created ${filePath}`);
|
|
23
|
+
await schemaService.init(name, path);
|
|
28
24
|
};
|
|
29
25
|
exports.handler = handler;
|
|
30
|
-
function createSchema(name) {
|
|
31
|
-
return {
|
|
32
|
-
name,
|
|
33
|
-
description: `The ${name} schema`,
|
|
34
|
-
createMode: 'allUsers',
|
|
35
|
-
readMode: ['creator'],
|
|
36
|
-
updateMode: ['creator'],
|
|
37
|
-
deleteMode: ['creator'],
|
|
38
|
-
statuses: {
|
|
39
|
-
new: {},
|
|
40
|
-
},
|
|
41
|
-
creationTransition: {
|
|
42
|
-
type: 'manual',
|
|
43
|
-
toStatus: 'new',
|
|
44
|
-
},
|
|
45
|
-
transitions: [],
|
|
46
|
-
properties: {
|
|
47
|
-
firstProperty: {
|
|
48
|
-
type: 'string',
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
$schema: (0, util_1.getSwaggerDocumentationUrl)('config-json-schemas/Schema.json'),
|
|
52
|
-
};
|
|
53
|
-
}
|
|
@@ -2,25 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.handler = exports.builder = exports.desc = exports.command = void 0;
|
|
4
4
|
const util_1 = require("../../../helpers/util");
|
|
5
|
-
const
|
|
5
|
+
const schemaService = require("../../../services/schemas");
|
|
6
6
|
exports.command = 'list';
|
|
7
7
|
exports.desc = 'List all schemas';
|
|
8
8
|
const builder = (yargs) => (0, util_1.epilogue)(yargs);
|
|
9
9
|
exports.builder = builder;
|
|
10
10
|
const handler = async function list({ isTTY }) {
|
|
11
|
-
|
|
12
|
-
if (schemas.length < 1) {
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
if (isTTY) {
|
|
16
|
-
console.table(schemas.map(schema => ({
|
|
17
|
-
Id: schema.id,
|
|
18
|
-
Name: schema.name,
|
|
19
|
-
Description: schema.description || '<none>',
|
|
20
|
-
})));
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
schemas.forEach(schema => console.log([schema.id, schema.name].join(',')));
|
|
24
|
-
}
|
|
11
|
+
await schemaService.list(isTTY);
|
|
25
12
|
};
|
|
26
13
|
exports.handler = handler;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="yargs" />
|
|
2
2
|
export declare const command = "sync";
|
|
3
3
|
export declare const desc = "Sync all schemas in a directory with the ExH cloud";
|
|
4
|
-
export declare const builder: (yargs: any) => import("yargs").Argv<import("yargs").Omit<{}, "file" | "dir" | "
|
|
4
|
+
export declare const builder: (yargs: any) => import("yargs").Argv<import("yargs").Omit<{}, "file" | "dir" | "dry" | "ignoreVerificationErrors"> & import("yargs").InferredOptionTypes<{
|
|
5
5
|
dir: {
|
|
6
6
|
demandOption: false;
|
|
7
7
|
describe: string;
|
|
@@ -24,11 +24,9 @@ export declare const builder: (yargs: any) => import("yargs").Argv<import("yargs
|
|
|
24
24
|
default: boolean;
|
|
25
25
|
};
|
|
26
26
|
}>>;
|
|
27
|
-
export declare const handler: ({
|
|
28
|
-
dir: any;
|
|
27
|
+
export declare const handler: ({ file, dir, dry, ignoreVerificationErrors }: {
|
|
29
28
|
file: any;
|
|
29
|
+
dir: any;
|
|
30
30
|
dry: any;
|
|
31
31
|
ignoreVerificationErrors: any;
|
|
32
32
|
}) => Promise<void>;
|
|
33
|
-
export declare function syncTargetFile(targetFile: string, dry?: boolean, ignoreVerificationErrors?: boolean): Promise<void>;
|
|
34
|
-
export declare function syncTargetDir(targetDir: string, dry?: boolean, ignoreVerificationErrors?: boolean): Promise<void>;
|
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const path = require("path");
|
|
5
|
-
const chalk = require("chalk");
|
|
3
|
+
exports.handler = exports.builder = exports.desc = exports.command = void 0;
|
|
6
4
|
const util_1 = require("../../../helpers/util");
|
|
7
|
-
const
|
|
8
|
-
const readJson_1 = require("./util/readJson");
|
|
9
|
-
const syncSchema_1 = require("./util/syncSchema");
|
|
10
|
-
const verify_1 = require("./verify");
|
|
5
|
+
const schemaService = require("../../../services/schemas");
|
|
11
6
|
exports.command = 'sync';
|
|
12
7
|
exports.desc = 'Sync all schemas in a directory with the ExH cloud';
|
|
13
8
|
const builder = (yargs) => (0, util_1.epilogue)(yargs).options({
|
|
@@ -34,38 +29,7 @@ const builder = (yargs) => (0, util_1.epilogue)(yargs).options({
|
|
|
34
29
|
},
|
|
35
30
|
});
|
|
36
31
|
exports.builder = builder;
|
|
37
|
-
const handler = async ({
|
|
38
|
-
|
|
39
|
-
console.log(chalk.red('No target is chosen to be synced. Please use flags "--file" or "--dir" when syncing'));
|
|
40
|
-
process.exit(1);
|
|
41
|
-
}
|
|
42
|
-
if (dir) {
|
|
43
|
-
await syncTargetDir(path.resolve(dir || '.'), dry, ignoreVerificationErrors);
|
|
44
|
-
}
|
|
45
|
-
if (file) {
|
|
46
|
-
await syncTargetFile(path.resolve(file), dry, ignoreVerificationErrors);
|
|
47
|
-
}
|
|
32
|
+
const handler = async ({ file, dir, dry, ignoreVerificationErrors }) => {
|
|
33
|
+
await schemaService.sync(file, dir, dry, ignoreVerificationErrors);
|
|
48
34
|
};
|
|
49
35
|
exports.handler = handler;
|
|
50
|
-
async function syncTargetFile(targetFile, dry, ignoreVerificationErrors) {
|
|
51
|
-
await (0, verify_1.handler)({ dir: null, file: targetFile, ignoreVerificationErrors });
|
|
52
|
-
const filePath = path.resolve(targetFile);
|
|
53
|
-
if (!filePath.endsWith('.json')) {
|
|
54
|
-
console.log(`Ignored ${path.basename(filePath)}, not a JSON file (needs .json extension)`);
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
console.log(chalk.bold(`Synchronizing ${path.basename(filePath)}`));
|
|
58
|
-
const targetSchema = await (0, readJson_1.readJsonFile)(filePath);
|
|
59
|
-
const syncSchema = syncSchema_1.SyncSchema.createSchemaSync(dry);
|
|
60
|
-
await syncSchema.sync(targetSchema);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
exports.syncTargetFile = syncTargetFile;
|
|
64
|
-
async function syncTargetDir(targetDir, dry, ignoreVerificationErrors) {
|
|
65
|
-
const targetFiles = (0, listFilesInDir_1.flatListFiles)(targetDir, '.json');
|
|
66
|
-
for (const filePath of targetFiles) {
|
|
67
|
-
await syncTargetFile(filePath, dry, ignoreVerificationErrors);
|
|
68
|
-
process.stdout.write('\n');
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
exports.syncTargetDir = syncTargetDir;
|
|
@@ -3,16 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.handler = exports.builder = exports.desc = exports.command = void 0;
|
|
4
4
|
const fs = require("fs");
|
|
5
5
|
const path = require("path");
|
|
6
|
-
const ajv_1 = require("ajv");
|
|
7
|
-
const chalk = require("chalk");
|
|
8
|
-
const metaschema = require("../../../config-json-schemas/Schema.json");
|
|
9
|
-
const error_1 = require("../../../helpers/error");
|
|
10
6
|
const util_1 = require("../../../helpers/util");
|
|
11
|
-
const
|
|
12
|
-
const schemaverify_1 = require("./util/schemaverify");
|
|
7
|
+
const schemaService = require("../../../services/schemas");
|
|
13
8
|
exports.command = 'verify';
|
|
14
9
|
exports.desc = 'Syntactically verify a local schema';
|
|
15
|
-
const builder = (yargs) => (0, util_1.epilogue)(yargs)
|
|
10
|
+
const builder = (yargs) => (0, util_1.epilogue)(yargs)
|
|
11
|
+
.options({
|
|
16
12
|
file: {
|
|
17
13
|
describe: 'schema json file which needs to be verified',
|
|
18
14
|
type: 'string',
|
|
@@ -21,7 +17,8 @@ const builder = (yargs) => (0, util_1.epilogue)(yargs).options({
|
|
|
21
17
|
describe: 'directory containing schemas to be verified',
|
|
22
18
|
type: 'string',
|
|
23
19
|
},
|
|
24
|
-
})
|
|
20
|
+
})
|
|
21
|
+
.check(({ file, dir }) => {
|
|
25
22
|
if (file && (!fs.existsSync(path.resolve(file)) || !fs.lstatSync(path.resolve(file)).isFile())) {
|
|
26
23
|
throw new Error('Schema file does not exist, please make sure you provided the correct file path');
|
|
27
24
|
}
|
|
@@ -35,48 +32,6 @@ const builder = (yargs) => (0, util_1.epilogue)(yargs).options({
|
|
|
35
32
|
});
|
|
36
33
|
exports.builder = builder;
|
|
37
34
|
const handler = async ({ file, dir, ignoreVerificationErrors }) => {
|
|
38
|
-
|
|
39
|
-
if (dir) {
|
|
40
|
-
files = await (0, listFilesInDir_1.flatListFiles)(dir, '.json');
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
files = [file];
|
|
44
|
-
}
|
|
45
|
-
const checkFile = (schemaPath) => {
|
|
46
|
-
let schema = {};
|
|
47
|
-
console.log(chalk.bold('Checking', schemaPath));
|
|
48
|
-
try {
|
|
49
|
-
schema = require(path.resolve(schemaPath));
|
|
50
|
-
}
|
|
51
|
-
catch (err) {
|
|
52
|
-
console.log(chalk.red(`Failed to load schema file ${file}. Possibly not a valid JSON file`));
|
|
53
|
-
console.log(err);
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
const ajv = new ajv_1.default();
|
|
57
|
-
for (const result of (new schemaverify_1.SchemaVerify(ajv, schema, metaschema)).RunChecks()) {
|
|
58
|
-
if (result.ok) {
|
|
59
|
-
console.log(chalk.green(`${result.test}... ✓`));
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
console.log(chalk.red(`${result.test}... x`));
|
|
63
|
-
for (const error of result.errors) {
|
|
64
|
-
if (typeof error === 'object') {
|
|
65
|
-
console.log('\t', chalk.red(JSON.stringify(error, null, 4)));
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
console.log('\t', chalk.red(error));
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
if (!ignoreVerificationErrors) {
|
|
72
|
-
throw new error_1.CommandError(`Schema ${schemaPath} contains error, please fix`);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
console.log();
|
|
77
|
-
};
|
|
78
|
-
for (const f of files) {
|
|
79
|
-
checkFile(f);
|
|
80
|
-
}
|
|
35
|
+
await schemaService.verify(file, dir, ignoreVerificationErrors);
|
|
81
36
|
};
|
|
82
37
|
exports.handler = handler;
|
package/build/commands/login.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.handler = exports.builder = exports.desc = exports.command = void 0;
|
|
4
|
-
const fs = require("fs/promises");
|
|
5
|
-
const chalk = require("chalk");
|
|
6
|
-
const constants_1 = require("../constants");
|
|
7
|
-
const exh_1 = require("../exh");
|
|
8
4
|
const util_1 = require("../helpers/util");
|
|
5
|
+
const authService = require("../services/auth");
|
|
9
6
|
exports.command = 'login';
|
|
10
7
|
exports.desc = 'Retrieve credentials from ExH';
|
|
11
8
|
const builder = (yargs) => (0, util_1.epilogue)(yargs).options({
|
|
@@ -37,23 +34,6 @@ const builder = (yargs) => (0, util_1.epilogue)(yargs).options({
|
|
|
37
34
|
});
|
|
38
35
|
exports.builder = builder;
|
|
39
36
|
const handler = async ({ host, email, password, consumerKey, consumerSecret }) => {
|
|
40
|
-
|
|
41
|
-
const response = await sdk.auth.authenticate({
|
|
42
|
-
email,
|
|
43
|
-
password,
|
|
44
|
-
});
|
|
45
|
-
try {
|
|
46
|
-
await fs.stat(constants_1.EXH_CONFIG_FILE_DIR);
|
|
47
|
-
}
|
|
48
|
-
catch (err) {
|
|
49
|
-
await fs.mkdir(constants_1.EXH_CONFIG_FILE_DIR);
|
|
50
|
-
}
|
|
51
|
-
await fs.writeFile(constants_1.EXH_CONFIG_FILE, `API_HOST=${host}
|
|
52
|
-
API_OAUTH_CONSUMER_KEY=${consumerKey}
|
|
53
|
-
API_OAUTH_CONSUMER_SECRET=${consumerSecret}
|
|
54
|
-
API_OAUTH_TOKEN=${response.token}
|
|
55
|
-
API_OAUTH_TOKEN_SECRET=${response.tokenSecret}
|
|
56
|
-
`);
|
|
57
|
-
console.log(chalk.green('Wrote credentials to', constants_1.EXH_CONFIG_FILE));
|
|
37
|
+
await authService.login(host, email, password, consumerKey, consumerSecret);
|
|
58
38
|
};
|
|
59
39
|
exports.handler = handler;
|
package/build/commands/sync.d.ts
CHANGED
|
@@ -49,7 +49,7 @@ export declare const builder: (yargs: any) => import("yargs").Argv<import("yargs
|
|
|
49
49
|
default: boolean;
|
|
50
50
|
};
|
|
51
51
|
}>>;
|
|
52
|
-
export declare const handler: (
|
|
52
|
+
export declare const handler: (options: {
|
|
53
53
|
path?: string;
|
|
54
54
|
schemas?: boolean;
|
|
55
55
|
tasks?: boolean;
|
package/build/commands/sync.js
CHANGED
|
@@ -1,17 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.handler = exports.builder = exports.desc = exports.command = void 0;
|
|
4
|
-
const fs_1 = require("fs");
|
|
5
4
|
const fs = require("fs/promises");
|
|
6
5
|
const ospath = require("path");
|
|
7
|
-
const chalk = require("chalk");
|
|
8
6
|
const repoConfig_1 = require("../helpers/repoConfig");
|
|
9
7
|
const util_1 = require("../helpers/util");
|
|
10
|
-
const
|
|
11
|
-
const localizations_1 = require("../services/localizations");
|
|
12
|
-
const sync_1 = require("./data/schemas/sync");
|
|
13
|
-
const sync_2 = require("./tasks/sync");
|
|
14
|
-
const sync_3 = require("./templates/sync");
|
|
8
|
+
const syncService = require("../services/sync");
|
|
15
9
|
exports.command = 'sync';
|
|
16
10
|
exports.desc = 'Sync your ExH configuration to the cloud environment';
|
|
17
11
|
const builder = (yargs) => (0, util_1.epilogue)(yargs)
|
|
@@ -63,7 +57,8 @@ If not, the local directory is assumed with a default configuration which assume
|
|
|
63
57
|
type: 'boolean',
|
|
64
58
|
default: false,
|
|
65
59
|
},
|
|
66
|
-
})
|
|
60
|
+
})
|
|
61
|
+
.check(async ({ path }) => {
|
|
67
62
|
if (path !== undefined) {
|
|
68
63
|
try {
|
|
69
64
|
await fs.access(ospath.join(process.cwd(), path, repoConfig_1.REPO_CONFIG_FILE));
|
|
@@ -78,44 +73,7 @@ If not, the local directory is assumed with a default configuration which assume
|
|
|
78
73
|
return true;
|
|
79
74
|
});
|
|
80
75
|
exports.builder = builder;
|
|
81
|
-
const handler = async (
|
|
82
|
-
|
|
83
|
-
const cfg = await (0, repoConfig_1.getRepoConfig)(targetPath);
|
|
84
|
-
const syncAll = !(schemas || tasks || templates || dispatchers || localizations);
|
|
85
|
-
if ((syncAll || schemas) && cfg.schemas) {
|
|
86
|
-
console.log(chalk.green('\n ⚙️ Syncing schemas ...'));
|
|
87
|
-
for (const schema of cfg.schemas) {
|
|
88
|
-
await (0, sync_1.syncTargetDir)(ospath.join(targetPath, schema), undefined, ignoreSchemaVerificationErrors);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
if ((syncAll || templates) && cfg.templates) {
|
|
92
|
-
console.log(chalk.green('\n ⚙️ Syncing templates...'));
|
|
93
|
-
for (const template of cfg.templates) {
|
|
94
|
-
await (0, sync_3.handler)({ path: ospath.join(targetPath, template), template: null });
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
if ((syncAll || tasks) && cfg.tasks) {
|
|
98
|
-
console.log(chalk.green('\n ⚙️ Syncing tasks...'));
|
|
99
|
-
for (const task of cfg.tasks) {
|
|
100
|
-
await (0, sync_2.handler)({ path: ospath.join(targetPath, task) });
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
if ((syncAll || localizations) && cfg.localizations) {
|
|
104
|
-
console.log(chalk.green('\n ⚙️ Syncing localizations...'));
|
|
105
|
-
for (const localization of cfg.localizations) {
|
|
106
|
-
await (0, localizations_1.sync)(ospath.join(targetPath, localization));
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
if ((syncAll || dispatchers)) {
|
|
110
|
-
const dispatchersPath = ospath.join(targetPath, 'dispatchers.json');
|
|
111
|
-
const isValidPath = (0, fs_1.existsSync)(dispatchersPath);
|
|
112
|
-
if (isValidPath) {
|
|
113
|
-
console.log(chalk.green('\n ⚙️ Syncing dispatchers...'));
|
|
114
|
-
await (0, dispatchers_1.sync)(dispatchersPath, cleanDispatchers);
|
|
115
|
-
}
|
|
116
|
-
else if (dispatchers) {
|
|
117
|
-
console.log(chalk.yellow('Warning: dispatchers.json not found'));
|
|
118
|
-
}
|
|
119
|
-
}
|
|
76
|
+
const handler = async (options) => {
|
|
77
|
+
await syncService.sync(options);
|
|
120
78
|
};
|
|
121
79
|
exports.handler = handler;
|
package/build/commands/whoami.js
CHANGED
|
@@ -2,19 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.handler = exports.builder = exports.desc = exports.command = void 0;
|
|
4
4
|
const util_1 = require("../helpers/util");
|
|
5
|
-
const
|
|
5
|
+
const authService = require("../services/auth");
|
|
6
6
|
exports.command = 'whoami';
|
|
7
7
|
exports.desc = 'Shows the currently logged in user';
|
|
8
8
|
const builder = (yargs) => (0, util_1.epilogue)(yargs);
|
|
9
9
|
exports.builder = builder;
|
|
10
|
-
const handler = async function
|
|
11
|
-
|
|
12
|
-
if (!host) {
|
|
13
|
-
console.log('No ExH cluster host was found in the configuration.');
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
console.log('You are targeting:', host);
|
|
17
|
-
const currentUser = await authRepository.fetchMe();
|
|
18
|
-
console.log('You are logged in as:', currentUser.email);
|
|
10
|
+
const handler = async function whoami() {
|
|
11
|
+
await authService.whoami();
|
|
19
12
|
};
|
|
20
13
|
exports.handler = handler;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.whoami = exports.login = void 0;
|
|
4
|
+
const fs = require("fs/promises");
|
|
5
|
+
const chalk = require("chalk");
|
|
6
|
+
const constants_1 = require("../constants");
|
|
7
|
+
const exh_1 = require("../exh");
|
|
8
|
+
const authRepository = require("../repositories/auth");
|
|
9
|
+
async function login(host, email, password, consumerKey, consumerSecret) {
|
|
10
|
+
const sdk = (0, exh_1.sdkInitOnly)(host, consumerKey, consumerSecret);
|
|
11
|
+
const response = await sdk.auth.authenticate({
|
|
12
|
+
email,
|
|
13
|
+
password,
|
|
14
|
+
});
|
|
15
|
+
try {
|
|
16
|
+
await fs.stat(constants_1.EXH_CONFIG_FILE_DIR);
|
|
17
|
+
}
|
|
18
|
+
catch (err) {
|
|
19
|
+
await fs.mkdir(constants_1.EXH_CONFIG_FILE_DIR);
|
|
20
|
+
}
|
|
21
|
+
await fs.writeFile(constants_1.EXH_CONFIG_FILE, `API_HOST=${host}
|
|
22
|
+
API_OAUTH_CONSUMER_KEY=${consumerKey}
|
|
23
|
+
API_OAUTH_CONSUMER_SECRET=${consumerSecret}
|
|
24
|
+
API_OAUTH_TOKEN=${response.token}
|
|
25
|
+
API_OAUTH_TOKEN_SECRET=${response.tokenSecret}
|
|
26
|
+
`);
|
|
27
|
+
console.log(chalk.green('Wrote credentials to', constants_1.EXH_CONFIG_FILE));
|
|
28
|
+
}
|
|
29
|
+
exports.login = login;
|
|
30
|
+
async function whoami() {
|
|
31
|
+
const host = authRepository.getHost();
|
|
32
|
+
if (!host) {
|
|
33
|
+
console.log('No ExH cluster host was found in the configuration.');
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
console.log('You are targeting:', host);
|
|
37
|
+
const currentUser = await authRepository.fetchMe();
|
|
38
|
+
console.log('You are logged in as:', currentUser.email);
|
|
39
|
+
}
|
|
40
|
+
exports.whoami = whoami;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.remove = exports.list = exports.sync = exports.verify = exports.init = void 0;
|
|
4
|
+
const chalk = require("chalk");
|
|
5
|
+
const schemaRepository = require("../../repositories/schemas");
|
|
6
|
+
var init_1 = require("./init");
|
|
7
|
+
Object.defineProperty(exports, "init", { enumerable: true, get: function () { return init_1.init; } });
|
|
8
|
+
var verify_1 = require("./verify");
|
|
9
|
+
Object.defineProperty(exports, "verify", { enumerable: true, get: function () { return verify_1.verify; } });
|
|
10
|
+
var sync_1 = require("./sync");
|
|
11
|
+
Object.defineProperty(exports, "sync", { enumerable: true, get: function () { return sync_1.sync; } });
|
|
12
|
+
async function list(isTTY) {
|
|
13
|
+
const schemas = await schemaRepository.fetchAll();
|
|
14
|
+
if (schemas.length < 1) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (isTTY) {
|
|
18
|
+
console.table(schemas.map(schema => ({
|
|
19
|
+
Id: schema.id,
|
|
20
|
+
Name: schema.name,
|
|
21
|
+
Description: schema.description || '<none>',
|
|
22
|
+
})));
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
schemas.forEach(schema => console.log([schema.id, schema.name].join(',')));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.list = list;
|
|
29
|
+
async function remove(id) {
|
|
30
|
+
const disableResponse = await schemaRepository.disable(id);
|
|
31
|
+
if (disableResponse.affectedRecords !== 1) {
|
|
32
|
+
console.log(chalk.red('Failed to delete schema', id));
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const deleteResponse = await schemaRepository.remove(id);
|
|
36
|
+
if (deleteResponse.affectedRecords) {
|
|
37
|
+
console.log(chalk.green('Successfully deleted schema', id));
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
console.log(chalk.red('Failed to delete schema', id));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.remove = remove;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function init(name: string, path: string): Promise<void>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.init = void 0;
|
|
4
|
+
const promises_1 = require("fs/promises");
|
|
5
|
+
const osPath = require("path");
|
|
6
|
+
const util_1 = require("../../helpers/util");
|
|
7
|
+
async function init(name, path) {
|
|
8
|
+
await (0, promises_1.mkdir)(path, { recursive: true });
|
|
9
|
+
const filePath = osPath.join(path, `${name}.json`);
|
|
10
|
+
await (0, promises_1.writeFile)(filePath, JSON.stringify(createSchema(name), null, 2));
|
|
11
|
+
console.log(`✅ Successfully created ${filePath}`);
|
|
12
|
+
}
|
|
13
|
+
exports.init = init;
|
|
14
|
+
function createSchema(name) {
|
|
15
|
+
return {
|
|
16
|
+
name,
|
|
17
|
+
description: `The ${name} schema`,
|
|
18
|
+
createMode: 'allUsers',
|
|
19
|
+
readMode: ['creator'],
|
|
20
|
+
updateMode: ['creator'],
|
|
21
|
+
deleteMode: ['creator'],
|
|
22
|
+
statuses: {
|
|
23
|
+
new: {},
|
|
24
|
+
},
|
|
25
|
+
creationTransition: {
|
|
26
|
+
type: 'manual',
|
|
27
|
+
toStatus: 'new',
|
|
28
|
+
},
|
|
29
|
+
transitions: [],
|
|
30
|
+
properties: {
|
|
31
|
+
firstProperty: {
|
|
32
|
+
type: 'string',
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
$schema: (0, util_1.getSwaggerDocumentationUrl)('config-json-schemas/Schema.json'),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare function sync(file?: string, dir?: string, dry?: boolean, ignoreVerificationErrors?: boolean): Promise<void>;
|
|
2
|
+
export declare function syncTargetFile(targetFile: string, dry?: boolean, ignoreVerificationErrors?: boolean): Promise<void>;
|
|
3
|
+
export declare function syncTargetDir(targetDir: string, dry?: boolean, ignoreVerificationErrors?: boolean): Promise<void>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.syncTargetDir = exports.syncTargetFile = exports.sync = void 0;
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const chalk = require("chalk");
|
|
6
|
+
const listFilesInDir_1 = require("./util/listFilesInDir");
|
|
7
|
+
const readJson_1 = require("./util/readJson");
|
|
8
|
+
const syncSchema_1 = require("./util/syncSchema");
|
|
9
|
+
const verify_1 = require("./verify");
|
|
10
|
+
async function sync(file, dir, dry, ignoreVerificationErrors) {
|
|
11
|
+
if (!file && !dir) {
|
|
12
|
+
console.log(chalk.red('No target is chosen to be synced. Please use flags "--file" or "--dir" when syncing'));
|
|
13
|
+
process.exit(1);
|
|
14
|
+
}
|
|
15
|
+
if (dir) {
|
|
16
|
+
await syncTargetDir(path.resolve(dir || '.'), dry, ignoreVerificationErrors);
|
|
17
|
+
}
|
|
18
|
+
if (file) {
|
|
19
|
+
await syncTargetFile(path.resolve(file), dry, ignoreVerificationErrors);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.sync = sync;
|
|
23
|
+
async function syncTargetFile(targetFile, dry, ignoreVerificationErrors) {
|
|
24
|
+
await (0, verify_1.verify)(targetFile, null, ignoreVerificationErrors);
|
|
25
|
+
const filePath = path.resolve(targetFile);
|
|
26
|
+
if (!filePath.endsWith('.json')) {
|
|
27
|
+
console.log(`Ignored ${path.basename(filePath)}, not a JSON file (needs .json extension)`);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
console.log(chalk.bold(`Synchronizing ${path.basename(filePath)}`));
|
|
31
|
+
const targetSchema = await (0, readJson_1.readJsonFile)(filePath);
|
|
32
|
+
const syncSchema = syncSchema_1.SyncSchema.createSchemaSync(dry);
|
|
33
|
+
await syncSchema.sync(targetSchema);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.syncTargetFile = syncTargetFile;
|
|
37
|
+
async function syncTargetDir(targetDir, dry, ignoreVerificationErrors) {
|
|
38
|
+
const targetFiles = (0, listFilesInDir_1.flatListFiles)(targetDir, '.json');
|
|
39
|
+
for (const filePath of targetFiles) {
|
|
40
|
+
await syncTargetFile(filePath, dry, ignoreVerificationErrors);
|
|
41
|
+
process.stdout.write('\n');
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.syncTargetDir = syncTargetDir;
|
|
@@ -9,7 +9,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.compareSchemaKey = exports.SyncSchema = void 0;
|
|
10
10
|
const chalk = require("chalk");
|
|
11
11
|
const _ = require("lodash");
|
|
12
|
-
const schemaRepository = require("
|
|
12
|
+
const schemaRepository = require("../../../repositories/schemas");
|
|
13
13
|
const statusHelpers_1 = require("../sync/statusHelpers");
|
|
14
14
|
const stripUnsupportedDescriptionFields_1 = require("./stripUnsupportedDescriptionFields");
|
|
15
15
|
class SyncSchema {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function verify(file?: string, dir?: string, ignoreVerificationErrors?: boolean): Promise<void>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.verify = void 0;
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const ajv_1 = require("ajv");
|
|
6
|
+
const chalk = require("chalk");
|
|
7
|
+
const metaschema = require("../../config-json-schemas/Schema.json");
|
|
8
|
+
const error_1 = require("../../helpers/error");
|
|
9
|
+
const listFilesInDir_1 = require("./util/listFilesInDir");
|
|
10
|
+
const schemaverify_1 = require("./util/schemaverify");
|
|
11
|
+
async function verify(file, dir, ignoreVerificationErrors) {
|
|
12
|
+
let files = [];
|
|
13
|
+
if (dir) {
|
|
14
|
+
files = await (0, listFilesInDir_1.flatListFiles)(dir, '.json');
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
files = [file];
|
|
18
|
+
}
|
|
19
|
+
const checkFile = (schemaPath) => {
|
|
20
|
+
let schema = {};
|
|
21
|
+
console.log(chalk.bold('Checking', schemaPath));
|
|
22
|
+
try {
|
|
23
|
+
schema = require(path.resolve(schemaPath));
|
|
24
|
+
}
|
|
25
|
+
catch (err) {
|
|
26
|
+
console.log(chalk.red(`Failed to load schema file ${file}. Possibly not a valid JSON file`));
|
|
27
|
+
console.log(err);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const ajv = new ajv_1.default();
|
|
31
|
+
for (const result of (new schemaverify_1.SchemaVerify(ajv, schema, metaschema)).RunChecks()) {
|
|
32
|
+
if (result.ok) {
|
|
33
|
+
console.log(chalk.green(`${result.test}... ✓`));
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
console.log(chalk.red(`${result.test}... x`));
|
|
37
|
+
for (const error of result.errors) {
|
|
38
|
+
if (typeof error === 'object') {
|
|
39
|
+
console.log('\t', chalk.red(JSON.stringify(error, null, 4)));
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
console.log('\t', chalk.red(error));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (!ignoreVerificationErrors) {
|
|
46
|
+
throw new error_1.CommandError(`Schema ${schemaPath} contains error, please fix`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
console.log();
|
|
51
|
+
};
|
|
52
|
+
for (const f of files) {
|
|
53
|
+
checkFile(f);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.verify = verify;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare function sync({ path, schemas, tasks, templates, dispatchers, cleanDispatchers, localizations, ignoreSchemaVerificationErrors, }: {
|
|
2
|
+
path?: string;
|
|
3
|
+
schemas?: boolean;
|
|
4
|
+
tasks?: boolean;
|
|
5
|
+
templates?: boolean;
|
|
6
|
+
dispatchers?: boolean;
|
|
7
|
+
cleanDispatchers?: boolean;
|
|
8
|
+
localizations?: boolean;
|
|
9
|
+
ignoreSchemaVerificationErrors?: boolean;
|
|
10
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sync = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const ospath = require("path");
|
|
6
|
+
const chalk = require("chalk");
|
|
7
|
+
const repoConfig_1 = require("../helpers/repoConfig");
|
|
8
|
+
const dispatcherService = require("../services/dispatchers");
|
|
9
|
+
const localizationService = require("../services/localizations");
|
|
10
|
+
const schemaService = require("../services/schemas");
|
|
11
|
+
const taskService = require("../services/tasks");
|
|
12
|
+
const templateService = require("../services/templates");
|
|
13
|
+
async function sync({ path, schemas, tasks, templates, dispatchers, cleanDispatchers, localizations, ignoreSchemaVerificationErrors, }) {
|
|
14
|
+
const targetPath = path || '.';
|
|
15
|
+
const cfg = await (0, repoConfig_1.getRepoConfig)(targetPath);
|
|
16
|
+
const syncAll = !(schemas || tasks || templates || dispatchers || localizations);
|
|
17
|
+
if ((syncAll || schemas) && cfg.schemas) {
|
|
18
|
+
console.log(chalk.green('\n ⚙️ Syncing schemas ...'));
|
|
19
|
+
for (const schema of cfg.schemas) {
|
|
20
|
+
await schemaService.sync(ospath.join(targetPath, schema), undefined, false, ignoreSchemaVerificationErrors);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if ((syncAll || templates) && cfg.templates) {
|
|
24
|
+
console.log(chalk.green('\n ⚙️ Syncing templates...'));
|
|
25
|
+
for (const template of cfg.templates) {
|
|
26
|
+
await templateService.sync(ospath.join(targetPath, template));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if ((syncAll || tasks) && cfg.tasks) {
|
|
30
|
+
console.log(chalk.green('\n ⚙️ Syncing tasks...'));
|
|
31
|
+
for (const task of cfg.tasks) {
|
|
32
|
+
await taskService.sync({ path: ospath.join(targetPath, task) });
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if ((syncAll || localizations) && cfg.localizations) {
|
|
36
|
+
console.log(chalk.green('\n ⚙️ Syncing localizations...'));
|
|
37
|
+
for (const localization of cfg.localizations) {
|
|
38
|
+
await localizationService.sync(ospath.join(targetPath, localization));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if ((syncAll || dispatchers)) {
|
|
42
|
+
const dispatchersPath = ospath.join(targetPath, 'dispatchers.json');
|
|
43
|
+
const isValidPath = (0, fs_1.existsSync)(dispatchersPath);
|
|
44
|
+
if (isValidPath) {
|
|
45
|
+
console.log(chalk.green('\n ⚙️ Syncing dispatchers...'));
|
|
46
|
+
await dispatcherService.sync(dispatchersPath, cleanDispatchers);
|
|
47
|
+
}
|
|
48
|
+
else if (dispatchers) {
|
|
49
|
+
console.log(chalk.yellow('Warning: dispatchers.json not found'));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.sync = sync;
|
package/package.json
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/build/{commands/data → services}/schemas/util/stripUnsupportedDescriptionFields.d.ts
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|