@extrahorizon/exh-cli 1.5.0 → 1.5.1-dev-27-7bdff2e

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 (92) hide show
  1. package/CHANGELOG.md +56 -53
  2. package/README.md +0 -12
  3. package/build/commands/completion.d.ts +5 -5
  4. package/build/commands/completion.js +38 -38
  5. package/build/commands/data/schemas/delete.d.ts +10 -10
  6. package/build/commands/data/schemas/delete.js +29 -29
  7. package/build/commands/data/schemas/list.d.ts +8 -8
  8. package/build/commands/data/schemas/list.js +20 -20
  9. package/build/commands/data/schemas/sync/statusHelpers.d.ts +3 -3
  10. package/build/commands/data/schemas/sync/statusHelpers.js +49 -49
  11. package/build/commands/data/schemas/sync.d.ts +35 -35
  12. package/build/commands/data/schemas/sync.js +72 -72
  13. package/build/commands/data/schemas/util/listFilesInDir.d.ts +1 -1
  14. package/build/commands/data/schemas/util/listFilesInDir.js +25 -25
  15. package/build/commands/data/schemas/util/metaschema.json +455 -455
  16. package/build/commands/data/schemas/util/readJson.d.ts +1 -1
  17. package/build/commands/data/schemas/util/readJson.js +11 -11
  18. package/build/commands/data/schemas/util/schemaverify.d.ts +28 -28
  19. package/build/commands/data/schemas/util/schemaverify.js +202 -202
  20. package/build/commands/data/schemas/util/syncSchema.d.ts +20 -20
  21. package/build/commands/data/schemas/util/syncSchema.js +276 -276
  22. package/build/commands/data/schemas/util/tests/listFilesInDir.test.d.ts +1 -1
  23. package/build/commands/data/schemas/util/tests/listFilesInDir.test.js +40 -40
  24. package/build/commands/data/schemas/verify.d.ts +18 -18
  25. package/build/commands/data/schemas/verify.js +82 -82
  26. package/build/commands/data/schemas.d.ts +5 -5
  27. package/build/commands/data/schemas.js +10 -10
  28. package/build/commands/data.d.ts +5 -5
  29. package/build/commands/data.js +10 -10
  30. package/build/commands/dispatchers/sync.d.ts +21 -21
  31. package/build/commands/dispatchers/sync.js +24 -24
  32. package/build/commands/dispatchers.d.ts +5 -5
  33. package/build/commands/dispatchers.js +10 -10
  34. package/build/commands/login.d.ts +37 -37
  35. package/build/commands/login.js +59 -59
  36. package/build/commands/sync.d.ts +55 -55
  37. package/build/commands/sync.js +107 -107
  38. package/build/commands/tasks/createrepo.d.ts +22 -22
  39. package/build/commands/tasks/createrepo.js +70 -70
  40. package/build/commands/tasks/delete.d.ts +10 -10
  41. package/build/commands/tasks/delete.js +29 -29
  42. package/build/commands/tasks/list.d.ts +8 -8
  43. package/build/commands/tasks/list.js +27 -27
  44. package/build/commands/tasks/sync.d.ts +56 -56
  45. package/build/commands/tasks/sync.js +122 -122
  46. package/build/commands/tasks/taskConfig.d.ts +24 -24
  47. package/build/commands/tasks/taskConfig.js +169 -169
  48. package/build/commands/tasks/util.d.ts +1 -1
  49. package/build/commands/tasks/util.js +27 -27
  50. package/build/commands/tasks.d.ts +5 -5
  51. package/build/commands/tasks.js +10 -10
  52. package/build/commands/templates/delete.d.ts +19 -19
  53. package/build/commands/templates/delete.js +48 -48
  54. package/build/commands/templates/get.d.ts +19 -19
  55. package/build/commands/templates/get.js +37 -37
  56. package/build/commands/templates/list.d.ts +9 -9
  57. package/build/commands/templates/list.js +25 -25
  58. package/build/commands/templates/sync.d.ts +22 -22
  59. package/build/commands/templates/sync.js +65 -65
  60. package/build/commands/templates/util/buildTemplates.d.ts +2 -2
  61. package/build/commands/templates/util/buildTemplates.js +50 -50
  62. package/build/commands/templates/util/readTemplateFiles.d.ts +3 -3
  63. package/build/commands/templates/util/readTemplateFiles.js +52 -52
  64. package/build/commands/templates/util/templateService.d.ts +8 -8
  65. package/build/commands/templates/util/templateService.js +18 -18
  66. package/build/commands/templates/util/uploadTemplate.d.ts +2 -2
  67. package/build/commands/templates/util/uploadTemplate.js +20 -20
  68. package/build/commands/templates/util/utils.d.ts +4 -4
  69. package/build/commands/templates/util/utils.js +22 -22
  70. package/build/commands/templates.d.ts +5 -5
  71. package/build/commands/templates.js +10 -10
  72. package/build/constants.d.ts +13 -13
  73. package/build/constants.js +37 -37
  74. package/build/exh.d.ts +3 -3
  75. package/build/exh.js +65 -65
  76. package/build/helpers/error.d.ts +2 -2
  77. package/build/helpers/error.js +6 -6
  78. package/build/helpers/repoConfig.d.ts +2 -2
  79. package/build/helpers/repoConfig.js +60 -60
  80. package/build/helpers/util.d.ts +3 -3
  81. package/build/helpers/util.js +36 -36
  82. package/build/index.d.ts +2 -2
  83. package/build/index.js +33 -33
  84. package/build/repositories/dispatchers.d.ts +8 -8
  85. package/build/repositories/dispatchers.js +31 -31
  86. package/build/repositories/functions.d.ts +24 -24
  87. package/build/repositories/functions.js +28 -28
  88. package/build/repositories/schemas.d.ts +44 -44
  89. package/build/repositories/schemas.js +86 -86
  90. package/build/services/dispatchers.d.ts +3 -3
  91. package/build/services/dispatchers.js +132 -132
  92. package/package.json +53 -53
@@ -1,169 +1,169 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getValidatedConfigIterator = exports.loadSingleConfigFile = exports.validateConfig = exports.assertExecutionPermission = exports.permissionModes = void 0;
4
- const assert_1 = require("assert");
5
- const fs = require("fs/promises");
6
- const ospath = require("path");
7
- const Joi = require("joi");
8
- const constants_1 = require("../../constants");
9
- var permissionModes;
10
- (function (permissionModes) {
11
- permissionModes["permissionRequired"] = "permissionRequired";
12
- permissionModes["allUsers"] = "allUsers";
13
- permissionModes["public"] = "public";
14
- })(permissionModes = exports.permissionModes || (exports.permissionModes = {}));
15
- const taskConfigSchema = Joi.object({
16
- name: Joi.string().pattern(/^[A-Za-z0-9-]+$/).required(),
17
- description: Joi.string(),
18
- entryPoint: Joi.string().required(),
19
- runtime: Joi.string().valid(...constants_1.runtimeChoices).required(),
20
- timeLimit: Joi.number().min(constants_1.limits.time.min).max(constants_1.limits.time.max),
21
- memoryLimit: Joi.number().min(constants_1.limits.memory.min).max(constants_1.limits.memory.max),
22
- path: Joi.string(),
23
- retryPolicy: Joi.object({
24
- enabled: Joi.boolean().required(),
25
- errorsToRetry: Joi.array().items(Joi.string()),
26
- }),
27
- environment: Joi.object().pattern(/.*/, Joi.string()),
28
- executionPermission: Joi.string().valid(...Object.values(permissionModes)),
29
- });
30
- function assertExecutionPermission(mode) {
31
- if (mode !== undefined && !Object.values(permissionModes).includes(mode)) {
32
- throw new assert_1.AssertionError({ message: `executionPermission incorrect. Should be one of ${Object.values(permissionModes).join(',')}` });
33
- }
34
- }
35
- exports.assertExecutionPermission = assertExecutionPermission;
36
- function replaceConfigVariables(config) {
37
- let result;
38
- switch (typeof config) {
39
- case 'object':
40
- if (Array.isArray(config)) {
41
- result = [];
42
- for (const element of config) {
43
- result.push(replaceConfigVariables(element));
44
- }
45
- }
46
- else {
47
- result = {};
48
- for (const [key, value] of Object.entries(config)) {
49
- result[key] = replaceConfigVariables(value);
50
- }
51
- }
52
- return result;
53
- case 'string':
54
- if (config.charAt(0) === '$') {
55
- const variable = config.slice(1);
56
- if (process.env[variable]) {
57
- return process.env[variable];
58
- }
59
- throw new Error(`Variable ${variable} not found in environment`);
60
- }
61
- return config;
62
- default:
63
- result = config;
64
- break;
65
- }
66
- return result;
67
- }
68
- async function validateConfig(config) {
69
- try {
70
- Joi.attempt(config, taskConfigSchema);
71
- }
72
- catch (err) {
73
- throw new Error(err.details[0]?.message || 'Unknown config validation error');
74
- }
75
- if (config.path) {
76
- try {
77
- await fs.access(config.path);
78
- }
79
- catch (err) {
80
- throw new Error(`Please provide a valid directory path for your code, ${config.path} not found`);
81
- }
82
- if ((await fs.stat(config.path)).isFile()) {
83
- throw new Error(`please provide a valid directory path for your code, ${config.path} points to a file`);
84
- }
85
- }
86
- else {
87
- throw new Error('Code path not specified');
88
- }
89
- assertExecutionPermission(config.executionPermission);
90
- return true;
91
- }
92
- exports.validateConfig = validateConfig;
93
- async function loadSingleConfigFile(path) {
94
- let taskConfig;
95
- try {
96
- const data = await fs.readFile(path);
97
- try {
98
- taskConfig = JSON.parse(data.toString());
99
- }
100
- catch (err) {
101
- throw new Error(`failed to parse file ${err.message}`);
102
- }
103
- }
104
- catch (err2) {
105
- throw new Error(`Invalid config file: ${err2.message}`);
106
- }
107
- taskConfig = replaceConfigVariables(taskConfig);
108
- if (taskConfig.path) {
109
- taskConfig.path = ospath.join(ospath.dirname(path), taskConfig.path);
110
- }
111
- return taskConfig;
112
- }
113
- exports.loadSingleConfigFile = loadSingleConfigFile;
114
- async function* getValidatedConfigIterator({ path, name, code, entryPoint, runtime, description, timeLimit, memoryLimit, executionPermission, env }) {
115
- let taskConfig = {};
116
- if (path) {
117
- const stat = await fs.stat(path);
118
- if (stat.isDirectory()) {
119
- const dirContents = await fs.readdir(path);
120
- for (const file of dirContents) {
121
- let filePath = ospath.join(path, file);
122
- if ((await fs.stat(filePath)).isDirectory()) {
123
- filePath = ospath.join(filePath, 'task-config.json');
124
- const cfg = await loadSingleConfigFile(filePath);
125
- if (cfg) {
126
- await validateConfig(cfg);
127
- yield cfg;
128
- }
129
- }
130
- }
131
- return;
132
- }
133
- taskConfig = await loadSingleConfigFile(path);
134
- if (!taskConfig) {
135
- throw new Error("Path is a file but doesn't point to a valid configuration file");
136
- }
137
- }
138
- if (name) {
139
- taskConfig.name = name;
140
- }
141
- if (code) {
142
- taskConfig.path = code;
143
- }
144
- if (entryPoint) {
145
- taskConfig.entryPoint = entryPoint;
146
- }
147
- if (runtime) {
148
- taskConfig.runtime = runtime;
149
- }
150
- if (description) {
151
- taskConfig.description = description;
152
- }
153
- if (timeLimit) {
154
- taskConfig.timeLimit = timeLimit;
155
- }
156
- if (memoryLimit) {
157
- taskConfig.memoryLimit = memoryLimit;
158
- }
159
- if (executionPermission) {
160
- taskConfig.executionPermission = executionPermission;
161
- }
162
- if (env && env.length) {
163
- const envArr = Array.isArray(env) ? env : [env];
164
- taskConfig.environment = envArr.map(e => e.split('=')).filter(e => e.length === 2).reduce((prev, curr) => ({ ...prev, [curr[0]]: curr[1] }), {});
165
- }
166
- await validateConfig(taskConfig);
167
- yield taskConfig;
168
- }
169
- exports.getValidatedConfigIterator = getValidatedConfigIterator;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getValidatedConfigIterator = exports.loadSingleConfigFile = exports.validateConfig = exports.assertExecutionPermission = exports.permissionModes = void 0;
4
+ const assert_1 = require("assert");
5
+ const fs = require("fs/promises");
6
+ const ospath = require("path");
7
+ const Joi = require("joi");
8
+ const constants_1 = require("../../constants");
9
+ var permissionModes;
10
+ (function (permissionModes) {
11
+ permissionModes["permissionRequired"] = "permissionRequired";
12
+ permissionModes["allUsers"] = "allUsers";
13
+ permissionModes["public"] = "public";
14
+ })(permissionModes = exports.permissionModes || (exports.permissionModes = {}));
15
+ const taskConfigSchema = Joi.object({
16
+ name: Joi.string().pattern(/^[A-Za-z0-9-]+$/).required(),
17
+ description: Joi.string(),
18
+ entryPoint: Joi.string().required(),
19
+ runtime: Joi.string().valid(...constants_1.runtimeChoices).required(),
20
+ timeLimit: Joi.number().min(constants_1.limits.time.min).max(constants_1.limits.time.max),
21
+ memoryLimit: Joi.number().min(constants_1.limits.memory.min).max(constants_1.limits.memory.max),
22
+ path: Joi.string(),
23
+ retryPolicy: Joi.object({
24
+ enabled: Joi.boolean().required(),
25
+ errorsToRetry: Joi.array().items(Joi.string()),
26
+ }),
27
+ environment: Joi.object().pattern(/.*/, Joi.string()),
28
+ executionPermission: Joi.string().valid(...Object.values(permissionModes)),
29
+ });
30
+ function assertExecutionPermission(mode) {
31
+ if (mode !== undefined && !Object.values(permissionModes).includes(mode)) {
32
+ throw new assert_1.AssertionError({ message: `executionPermission incorrect. Should be one of ${Object.values(permissionModes).join(',')}` });
33
+ }
34
+ }
35
+ exports.assertExecutionPermission = assertExecutionPermission;
36
+ function replaceConfigVariables(config) {
37
+ let result;
38
+ switch (typeof config) {
39
+ case 'object':
40
+ if (Array.isArray(config)) {
41
+ result = [];
42
+ for (const element of config) {
43
+ result.push(replaceConfigVariables(element));
44
+ }
45
+ }
46
+ else {
47
+ result = {};
48
+ for (const [key, value] of Object.entries(config)) {
49
+ result[key] = replaceConfigVariables(value);
50
+ }
51
+ }
52
+ return result;
53
+ case 'string':
54
+ if (config.charAt(0) === '$') {
55
+ const variable = config.slice(1);
56
+ if (process.env[variable]) {
57
+ return process.env[variable];
58
+ }
59
+ throw new Error(`Variable ${variable} not found in environment`);
60
+ }
61
+ return config;
62
+ default:
63
+ result = config;
64
+ break;
65
+ }
66
+ return result;
67
+ }
68
+ async function validateConfig(config) {
69
+ try {
70
+ Joi.attempt(config, taskConfigSchema);
71
+ }
72
+ catch (err) {
73
+ throw new Error(err.details[0]?.message || 'Unknown config validation error');
74
+ }
75
+ if (config.path) {
76
+ try {
77
+ await fs.access(config.path);
78
+ }
79
+ catch (err) {
80
+ throw new Error(`Please provide a valid directory path for your code, ${config.path} not found`);
81
+ }
82
+ if ((await fs.stat(config.path)).isFile()) {
83
+ throw new Error(`please provide a valid directory path for your code, ${config.path} points to a file`);
84
+ }
85
+ }
86
+ else {
87
+ throw new Error('Code path not specified');
88
+ }
89
+ assertExecutionPermission(config.executionPermission);
90
+ return true;
91
+ }
92
+ exports.validateConfig = validateConfig;
93
+ async function loadSingleConfigFile(path) {
94
+ let taskConfig;
95
+ try {
96
+ const data = await fs.readFile(path);
97
+ try {
98
+ taskConfig = JSON.parse(data.toString());
99
+ }
100
+ catch (err) {
101
+ throw new Error(`failed to parse file ${err.message}`);
102
+ }
103
+ }
104
+ catch (err2) {
105
+ throw new Error(`Invalid config file: ${err2.message}`);
106
+ }
107
+ taskConfig = replaceConfigVariables(taskConfig);
108
+ if (taskConfig.path) {
109
+ taskConfig.path = ospath.join(ospath.dirname(path), taskConfig.path);
110
+ }
111
+ return taskConfig;
112
+ }
113
+ exports.loadSingleConfigFile = loadSingleConfigFile;
114
+ async function* getValidatedConfigIterator({ path, name, code, entryPoint, runtime, description, timeLimit, memoryLimit, executionPermission, env }) {
115
+ let taskConfig = {};
116
+ if (path) {
117
+ const stat = await fs.stat(path);
118
+ if (stat.isDirectory()) {
119
+ const dirContents = await fs.readdir(path);
120
+ for (const file of dirContents) {
121
+ let filePath = ospath.join(path, file);
122
+ if ((await fs.stat(filePath)).isDirectory()) {
123
+ filePath = ospath.join(filePath, 'task-config.json');
124
+ const cfg = await loadSingleConfigFile(filePath);
125
+ if (cfg) {
126
+ await validateConfig(cfg);
127
+ yield cfg;
128
+ }
129
+ }
130
+ }
131
+ return;
132
+ }
133
+ taskConfig = await loadSingleConfigFile(path);
134
+ if (!taskConfig) {
135
+ throw new Error("Path is a file but doesn't point to a valid configuration file");
136
+ }
137
+ }
138
+ if (name) {
139
+ taskConfig.name = name;
140
+ }
141
+ if (code) {
142
+ taskConfig.path = code;
143
+ }
144
+ if (entryPoint) {
145
+ taskConfig.entryPoint = entryPoint;
146
+ }
147
+ if (runtime) {
148
+ taskConfig.runtime = runtime;
149
+ }
150
+ if (description) {
151
+ taskConfig.description = description;
152
+ }
153
+ if (timeLimit) {
154
+ taskConfig.timeLimit = timeLimit;
155
+ }
156
+ if (memoryLimit) {
157
+ taskConfig.memoryLimit = memoryLimit;
158
+ }
159
+ if (executionPermission) {
160
+ taskConfig.executionPermission = executionPermission;
161
+ }
162
+ if (env && env.length) {
163
+ const envArr = Array.isArray(env) ? env : [env];
164
+ taskConfig.environment = envArr.map(e => e.split('=')).filter(e => e.length === 2).reduce((prev, curr) => ({ ...prev, [curr[0]]: curr[1] }), {});
165
+ }
166
+ await validateConfig(taskConfig);
167
+ yield taskConfig;
168
+ }
169
+ exports.getValidatedConfigIterator = getValidatedConfigIterator;
@@ -1 +1 @@
1
- export declare function zipFileFromDirectory(path: string): Promise<string>;
1
+ export declare function zipFileFromDirectory(path: string): Promise<string>;
@@ -1,27 +1,27 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.zipFileFromDirectory = void 0;
4
- const fs_1 = require("fs");
5
- const os_1 = require("os");
6
- const archiver = require("archiver");
7
- const uuid_1 = require("uuid");
8
- async function zipFileFromDirectory(path) {
9
- return new Promise((res, rej) => {
10
- const tmpPath = `${(0, os_1.tmpdir)()}/${(0, uuid_1.v4)()}`;
11
- const output = (0, fs_1.createWriteStream)(tmpPath);
12
- const archive = archiver('zip', {
13
- zlib: { level: 9 },
14
- });
15
- output.on('close', () => {
16
- res(tmpPath);
17
- });
18
- archive.on('error', (err) => {
19
- (0, fs_1.unlink)(tmpPath, msg => { console.log(msg); });
20
- rej(err);
21
- });
22
- archive.pipe(output);
23
- archive.directory(`${path}/`, false);
24
- archive.finalize();
25
- });
26
- }
27
- exports.zipFileFromDirectory = zipFileFromDirectory;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.zipFileFromDirectory = void 0;
4
+ const fs_1 = require("fs");
5
+ const os_1 = require("os");
6
+ const archiver = require("archiver");
7
+ const uuid_1 = require("uuid");
8
+ async function zipFileFromDirectory(path) {
9
+ return new Promise((res, rej) => {
10
+ const tmpPath = `${(0, os_1.tmpdir)()}/${(0, uuid_1.v4)()}`;
11
+ const output = (0, fs_1.createWriteStream)(tmpPath);
12
+ const archive = archiver('zip', {
13
+ zlib: { level: 9 },
14
+ });
15
+ output.on('close', () => {
16
+ res(tmpPath);
17
+ });
18
+ archive.on('error', (err) => {
19
+ (0, fs_1.unlink)(tmpPath, msg => { console.log(msg); });
20
+ rej(err);
21
+ });
22
+ archive.pipe(output);
23
+ archive.directory(`${path}/`, false);
24
+ archive.finalize();
25
+ });
26
+ }
27
+ exports.zipFileFromDirectory = zipFileFromDirectory;
@@ -1,5 +1,5 @@
1
- /// <reference types="yargs" />
2
- export declare const command = "tasks <command>";
3
- export declare const desc = "Manage tasks";
4
- export declare const builder: (yargs: any) => import("yargs").Argv<{}>;
5
- export declare const handler: () => void;
1
+ /// <reference types="yargs" />
2
+ export declare const command = "tasks <command>";
3
+ export declare const desc = "Manage tasks";
4
+ export declare const builder: (yargs: any) => import("yargs").Argv<{}>;
5
+ export declare const handler: () => void;
@@ -1,10 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.handler = exports.builder = exports.desc = exports.command = void 0;
4
- const util_1 = require("../helpers/util");
5
- exports.command = 'tasks <command>';
6
- exports.desc = 'Manage tasks';
7
- const builder = (yargs) => (0, util_1.epilogue)(yargs).commandDir('tasks');
8
- exports.builder = builder;
9
- const handler = () => { };
10
- exports.handler = handler;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handler = exports.builder = exports.desc = exports.command = void 0;
4
+ const util_1 = require("../helpers/util");
5
+ exports.command = 'tasks <command>';
6
+ exports.desc = 'Manage tasks';
7
+ const builder = (yargs) => (0, util_1.epilogue)(yargs).commandDir('tasks');
8
+ exports.builder = builder;
9
+ const handler = () => { };
10
+ exports.handler = handler;
@@ -1,19 +1,19 @@
1
- /// <reference types="yargs" />
2
- import { OAuth1Client } from '@extrahorizon/javascript-sdk';
3
- export declare const command = "delete";
4
- export declare const desc = "Delete a template";
5
- export declare const builder: (yargs: any) => import("yargs").Argv<import("yargs").Omit<{}, "id" | "name"> & import("yargs").InferredOptionTypes<{
6
- name: {
7
- describe: string;
8
- type: "string";
9
- };
10
- id: {
11
- describe: string;
12
- type: "string";
13
- };
14
- }>>;
15
- export declare const handler: ({ sdk, name, id }: {
16
- sdk: OAuth1Client;
17
- name: string;
18
- id: string;
19
- }) => Promise<void>;
1
+ /// <reference types="yargs" />
2
+ import { OAuth1Client } from '@extrahorizon/javascript-sdk';
3
+ export declare const command = "delete";
4
+ export declare const desc = "Delete a template";
5
+ export declare const builder: (yargs: any) => import("yargs").Argv<import("yargs").Omit<{}, "id" | "name"> & import("yargs").InferredOptionTypes<{
6
+ name: {
7
+ describe: string;
8
+ type: "string";
9
+ };
10
+ id: {
11
+ describe: string;
12
+ type: "string";
13
+ };
14
+ }>>;
15
+ export declare const handler: ({ sdk, name, id }: {
16
+ sdk: OAuth1Client;
17
+ name: string;
18
+ id: string;
19
+ }) => Promise<void>;
@@ -1,48 +1,48 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.handler = exports.builder = exports.desc = exports.command = void 0;
4
- const chalk = require("chalk");
5
- const util_1 = require("../../helpers/util");
6
- exports.command = 'delete';
7
- exports.desc = 'Delete a template';
8
- const builder = (yargs) => (0, util_1.epilogue)(yargs).options({
9
- name: {
10
- describe: 'Name of the template to delete',
11
- type: 'string',
12
- },
13
- id: {
14
- describe: 'ID of the template to delete',
15
- type: 'string',
16
- },
17
- }).check(({ id, name }) => {
18
- if ((!id && !name) || (id && name)) {
19
- throw new Error('Either id or name needs to be provided');
20
- }
21
- return true;
22
- });
23
- exports.builder = builder;
24
- const handler = async function list({ sdk, name, id }) {
25
- let template = null;
26
- if (name) {
27
- template = await sdk.templates.findByName(name);
28
- }
29
- if (id) {
30
- template = await sdk.templates.findById(id);
31
- }
32
- if (!template) {
33
- console.log(chalk.red('Template not found!'));
34
- return;
35
- }
36
- try {
37
- const { affectedRecords } = await sdk.templates.remove(template.id);
38
- if (!affectedRecords) {
39
- console.log(chalk.red('Failed to remove template', name));
40
- return;
41
- }
42
- console.log('Template deleted');
43
- }
44
- catch (err) {
45
- console.log(chalk.red('Failed to remove template', name));
46
- }
47
- };
48
- exports.handler = handler;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handler = exports.builder = exports.desc = exports.command = void 0;
4
+ const chalk = require("chalk");
5
+ const util_1 = require("../../helpers/util");
6
+ exports.command = 'delete';
7
+ exports.desc = 'Delete a template';
8
+ const builder = (yargs) => (0, util_1.epilogue)(yargs).options({
9
+ name: {
10
+ describe: 'Name of the template to delete',
11
+ type: 'string',
12
+ },
13
+ id: {
14
+ describe: 'ID of the template to delete',
15
+ type: 'string',
16
+ },
17
+ }).check(({ id, name }) => {
18
+ if ((!id && !name) || (id && name)) {
19
+ throw new Error('Either id or name needs to be provided');
20
+ }
21
+ return true;
22
+ });
23
+ exports.builder = builder;
24
+ const handler = async function list({ sdk, name, id }) {
25
+ let template = null;
26
+ if (name) {
27
+ template = await sdk.templates.findByName(name);
28
+ }
29
+ if (id) {
30
+ template = await sdk.templates.findById(id);
31
+ }
32
+ if (!template) {
33
+ console.log(chalk.red('Template not found!'));
34
+ return;
35
+ }
36
+ try {
37
+ const { affectedRecords } = await sdk.templates.remove(template.id);
38
+ if (!affectedRecords) {
39
+ console.log(chalk.red('Failed to remove template', name));
40
+ return;
41
+ }
42
+ console.log('Template deleted');
43
+ }
44
+ catch (err) {
45
+ console.log(chalk.red('Failed to remove template', name));
46
+ }
47
+ };
48
+ exports.handler = handler;
@@ -1,19 +1,19 @@
1
- /// <reference types="yargs" />
2
- import { OAuth1Client } from '@extrahorizon/javascript-sdk';
3
- export declare const command = "get";
4
- export declare const desc = "Fetch a template";
5
- export declare const builder: (yargs: any) => import("yargs").Argv<import("yargs").Omit<{}, "id" | "name"> & import("yargs").InferredOptionTypes<{
6
- name: {
7
- describe: string;
8
- type: "string";
9
- };
10
- id: {
11
- describe: string;
12
- type: "string";
13
- };
14
- }>>;
15
- export declare const handler: ({ sdk, name, id }: {
16
- sdk: OAuth1Client;
17
- name: string;
18
- id: string;
19
- }) => Promise<void>;
1
+ /// <reference types="yargs" />
2
+ import { OAuth1Client } from '@extrahorizon/javascript-sdk';
3
+ export declare const command = "get";
4
+ export declare const desc = "Fetch a template";
5
+ export declare const builder: (yargs: any) => import("yargs").Argv<import("yargs").Omit<{}, "id" | "name"> & import("yargs").InferredOptionTypes<{
6
+ name: {
7
+ describe: string;
8
+ type: "string";
9
+ };
10
+ id: {
11
+ describe: string;
12
+ type: "string";
13
+ };
14
+ }>>;
15
+ export declare const handler: ({ sdk, name, id }: {
16
+ sdk: OAuth1Client;
17
+ name: string;
18
+ id: string;
19
+ }) => Promise<void>;