@contrail/cli 1.0.9 → 1.0.12
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/.eslint.js +54 -0
- package/.eslintrc.js +20 -0
- package/lib/auth/login.js +30 -3
- package/lib/cli.js +4 -0
- package/lib/config/config.d.ts +5 -0
- package/lib/config/config.js +59 -0
- package/lib/types/interfaces.d.ts +4 -1
- package/lib/types/option-set-uploader.js +4 -0
- package/lib/types/types-extractor.js +2 -0
- package/lib/types/types-uploader.js +8 -0
- package/option_sets.yml +15 -0
- package/package.json +1 -1
- package/src/auth/login.ts +36 -7
- package/src/cli.ts +4 -0
- package/src/config/config.ts +65 -0
- package/src/types/interfaces.ts +3 -0
- package/src/types/option-set-uploader.ts +4 -0
- package/src/types/types-extractor.ts +2 -0
- package/src/types/types-uploader.ts +8 -0
- package/templates/typescript/package-lock.json +14 -0
- package/templates/typescript/package.json +4 -2
- package/test/actions/exampleAction.d.ts +1 -0
- package/test/actions/exampleAction.js +40 -0
- package/test/actions/exampleAction.ts +39 -0
- package/test/app.yml +46 -0
- package/test/option_sets.yml +15 -0
- package/test/package-lock.json +57 -0
- package/test/package.json +26 -0
- package/test/tsconfig.json +31 -0
- package/test/types.yml +1621 -0
- package/types.yml +1621 -0
package/.eslint.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
env: {
|
|
3
|
+
browser: true,
|
|
4
|
+
es2021: true,
|
|
5
|
+
node: true
|
|
6
|
+
|
|
7
|
+
},
|
|
8
|
+
extends: [
|
|
9
|
+
'eslint:recommended',
|
|
10
|
+
'plugin:@typescript-eslint/eslint-recommended',
|
|
11
|
+
'plugin:@typescript-eslint/recommended'
|
|
12
|
+
],
|
|
13
|
+
parser: '@typescript-eslint/parser',
|
|
14
|
+
parserOptions: {
|
|
15
|
+
ecmaVersion: 'latest',
|
|
16
|
+
sourceType: 'module'
|
|
17
|
+
},
|
|
18
|
+
plugins: [
|
|
19
|
+
'@typescript-eslint',
|
|
20
|
+
'unused-imports'
|
|
21
|
+
],
|
|
22
|
+
rules: {
|
|
23
|
+
indent: [
|
|
24
|
+
'error',
|
|
25
|
+
2
|
|
26
|
+
],
|
|
27
|
+
'linebreak-style': [
|
|
28
|
+
'error',
|
|
29
|
+
'unix'
|
|
30
|
+
],
|
|
31
|
+
'quote-props': ['error', 'as-needed'],
|
|
32
|
+
quotes: [
|
|
33
|
+
'error',
|
|
34
|
+
'single'
|
|
35
|
+
],
|
|
36
|
+
semi: [
|
|
37
|
+
'error',
|
|
38
|
+
'always'
|
|
39
|
+
],
|
|
40
|
+
'no-multiple-empty-lines': ['error', { max: 1, maxEOF: 0 }],
|
|
41
|
+
'no-trailing-spaces': 'error',
|
|
42
|
+
'no-mixed-spaces-and-tabs': ['error', 'smart-tabs'],
|
|
43
|
+
'@typescript-eslint/no-empty-function': ['error', { allow: ['arrowFunctions'] }],
|
|
44
|
+
'@typescript-eslint/no-explicit-any': 'off',
|
|
45
|
+
'@typescript-eslint/no-var-requires': 'warn',
|
|
46
|
+
'no-unused-vars': 'off',
|
|
47
|
+
'unused-imports/no-unused-imports': 'error',
|
|
48
|
+
'unused-imports/no-unused-vars': [
|
|
49
|
+
'warn',
|
|
50
|
+
{ vars: 'all', varsIgnorePattern: '^_', args: 'after-used', argsIgnorePattern: '^_' }
|
|
51
|
+
]
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
"env": {
|
|
3
|
+
"browser": true,
|
|
4
|
+
"es2021": true
|
|
5
|
+
},
|
|
6
|
+
"extends": [
|
|
7
|
+
"eslint:recommended",
|
|
8
|
+
"plugin:@typescript-eslint/recommended"
|
|
9
|
+
],
|
|
10
|
+
"parser": "@typescript-eslint/parser",
|
|
11
|
+
"parserOptions": {
|
|
12
|
+
"ecmaVersion": "latest",
|
|
13
|
+
"sourceType": "module"
|
|
14
|
+
},
|
|
15
|
+
"plugins": [
|
|
16
|
+
"@typescript-eslint"
|
|
17
|
+
],
|
|
18
|
+
"rules": {
|
|
19
|
+
}
|
|
20
|
+
}
|
package/lib/auth/login.js
CHANGED
|
@@ -1,12 +1,33 @@
|
|
|
1
1
|
const AmazonCognitoIdentity = require('amazon-cognito-identity-js');
|
|
2
2
|
import inquirer from 'inquirer';
|
|
3
|
-
import { Request, setConfig } from '@contrail/sdk';
|
|
3
|
+
import { Request, setConfig as setSdkConfig } from '@contrail/sdk';
|
|
4
4
|
import { Auth } from './auth';
|
|
5
|
+
import { getConfig, storeConfig } from '../config/config';
|
|
5
6
|
const CONFIGURATION = {
|
|
6
7
|
userPoolId: 'us-east-1_x8hXZUsL6',
|
|
7
8
|
clientId: process.env.CONTRAIL_COGNITO_CLIENT_ID || '2oubek96sue5rsncovtqhs3scm',
|
|
8
9
|
};
|
|
9
10
|
export async function authUser() {
|
|
11
|
+
console.debug("authorizing user");
|
|
12
|
+
const config = await getConfig();
|
|
13
|
+
if (config &&
|
|
14
|
+
config.apiUserToken &&
|
|
15
|
+
config.apiGateway &&
|
|
16
|
+
config.orgSlug) {
|
|
17
|
+
console.debug("populating auth config from fs config");
|
|
18
|
+
Auth.config = {
|
|
19
|
+
apiUserToken: config.apiUserToken,
|
|
20
|
+
apiGateway: config.apiGateway,
|
|
21
|
+
orgSlug: config.orgSlug,
|
|
22
|
+
};
|
|
23
|
+
setSdkConfig(Auth.config);
|
|
24
|
+
try {
|
|
25
|
+
return await refreshCurrentUserOrg();
|
|
26
|
+
}
|
|
27
|
+
catch (e) {
|
|
28
|
+
console.log("Token expired. Requesting auth credentials...");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
10
31
|
const questions = [];
|
|
11
32
|
if (!process.env.CONTRAIL_CLI_EMAIL) {
|
|
12
33
|
questions.push({
|
|
@@ -85,7 +106,7 @@ async function setAuthContext(user, params) {
|
|
|
85
106
|
apiGateway = 'https://api.vibeiq.com/dev/api';
|
|
86
107
|
}
|
|
87
108
|
else {
|
|
88
|
-
apiGateway = 'https://api.vibeiq.com/
|
|
109
|
+
apiGateway = 'https://api.dev.vibeiq.com/dev/api';
|
|
89
110
|
}
|
|
90
111
|
// Set Auth Config
|
|
91
112
|
Auth.config = {
|
|
@@ -94,7 +115,11 @@ async function setAuthContext(user, params) {
|
|
|
94
115
|
orgSlug: params.orgSlug,
|
|
95
116
|
};
|
|
96
117
|
// SET SDK CONFIG
|
|
97
|
-
|
|
118
|
+
setSdkConfig(Auth.config);
|
|
119
|
+
return refreshCurrentUserOrg();
|
|
120
|
+
}
|
|
121
|
+
async function refreshCurrentUserOrg() {
|
|
122
|
+
console.debug("refreshing current user org");
|
|
98
123
|
const currentUser = await Request.request('/users/current', {
|
|
99
124
|
method: 'GET',
|
|
100
125
|
headers: {
|
|
@@ -109,5 +134,7 @@ async function setAuthContext(user, params) {
|
|
|
109
134
|
if (org) {
|
|
110
135
|
Auth.config.orgId = org.orgId || org.id;
|
|
111
136
|
}
|
|
137
|
+
// cache config in the fs
|
|
138
|
+
storeConfig(Object.assign({}, Auth.config));
|
|
112
139
|
return Object.assign({}, Auth.config);
|
|
113
140
|
}
|
package/lib/cli.js
CHANGED
|
@@ -12,6 +12,10 @@ export async function cli(args) {
|
|
|
12
12
|
const fullCommand = args[2];
|
|
13
13
|
let domain;
|
|
14
14
|
let command;
|
|
15
|
+
if (!fullCommand) {
|
|
16
|
+
printIllegalCommand();
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
15
19
|
const commandParts = fullCommand.split('.');
|
|
16
20
|
if (!(commandParts === null || commandParts === void 0 ? void 0 : commandParts.length)) {
|
|
17
21
|
printIllegalCommand();
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function initializeVibeIQConfig(): Promise<void>;
|
|
2
|
+
export declare function readVibeIQConfig(): Promise<any>;
|
|
3
|
+
export declare function writeVibeIQConfig(config: Object): Promise<void>;
|
|
4
|
+
export declare function getConfig(): Promise<any>;
|
|
5
|
+
export declare function storeConfig(incomingConfig: Object): Promise<void>;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { promises as fsPromises } from 'fs';
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
import { homedir } from 'os';
|
|
4
|
+
const userHomeDir = homedir();
|
|
5
|
+
const configDirectoryLocation = join(userHomeDir, '.vibeiq');
|
|
6
|
+
const configFileLocation = join(configDirectoryLocation, 'config.json');
|
|
7
|
+
export async function initializeVibeIQConfig() {
|
|
8
|
+
try {
|
|
9
|
+
await fsPromises.mkdir(configDirectoryLocation, { recursive: true });
|
|
10
|
+
}
|
|
11
|
+
catch (e) {
|
|
12
|
+
console.error("could not initialize vibeiq directory");
|
|
13
|
+
throw e;
|
|
14
|
+
}
|
|
15
|
+
try {
|
|
16
|
+
await fsPromises.writeFile(configFileLocation, '{}');
|
|
17
|
+
}
|
|
18
|
+
catch (e) {
|
|
19
|
+
console.error(`could not initialize config file (${configFileLocation}).`);
|
|
20
|
+
throw e;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export async function readVibeIQConfig() {
|
|
24
|
+
let fileContent;
|
|
25
|
+
try {
|
|
26
|
+
fileContent = await fsPromises.readFile(configFileLocation);
|
|
27
|
+
}
|
|
28
|
+
catch (e) {
|
|
29
|
+
console.debug(`failed to open config file (${configFileLocation}) for reading.`);
|
|
30
|
+
console.debug('trying to initialize config file');
|
|
31
|
+
await initializeVibeIQConfig();
|
|
32
|
+
console.error(`Could not open config file (${configFileLocation}) for reading.`);
|
|
33
|
+
throw e;
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
return JSON.parse(fileContent);
|
|
37
|
+
}
|
|
38
|
+
catch (e) {
|
|
39
|
+
console.error(`Could not parse local vibeiq config. The file (${configFileLocation}) might be malformed`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export async function writeVibeIQConfig(config) {
|
|
43
|
+
try {
|
|
44
|
+
await fsPromises.writeFile(configFileLocation, JSON.stringify(config, null, 2));
|
|
45
|
+
}
|
|
46
|
+
catch (e) {
|
|
47
|
+
console.error(`Could not open config file (${configFileLocation}) for writing.`);
|
|
48
|
+
throw e;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
export async function getConfig() {
|
|
52
|
+
console.debug("getting config from file system");
|
|
53
|
+
return await readVibeIQConfig();
|
|
54
|
+
}
|
|
55
|
+
export async function storeConfig(incomingConfig) {
|
|
56
|
+
const config = await readVibeIQConfig();
|
|
57
|
+
const newConfig = Object.assign(Object.assign({}, config), incomingConfig);
|
|
58
|
+
await writeVibeIQConfig(newConfig);
|
|
59
|
+
}
|
|
@@ -19,6 +19,8 @@ export interface ReducedTypeProperties {
|
|
|
19
19
|
defaultValue: string;
|
|
20
20
|
propertyLevel: string;
|
|
21
21
|
inherited: boolean;
|
|
22
|
+
formulaFunction?: string;
|
|
23
|
+
validationFunction?: string;
|
|
22
24
|
}
|
|
23
25
|
export interface ReducedOptionSet {
|
|
24
26
|
name: string;
|
|
@@ -46,5 +48,6 @@ export declare enum PropertyType {
|
|
|
46
48
|
Constant = "constant",
|
|
47
49
|
Composite = "composite",
|
|
48
50
|
UserList = "userList",
|
|
49
|
-
Image = "image"
|
|
51
|
+
Image = "image",
|
|
52
|
+
Json = "json"
|
|
50
53
|
}
|
|
@@ -30,6 +30,10 @@ export async function uploadOptionSets() {
|
|
|
30
30
|
try {
|
|
31
31
|
const found = currentOptionSetsByName[optionSet.name];
|
|
32
32
|
if (!found) {
|
|
33
|
+
if (!optionSet.optionSet) {
|
|
34
|
+
console.log('No OptionSet for: ', optionSet.name);
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
33
37
|
console.log('Creating: ', optionSet.name);
|
|
34
38
|
await new Entities().create({
|
|
35
39
|
entityName: 'type-property-option-set',
|
|
@@ -75,6 +75,8 @@ async function getReducedTypes(optionSets) {
|
|
|
75
75
|
defaultValue: typeProperty.defaultValue,
|
|
76
76
|
propertyLevel: typeProperty.propertyLevel,
|
|
77
77
|
inherited: typeProperty.inherited,
|
|
78
|
+
formulaFunction: typeProperty.formulaFunction,
|
|
79
|
+
validationFunction: typeProperty.validationFunction,
|
|
78
80
|
};
|
|
79
81
|
reducedTypeProperties.push(reducedTypeProperty);
|
|
80
82
|
}
|
|
@@ -146,6 +146,8 @@ async function uploadReducedTypeProperties(type, currentPropertyTypes, newProper
|
|
|
146
146
|
referencedTypeRootSlug: newPropertyType.referencedTypeRootSlug,
|
|
147
147
|
defaultValue: newPropertyType.defaultValue,
|
|
148
148
|
propertyLevel: newPropertyType.propertyLevel,
|
|
149
|
+
formulaFunction: newPropertyType.formulaFunction,
|
|
150
|
+
validationFunction: newPropertyType.validationFunction,
|
|
149
151
|
}),
|
|
150
152
|
headers: {
|
|
151
153
|
'Accept': 'application/json',
|
|
@@ -170,6 +172,8 @@ async function uploadReducedTypeProperties(type, currentPropertyTypes, newProper
|
|
|
170
172
|
referencedTypeRootSlug: newPropertyType.referencedTypeRootSlug,
|
|
171
173
|
defaultValue: newPropertyType.defaultValue,
|
|
172
174
|
propertyLevel: newPropertyType.propertyLevel,
|
|
175
|
+
formulaFunction: newPropertyType.formulaFunction,
|
|
176
|
+
validationFunction: newPropertyType.validationFunction,
|
|
173
177
|
},
|
|
174
178
|
});
|
|
175
179
|
}
|
|
@@ -210,6 +214,8 @@ function typePropertiesEqual(typeProperty1, typeProperty2, optionSetIdByName) {
|
|
|
210
214
|
referencedTypeRootSlug: typeProperty1.referencedTypeRootSlug,
|
|
211
215
|
defaultValue: typeProperty1.defaultValue,
|
|
212
216
|
propertyLevel: typeProperty1.propertyLevel,
|
|
217
|
+
formulaFunction: typeProperty1.formulaFunction,
|
|
218
|
+
validationFunction: typeProperty1.validationFunction,
|
|
213
219
|
};
|
|
214
220
|
const reducedProperty2 = {
|
|
215
221
|
isArchived: typeProperty2.isArchived,
|
|
@@ -223,6 +229,8 @@ function typePropertiesEqual(typeProperty1, typeProperty2, optionSetIdByName) {
|
|
|
223
229
|
referencedTypeRootSlug: typeProperty2.referencedTypeRootSlug,
|
|
224
230
|
defaultValue: typeProperty2.defaultValue,
|
|
225
231
|
propertyLevel: typeProperty2.propertyLevel,
|
|
232
|
+
formulaFunction: typeProperty2.formulaFunction,
|
|
233
|
+
validationFunction: typeProperty2.validationFunction,
|
|
226
234
|
};
|
|
227
235
|
return _.isEqual(reducedProperty1, reducedProperty2);
|
|
228
236
|
}
|
package/option_sets.yml
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
optionSets:
|
|
2
|
+
- name: Collection
|
|
3
|
+
isArchived: false
|
|
4
|
+
optionSet:
|
|
5
|
+
- value: collection_1
|
|
6
|
+
display: Collection 1
|
|
7
|
+
- value: collection_2
|
|
8
|
+
display: Collection 2
|
|
9
|
+
- name: Gender
|
|
10
|
+
isArchived: false
|
|
11
|
+
optionSet:
|
|
12
|
+
- value: womens
|
|
13
|
+
display: Women's
|
|
14
|
+
- value: mens
|
|
15
|
+
display: Men's
|
package/package.json
CHANGED
package/src/auth/login.ts
CHANGED
|
@@ -1,14 +1,37 @@
|
|
|
1
1
|
const AmazonCognitoIdentity = require('amazon-cognito-identity-js');
|
|
2
2
|
import inquirer from 'inquirer';
|
|
3
|
-
import { Request, setConfig } from '@contrail/sdk';
|
|
3
|
+
import { Request, setConfig as setSdkConfig } from '@contrail/sdk';
|
|
4
4
|
import { Auth, AuthContext } from './auth';
|
|
5
|
+
import { getConfig, storeConfig } from '../config/config';
|
|
5
6
|
|
|
6
7
|
const CONFIGURATION = {
|
|
7
8
|
userPoolId: 'us-east-1_x8hXZUsL6',
|
|
8
9
|
clientId: process.env.CONTRAIL_COGNITO_CLIENT_ID || '2oubek96sue5rsncovtqhs3scm',
|
|
9
10
|
};
|
|
10
11
|
|
|
11
|
-
export async function authUser(): Promise<AuthContext>{
|
|
12
|
+
export async function authUser(): Promise<AuthContext> {
|
|
13
|
+
console.debug("authorizing user")
|
|
14
|
+
const config = await getConfig();
|
|
15
|
+
if (
|
|
16
|
+
config &&
|
|
17
|
+
config.apiUserToken &&
|
|
18
|
+
config.apiGateway &&
|
|
19
|
+
config.orgSlug
|
|
20
|
+
) {
|
|
21
|
+
console.debug("populating auth config from fs config")
|
|
22
|
+
Auth.config = {
|
|
23
|
+
apiUserToken: config.apiUserToken,
|
|
24
|
+
apiGateway: config.apiGateway,
|
|
25
|
+
orgSlug: config.orgSlug,
|
|
26
|
+
};
|
|
27
|
+
setSdkConfig(Auth.config);
|
|
28
|
+
try {
|
|
29
|
+
return await refreshCurrentUserOrg();
|
|
30
|
+
} catch (e) {
|
|
31
|
+
console.log("Token expired. Requesting auth credentials...")
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
}
|
|
12
35
|
const questions = [];
|
|
13
36
|
if (!process.env.CONTRAIL_CLI_EMAIL) {
|
|
14
37
|
questions.push({
|
|
@@ -41,7 +64,7 @@ export async function authUser(): Promise<AuthContext>{
|
|
|
41
64
|
password: process.env.CONTRAIL_CLI_PASSWORD || answers.password,
|
|
42
65
|
orgSlug: process.env.CONTRAIL_CLI_ORGSLUG || answers.orgSlug,
|
|
43
66
|
};
|
|
44
|
-
if (!params.email || !params.password){
|
|
67
|
+
if (!params.email || !params.password) {
|
|
45
68
|
throw new Error('Email and Password required');
|
|
46
69
|
}
|
|
47
70
|
|
|
@@ -64,7 +87,7 @@ export async function authUser(): Promise<AuthContext>{
|
|
|
64
87
|
|
|
65
88
|
const cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData);
|
|
66
89
|
|
|
67
|
-
return new Promise(
|
|
90
|
+
return new Promise((resolve, reject) => {
|
|
68
91
|
cognitoUser.authenticateUser(authDetails, {
|
|
69
92
|
onSuccess: async (result) => {
|
|
70
93
|
const user = result;
|
|
@@ -96,7 +119,7 @@ async function setAuthContext(user, params): Promise<AuthContext> {
|
|
|
96
119
|
if (answers.environment === 'Dev') {
|
|
97
120
|
apiGateway = 'https://api.vibeiq.com/dev/api';
|
|
98
121
|
} else {
|
|
99
|
-
apiGateway = 'https://api.vibeiq.com/
|
|
122
|
+
apiGateway = 'https://api.dev.vibeiq.com/dev/api';
|
|
100
123
|
}
|
|
101
124
|
|
|
102
125
|
// Set Auth Config
|
|
@@ -106,8 +129,13 @@ async function setAuthContext(user, params): Promise<AuthContext> {
|
|
|
106
129
|
orgSlug: params.orgSlug,
|
|
107
130
|
};
|
|
108
131
|
// SET SDK CONFIG
|
|
109
|
-
|
|
132
|
+
setSdkConfig(Auth.config);
|
|
110
133
|
|
|
134
|
+
return refreshCurrentUserOrg();
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
async function refreshCurrentUserOrg() {
|
|
138
|
+
console.debug("refreshing current user org")
|
|
111
139
|
const currentUser = await Request.request('/users/current', {
|
|
112
140
|
method: 'GET',
|
|
113
141
|
headers: {
|
|
@@ -122,6 +150,7 @@ async function setAuthContext(user, params): Promise<AuthContext> {
|
|
|
122
150
|
if (org) {
|
|
123
151
|
Auth.config.orgId = org.orgId || org.id;
|
|
124
152
|
}
|
|
125
|
-
|
|
153
|
+
// cache config in the fs
|
|
154
|
+
storeConfig(Object.assign({}, Auth.config))
|
|
126
155
|
return Object.assign({}, Auth.config);
|
|
127
156
|
}
|
package/src/cli.ts
CHANGED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { readFileSync, access, promises as fsPromises, write } from 'fs';
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
import {homedir} from 'os';
|
|
4
|
+
const userHomeDir = homedir();
|
|
5
|
+
const configDirectoryLocation = join(userHomeDir, '.vibeiq');
|
|
6
|
+
const configFileLocation = join(configDirectoryLocation, 'config.json');
|
|
7
|
+
|
|
8
|
+
export async function initializeVibeIQConfig() {
|
|
9
|
+
try{
|
|
10
|
+
await fsPromises.mkdir(configDirectoryLocation, {recursive: true})
|
|
11
|
+
} catch (e) {
|
|
12
|
+
console.error("could not initialize vibeiq directory")
|
|
13
|
+
throw e
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
try {
|
|
17
|
+
await fsPromises.writeFile(configFileLocation, '{}');
|
|
18
|
+
} catch (e) {
|
|
19
|
+
console.error(`could not initialize config file (${configFileLocation}).`)
|
|
20
|
+
throw e;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export async function readVibeIQConfig() {
|
|
24
|
+
let fileContent;
|
|
25
|
+
try {
|
|
26
|
+
fileContent = await fsPromises.readFile(configFileLocation);
|
|
27
|
+
} catch (e) {
|
|
28
|
+
console.debug(`failed to open config file (${configFileLocation}) for reading.`);
|
|
29
|
+
console.debug('trying to initialize config file');
|
|
30
|
+
await initializeVibeIQConfig();
|
|
31
|
+
console.error(`Could not open config file (${configFileLocation}) for reading.`);
|
|
32
|
+
throw e
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
try {
|
|
36
|
+
return JSON.parse(fileContent);
|
|
37
|
+
} catch (e) {
|
|
38
|
+
console.error(`Could not parse local vibeiq config. The file (${configFileLocation}) might be malformed`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
export async function writeVibeIQConfig(config: Object) {
|
|
44
|
+
try {
|
|
45
|
+
await fsPromises.writeFile(configFileLocation, JSON.stringify(config, null, 2));
|
|
46
|
+
} catch (e) {
|
|
47
|
+
console.error(`Could not open config file (${configFileLocation}) for writing.`);
|
|
48
|
+
throw e
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export async function getConfig() {
|
|
53
|
+
console.debug("getting config from file system")
|
|
54
|
+
return await readVibeIQConfig();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export async function storeConfig(incomingConfig: Object) {
|
|
58
|
+
const config = await readVibeIQConfig();
|
|
59
|
+
const newConfig = {
|
|
60
|
+
...config,
|
|
61
|
+
...incomingConfig
|
|
62
|
+
};
|
|
63
|
+
await writeVibeIQConfig(newConfig);
|
|
64
|
+
}
|
|
65
|
+
|
package/src/types/interfaces.ts
CHANGED
|
@@ -20,6 +20,8 @@ export interface ReducedTypeProperties {
|
|
|
20
20
|
defaultValue: string;
|
|
21
21
|
propertyLevel: string;
|
|
22
22
|
inherited: boolean;
|
|
23
|
+
formulaFunction?: string;
|
|
24
|
+
validationFunction?: string;
|
|
23
25
|
}
|
|
24
26
|
|
|
25
27
|
export interface ReducedOptionSet {
|
|
@@ -50,4 +52,5 @@ export declare enum PropertyType {
|
|
|
50
52
|
Composite = 'composite',
|
|
51
53
|
UserList = 'userList',
|
|
52
54
|
Image = 'image',
|
|
55
|
+
Json = 'json',
|
|
53
56
|
}
|
|
@@ -37,6 +37,10 @@ export async function uploadOptionSets() {
|
|
|
37
37
|
try {
|
|
38
38
|
const found = currentOptionSetsByName[optionSet.name];
|
|
39
39
|
if (!found) {
|
|
40
|
+
if (!optionSet.optionSet) {
|
|
41
|
+
console.log('No OptionSet for: ', optionSet.name);
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
40
44
|
console.log('Creating: ', optionSet.name);
|
|
41
45
|
await new Entities().create({
|
|
42
46
|
entityName: 'type-property-option-set',
|
|
@@ -95,6 +95,8 @@ async function getReducedTypes(optionSets) {
|
|
|
95
95
|
defaultValue: typeProperty.defaultValue,
|
|
96
96
|
propertyLevel: typeProperty.propertyLevel,
|
|
97
97
|
inherited: typeProperty.inherited,
|
|
98
|
+
formulaFunction: typeProperty.formulaFunction,
|
|
99
|
+
validationFunction: typeProperty.validationFunction,
|
|
98
100
|
};
|
|
99
101
|
|
|
100
102
|
reducedTypeProperties.push(reducedTypeProperty);
|
|
@@ -173,6 +173,8 @@ async function uploadReducedTypeProperties(type, currentPropertyTypes, newProper
|
|
|
173
173
|
referencedTypeRootSlug: newPropertyType.referencedTypeRootSlug,
|
|
174
174
|
defaultValue: newPropertyType.defaultValue,
|
|
175
175
|
propertyLevel: newPropertyType.propertyLevel,
|
|
176
|
+
formulaFunction: newPropertyType.formulaFunction,
|
|
177
|
+
validationFunction: newPropertyType.validationFunction,
|
|
176
178
|
}),
|
|
177
179
|
headers: {
|
|
178
180
|
'Accept': 'application/json',
|
|
@@ -197,6 +199,8 @@ async function uploadReducedTypeProperties(type, currentPropertyTypes, newProper
|
|
|
197
199
|
referencedTypeRootSlug: newPropertyType.referencedTypeRootSlug,
|
|
198
200
|
defaultValue: newPropertyType.defaultValue,
|
|
199
201
|
propertyLevel: newPropertyType.propertyLevel,
|
|
202
|
+
formulaFunction: newPropertyType.formulaFunction,
|
|
203
|
+
validationFunction: newPropertyType.validationFunction,
|
|
200
204
|
},
|
|
201
205
|
});
|
|
202
206
|
}
|
|
@@ -241,6 +245,8 @@ function typePropertiesEqual(typeProperty1, typeProperty2, optionSetIdByName): b
|
|
|
241
245
|
referencedTypeRootSlug: typeProperty1.referencedTypeRootSlug,
|
|
242
246
|
defaultValue: typeProperty1.defaultValue,
|
|
243
247
|
propertyLevel: typeProperty1.propertyLevel,
|
|
248
|
+
formulaFunction: typeProperty1.formulaFunction,
|
|
249
|
+
validationFunction: typeProperty1.validationFunction,
|
|
244
250
|
};
|
|
245
251
|
|
|
246
252
|
const reducedProperty2 = {
|
|
@@ -255,6 +261,8 @@ function typePropertiesEqual(typeProperty1, typeProperty2, optionSetIdByName): b
|
|
|
255
261
|
referencedTypeRootSlug: typeProperty2.referencedTypeRootSlug,
|
|
256
262
|
defaultValue: typeProperty2.defaultValue,
|
|
257
263
|
propertyLevel: typeProperty2.propertyLevel,
|
|
264
|
+
formulaFunction: typeProperty2.formulaFunction,
|
|
265
|
+
validationFunction: typeProperty2.validationFunction,
|
|
258
266
|
};
|
|
259
267
|
|
|
260
268
|
return _.isEqual(reducedProperty1, reducedProperty2);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "test-app",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"lockfileVersion": 1,
|
|
5
|
+
"requires": true,
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"typescript": {
|
|
8
|
+
"version": "4.7.4",
|
|
9
|
+
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.7.4.tgz",
|
|
10
|
+
"integrity": "sha512-C0WQT0gezHuw6AdY1M2jxUO83Rjf0HP7Sk1DtXj6j1EwkQNZrHAg2XPWlq62oqEhYvONq5pkC2Y9oPljWToLmQ==",
|
|
11
|
+
"dev": true
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -14,11 +14,13 @@
|
|
|
14
14
|
"build": "tsc",
|
|
15
15
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
16
16
|
},
|
|
17
|
-
"keywords": [
|
|
18
|
-
],
|
|
17
|
+
"keywords": [],
|
|
19
18
|
"author": "",
|
|
20
19
|
"license": "ISC",
|
|
21
20
|
"dependencies": {
|
|
22
21
|
"chalk": "^4.0.0"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"typescript": "^4.7.4"
|
|
23
25
|
}
|
|
24
26
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
async function execute(config, event, Functions) {
|
|
4
|
+
const getBodyFromEvent = (config, event) => {
|
|
5
|
+
let body = Functions.stringUtil.parseVariables(config.message, event);
|
|
6
|
+
console.log('body: ', body);
|
|
7
|
+
if (config.sendDetails) {
|
|
8
|
+
const data = event;
|
|
9
|
+
const properties = {};
|
|
10
|
+
let addedProperty = false;
|
|
11
|
+
for (const property of config.fieldsToForward) {
|
|
12
|
+
const variableLevels = property.split('.');
|
|
13
|
+
let replacementValue = data;
|
|
14
|
+
for (let i = 0; i < variableLevels.length; i++) {
|
|
15
|
+
replacementValue = replacementValue[variableLevels[i]];
|
|
16
|
+
}
|
|
17
|
+
properties[property] = replacementValue;
|
|
18
|
+
addedProperty = true;
|
|
19
|
+
}
|
|
20
|
+
if (addedProperty) {
|
|
21
|
+
body = body + ' Properties: ' + JSON.stringify(properties) + '.';
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return JSON.stringify({ text: body });
|
|
25
|
+
};
|
|
26
|
+
const body = getBodyFromEvent(config, event);
|
|
27
|
+
console.log('Sending message: ', body);
|
|
28
|
+
const response = await Functions.fetch(config.url, {
|
|
29
|
+
method: 'POST',
|
|
30
|
+
body: body,
|
|
31
|
+
headers: { 'Content-Type': 'application/json' }
|
|
32
|
+
});
|
|
33
|
+
if (!response.ok) {
|
|
34
|
+
console.log('Webhook event failed to publish');
|
|
35
|
+
console.log('Response: ', JSON.stringify(response));
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
console.log('Published!');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export { } // Leave empty export - This allows for multiple files with a function named execute.
|
|
2
|
+
async function execute(config, event, Functions) {
|
|
3
|
+
const getBodyFromEvent = (config, event) => {
|
|
4
|
+
let body = Functions.stringUtil.parseVariables(config.message, event);
|
|
5
|
+
console.log('body: ', body);
|
|
6
|
+
if (config.sendDetails) {
|
|
7
|
+
const data = event;
|
|
8
|
+
const properties = {};
|
|
9
|
+
let addedProperty = false;
|
|
10
|
+
for (const property of config.fieldsToForward) {
|
|
11
|
+
const variableLevels = property.split('.');
|
|
12
|
+
let replacementValue = data;
|
|
13
|
+
for (let i = 0; i < variableLevels.length; i++) {
|
|
14
|
+
replacementValue = replacementValue[variableLevels[i]];
|
|
15
|
+
}
|
|
16
|
+
properties[property] = replacementValue;
|
|
17
|
+
addedProperty = true;
|
|
18
|
+
}
|
|
19
|
+
if (addedProperty) {
|
|
20
|
+
body = body + ' Properties: ' + JSON.stringify(properties) + '.';
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return JSON.stringify({ text: body });
|
|
24
|
+
};
|
|
25
|
+
const body = getBodyFromEvent(config, event);
|
|
26
|
+
console.log('Sending message: ', body);
|
|
27
|
+
const response = await Functions.fetch(config.url, {
|
|
28
|
+
method: 'POST',
|
|
29
|
+
body: body,
|
|
30
|
+
headers: { 'Content-Type': 'application/json' }
|
|
31
|
+
});
|
|
32
|
+
if (!response.ok) {
|
|
33
|
+
console.log('Webhook event failed to publish');
|
|
34
|
+
console.log('Response: ', JSON.stringify(response));
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
console.log('Published!');
|
|
38
|
+
}
|
|
39
|
+
}
|