@extrahorizon/exh-cli 1.10.0-dev-102-009ca37 → 1.10.0-dev-104-c76c2f8
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.
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference types="yargs" />
|
|
2
|
+
export declare const command = "init <name>";
|
|
3
|
+
export declare const desc = "Create a basic schema configuration file";
|
|
4
|
+
export declare const builder: (yargs: any) => import("yargs").Argv<import("yargs").Omit<{
|
|
5
|
+
name: string;
|
|
6
|
+
}, "path"> & import("yargs").InferredOptionTypes<{
|
|
7
|
+
path: {
|
|
8
|
+
description: string;
|
|
9
|
+
type: "string";
|
|
10
|
+
default: string;
|
|
11
|
+
};
|
|
12
|
+
}>>;
|
|
13
|
+
export declare const handler: ({ name, path }: {
|
|
14
|
+
name: string;
|
|
15
|
+
path: string;
|
|
16
|
+
}) => Promise<void>;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handler = exports.builder = exports.desc = exports.command = void 0;
|
|
4
|
+
const promises_1 = require("fs/promises");
|
|
5
|
+
const osPath = require("path");
|
|
6
|
+
const util_1 = require("../../../helpers/util");
|
|
7
|
+
exports.command = 'init <name>';
|
|
8
|
+
exports.desc = 'Create a basic schema configuration file';
|
|
9
|
+
const builder = (yargs) => (0, util_1.epilogue)(yargs)
|
|
10
|
+
.positional('name', {
|
|
11
|
+
demandOption: true,
|
|
12
|
+
description: 'The name of the new schema',
|
|
13
|
+
type: 'string',
|
|
14
|
+
})
|
|
15
|
+
.options({
|
|
16
|
+
path: {
|
|
17
|
+
description: 'The path to the folder where the schema should be created',
|
|
18
|
+
type: 'string',
|
|
19
|
+
default: './schemas',
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
exports.builder = builder;
|
|
23
|
+
const handler = async function init({ name, path }) {
|
|
24
|
+
await (0, promises_1.mkdir)(path, { recursive: true });
|
|
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}`);
|
|
28
|
+
};
|
|
29
|
+
exports.handler = handler;
|
|
30
|
+
function createSchema(name) {
|
|
31
|
+
return {
|
|
32
|
+
$schema: 'https://swagger.extrahorizon.com/cli/1.10.0/config-json-schemas/Schema.json',
|
|
33
|
+
name,
|
|
34
|
+
description: `The ${name} schema`,
|
|
35
|
+
createMode: 'allUsers',
|
|
36
|
+
readMode: ['creator'],
|
|
37
|
+
updateMode: ['creator'],
|
|
38
|
+
deleteMode: ['creator'],
|
|
39
|
+
statuses: {
|
|
40
|
+
new: {},
|
|
41
|
+
},
|
|
42
|
+
creationTransition: {
|
|
43
|
+
type: 'manual',
|
|
44
|
+
toStatus: 'new',
|
|
45
|
+
},
|
|
46
|
+
transitions: [],
|
|
47
|
+
properties: {
|
|
48
|
+
firstProperty: {
|
|
49
|
+
type: 'string',
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.syncFunctionUser = exports.zipFileFromDirectory = void 0;
|
|
4
|
+
const crypto_1 = require("crypto");
|
|
4
5
|
const fs_1 = require("fs");
|
|
5
6
|
const os_1 = require("os");
|
|
6
7
|
const javascript_sdk_1 = require("@extrahorizon/javascript-sdk");
|
|
7
8
|
const archiver = require("archiver");
|
|
8
9
|
const chalk = require("chalk");
|
|
9
|
-
const uuid_1 = require("uuid");
|
|
10
10
|
const authRepository = require("../../repositories/auth");
|
|
11
11
|
const functionRepository = require("../../repositories/functions");
|
|
12
12
|
const userRepository = require("../../repositories/user");
|
|
13
13
|
async function zipFileFromDirectory(path) {
|
|
14
14
|
return new Promise((res, rej) => {
|
|
15
|
-
const tmpPath = `${(0, os_1.tmpdir)()}/${(
|
|
15
|
+
const tmpPath = `${(0, os_1.tmpdir)()}/${randomHexString()}`;
|
|
16
16
|
const output = (0, fs_1.createWriteStream)(tmpPath);
|
|
17
17
|
const archive = archiver('zip', {
|
|
18
18
|
zlib: { level: 9 },
|
|
@@ -34,7 +34,7 @@ async function syncFunctionUser(sdk, data) {
|
|
|
34
34
|
const { taskName, targetEmail, targetPermissions } = data;
|
|
35
35
|
const email = (targetEmail || `exh.tasks+${taskName}@extrahorizon.com`).toLowerCase();
|
|
36
36
|
validateEmail(email);
|
|
37
|
-
const password = `0Oo-${(
|
|
37
|
+
const password = `0Oo-${randomHexString()}`;
|
|
38
38
|
const roleName = `exh.tasks.${taskName}`;
|
|
39
39
|
const role = await syncRoleWithPermissions(sdk, taskName, roleName, targetPermissions);
|
|
40
40
|
let user = await userRepository.findUserByEmail(sdk, email);
|
|
@@ -142,3 +142,6 @@ function validateEmail(email) {
|
|
|
142
142
|
throw new Error('Invalid email address');
|
|
143
143
|
}
|
|
144
144
|
}
|
|
145
|
+
function randomHexString() {
|
|
146
|
+
return (0, crypto_1.randomBytes)(16).toString('hex');
|
|
147
|
+
}
|
package/build/index.js
CHANGED
|
@@ -10,6 +10,7 @@ yargs((0, helpers_1.hideBin)(process.argv))
|
|
|
10
10
|
.middleware(async (argv) => {
|
|
11
11
|
const isTTY = tty.isatty(process.stdout.fd);
|
|
12
12
|
if ((0, lodash_1.isEqual)(argv._, ['login']) ||
|
|
13
|
+
(0, lodash_1.isEqual)(argv._, ['data', 'schemas', 'init']) ||
|
|
13
14
|
(0, lodash_1.isEqual)(argv._, ['data', 'schemas', 'verify']) ||
|
|
14
15
|
(0, lodash_1.isEqual)(argv._, ['tasks', 'create-repo']) ||
|
|
15
16
|
(0, lodash_1.isEqual)(argv._, ['completion']) ||
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@extrahorizon/exh-cli",
|
|
3
|
-
"version": "1.10.0-dev-
|
|
3
|
+
"version": "1.10.0-dev-104-c76c2f8",
|
|
4
4
|
"main": "build/index.js",
|
|
5
5
|
"exports": "./build/index.js",
|
|
6
6
|
"license": "MIT",
|
|
@@ -47,7 +47,6 @@
|
|
|
47
47
|
"chalk": "^4.0.0",
|
|
48
48
|
"joi": "^17.6.0",
|
|
49
49
|
"lodash": "^4.17.21",
|
|
50
|
-
"uuid": "^8.3.2",
|
|
51
50
|
"yargs": "^17.5.1"
|
|
52
51
|
}
|
|
53
52
|
}
|