@contrail/cli 1.0.0 → 1.0.5
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/.vscode/settings.json +5 -5
- package/bin/init +3 -3
- package/lib/{create-app → apps/create-app}/create.d.ts +1 -1
- package/lib/apps/create-app/create.js +59 -0
- package/lib/apps/create-app/setup-template.d.ts +1 -0
- package/lib/apps/create-app/setup-template.js +34 -0
- package/lib/{deploy-app → apps/deploy-app}/actions-deployer.d.ts +10 -10
- package/lib/{deploy-app → apps/deploy-app}/actions-deployer.js +97 -78
- package/lib/apps/deploy-app/app-deployer.d.ts +8 -0
- package/lib/{deploy-app → apps/deploy-app}/app-deployer.js +79 -58
- package/lib/apps/deploy-app/app-template-parsers.d.ts +7 -0
- package/lib/apps/deploy-app/app-template-parsers.js +37 -0
- package/lib/{deploy-app → apps/deploy-app}/deploy.d.ts +2 -2
- package/lib/apps/deploy-app/deploy.js +58 -0
- package/lib/apps/deploy-app/interfaces.d.ts +74 -0
- package/lib/apps/deploy-app/interfaces.js +4 -0
- package/lib/auth/auth.d.ts +9 -0
- package/lib/auth/auth.js +2 -0
- package/lib/auth/login.d.ts +2 -1
- package/lib/auth/login.js +113 -79
- package/lib/cli.d.ts +5 -5
- package/lib/cli.js +36 -30
- package/lib/common.d.ts +1 -0
- package/lib/common.js +5 -0
- package/lib/types/interfaces.d.ts +51 -0
- package/lib/{deploy-app → types}/interfaces.js +0 -0
- package/lib/types/option-set-uploader.d.ts +1 -0
- package/lib/types/option-set-uploader.js +75 -0
- package/lib/types/types-extractor.d.ts +1 -0
- package/lib/types/types-extractor.js +93 -0
- package/lib/types/types-uploader.d.ts +1 -0
- package/lib/types/types-uploader.js +171 -0
- package/package.json +63 -63
- package/publish.sh +5 -0
- package/src/apps/create-app/create.ts +73 -0
- package/src/apps/create-app/setup-template.ts +38 -0
- package/src/{deploy-app → apps/deploy-app}/actions-deployer.ts +122 -87
- package/src/{deploy-app → apps/deploy-app}/app-deployer.ts +86 -63
- package/src/apps/deploy-app/app-template-parsers.ts +43 -0
- package/src/apps/deploy-app/deploy.ts +67 -0
- package/src/apps/deploy-app/interfaces.ts +78 -0
- package/src/auth/auth.ts +10 -0
- package/src/auth/login.ts +127 -89
- package/src/cli.ts +38 -33
- package/src/common.ts +5 -0
- package/src/types/interfaces.ts +54 -0
- package/src/types/option-set-uploader.ts +83 -0
- package/src/types/types-extractor.ts +116 -0
- package/src/types/types-uploader.ts +198 -0
- package/templates/javascript/actions/example/action.js +37 -37
- package/templates/javascript/app.yml +54 -42
- package/templates/javascript/package.json +23 -23
- package/templates/typescript/actions/exampleAction.ts +38 -0
- package/templates/typescript/app.yml +56 -0
- package/templates/typescript/package.json +24 -0
- package/templates/typescript/tsconfig.json +31 -0
- package/tsconfig.json +30 -22
- package/tslint.json +57 -57
- package/lib/create-app/create.js +0 -48
- package/lib/create-app/setup-template.d.ts +0 -1
- package/lib/create-app/setup-template.js +0 -48
- package/lib/deploy-app/actions.d.ts +0 -5
- package/lib/deploy-app/actions.js +0 -17
- package/lib/deploy-app/app-declaration.d.ts +0 -20
- package/lib/deploy-app/app-declaration.js +0 -0
- package/lib/deploy-app/app-deployer.d.ts +0 -9
- package/lib/deploy-app/app.d.ts +0 -8
- package/lib/deploy-app/app.js +0 -56
- package/lib/deploy-app/deploy.js +0 -30
- package/lib/deploy-app/interfaces.d.ts +0 -34
- package/src/create-app/create.ts +0 -58
- package/src/create-app/setup-template.ts +0 -61
- package/src/deploy-app/deploy.ts +0 -34
- package/src/deploy-app/interfaces.ts +0 -35
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/** Describes the derivative JSON / object represented
|
|
2
|
+
* in app.yml file.
|
|
3
|
+
*/
|
|
4
|
+
export interface AppDeclaration {
|
|
5
|
+
appIdentifier: string;
|
|
6
|
+
appName: string;
|
|
7
|
+
appDescription?: string;
|
|
8
|
+
visibility: 'private' | 'public';
|
|
9
|
+
publisher: string;
|
|
10
|
+
version: string;
|
|
11
|
+
eventWorkflowTriggerKeyMapping: string;
|
|
12
|
+
thumbnail?: string;
|
|
13
|
+
keywords?: Array<string>;
|
|
14
|
+
actions?: {
|
|
15
|
+
[key: string]: AppActionDeclaration;
|
|
16
|
+
};
|
|
17
|
+
appConfiguration: ConfigPropertyElements;
|
|
18
|
+
triggers: {
|
|
19
|
+
[key: string]: AppTriggerDeclaration;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export interface ConfigPropertyElements {
|
|
23
|
+
[key: string]: ConfigPropertyElement;
|
|
24
|
+
}
|
|
25
|
+
export interface ConfigPropertyElement {
|
|
26
|
+
propertyType: string;
|
|
27
|
+
options?: any[];
|
|
28
|
+
label: string;
|
|
29
|
+
}
|
|
30
|
+
export interface AppActionDeclaration {
|
|
31
|
+
handler: string;
|
|
32
|
+
name: string;
|
|
33
|
+
description?: string;
|
|
34
|
+
actionConfiguration?: ConfigPropertyElements;
|
|
35
|
+
}
|
|
36
|
+
export interface AppTriggerDeclaration {
|
|
37
|
+
key: string;
|
|
38
|
+
name: string;
|
|
39
|
+
external?: boolean;
|
|
40
|
+
description?: string;
|
|
41
|
+
}
|
|
42
|
+
export interface App {
|
|
43
|
+
id: string;
|
|
44
|
+
identifier: string;
|
|
45
|
+
name: string;
|
|
46
|
+
public: boolean;
|
|
47
|
+
description?: string;
|
|
48
|
+
publisher: string;
|
|
49
|
+
thumbnail: string;
|
|
50
|
+
eventWorkflowTriggerKeyMapping: string;
|
|
51
|
+
configProperties?: ConfigProperty[];
|
|
52
|
+
triggerKeyDefinitions?: TriggerKeyDefinition[];
|
|
53
|
+
}
|
|
54
|
+
export declare class ConfigProperty {
|
|
55
|
+
slug: string;
|
|
56
|
+
propertyType: string;
|
|
57
|
+
options?: any[];
|
|
58
|
+
label: string;
|
|
59
|
+
}
|
|
60
|
+
export interface EventWorkflowActionDefinition {
|
|
61
|
+
id?: string;
|
|
62
|
+
identifier?: string;
|
|
63
|
+
name?: string;
|
|
64
|
+
executeFunctionString?: string;
|
|
65
|
+
ownerKey?: string;
|
|
66
|
+
public?: boolean;
|
|
67
|
+
configProperties?: ConfigProperty[];
|
|
68
|
+
}
|
|
69
|
+
export declare class TriggerKeyDefinition {
|
|
70
|
+
name: string;
|
|
71
|
+
description?: string;
|
|
72
|
+
triggerKey: string;
|
|
73
|
+
external?: boolean;
|
|
74
|
+
}
|
package/lib/auth/auth.js
ADDED
package/lib/auth/login.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { AuthContext } from './auth';
|
|
2
|
+
export declare function authUser(): Promise<AuthContext>;
|
package/lib/auth/login.js
CHANGED
|
@@ -1,79 +1,113 @@
|
|
|
1
|
-
const AmazonCognitoIdentity = require('amazon-cognito-identity-js');
|
|
2
|
-
import inquirer from 'inquirer';
|
|
3
|
-
import { setConfig } from '@contrail/sdk';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
reject(err);
|
|
68
|
-
},
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
async function
|
|
73
|
-
//
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
1
|
+
const AmazonCognitoIdentity = require('amazon-cognito-identity-js');
|
|
2
|
+
import inquirer from 'inquirer';
|
|
3
|
+
import { Request, setConfig } from '@contrail/sdk';
|
|
4
|
+
import { Auth } from './auth';
|
|
5
|
+
const CONFIGURATION = {
|
|
6
|
+
userPoolId: 'us-east-1_x8hXZUsL6',
|
|
7
|
+
clientId: process.env.CONTRAIL_COGNITO_CLIENT_ID || '2oubek96sue5rsncovtqhs3scm',
|
|
8
|
+
};
|
|
9
|
+
export async function authUser() {
|
|
10
|
+
const questions = [];
|
|
11
|
+
if (!process.env.CONTRAIL_CLI_EMAIL) {
|
|
12
|
+
questions.push({
|
|
13
|
+
type: 'input',
|
|
14
|
+
name: 'email',
|
|
15
|
+
validate: (val) => !!val,
|
|
16
|
+
message: 'Email',
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
if (!process.env.CONTRAIL_CLI_PASSWORD) {
|
|
20
|
+
questions.push({
|
|
21
|
+
type: 'password',
|
|
22
|
+
name: 'password',
|
|
23
|
+
validate: (val) => !!val,
|
|
24
|
+
message: 'Password',
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
if (!process.env.CONTRAIL_CLI_ORGSLUG) {
|
|
28
|
+
questions.push({
|
|
29
|
+
type: 'input',
|
|
30
|
+
name: 'orgSlug',
|
|
31
|
+
validate: (val) => !!val,
|
|
32
|
+
message: 'Org (slug)',
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
const answers = await inquirer.prompt(questions);
|
|
36
|
+
const params = {
|
|
37
|
+
email: process.env.CONTRAIL_CLI_EMAIL || answers.email,
|
|
38
|
+
password: process.env.CONTRAIL_CLI_PASSWORD || answers.password,
|
|
39
|
+
orgSlug: process.env.CONTRAIL_CLI_ORGSLUG || answers.orgSlug,
|
|
40
|
+
};
|
|
41
|
+
if (!params.email || !params.password) {
|
|
42
|
+
throw new Error('Email and Password required');
|
|
43
|
+
}
|
|
44
|
+
const poolData = {
|
|
45
|
+
UserPoolId: CONFIGURATION.userPoolId,
|
|
46
|
+
ClientId: CONFIGURATION.clientId,
|
|
47
|
+
};
|
|
48
|
+
const userPool = new AmazonCognitoIdentity.CognitoUserPool(poolData);
|
|
49
|
+
const authData = {
|
|
50
|
+
Username: params.email,
|
|
51
|
+
Password: params.password,
|
|
52
|
+
};
|
|
53
|
+
const authDetails = new AmazonCognitoIdentity.AuthenticationDetails(authData);
|
|
54
|
+
const userData = {
|
|
55
|
+
Username: params.email,
|
|
56
|
+
Pool: userPool,
|
|
57
|
+
};
|
|
58
|
+
const cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData);
|
|
59
|
+
return new Promise((resolve, reject) => {
|
|
60
|
+
cognitoUser.authenticateUser(authDetails, {
|
|
61
|
+
onSuccess: async (result) => {
|
|
62
|
+
const user = result;
|
|
63
|
+
const config = await setAuthContext(user, params);
|
|
64
|
+
resolve(config);
|
|
65
|
+
},
|
|
66
|
+
onFailure: (err) => {
|
|
67
|
+
reject(err);
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
async function setAuthContext(user, params) {
|
|
73
|
+
// TODO Dont allow user to set this - they could set dev
|
|
74
|
+
const questions = [];
|
|
75
|
+
questions.push({
|
|
76
|
+
type: 'list',
|
|
77
|
+
name: 'environment',
|
|
78
|
+
message: 'Which environment would you like to use?',
|
|
79
|
+
choices: ['Dev', 'Prod'],
|
|
80
|
+
default: 'Dev',
|
|
81
|
+
});
|
|
82
|
+
let apiGateway;
|
|
83
|
+
const answers = await inquirer.prompt(questions);
|
|
84
|
+
if (answers.environment === 'Dev') {
|
|
85
|
+
apiGateway = 'https://api.vibeiq.com/dev/api';
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
apiGateway = 'https://api.vibeiq.com/prod/api';
|
|
89
|
+
}
|
|
90
|
+
// Set Auth Config
|
|
91
|
+
Auth.config = {
|
|
92
|
+
apiUserToken: user.idToken.jwtToken,
|
|
93
|
+
apiGateway,
|
|
94
|
+
orgSlug: params.orgSlug,
|
|
95
|
+
};
|
|
96
|
+
// SET SDK CONFIG
|
|
97
|
+
setConfig(Auth.config);
|
|
98
|
+
const currentUser = await Request.request('/users/current', {
|
|
99
|
+
method: 'GET',
|
|
100
|
+
headers: {
|
|
101
|
+
'Accept': 'application/json',
|
|
102
|
+
'Content-Type': 'application/json',
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
if (!currentUser) {
|
|
106
|
+
throw Error('Could not get current user');
|
|
107
|
+
}
|
|
108
|
+
const org = currentUser.orgs.find(o => o.orgSlug === Auth.config.orgSlug);
|
|
109
|
+
if (org) {
|
|
110
|
+
Auth.config.orgId = org.orgId || org.id;
|
|
111
|
+
}
|
|
112
|
+
return Object.assign({}, Auth.config);
|
|
113
|
+
}
|
package/lib/cli.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Built using documentation here:
|
|
3
|
-
* https://www.twilio.com/blog/how-to-build-a-cli-with-node-js
|
|
4
|
-
*/
|
|
5
|
-
export declare function cli(args: any): Promise<void>;
|
|
1
|
+
/**
|
|
2
|
+
* Built using documentation here:
|
|
3
|
+
* https://www.twilio.com/blog/how-to-build-a-cli-with-node-js
|
|
4
|
+
*/
|
|
5
|
+
export declare function cli(args: any): Promise<void>;
|
package/lib/cli.js
CHANGED
|
@@ -1,30 +1,36 @@
|
|
|
1
|
-
import { create } from './create-app/create';
|
|
2
|
-
import { deployApp, removeApp } from './deploy-app/deploy';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
1
|
+
import { create } from './apps/create-app/create';
|
|
2
|
+
import { deployApp, removeApp } from './apps/deploy-app/deploy';
|
|
3
|
+
import { getTypes } from './types/types-extractor';
|
|
4
|
+
import { uploadTypes } from './types/types-uploader';
|
|
5
|
+
/**
|
|
6
|
+
* Built using documentation here:
|
|
7
|
+
* https://www.twilio.com/blog/how-to-build-a-cli-with-node-js
|
|
8
|
+
*/
|
|
9
|
+
export async function cli(args) {
|
|
10
|
+
const command = args[2];
|
|
11
|
+
switch (command) {
|
|
12
|
+
case 'create-app': {
|
|
13
|
+
create(args);
|
|
14
|
+
break;
|
|
15
|
+
}
|
|
16
|
+
case 'deploy-app': {
|
|
17
|
+
deployApp(args);
|
|
18
|
+
break;
|
|
19
|
+
}
|
|
20
|
+
case 'remove-app': {
|
|
21
|
+
removeApp(args);
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
case 'extract-types': {
|
|
25
|
+
getTypes(args);
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
case 'upload-types': {
|
|
29
|
+
uploadTypes(args);
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
default: {
|
|
33
|
+
console.log('Illegal command.');
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
package/lib/common.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getSeparatorByPlatform(): "\\" | "/";
|
package/lib/common.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export interface ReducedType {
|
|
2
|
+
slug: string;
|
|
3
|
+
label: string;
|
|
4
|
+
typePath: string;
|
|
5
|
+
isArchived: boolean;
|
|
6
|
+
typeProperties: ReducedType[];
|
|
7
|
+
}
|
|
8
|
+
export interface ReducedTypeProperties {
|
|
9
|
+
id: string;
|
|
10
|
+
isArchived: boolean;
|
|
11
|
+
propertyType: PropertyType;
|
|
12
|
+
slug: string;
|
|
13
|
+
label: string;
|
|
14
|
+
editable: boolean;
|
|
15
|
+
core: boolean;
|
|
16
|
+
typePropertyOptionSetId: string;
|
|
17
|
+
formula: string;
|
|
18
|
+
referencedTypeRootSlug: string;
|
|
19
|
+
defaultValue: string;
|
|
20
|
+
propertyLevel: string;
|
|
21
|
+
inherited: boolean;
|
|
22
|
+
}
|
|
23
|
+
export interface ReducedOptionSet {
|
|
24
|
+
id: string;
|
|
25
|
+
name: string;
|
|
26
|
+
isArchived: boolean;
|
|
27
|
+
optionSet: any[];
|
|
28
|
+
}
|
|
29
|
+
export declare enum PropertyType {
|
|
30
|
+
Text = "text",
|
|
31
|
+
String = "string",
|
|
32
|
+
Number = "number",
|
|
33
|
+
Date = "date",
|
|
34
|
+
Boolean = "boolean",
|
|
35
|
+
MultiSelect = "multi_select",
|
|
36
|
+
SingleSelect = "choice",
|
|
37
|
+
Url = "url",
|
|
38
|
+
Currency = "currency",
|
|
39
|
+
Percent = "percent",
|
|
40
|
+
Rating = "rating",
|
|
41
|
+
Formula = "formula",
|
|
42
|
+
ObjectReference = "object_reference",
|
|
43
|
+
ObjectReferenceList = "object_ref_list",
|
|
44
|
+
DataGrid = "data_grid",
|
|
45
|
+
CascadingSelect = "cascading_select",
|
|
46
|
+
Sequence = "sequence",
|
|
47
|
+
Constant = "constant",
|
|
48
|
+
Composite = "composite",
|
|
49
|
+
UserList = "userList",
|
|
50
|
+
Image = "image"
|
|
51
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function uploadOptionSets(): Promise<void>;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { Entities } from '@contrail/sdk';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import { getSeparatorByPlatform } from '../common';
|
|
4
|
+
const yaml = require('js-yaml');
|
|
5
|
+
function loadOptionSets() {
|
|
6
|
+
const TARGET_DIR = process.cwd();
|
|
7
|
+
try {
|
|
8
|
+
const separator = getSeparatorByPlatform();
|
|
9
|
+
const doc = yaml.load(fs.readFileSync(TARGET_DIR + separator + 'option_sets.yml', 'utf8'));
|
|
10
|
+
return doc.optionSets;
|
|
11
|
+
}
|
|
12
|
+
catch (e) {
|
|
13
|
+
throw new Error(`ERROR PARSING YAML: ${e}`);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export async function uploadOptionSets() {
|
|
17
|
+
const optionSets = loadOptionSets();
|
|
18
|
+
const currentOptionSets = await new Entities().get({
|
|
19
|
+
entityName: 'type-property-option-set',
|
|
20
|
+
});
|
|
21
|
+
const currentOptionSetsByName = {};
|
|
22
|
+
for (const currentOptionSet of currentOptionSets) {
|
|
23
|
+
currentOptionSetsByName[currentOptionSet.name] = currentOptionSet;
|
|
24
|
+
}
|
|
25
|
+
const newOptionSetsByName = {};
|
|
26
|
+
for (const optionSet of optionSets) {
|
|
27
|
+
newOptionSetsByName[optionSet.name] = optionSet;
|
|
28
|
+
}
|
|
29
|
+
for (const optionSet of optionSets) {
|
|
30
|
+
try {
|
|
31
|
+
const found = currentOptionSetsByName[optionSet.name];
|
|
32
|
+
if (!found) {
|
|
33
|
+
console.log('Creating: ', optionSet.name);
|
|
34
|
+
await new Entities().create({
|
|
35
|
+
entityName: 'type-property-option-set',
|
|
36
|
+
object: {
|
|
37
|
+
name: optionSet.name,
|
|
38
|
+
optionSet: optionSet.optionSet,
|
|
39
|
+
isArchived: optionSet.isArchived,
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
console.log('Updating: ', optionSet.name);
|
|
45
|
+
await new Entities().update({
|
|
46
|
+
entityName: 'type-property-option-set',
|
|
47
|
+
id: found.id,
|
|
48
|
+
object: {
|
|
49
|
+
name: optionSet.name,
|
|
50
|
+
optionSet: optionSet.optionSet,
|
|
51
|
+
isArchived: optionSet.isArchived,
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
throw new Error(`Error Uploading OptionSets: ${err}`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
for (const currentOptionSet of currentOptionSets) {
|
|
61
|
+
try {
|
|
62
|
+
const found = newOptionSetsByName[currentOptionSet.name];
|
|
63
|
+
if (!found) {
|
|
64
|
+
console.log('Deleting: ', currentOptionSet.name);
|
|
65
|
+
await new Entities().delete({
|
|
66
|
+
entityName: 'type-property-option-set',
|
|
67
|
+
id: currentOptionSet.id,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
catch (err) {
|
|
72
|
+
throw new Error(`Error Deleting OptionSets: ${err}`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getTypes(args: any): Promise<void>;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { Entities } from '@contrail/sdk';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import { authUser } from '../auth/login';
|
|
5
|
+
import { getSeparatorByPlatform } from '../common';
|
|
6
|
+
const yaml = require('js-yaml');
|
|
7
|
+
export async function getTypes(args) {
|
|
8
|
+
try {
|
|
9
|
+
const userConfig = await authUser();
|
|
10
|
+
console.log(`%s Getting all types for orgId: ${userConfig.orgId}`, chalk.blue.bold('START'));
|
|
11
|
+
console.log(`%s Retrieving`, chalk.yellow.bold('OPTION SETS'));
|
|
12
|
+
await getOptionSets();
|
|
13
|
+
console.log(`%s Retrieved`, chalk.yellow.bold('OPTION SETS'));
|
|
14
|
+
console.log(`%s Retrieving`, chalk.yellow.bold('TYPES'));
|
|
15
|
+
await getReducedTypes();
|
|
16
|
+
console.log(`%s Retrieved`, chalk.yellow.bold('TYPES'));
|
|
17
|
+
}
|
|
18
|
+
catch (e) {
|
|
19
|
+
console.log(`%s Types Retrieval Failed. ${e}`, chalk.red.bold('FAIL'));
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
console.log('%s Types Retrieval Complete.', chalk.green.bold('COMPLETE'));
|
|
23
|
+
}
|
|
24
|
+
async function getOptionSets() {
|
|
25
|
+
const optionSets = await new Entities().get({
|
|
26
|
+
entityName: 'type-property-option-set',
|
|
27
|
+
});
|
|
28
|
+
const reducedOptionSets = [];
|
|
29
|
+
for (const optionSet of optionSets) {
|
|
30
|
+
const reducedOptionSet = {
|
|
31
|
+
id: optionSet.id,
|
|
32
|
+
name: optionSet.name,
|
|
33
|
+
isArchived: optionSet.isArchived,
|
|
34
|
+
optionSet: optionSet.optionSet,
|
|
35
|
+
};
|
|
36
|
+
reducedOptionSets.push(reducedOptionSet);
|
|
37
|
+
}
|
|
38
|
+
const optionSetsHolder = {
|
|
39
|
+
optionSets: reducedOptionSets,
|
|
40
|
+
};
|
|
41
|
+
const CURRENT_DIR = process.cwd();
|
|
42
|
+
const separator = getSeparatorByPlatform();
|
|
43
|
+
const yamlStr = yaml.dump(optionSetsHolder);
|
|
44
|
+
fs.writeFileSync(CURRENT_DIR + separator + 'option_sets.yml', yamlStr, 'utf8');
|
|
45
|
+
}
|
|
46
|
+
async function getReducedTypes() {
|
|
47
|
+
const types = await new Entities().get({
|
|
48
|
+
entityName: 'type',
|
|
49
|
+
});
|
|
50
|
+
console.log('Found types: ', types.length);
|
|
51
|
+
const reducedTypes = [];
|
|
52
|
+
for (const type of types) {
|
|
53
|
+
const typeWithProperties = await new Entities().get({
|
|
54
|
+
entityName: 'type',
|
|
55
|
+
id: type.id,
|
|
56
|
+
relations: ['typeProperties'],
|
|
57
|
+
});
|
|
58
|
+
const reducedTypeProperties = [];
|
|
59
|
+
for (const typeProperty of typeWithProperties.typeProperties) {
|
|
60
|
+
const reducedTypeProperty = {
|
|
61
|
+
id: typeProperty.id,
|
|
62
|
+
isArchived: typeProperty.isArchived,
|
|
63
|
+
propertyType: typeProperty.propertyType,
|
|
64
|
+
slug: typeProperty.slug,
|
|
65
|
+
label: typeProperty.label,
|
|
66
|
+
editable: typeProperty.editable,
|
|
67
|
+
core: typeProperty.core,
|
|
68
|
+
typePropertyOptionSetId: typeProperty.typePropertyOptionSetId,
|
|
69
|
+
formula: typeProperty.formula,
|
|
70
|
+
referencedTypeRootSlug: typeProperty.referencedTypeRootSlug,
|
|
71
|
+
defaultValue: typeProperty.defaultValue,
|
|
72
|
+
propertyLevel: typeProperty.propertyLevel,
|
|
73
|
+
inherited: typeProperty.inherited,
|
|
74
|
+
};
|
|
75
|
+
reducedTypeProperties.push(reducedTypeProperty);
|
|
76
|
+
}
|
|
77
|
+
const reducedType = {
|
|
78
|
+
slug: typeWithProperties.slug,
|
|
79
|
+
label: typeWithProperties.label,
|
|
80
|
+
typePath: typeWithProperties.typePath,
|
|
81
|
+
isArchived: typeWithProperties.isArchived,
|
|
82
|
+
typeProperties: reducedTypeProperties,
|
|
83
|
+
};
|
|
84
|
+
reducedTypes.push(reducedType);
|
|
85
|
+
}
|
|
86
|
+
const typesHolder = {
|
|
87
|
+
types: reducedTypes,
|
|
88
|
+
};
|
|
89
|
+
const CURRENT_DIR = process.cwd();
|
|
90
|
+
const separator = getSeparatorByPlatform();
|
|
91
|
+
const yamlStr = yaml.dump(typesHolder);
|
|
92
|
+
fs.writeFileSync(CURRENT_DIR + separator + 'types.yml', yamlStr, 'utf8');
|
|
93
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function uploadTypes(args: any): Promise<void>;
|