@extrahorizon/exh-cli 1.12.0-dev-131-de586fc → 1.12.0-feat-132-3d57f4e
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.d.ts +1 -2
- package/build/commands/data/schemas/delete.js +3 -3
- package/build/commands/data/schemas/list.d.ts +1 -2
- package/build/commands/data/schemas/list.js +3 -2
- package/build/commands/data/schemas/sync.d.ts +3 -4
- package/build/commands/data/schemas/sync.js +7 -7
- package/build/commands/data/schemas/util/syncSchema.d.ts +2 -3
- package/build/commands/data/schemas/util/syncSchema.js +18 -19
- package/build/commands/dispatchers/sync.d.ts +1 -3
- package/build/commands/dispatchers/sync.js +2 -2
- package/build/commands/localizations/sync.d.ts +1 -3
- package/build/commands/localizations/sync.js +2 -2
- package/build/commands/sync.d.ts +1 -3
- package/build/commands/sync.js +6 -6
- package/build/commands/tasks/delete.d.ts +1 -2
- package/build/commands/tasks/delete.js +2 -2
- package/build/commands/tasks/list.d.ts +1 -2
- package/build/commands/tasks/list.js +3 -2
- package/build/commands/tasks/sync.d.ts +1 -2
- package/build/commands/tasks/sync.js +8 -8
- package/build/commands/tasks/util.d.ts +1 -2
- package/build/commands/tasks/util.js +18 -18
- package/build/commands/templates/delete.d.ts +1 -3
- package/build/commands/templates/delete.js +5 -4
- package/build/commands/templates/get.d.ts +1 -3
- package/build/commands/templates/get.js +3 -2
- package/build/commands/templates/list.d.ts +1 -3
- package/build/commands/templates/list.js +3 -2
- package/build/commands/templates/sync.d.ts +1 -2
- package/build/commands/templates/sync.js +2 -2
- package/build/commands/templates/util/templateService.d.ts +1 -2
- package/build/commands/templates/util/templateService.js +3 -2
- package/build/commands/whoami.d.ts +1 -4
- package/build/commands/whoami.js +3 -3
- package/build/exh.d.ts +1 -0
- package/build/exh.js +8 -1
- package/build/index.js +3 -3
- package/build/repositories/auth.d.ts +3 -4
- package/build/repositories/auth.js +7 -6
- package/build/repositories/dispatchers.d.ts +8 -8
- package/build/repositories/dispatchers.js +15 -14
- package/build/repositories/functions.d.ts +5 -6
- package/build/repositories/functions.js +11 -10
- package/build/repositories/localizations.d.ts +3 -3
- package/build/repositories/localizations.js +5 -4
- package/build/repositories/schemas.d.ts +18 -18
- package/build/repositories/schemas.js +35 -34
- package/build/repositories/user.d.ts +9 -9
- package/build/repositories/user.js +17 -16
- package/build/services/dispatchers.d.ts +1 -2
- package/build/services/dispatchers.js +18 -18
- package/build/services/localizations/index.d.ts +1 -2
- package/build/services/localizations/index.js +2 -2
- package/build/services/localizations/syncLocalizations.d.ts +1 -2
- package/build/services/localizations/syncLocalizations.js +3 -3
- package/package.json +1 -1
|
@@ -4,7 +4,6 @@ export declare const desc = "Delete a schema";
|
|
|
4
4
|
export declare const builder: (yargs: any) => import("yargs").Argv<{
|
|
5
5
|
id: string;
|
|
6
6
|
}>;
|
|
7
|
-
export declare const handler: ({
|
|
8
|
-
sdk: any;
|
|
7
|
+
export declare const handler: ({ id }: {
|
|
9
8
|
id: any;
|
|
10
9
|
}) => Promise<void>;
|
|
@@ -12,13 +12,13 @@ const builder = (yargs) => (0, util_1.epilogue)(yargs).option('id', {
|
|
|
12
12
|
type: 'string',
|
|
13
13
|
});
|
|
14
14
|
exports.builder = builder;
|
|
15
|
-
const handler = async ({
|
|
16
|
-
const disableResponse = await schemaRepository.disable(
|
|
15
|
+
const handler = async ({ id }) => {
|
|
16
|
+
const disableResponse = await schemaRepository.disable(id);
|
|
17
17
|
if (disableResponse.affectedRecords !== 1) {
|
|
18
18
|
console.log(chalk.red('Failed to delete schema', id));
|
|
19
19
|
return;
|
|
20
20
|
}
|
|
21
|
-
const deleteResponse = await schemaRepository.remove(
|
|
21
|
+
const deleteResponse = await schemaRepository.remove(id);
|
|
22
22
|
if (deleteResponse.affectedRecords) {
|
|
23
23
|
console.log(chalk.green('Successfully deleted schema', id));
|
|
24
24
|
}
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
export declare const command = "list";
|
|
3
3
|
export declare const desc = "List all schemas";
|
|
4
4
|
export declare const builder: (yargs: any) => import("yargs").Argv<{}>;
|
|
5
|
-
export declare const handler: ({
|
|
6
|
-
sdk: any;
|
|
5
|
+
export declare const handler: ({ isTTY }: {
|
|
7
6
|
isTTY: any;
|
|
8
7
|
}) => Promise<void>;
|
|
@@ -1,13 +1,14 @@
|
|
|
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");
|
|
4
5
|
const util_1 = require("../../../helpers/util");
|
|
5
6
|
exports.command = 'list';
|
|
6
7
|
exports.desc = 'List all schemas';
|
|
7
8
|
const builder = (yargs) => (0, util_1.epilogue)(yargs);
|
|
8
9
|
exports.builder = builder;
|
|
9
|
-
const handler = async function list({
|
|
10
|
-
const schemaListResponse = await
|
|
10
|
+
const handler = async function list({ isTTY }) {
|
|
11
|
+
const schemaListResponse = await (0, exh_1.getSdk)().raw.get('/data/v1/');
|
|
11
12
|
if (schemaListResponse.data.data.length !== 0) {
|
|
12
13
|
if (isTTY) {
|
|
13
14
|
console.table(schemaListResponse.data.data.map((c) => ({ Id: c.id, Name: c.name, Description: c.description || '<none>' })));
|
|
@@ -24,12 +24,11 @@ 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
|
-
sdk: any;
|
|
27
|
+
export declare const handler: ({ dir, file, dry, ignoreVerificationErrors }: {
|
|
29
28
|
dir: any;
|
|
30
29
|
file: any;
|
|
31
30
|
dry: any;
|
|
32
31
|
ignoreVerificationErrors: any;
|
|
33
32
|
}) => Promise<void>;
|
|
34
|
-
export declare function syncTargetFile(
|
|
35
|
-
export declare function syncTargetDir(
|
|
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>;
|
|
@@ -34,20 +34,20 @@ const builder = (yargs) => (0, util_1.epilogue)(yargs).options({
|
|
|
34
34
|
},
|
|
35
35
|
});
|
|
36
36
|
exports.builder = builder;
|
|
37
|
-
const handler = async ({
|
|
37
|
+
const handler = async ({ dir, file, dry, ignoreVerificationErrors }) => {
|
|
38
38
|
if (!file && !dir) {
|
|
39
39
|
console.log(chalk.red('No target is chosen to be synced. Please use flags "--file" or "--dir" when syncing'));
|
|
40
40
|
process.exit(1);
|
|
41
41
|
}
|
|
42
42
|
if (dir) {
|
|
43
|
-
await syncTargetDir(
|
|
43
|
+
await syncTargetDir(path.resolve(dir || '.'), dry, ignoreVerificationErrors);
|
|
44
44
|
}
|
|
45
45
|
if (file) {
|
|
46
|
-
await syncTargetFile(
|
|
46
|
+
await syncTargetFile(path.resolve(file), dry, ignoreVerificationErrors);
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
49
|
exports.handler = handler;
|
|
50
|
-
async function syncTargetFile(
|
|
50
|
+
async function syncTargetFile(targetFile, dry, ignoreVerificationErrors) {
|
|
51
51
|
await (0, verify_1.handler)({ dir: null, file: targetFile, ignoreVerificationErrors });
|
|
52
52
|
const filePath = path.resolve(targetFile);
|
|
53
53
|
if (!filePath.endsWith('.json')) {
|
|
@@ -56,15 +56,15 @@ async function syncTargetFile(sdk, targetFile, dry, ignoreVerificationErrors) {
|
|
|
56
56
|
else {
|
|
57
57
|
console.log(chalk.bold(`Synchronizing ${path.basename(filePath)}`));
|
|
58
58
|
const targetSchema = await (0, readJson_1.readJsonFile)(filePath);
|
|
59
|
-
const syncSchema = syncSchema_1.SyncSchema.createSchemaSync(
|
|
59
|
+
const syncSchema = syncSchema_1.SyncSchema.createSchemaSync(dry);
|
|
60
60
|
await syncSchema.sync(targetSchema);
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
exports.syncTargetFile = syncTargetFile;
|
|
64
|
-
async function syncTargetDir(
|
|
64
|
+
async function syncTargetDir(targetDir, dry, ignoreVerificationErrors) {
|
|
65
65
|
const targetFiles = (0, listFilesInDir_1.flatListFiles)(targetDir, '.json');
|
|
66
66
|
for (const filePath of targetFiles) {
|
|
67
|
-
await syncTargetFile(
|
|
67
|
+
await syncTargetFile(filePath, dry, ignoreVerificationErrors);
|
|
68
68
|
process.stdout.write('\n');
|
|
69
69
|
}
|
|
70
70
|
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
export declare class SyncSchema {
|
|
2
2
|
#private;
|
|
3
|
-
private sdk;
|
|
4
3
|
private dry;
|
|
5
4
|
private cloudSchema;
|
|
6
5
|
private localSchema;
|
|
7
|
-
static createSchemaSync(
|
|
8
|
-
constructor(
|
|
6
|
+
static createSchemaSync(dry?: boolean): SyncSchema;
|
|
7
|
+
constructor(dry?: boolean);
|
|
9
8
|
sync(target: any): Promise<void>;
|
|
10
9
|
}
|
|
11
10
|
export declare type Changes = {
|
|
@@ -13,15 +13,14 @@ const schemaRepository = require("../../../../repositories/schemas");
|
|
|
13
13
|
const statusHelpers_1 = require("../sync/statusHelpers");
|
|
14
14
|
const stripUnsupportedDescriptionFields_1 = require("./stripUnsupportedDescriptionFields");
|
|
15
15
|
class SyncSchema {
|
|
16
|
-
constructor(
|
|
16
|
+
constructor(dry) {
|
|
17
17
|
_SyncSchema_instances.add(this);
|
|
18
18
|
this.cloudSchema = null;
|
|
19
19
|
this.localSchema = null;
|
|
20
|
-
this.sdk = sdk;
|
|
21
20
|
this.dry = dry;
|
|
22
21
|
}
|
|
23
|
-
static createSchemaSync(
|
|
24
|
-
return new SyncSchema(
|
|
22
|
+
static createSchemaSync(dry) {
|
|
23
|
+
return new SyncSchema(dry);
|
|
25
24
|
}
|
|
26
25
|
async sync(target) {
|
|
27
26
|
this.localSchema = (0, stripUnsupportedDescriptionFields_1.stripUnsupportedDescriptionFields)(target);
|
|
@@ -30,13 +29,13 @@ class SyncSchema {
|
|
|
30
29
|
return;
|
|
31
30
|
}
|
|
32
31
|
console.log(`Syncing ${this.localSchema.name}`);
|
|
33
|
-
this.cloudSchema = await schemaRepository.fetchSchemaByName(this.
|
|
32
|
+
this.cloudSchema = await schemaRepository.fetchSchemaByName(this.localSchema.name);
|
|
34
33
|
if (!this.cloudSchema) {
|
|
35
34
|
if (this.dry) {
|
|
36
35
|
console.log(`\t-> Will be created: ${chalk.green(this.localSchema.name)}`);
|
|
37
36
|
return;
|
|
38
37
|
}
|
|
39
|
-
this.cloudSchema = await schemaRepository.createSchema(this.
|
|
38
|
+
this.cloudSchema = await schemaRepository.createSchema(this.localSchema.name, this.localSchema.description);
|
|
40
39
|
}
|
|
41
40
|
await __classPrivateFieldGet(this, _SyncSchema_instances, "m", _SyncSchema_syncRootAttributes).call(this);
|
|
42
41
|
await __classPrivateFieldGet(this, _SyncSchema_instances, "m", _SyncSchema_syncProperties).call(this);
|
|
@@ -55,7 +54,7 @@ _SyncSchema_instances = new WeakSet(), _SyncSchema_syncRootAttributes = async fu
|
|
|
55
54
|
return;
|
|
56
55
|
}
|
|
57
56
|
if (Object.keys(diff).length > 0) {
|
|
58
|
-
await schemaRepository.updateSchema(this.
|
|
57
|
+
await schemaRepository.updateSchema(this.cloudSchema.id, diff);
|
|
59
58
|
}
|
|
60
59
|
}, _SyncSchema_syncProperties = async function _SyncSchema_syncProperties() {
|
|
61
60
|
const propertiesDiff = compareSchemaKey(this.localSchema, this.cloudSchema, 'properties');
|
|
@@ -66,18 +65,18 @@ _SyncSchema_instances = new WeakSet(), _SyncSchema_syncRootAttributes = async fu
|
|
|
66
65
|
const { toAdd, toRemove, toUpdate } = propertiesDiff;
|
|
67
66
|
for (const key of toAdd) {
|
|
68
67
|
console.log(`properties: adding ${key}`);
|
|
69
|
-
await schemaRepository.createProperty(this.
|
|
68
|
+
await schemaRepository.createProperty(this.cloudSchema.id, {
|
|
70
69
|
name: key,
|
|
71
70
|
configuration: this.localSchema.properties[key],
|
|
72
71
|
});
|
|
73
72
|
}
|
|
74
73
|
for (const key of toUpdate) {
|
|
75
74
|
console.log(`properties: updating ${key}`);
|
|
76
|
-
await schemaRepository.updateProperty(this.
|
|
75
|
+
await schemaRepository.updateProperty(this.cloudSchema.id, key, this.localSchema.properties[key]);
|
|
77
76
|
}
|
|
78
77
|
for (const key of toRemove) {
|
|
79
78
|
console.log(`properties: removing ${key}`);
|
|
80
|
-
await schemaRepository.deleteProperty(this.
|
|
79
|
+
await schemaRepository.deleteProperty(this.cloudSchema.id, key);
|
|
81
80
|
}
|
|
82
81
|
}, _SyncSchema_updateStatuses = async function _SyncSchema_updateStatuses() {
|
|
83
82
|
const changes = (0, statusHelpers_1.compareStatuses)(this.localSchema, this.cloudSchema);
|
|
@@ -88,12 +87,12 @@ _SyncSchema_instances = new WeakSet(), _SyncSchema_syncRootAttributes = async fu
|
|
|
88
87
|
const { toAdd, toUpdate } = changes;
|
|
89
88
|
for (const key of toAdd) {
|
|
90
89
|
console.log(`statuses: adding ${key}`);
|
|
91
|
-
await schemaRepository.createStatus(this.
|
|
90
|
+
await schemaRepository.createStatus(this.cloudSchema.id, key, this.localSchema.statuses[key]);
|
|
92
91
|
}
|
|
93
92
|
for (const key of toUpdate) {
|
|
94
93
|
console.log(`statuses: updating ${key}`);
|
|
95
94
|
const data = (0, statusHelpers_1.calculateStatusUpdateData)(this.localSchema.statuses[key], this.cloudSchema.statuses[key]);
|
|
96
|
-
await schemaRepository.updateStatus(this.
|
|
95
|
+
await schemaRepository.updateStatus(this.cloudSchema.id, key, data);
|
|
97
96
|
}
|
|
98
97
|
}, _SyncSchema_syncCreationTransition = async function _SyncSchema_syncCreationTransition() {
|
|
99
98
|
if (!this.localSchema.creationTransition) {
|
|
@@ -106,7 +105,7 @@ _SyncSchema_instances = new WeakSet(), _SyncSchema_syncRootAttributes = async fu
|
|
|
106
105
|
return;
|
|
107
106
|
}
|
|
108
107
|
console.log('creation transition: updating');
|
|
109
|
-
await schemaRepository.updateCreationTransition(this.
|
|
108
|
+
await schemaRepository.updateCreationTransition(this.cloudSchema.id, this.localSchema.creationTransition);
|
|
110
109
|
}
|
|
111
110
|
}, _SyncSchema_syncTransitions = async function _SyncSchema_syncTransitions() {
|
|
112
111
|
const transitionsDiff = compareSchemaKey(this.localSchema, this.cloudSchema, 'transitions');
|
|
@@ -117,16 +116,16 @@ _SyncSchema_instances = new WeakSet(), _SyncSchema_syncRootAttributes = async fu
|
|
|
117
116
|
const { toAdd, toRemove, toUpdate } = transitionsDiff;
|
|
118
117
|
for (const transition of toAdd) {
|
|
119
118
|
console.log(`transitions: adding ${transition.name}`);
|
|
120
|
-
await schemaRepository.createTransition(this.
|
|
119
|
+
await schemaRepository.createTransition(this.cloudSchema.id, transition);
|
|
121
120
|
}
|
|
122
121
|
for (const transition of toUpdate) {
|
|
123
122
|
console.log(`transitions: updating ${transition.name}`);
|
|
124
123
|
const currentTransition = findTransitionByName(transition.name, this.cloudSchema.transitions);
|
|
125
|
-
await schemaRepository.updateTransition(this.
|
|
124
|
+
await schemaRepository.updateTransition(this.cloudSchema.id, currentTransition.id, transition);
|
|
126
125
|
}
|
|
127
126
|
for (const transition of toRemove) {
|
|
128
127
|
console.log(`transitions: removing ${transition.name}`);
|
|
129
|
-
await schemaRepository.deleteTransition(this.
|
|
128
|
+
await schemaRepository.deleteTransition(this.cloudSchema.id, transition.id);
|
|
130
129
|
}
|
|
131
130
|
}, _SyncSchema_pruneStatuses = async function _SyncSchema_pruneStatuses() {
|
|
132
131
|
if (this.dry) {
|
|
@@ -135,7 +134,7 @@ _SyncSchema_instances = new WeakSet(), _SyncSchema_syncRootAttributes = async fu
|
|
|
135
134
|
const excessStatuses = _.difference(Object.keys(this.cloudSchema.statuses), Object.keys(this.localSchema.statuses));
|
|
136
135
|
for (const key of excessStatuses) {
|
|
137
136
|
console.log(`statuses: removing ${key}`);
|
|
138
|
-
await schemaRepository.deleteStatus(this.
|
|
137
|
+
await schemaRepository.deleteStatus(this.cloudSchema.id, key);
|
|
139
138
|
}
|
|
140
139
|
}, _SyncSchema_syncIndexes = async function _SyncSchema_syncIndexes() {
|
|
141
140
|
const { newIndexes, removedIndexes } = compareIndexes(this.localSchema, this.cloudSchema);
|
|
@@ -145,11 +144,11 @@ _SyncSchema_instances = new WeakSet(), _SyncSchema_syncRootAttributes = async fu
|
|
|
145
144
|
}
|
|
146
145
|
for (const idx of removedIndexes) {
|
|
147
146
|
console.log(`Indexes: remove index ${idx.id}`);
|
|
148
|
-
await schemaRepository.deleteIndex(this.
|
|
147
|
+
await schemaRepository.deleteIndex(this.cloudSchema.id, idx.id);
|
|
149
148
|
}
|
|
150
149
|
for (const idx of newIndexes) {
|
|
151
150
|
console.log('\t-> Creating new index');
|
|
152
|
-
await schemaRepository.createIndex(this.
|
|
151
|
+
await schemaRepository.createIndex(this.cloudSchema.id, idx);
|
|
153
152
|
}
|
|
154
153
|
};
|
|
155
154
|
function deepDiff(object, other) {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { OAuth1Client } from '@extrahorizon/javascript-sdk';
|
|
2
1
|
import { Argv } from 'yargs';
|
|
3
2
|
export declare const command = "sync";
|
|
4
3
|
export declare const desc = "Synchronize Dispatchers, if a declared Dispatcher does not exist, it will be created";
|
|
@@ -14,8 +13,7 @@ export declare const builder: (yargs: Argv) => Argv<import("yargs").Omit<{}, "fi
|
|
|
14
13
|
type: "boolean";
|
|
15
14
|
};
|
|
16
15
|
}>>;
|
|
17
|
-
export declare const handler: ({
|
|
18
|
-
sdk: OAuth1Client;
|
|
16
|
+
export declare const handler: ({ file, clean }: {
|
|
19
17
|
file: string;
|
|
20
18
|
clean: boolean;
|
|
21
19
|
}) => Promise<void>;
|
|
@@ -18,7 +18,7 @@ const builder = (yargs) => (0, util_1.epilogue)(yargs).options({
|
|
|
18
18
|
},
|
|
19
19
|
});
|
|
20
20
|
exports.builder = builder;
|
|
21
|
-
const handler = async ({
|
|
22
|
-
await dispatchersService.sync(
|
|
21
|
+
const handler = async ({ file, clean }) => {
|
|
22
|
+
await dispatchersService.sync(file, clean);
|
|
23
23
|
};
|
|
24
24
|
exports.handler = handler;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/// <reference types="yargs" />
|
|
2
|
-
import { OAuth1Client } from '@extrahorizon/javascript-sdk';
|
|
3
2
|
export declare const command = "sync";
|
|
4
3
|
export declare const desc = "Sync all localizations in a directory with the ExH cloud";
|
|
5
4
|
export declare const builder: (yargs: any) => import("yargs").Argv<import("yargs").Omit<{}, "path"> & import("yargs").InferredOptionTypes<{
|
|
@@ -10,7 +9,6 @@ export declare const builder: (yargs: any) => import("yargs").Argv<import("yargs
|
|
|
10
9
|
default: string;
|
|
11
10
|
};
|
|
12
11
|
}>>;
|
|
13
|
-
export declare const handler: ({
|
|
14
|
-
sdk: OAuth1Client;
|
|
12
|
+
export declare const handler: ({ path }: {
|
|
15
13
|
path?: string;
|
|
16
14
|
}) => Promise<void>;
|
|
@@ -14,7 +14,7 @@ const builder = (yargs) => (0, util_1.epilogue)(yargs).options({
|
|
|
14
14
|
},
|
|
15
15
|
});
|
|
16
16
|
exports.builder = builder;
|
|
17
|
-
const handler = async ({
|
|
18
|
-
await localizationsService.sync(
|
|
17
|
+
const handler = async ({ path }) => {
|
|
18
|
+
await localizationsService.sync(path);
|
|
19
19
|
};
|
|
20
20
|
exports.handler = handler;
|
package/build/commands/sync.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/// <reference types="yargs" />
|
|
2
|
-
import { OAuth1Client } from '@extrahorizon/javascript-sdk';
|
|
3
2
|
export declare const command = "sync";
|
|
4
3
|
export declare const desc = "Sync your ExH configuration to the cloud environment";
|
|
5
4
|
export declare const builder: (yargs: any) => import("yargs").Argv<import("yargs").Omit<{}, "path" | "schemas" | "tasks" | "dispatchers" | "localizations" | "templates" | "cleanDispatchers" | "ignoreSchemaVerificationErrors"> & import("yargs").InferredOptionTypes<{
|
|
@@ -50,8 +49,7 @@ export declare const builder: (yargs: any) => import("yargs").Argv<import("yargs
|
|
|
50
49
|
default: boolean;
|
|
51
50
|
};
|
|
52
51
|
}>>;
|
|
53
|
-
export declare const handler: ({
|
|
54
|
-
sdk: OAuth1Client;
|
|
52
|
+
export declare const handler: ({ path, schemas, tasks, templates, dispatchers, cleanDispatchers, localizations, ignoreSchemaVerificationErrors, }: {
|
|
55
53
|
path?: string;
|
|
56
54
|
schemas?: boolean;
|
|
57
55
|
tasks?: boolean;
|
package/build/commands/sync.js
CHANGED
|
@@ -78,32 +78,32 @@ If not, the local directory is assumed with a default configuration which assume
|
|
|
78
78
|
return true;
|
|
79
79
|
});
|
|
80
80
|
exports.builder = builder;
|
|
81
|
-
const handler = async ({
|
|
81
|
+
const handler = async ({ path, schemas, tasks, templates, dispatchers, cleanDispatchers, localizations, ignoreSchemaVerificationErrors, }) => {
|
|
82
82
|
const targetPath = path || '.';
|
|
83
83
|
const cfg = await (0, repoConfig_1.getRepoConfig)(targetPath);
|
|
84
84
|
const syncAll = !(schemas || tasks || templates || dispatchers || localizations);
|
|
85
85
|
if ((syncAll || schemas) && cfg.schemas) {
|
|
86
86
|
console.log(chalk.green('\n ⚙️ Syncing schemas ...'));
|
|
87
87
|
for (const schema of cfg.schemas) {
|
|
88
|
-
await (0, sync_1.syncTargetDir)(
|
|
88
|
+
await (0, sync_1.syncTargetDir)(ospath.join(targetPath, schema), undefined, ignoreSchemaVerificationErrors);
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
if ((syncAll || templates) && cfg.templates) {
|
|
92
92
|
console.log(chalk.green('\n ⚙️ Syncing templates...'));
|
|
93
93
|
for (const template of cfg.templates) {
|
|
94
|
-
await (0, sync_3.handler)({
|
|
94
|
+
await (0, sync_3.handler)({ path: ospath.join(targetPath, template), template: null });
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
if ((syncAll || tasks) && cfg.tasks) {
|
|
98
98
|
console.log(chalk.green('\n ⚙️ Syncing tasks...'));
|
|
99
99
|
for (const task of cfg.tasks) {
|
|
100
|
-
await (0, sync_2.handler)({
|
|
100
|
+
await (0, sync_2.handler)({ path: ospath.join(targetPath, task) });
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
if ((syncAll || localizations) && cfg.localizations) {
|
|
104
104
|
console.log(chalk.green('\n ⚙️ Syncing localizations...'));
|
|
105
105
|
for (const localization of cfg.localizations) {
|
|
106
|
-
await (0, localizations_1.sync)(
|
|
106
|
+
await (0, localizations_1.sync)(ospath.join(targetPath, localization));
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
if ((syncAll || dispatchers)) {
|
|
@@ -111,7 +111,7 @@ const handler = async ({ sdk, path, schemas, tasks, templates, dispatchers, clea
|
|
|
111
111
|
const isValidPath = (0, fs_1.existsSync)(dispatchersPath);
|
|
112
112
|
if (isValidPath) {
|
|
113
113
|
console.log(chalk.green('\n ⚙️ Syncing dispatchers...'));
|
|
114
|
-
await (0, dispatchers_1.sync)(
|
|
114
|
+
await (0, dispatchers_1.sync)(dispatchersPath, cleanDispatchers);
|
|
115
115
|
}
|
|
116
116
|
else if (dispatchers) {
|
|
117
117
|
console.log(chalk.yellow('Warning: dispatchers.json not found'));
|
|
@@ -4,7 +4,6 @@ export declare const desc = "Delete a task";
|
|
|
4
4
|
export declare const builder: (yargs: any) => import("yargs").Argv<{
|
|
5
5
|
name: string;
|
|
6
6
|
}>;
|
|
7
|
-
export declare const handler: ({
|
|
8
|
-
sdk: any;
|
|
7
|
+
export declare const handler: ({ name }: {
|
|
9
8
|
name: any;
|
|
10
9
|
}) => Promise<void>;
|
|
@@ -12,9 +12,9 @@ const builder = (yargs) => (0, util_1.epilogue)(yargs).option('name', {
|
|
|
12
12
|
type: 'string',
|
|
13
13
|
});
|
|
14
14
|
exports.builder = builder;
|
|
15
|
-
const handler = async ({
|
|
15
|
+
const handler = async ({ name }) => {
|
|
16
16
|
try {
|
|
17
|
-
const response = await functionRepository.remove(
|
|
17
|
+
const response = await functionRepository.remove(name);
|
|
18
18
|
if (response?.affectedRecords) {
|
|
19
19
|
console.log(chalk.green('Successfully deleted task', name));
|
|
20
20
|
}
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
export declare const command = "list";
|
|
3
3
|
export declare const desc = "List all tasks";
|
|
4
4
|
export declare const builder: (yargs: any) => import("yargs").Argv<{}>;
|
|
5
|
-
export declare const handler: ({
|
|
6
|
-
sdk: any;
|
|
5
|
+
export declare const handler: ({ isTTY }: {
|
|
7
6
|
isTTY: any;
|
|
8
7
|
}) => Promise<void>;
|
|
@@ -1,15 +1,16 @@
|
|
|
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");
|
|
4
5
|
const util_1 = require("../../helpers/util");
|
|
5
6
|
exports.command = 'list';
|
|
6
7
|
exports.desc = 'List all tasks';
|
|
7
8
|
const builder = (yargs) => (0, util_1.epilogue)(yargs);
|
|
8
9
|
exports.builder = builder;
|
|
9
|
-
const handler = async function list({
|
|
10
|
+
const handler = async function list({ isTTY }) {
|
|
10
11
|
let functionResponse;
|
|
11
12
|
try {
|
|
12
|
-
functionResponse = await
|
|
13
|
+
functionResponse = await (0, exh_1.getSdk)().raw.get('/tasks/v1/functions');
|
|
13
14
|
}
|
|
14
15
|
catch (err) {
|
|
15
16
|
console.log(err);
|
|
@@ -53,7 +53,6 @@ export declare const builder: (yargs: any) => import("yargs").Argv<import("yargs
|
|
|
53
53
|
type: "number";
|
|
54
54
|
};
|
|
55
55
|
}>>;
|
|
56
|
-
export declare const handler: ({
|
|
56
|
+
export declare const handler: ({ ...cmdLineParams }: {
|
|
57
57
|
[x: string]: any;
|
|
58
|
-
sdk: any;
|
|
59
58
|
}) => Promise<void>;
|
|
@@ -71,17 +71,17 @@ const builder = (yargs) => (0, util_1.epilogue)(yargs).options({
|
|
|
71
71
|
return true;
|
|
72
72
|
});
|
|
73
73
|
exports.builder = builder;
|
|
74
|
-
const handler = async ({
|
|
74
|
+
const handler = async ({ ...cmdLineParams }) => {
|
|
75
75
|
for await (const config of (0, taskConfig_1.getValidatedConfigIterator)(cmdLineParams)) {
|
|
76
76
|
console.log('Syncing task', config.name, '...');
|
|
77
|
-
await syncSingleTask(
|
|
77
|
+
await syncSingleTask(config);
|
|
78
78
|
}
|
|
79
79
|
};
|
|
80
80
|
exports.handler = handler;
|
|
81
|
-
async function syncSingleTask(
|
|
81
|
+
async function syncSingleTask(config) {
|
|
82
82
|
const uploadFilePath = await (0, util_2.zipFileFromDirectory)(config.path);
|
|
83
83
|
const file = await fs.readFile(uploadFilePath);
|
|
84
|
-
const allFunctions = await functionRepository.find(
|
|
84
|
+
const allFunctions = await functionRepository.find();
|
|
85
85
|
const myFunction = allFunctions.find((f) => f.name === config.name);
|
|
86
86
|
const request = {
|
|
87
87
|
name: config.name,
|
|
@@ -109,7 +109,7 @@ async function syncSingleTask(sdk, config) {
|
|
|
109
109
|
request.retryPolicy = config.retryPolicy;
|
|
110
110
|
}
|
|
111
111
|
if (config.executionCredentials) {
|
|
112
|
-
const credentials = await (0, util_2.syncFunctionUser)(
|
|
112
|
+
const credentials = await (0, util_2.syncFunctionUser)({
|
|
113
113
|
taskName: config.name,
|
|
114
114
|
targetEmail: config.executionCredentials.email,
|
|
115
115
|
targetPermissions: config.executionCredentials.permissions,
|
|
@@ -131,15 +131,15 @@ async function syncSingleTask(sdk, config) {
|
|
|
131
131
|
request.environmentVariables = environmentVariables;
|
|
132
132
|
}
|
|
133
133
|
if (myFunction === undefined) {
|
|
134
|
-
await functionRepository.create(
|
|
134
|
+
await functionRepository.create(request);
|
|
135
135
|
console.log(chalk.green('Successfully created task', config.name));
|
|
136
136
|
}
|
|
137
137
|
else {
|
|
138
|
-
const existingFunction = await functionRepository.findByName(
|
|
138
|
+
const existingFunction = await functionRepository.findByName(myFunction.name);
|
|
139
139
|
if (request.runtime === existingFunction.runtime) {
|
|
140
140
|
delete request.runtime;
|
|
141
141
|
}
|
|
142
|
-
const updateResponse = await functionRepository.update(
|
|
142
|
+
const updateResponse = await functionRepository.update(request);
|
|
143
143
|
if (!updateResponse?.affectedRecords) {
|
|
144
144
|
throw new Error(`Failed to update task ${request.name}`);
|
|
145
145
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { OAuth1Client } from '@extrahorizon/javascript-sdk';
|
|
2
1
|
export declare function zipFileFromDirectory(path: string): Promise<string>;
|
|
3
|
-
export declare function syncFunctionUser(
|
|
2
|
+
export declare function syncFunctionUser(data: {
|
|
4
3
|
taskName: string;
|
|
5
4
|
targetEmail?: string;
|
|
6
5
|
targetPermissions: string[];
|
|
@@ -30,18 +30,18 @@ async function zipFileFromDirectory(path) {
|
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
32
|
exports.zipFileFromDirectory = zipFileFromDirectory;
|
|
33
|
-
async function syncFunctionUser(
|
|
33
|
+
async function syncFunctionUser(data) {
|
|
34
34
|
const { taskName, targetEmail, targetPermissions } = data;
|
|
35
35
|
const email = (targetEmail || `exh.tasks+${taskName}@extrahorizon.com`).toLowerCase();
|
|
36
36
|
validateEmail(email);
|
|
37
37
|
const password = `0Oo-${randomHexString()}`;
|
|
38
38
|
const roleName = `exh.tasks.${taskName}`;
|
|
39
|
-
const role = await syncRoleWithPermissions(
|
|
40
|
-
let user = await userRepository.findUserByEmail(
|
|
39
|
+
const role = await syncRoleWithPermissions(taskName, roleName, targetPermissions);
|
|
40
|
+
let user = await userRepository.findUserByEmail(email);
|
|
41
41
|
console.group(chalk.white(`🔄 Syncing user: ${email}`));
|
|
42
42
|
if (!user) {
|
|
43
43
|
console.log(chalk.white('⚙️ Creating the user...'));
|
|
44
|
-
user = await userRepository.createUser(
|
|
44
|
+
user = await userRepository.createUser({
|
|
45
45
|
firstName: `${taskName}`,
|
|
46
46
|
lastName: 'exh.tasks',
|
|
47
47
|
email,
|
|
@@ -49,14 +49,14 @@ async function syncFunctionUser(sdk, data) {
|
|
|
49
49
|
phoneNumber: '0000000000',
|
|
50
50
|
language: 'EN',
|
|
51
51
|
});
|
|
52
|
-
await assignRoleToUser(
|
|
53
|
-
const oAuth1Tokens = await createOAuth1Tokens(
|
|
52
|
+
await assignRoleToUser(user.id, role.id);
|
|
53
|
+
const oAuth1Tokens = await createOAuth1Tokens(email, password);
|
|
54
54
|
console.groupEnd();
|
|
55
55
|
console.log(chalk.green('✅ Successfully synced user'));
|
|
56
56
|
console.log('');
|
|
57
57
|
return oAuth1Tokens;
|
|
58
58
|
}
|
|
59
|
-
const currentFunction = await functionRepository.findByName(
|
|
59
|
+
const currentFunction = await functionRepository.findByName(taskName);
|
|
60
60
|
const hasExistingCredentials = (currentFunction?.environmentVariables?.API_HOST?.value &&
|
|
61
61
|
currentFunction?.environmentVariables?.API_OAUTH_TOKEN_SECRET?.value &&
|
|
62
62
|
currentFunction?.environmentVariables?.API_OAUTH_TOKEN?.value &&
|
|
@@ -79,7 +79,7 @@ async function syncFunctionUser(sdk, data) {
|
|
|
79
79
|
console.log(chalk.white('⚙️ Reusing existing user credentials...'));
|
|
80
80
|
const userRole = user.roles?.find(({ name }) => name === roleName);
|
|
81
81
|
if (!userRole) {
|
|
82
|
-
await assignRoleToUser(
|
|
82
|
+
await assignRoleToUser(user.id, role.id);
|
|
83
83
|
}
|
|
84
84
|
console.groupEnd();
|
|
85
85
|
console.log(chalk.green('✅ Successfully synced user'));
|
|
@@ -90,18 +90,18 @@ async function syncFunctionUser(sdk, data) {
|
|
|
90
90
|
};
|
|
91
91
|
}
|
|
92
92
|
exports.syncFunctionUser = syncFunctionUser;
|
|
93
|
-
async function syncRoleWithPermissions(
|
|
93
|
+
async function syncRoleWithPermissions(taskName, roleName, targetPermissions) {
|
|
94
94
|
console.group(chalk.white(`🔄 Syncing role: ${roleName}`));
|
|
95
95
|
if (targetPermissions.length === 0) {
|
|
96
96
|
console.log(chalk.yellow('⚠️ The executionCredentials.permissions field has no permissions defined'));
|
|
97
97
|
}
|
|
98
|
-
let role = await userRepository.findGlobalRoleByName(
|
|
98
|
+
let role = await userRepository.findGlobalRoleByName(roleName);
|
|
99
99
|
if (!role) {
|
|
100
100
|
console.log(chalk.white('⚙️ Creating the role...'));
|
|
101
101
|
const roleDescription = `A role created by the CLI for the execution of the task ${taskName}`;
|
|
102
|
-
role = await userRepository.createGlobalRole(
|
|
102
|
+
role = await userRepository.createGlobalRole(roleName, roleDescription);
|
|
103
103
|
if (targetPermissions.length !== 0) {
|
|
104
|
-
await userRepository.addPermissionsToGlobalRole(
|
|
104
|
+
await userRepository.addPermissionsToGlobalRole(roleName, targetPermissions);
|
|
105
105
|
}
|
|
106
106
|
console.log(chalk.white(`🔐 Permissions added: [${targetPermissions.join(', ')}]`));
|
|
107
107
|
console.groupEnd();
|
|
@@ -114,11 +114,11 @@ async function syncRoleWithPermissions(sdk, taskName, roleName, targetPermission
|
|
|
114
114
|
const permissionsToAdd = targetPermissions.filter(targetPermission => !currentPermissions.includes(targetPermission));
|
|
115
115
|
const permissionsToRemove = currentPermissions.filter(currentPermission => !targetPermissions.includes(currentPermission));
|
|
116
116
|
if (permissionsToAdd.length > 0) {
|
|
117
|
-
await userRepository.addPermissionsToGlobalRole(
|
|
117
|
+
await userRepository.addPermissionsToGlobalRole(roleName, permissionsToAdd);
|
|
118
118
|
console.log(chalk.white(`🔐 Permissions added: [${permissionsToAdd.join(',')}]`));
|
|
119
119
|
}
|
|
120
120
|
if (permissionsToRemove.length > 0) {
|
|
121
|
-
await userRepository.removePermissionsFromGlobalRole(
|
|
121
|
+
await userRepository.removePermissionsFromGlobalRole(roleName, permissionsToRemove);
|
|
122
122
|
console.log(chalk.white(`🔐 Permissions removed: [${permissionsToRemove.join(',')}]`));
|
|
123
123
|
}
|
|
124
124
|
console.groupEnd();
|
|
@@ -126,13 +126,13 @@ async function syncRoleWithPermissions(sdk, taskName, roleName, targetPermission
|
|
|
126
126
|
console.log('');
|
|
127
127
|
return role;
|
|
128
128
|
}
|
|
129
|
-
async function assignRoleToUser(
|
|
129
|
+
async function assignRoleToUser(userId, roleId) {
|
|
130
130
|
console.log(chalk.white('⚙️ Assigning the role to the user...'));
|
|
131
|
-
await userRepository.addGlobalRoleToUser(
|
|
131
|
+
await userRepository.addGlobalRoleToUser(userId, roleId);
|
|
132
132
|
}
|
|
133
|
-
async function createOAuth1Tokens(
|
|
133
|
+
async function createOAuth1Tokens(email, password) {
|
|
134
134
|
console.log(chalk.white('⚙️ Creating credentials...'));
|
|
135
|
-
const response = await authRepository.createOAuth1Tokens(
|
|
135
|
+
const response = await authRepository.createOAuth1Tokens(email, password);
|
|
136
136
|
const { token, tokenSecret } = response;
|
|
137
137
|
return { token, tokenSecret };
|
|
138
138
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/// <reference types="yargs" />
|
|
2
|
-
import { OAuth1Client } from '@extrahorizon/javascript-sdk';
|
|
3
2
|
export declare const command = "delete";
|
|
4
3
|
export declare const desc = "Delete a template";
|
|
5
4
|
export declare const builder: (yargs: any) => import("yargs").Argv<import("yargs").Omit<{}, "id" | "name"> & import("yargs").InferredOptionTypes<{
|
|
@@ -12,8 +11,7 @@ export declare const builder: (yargs: any) => import("yargs").Argv<import("yargs
|
|
|
12
11
|
type: "string";
|
|
13
12
|
};
|
|
14
13
|
}>>;
|
|
15
|
-
export declare const handler: ({
|
|
16
|
-
sdk: OAuth1Client;
|
|
14
|
+
export declare const handler: ({ name, id }: {
|
|
17
15
|
name: string;
|
|
18
16
|
id: string;
|
|
19
17
|
}) => Promise<void>;
|