@extrahorizon/exh-cli 1.12.0-feat-132-3d57f4e → 1.12.0

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.
Files changed (99) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/build/commands/data/schemas/delete.js +2 -14
  3. package/build/commands/data/schemas/init.js +2 -30
  4. package/build/commands/data/schemas/list.js +2 -10
  5. package/build/commands/data/schemas/sync.d.ts +3 -5
  6. package/build/commands/data/schemas/sync.js +4 -40
  7. package/build/commands/data/schemas/verify.js +6 -51
  8. package/build/commands/login.js +2 -22
  9. package/build/commands/sync.d.ts +1 -1
  10. package/build/commands/sync.js +5 -47
  11. package/build/commands/tasks/createrepo.js +6 -47
  12. package/build/commands/tasks/delete.js +2 -14
  13. package/build/commands/tasks/list.js +2 -17
  14. package/build/commands/tasks/sync.js +6 -80
  15. package/build/commands/templates/delete.d.ts +2 -2
  16. package/build/commands/templates/delete.js +6 -26
  17. package/build/commands/templates/get.d.ts +2 -2
  18. package/build/commands/templates/get.js +6 -15
  19. package/build/commands/templates/list.js +2 -15
  20. package/build/commands/templates/sync.d.ts +2 -4
  21. package/build/commands/templates/sync.js +7 -33
  22. package/build/commands/whoami.js +3 -10
  23. package/build/config-json-schemas/Dispatchers.json +120 -0
  24. package/build/config-json-schemas/Template.json +303 -0
  25. package/build/helpers/util.d.ts +1 -0
  26. package/build/helpers/util.js +11 -1
  27. package/build/repositories/functions.d.ts +1 -1
  28. package/build/repositories/schemas.d.ts +2 -2
  29. package/build/repositories/schemas.js +7 -1
  30. package/build/repositories/templates.d.ts +7 -0
  31. package/build/repositories/templates.js +28 -0
  32. package/build/repositories/templatesV2.d.ts +7 -0
  33. package/build/repositories/templatesV2.js +28 -0
  34. package/build/services/auth.d.ts +2 -0
  35. package/build/services/auth.js +40 -0
  36. package/build/services/dispatchers.js +11 -39
  37. package/build/services/schemas/index.d.ts +5 -0
  38. package/build/services/schemas/index.js +43 -0
  39. package/build/services/schemas/init.d.ts +1 -0
  40. package/build/services/schemas/init.js +37 -0
  41. package/build/services/schemas/sync.d.ts +3 -0
  42. package/build/services/schemas/sync.js +44 -0
  43. package/build/{commands/data → services}/schemas/util/syncSchema.js +1 -1
  44. package/build/services/schemas/verify.d.ts +1 -0
  45. package/build/services/schemas/verify.js +56 -0
  46. package/build/services/sync.d.ts +10 -0
  47. package/build/services/sync.js +53 -0
  48. package/build/services/tasks/createRepo.d.ts +5 -0
  49. package/build/services/tasks/createRepo.js +52 -0
  50. package/build/services/tasks/index.d.ts +5 -0
  51. package/build/services/tasks/index.js +50 -0
  52. package/build/services/tasks/sync.d.ts +1 -0
  53. package/build/services/tasks/sync.js +84 -0
  54. package/build/{commands → services}/tasks/taskConfig.d.ts +1 -1
  55. package/build/{commands → services}/tasks/taskConfig.js +1 -7
  56. package/build/services/templates/get.d.ts +4 -0
  57. package/build/services/templates/get.js +53 -0
  58. package/build/services/templates/index.d.ts +4 -0
  59. package/build/services/templates/index.js +11 -0
  60. package/build/services/templates/list.d.ts +1 -0
  61. package/build/services/templates/list.js +44 -0
  62. package/build/services/templates/remove.d.ts +1 -0
  63. package/build/services/templates/remove.js +53 -0
  64. package/build/services/templates/sync.d.ts +2 -0
  65. package/build/services/templates/sync.js +36 -0
  66. package/build/services/templates/util/buildTemplates.d.ts +1 -0
  67. package/build/services/templates/util/buildTemplates.js +168 -0
  68. package/build/services/templates/util/models.d.ts +12 -0
  69. package/build/services/templates/util/models.js +2 -0
  70. package/build/services/templates/util/readTemplateFiles.d.ts +4 -0
  71. package/build/services/templates/util/readTemplateFiles.js +66 -0
  72. package/build/services/templates/util/uploadTemplate.d.ts +1 -0
  73. package/build/services/templates/util/uploadTemplate.js +48 -0
  74. package/build/{commands → services}/templates/util/utils.d.ts +2 -0
  75. package/build/{commands → services}/templates/util/utils.js +7 -1
  76. package/package.json +3 -3
  77. package/build/commands/templates/util/buildTemplates.d.ts +0 -2
  78. package/build/commands/templates/util/buildTemplates.js +0 -50
  79. package/build/commands/templates/util/readTemplateFiles.d.ts +0 -3
  80. package/build/commands/templates/util/readTemplateFiles.js +0 -52
  81. package/build/commands/templates/util/templateService.d.ts +0 -7
  82. package/build/commands/templates/util/templateService.js +0 -19
  83. package/build/commands/templates/util/uploadTemplate.d.ts +0 -2
  84. package/build/commands/templates/util/uploadTemplate.js +0 -20
  85. /package/build/{commands/data → services}/schemas/sync/statusHelpers.d.ts +0 -0
  86. /package/build/{commands/data → services}/schemas/sync/statusHelpers.js +0 -0
  87. /package/build/{commands/data → services}/schemas/util/listFilesInDir.d.ts +0 -0
  88. /package/build/{commands/data → services}/schemas/util/listFilesInDir.js +0 -0
  89. /package/build/{commands/data → services}/schemas/util/readJson.d.ts +0 -0
  90. /package/build/{commands/data → services}/schemas/util/readJson.js +0 -0
  91. /package/build/{commands/data → services}/schemas/util/schemaverify.d.ts +0 -0
  92. /package/build/{commands/data → services}/schemas/util/schemaverify.js +0 -0
  93. /package/build/{commands/data → services}/schemas/util/stripUnsupportedDescriptionFields.d.ts +0 -0
  94. /package/build/{commands/data → services}/schemas/util/stripUnsupportedDescriptionFields.js +0 -0
  95. /package/build/{commands/data → services}/schemas/util/syncSchema.d.ts +0 -0
  96. /package/build/{commands/data → services}/schemas/util/tests/listFilesInDir.test.d.ts +0 -0
  97. /package/build/{commands/data → services}/schemas/util/tests/listFilesInDir.test.js +0 -0
  98. /package/build/{commands → services}/tasks/util.d.ts +0 -0
  99. /package/build/{commands → services}/tasks/util.js +0 -0
package/CHANGELOG.md CHANGED
@@ -4,6 +4,19 @@
4
4
  * Now adding `$schema` as the last property when creating a new schema via `exh data schemas init`
5
5
  * The `exh tasks create-repo` command now creates `package.json` and `task-config.json` files with 2 spaces indentation instead of 4 spaces.
6
6
  * You no longer need to include the `name` property when defining an index in a schema, as it was never actually used by the backend.
7
+ * Updated the ExH SDK to the latest version
8
+ * For the features mentioned above
9
+ * For an `axios` update to resolve a warning about `CVE-2026-25639` (not affecting the CLI)
10
+ * Updated the `qs` package to resolve a warning about `CVE-2026-2391` (not affecting the CLI)
11
+ * Added support for the template service V2 in the all `exh templates` commands.
12
+ * `exh templates list` lists templates from both template service V1 and template service V2.
13
+ * `exh templates get` gets templates from both template service V1 and template service V2.
14
+ * `exh templates delete` deletes templates from both template service V1 and template service V2.
15
+ * `exh templates sync` now syncs templates to the template service V2 and template service V1 depending on the properties in the `template.json` file.
16
+ * Added autocomplete support and inline documentation for `template.json`
17
+ * Via `"$schema": "https://swagger.extrahorizon.com/cli/1.12.0/config-json-schemas/Template.json"`
18
+ * Added autocomplete support and inline documentation for `dispatchers.json`
19
+ * Via `"$schema": "https://swagger.extrahorizon.com/cli/1.12.0/config-json-schemas/Dispatchers.json"`
7
20
 
8
21
  ### v1.11.1
9
22
  * Updated the ExH SDK to `8.8.2` to fix a security warning from `qs`
@@ -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 schemaRepository = require("../../../repositories/schemas");
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
- const disableResponse = await schemaRepository.disable(id);
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 (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}`);
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
- }
@@ -1,21 +1,13 @@
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 exh_1 = require("../../../exh");
5
4
  const util_1 = require("../../../helpers/util");
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
- const schemaListResponse = await (0, exh_1.getSdk)().raw.get('/data/v1/');
12
- if (schemaListResponse.data.data.length !== 0) {
13
- if (isTTY) {
14
- console.table(schemaListResponse.data.data.map((c) => ({ Id: c.id, Name: c.name, Description: c.description || '<none>' })));
15
- }
16
- else {
17
- schemaListResponse.data.data.forEach((f) => (console.log([f.id, f.name].join(','))));
18
- }
19
- }
11
+ await schemaService.list(isTTY);
20
12
  };
21
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" | "ignoreVerificationErrors" | "dry"> & import("yargs").InferredOptionTypes<{
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: ({ dir, file, dry, ignoreVerificationErrors }: {
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.syncTargetDir = exports.syncTargetFile = exports.handler = exports.builder = exports.desc = exports.command = void 0;
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 listFilesInDir_1 = require("./util/listFilesInDir");
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 ({ dir, file, dry, ignoreVerificationErrors }) => {
38
- if (!file && !dir) {
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 listFilesInDir_1 = require("./util/listFilesInDir");
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).options({
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
- }).check(({ file, dir }) => {
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
- let files = [];
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;
@@ -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
- const sdk = (0, exh_1.sdkInitOnly)(host, consumerKey, consumerSecret);
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;
@@ -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: ({ path, schemas, tasks, templates, dispatchers, cleanDispatchers, localizations, ignoreSchemaVerificationErrors, }: {
52
+ export declare const handler: (options: {
53
53
  path?: string;
54
54
  schemas?: boolean;
55
55
  tasks?: boolean;
@@ -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 dispatchers_1 = require("../services/dispatchers");
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
- }).check(async ({ path }) => {
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 ({ path, schemas, tasks, templates, dispatchers, cleanDispatchers, localizations, ignoreSchemaVerificationErrors, }) => {
82
- const targetPath = path || '.';
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;
@@ -1,16 +1,17 @@
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 chalk = require("chalk");
6
4
  const util_1 = require("../../helpers/util");
5
+ const tasksService = require("../../services/tasks");
7
6
  exports.command = 'create-repo <name>';
8
7
  exports.desc = 'Create a new task repository';
9
- const builder = (yargs) => (0, util_1.epilogue)(yargs).positional('name', {
8
+ const builder = (yargs) => (0, util_1.epilogue)(yargs)
9
+ .positional('name', {
10
10
  demandOption: true,
11
11
  description: 'The name of the new repo/task',
12
12
  type: 'string',
13
- }).options({
13
+ })
14
+ .options({
14
15
  repo: {
15
16
  description: 'repository template to clone',
16
17
  type: 'string',
@@ -23,49 +24,7 @@ const builder = (yargs) => (0, util_1.epilogue)(yargs).positional('name', {
23
24
  },
24
25
  });
25
26
  exports.builder = builder;
26
- async function changePackageFile(name) {
27
- try {
28
- const pkg = JSON.parse((await (0, promises_1.readFile)(`${name}/package.json`)).toString());
29
- pkg.name = name;
30
- await (0, promises_1.writeFile)(`${name}/package.json`, JSON.stringify(pkg, null, 2));
31
- }
32
- catch (err) {
33
- console.log('WARN: package.json not found. (possibly not a javascript repository');
34
- }
35
- try {
36
- const taskConfig = JSON.parse((await (0, promises_1.readFile)(`${name}/task-config.json`)).toString());
37
- taskConfig.$schema = (0, util_1.getSwaggerDocumentationUrl)('config-json-schemas/TaskConfig.json');
38
- taskConfig.name = name;
39
- taskConfig.description = `${name} task`;
40
- await (0, promises_1.writeFile)(`${name}/task-config.json`, JSON.stringify(taskConfig, null, 2));
41
- }
42
- catch (err) { }
43
- }
44
27
  const handler = async ({ name, repo, git }) => {
45
- try {
46
- await (0, util_1.asyncExec)('git --version');
47
- }
48
- catch (err) {
49
- console.log(chalk.red('Git is not installed. Please install git first.'));
50
- }
51
- console.log(`Creating new repo ${chalk.green(name)}...`);
52
- try {
53
- await (0, util_1.asyncExec)(`git clone ${repo} ${name}`);
54
- try {
55
- await changePackageFile(name);
56
- }
57
- catch (err) { }
58
- await (0, util_1.asyncExec)(`cd ${name} && rm -rf .git`);
59
- if (git) {
60
- console.log('Initializing git');
61
- await (0, util_1.asyncExec)(`cd ${name} && git init . && git add . && git commit -m "First commit"`);
62
- }
63
- console.log('Done! 🎉');
64
- }
65
- catch (err) {
66
- await (0, util_1.asyncExec)(`rm -rf ${name}`);
67
- console.log(chalk.red('Failed to create repo'));
68
- console.log(err);
69
- }
28
+ await tasksService.createRepo({ name, repo, git });
70
29
  };
71
30
  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 chalk = require("chalk");
5
4
  const util_1 = require("../../helpers/util");
6
- const functionRepository = require("../../repositories/functions");
5
+ const tasksService = require("../../services/tasks");
7
6
  exports.command = 'delete';
8
7
  exports.desc = 'Delete a task';
9
8
  const builder = (yargs) => (0, util_1.epilogue)(yargs).option('name', {
@@ -13,17 +12,6 @@ const builder = (yargs) => (0, util_1.epilogue)(yargs).option('name', {
13
12
  });
14
13
  exports.builder = builder;
15
14
  const handler = async ({ name }) => {
16
- try {
17
- const response = await functionRepository.remove(name);
18
- if (response?.affectedRecords) {
19
- console.log(chalk.green('Successfully deleted task', name));
20
- }
21
- else {
22
- console.log(chalk.red('Failed to delete task', name));
23
- }
24
- }
25
- catch (err) {
26
- console.log(chalk.red('Failed to delete task:', err.message));
27
- }
15
+ await tasksService.remove(name);
28
16
  };
29
17
  exports.handler = handler;
@@ -1,28 +1,13 @@
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 exh_1 = require("../../exh");
5
4
  const util_1 = require("../../helpers/util");
5
+ const taskService = require("../../services/tasks");
6
6
  exports.command = 'list';
7
7
  exports.desc = 'List all tasks';
8
8
  const builder = (yargs) => (0, util_1.epilogue)(yargs);
9
9
  exports.builder = builder;
10
10
  const handler = async function list({ isTTY }) {
11
- let functionResponse;
12
- try {
13
- functionResponse = await (0, exh_1.getSdk)().raw.get('/tasks/v1/functions');
14
- }
15
- catch (err) {
16
- console.log(err);
17
- return;
18
- }
19
- if (functionResponse.data.data.length !== 0) {
20
- if (isTTY) {
21
- console.table(functionResponse.data.data.map((c) => ({ Name: c.name, Description: c.Description || '<none>', 'Last updated': c.updateTimestamp.toISOString() })));
22
- }
23
- else {
24
- functionResponse.data.data.forEach((f) => (console.log(f.name)));
25
- }
26
- }
11
+ await taskService.list(isTTY);
27
12
  };
28
13
  exports.handler = handler;
@@ -1,20 +1,18 @@
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
4
  const constants_1 = require("../../constants");
7
5
  const util_1 = require("../../helpers/util");
8
- const functionRepository = require("../../repositories/functions");
9
- const taskConfig_1 = require("./taskConfig");
10
- const util_2 = require("./util");
6
+ const tasksService = require("../../services/tasks");
7
+ const taskConfig_1 = require("../../services/tasks/taskConfig");
11
8
  exports.command = 'sync';
12
9
  exports.desc = 'Sync a task. Will create the task first if it doesn\'t exist yet';
13
- const builder = (yargs) => (0, util_1.epilogue)(yargs).options({
10
+ const builder = (yargs) => (0, util_1.epilogue)(yargs)
11
+ .options({
14
12
  path: {
15
13
  demandOption: false,
16
14
  describe: `Path of the configuration json file containing task parameters. If a directory is given instead, all sub-directories will be searched for a task-config.json file & synced.
17
- If this option is not used, each parameter (name, code, entryPoint, runtime, ...) will need to be supplied separately`,
15
+ If this option is not used, each parameter (name, code, entryPoint, runtime, ...) will need to be supplied separately`,
18
16
  type: 'string',
19
17
  },
20
18
  name: {
@@ -72,78 +70,6 @@ const builder = (yargs) => (0, util_1.epilogue)(yargs).options({
72
70
  });
73
71
  exports.builder = builder;
74
72
  const handler = async ({ ...cmdLineParams }) => {
75
- for await (const config of (0, taskConfig_1.getValidatedConfigIterator)(cmdLineParams)) {
76
- console.log('Syncing task', config.name, '...');
77
- await syncSingleTask(config);
78
- }
73
+ await tasksService.sync(cmdLineParams);
79
74
  };
80
75
  exports.handler = handler;
81
- async function syncSingleTask(config) {
82
- const uploadFilePath = await (0, util_2.zipFileFromDirectory)(config.path);
83
- const file = await fs.readFile(uploadFilePath);
84
- const allFunctions = await functionRepository.find();
85
- const myFunction = allFunctions.find((f) => f.name === config.name);
86
- const request = {
87
- name: config.name,
88
- description: config.description || 'none',
89
- entryPoint: config.entryPoint,
90
- code: file.toString('base64'),
91
- runtime: config.runtime,
92
- };
93
- if (config.executionPermission || config.defaultPriority) {
94
- request.executionOptions = {};
95
- }
96
- if (config.defaultPriority) {
97
- request.executionOptions.defaultPriority = config.defaultPriority;
98
- }
99
- if (config.executionPermission) {
100
- request.executionOptions.permissionMode = config.executionPermission;
101
- }
102
- if (config.timeLimit) {
103
- request.timeLimit = config.timeLimit;
104
- }
105
- if (config.memoryLimit) {
106
- request.memoryLimit = config.memoryLimit;
107
- }
108
- if (config.retryPolicy) {
109
- request.retryPolicy = config.retryPolicy;
110
- }
111
- if (config.executionCredentials) {
112
- const credentials = await (0, util_2.syncFunctionUser)({
113
- taskName: config.name,
114
- targetEmail: config.executionCredentials.email,
115
- targetPermissions: config.executionCredentials.permissions,
116
- });
117
- config.environment = {
118
- ...config.environment,
119
- API_HOST: process.env.API_HOST,
120
- API_OAUTH_CONSUMER_KEY: process.env.API_OAUTH_CONSUMER_KEY,
121
- API_OAUTH_CONSUMER_SECRET: process.env.API_OAUTH_CONSUMER_SECRET,
122
- API_OAUTH_TOKEN: credentials.token,
123
- API_OAUTH_TOKEN_SECRET: credentials.tokenSecret,
124
- };
125
- }
126
- if (config.environment) {
127
- const environmentVariables = {};
128
- for (const [key, value] of Object.entries(config.environment)) {
129
- environmentVariables[key] = { value };
130
- }
131
- request.environmentVariables = environmentVariables;
132
- }
133
- if (myFunction === undefined) {
134
- await functionRepository.create(request);
135
- console.log(chalk.green('Successfully created task', config.name));
136
- }
137
- else {
138
- const existingFunction = await functionRepository.findByName(myFunction.name);
139
- if (request.runtime === existingFunction.runtime) {
140
- delete request.runtime;
141
- }
142
- const updateResponse = await functionRepository.update(request);
143
- if (!updateResponse?.affectedRecords) {
144
- throw new Error(`Failed to update task ${request.name}`);
145
- }
146
- console.log(chalk.green('Successfully updated task', config.name));
147
- }
148
- await fs.unlink(uploadFilePath);
149
- }
@@ -12,6 +12,6 @@ export declare const builder: (yargs: any) => import("yargs").Argv<import("yargs
12
12
  };
13
13
  }>>;
14
14
  export declare const handler: ({ name, id }: {
15
- name: string;
16
- id: string;
15
+ name?: string;
16
+ id?: string;
17
17
  }) => Promise<void>;