@contrail/cli 1.0.10 → 1.0.14
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 +42 -14
- 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/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 +48 -20
- package/src/cli.ts +4 -0
- package/src/config/config.ts +65 -0
- package/src/types/interfaces.ts +3 -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({
|
|
@@ -70,19 +91,20 @@ export async function authUser() {
|
|
|
70
91
|
});
|
|
71
92
|
}
|
|
72
93
|
async function setAuthContext(user, params) {
|
|
73
|
-
|
|
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
|
-
});
|
|
94
|
+
const config = await getConfig();
|
|
82
95
|
let apiGateway;
|
|
83
|
-
|
|
84
|
-
if (
|
|
85
|
-
|
|
96
|
+
console.log(config.environments);
|
|
97
|
+
if (config.environments) {
|
|
98
|
+
const questions = [];
|
|
99
|
+
questions.push({
|
|
100
|
+
type: 'list',
|
|
101
|
+
name: 'environment',
|
|
102
|
+
message: 'Which environment would you like to use?',
|
|
103
|
+
choices: Object.keys(config.environments),
|
|
104
|
+
default: Object.keys(config.environments)[0],
|
|
105
|
+
});
|
|
106
|
+
const answers = await inquirer.prompt(questions);
|
|
107
|
+
apiGateway = config.environments[answers.environment];
|
|
86
108
|
}
|
|
87
109
|
else {
|
|
88
110
|
apiGateway = 'https://api.vibeiq.com/prod/api';
|
|
@@ -94,7 +116,11 @@ async function setAuthContext(user, params) {
|
|
|
94
116
|
orgSlug: params.orgSlug,
|
|
95
117
|
};
|
|
96
118
|
// SET SDK CONFIG
|
|
97
|
-
|
|
119
|
+
setSdkConfig(Auth.config);
|
|
120
|
+
return refreshCurrentUserOrg();
|
|
121
|
+
}
|
|
122
|
+
async function refreshCurrentUserOrg() {
|
|
123
|
+
console.debug("refreshing current user org");
|
|
98
124
|
const currentUser = await Request.request('/users/current', {
|
|
99
125
|
method: 'GET',
|
|
100
126
|
headers: {
|
|
@@ -109,5 +135,7 @@ async function setAuthContext(user, params) {
|
|
|
109
135
|
if (org) {
|
|
110
136
|
Auth.config.orgId = org.orgId || org.id;
|
|
111
137
|
}
|
|
138
|
+
// cache config in the fs
|
|
139
|
+
storeConfig(Object.assign({}, Auth.config));
|
|
112
140
|
return Object.assign({}, Auth.config);
|
|
113
141
|
}
|
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
|
}
|
|
@@ -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;
|
|
@@ -80,21 +103,20 @@ export async function authUser(): Promise<AuthContext>{
|
|
|
80
103
|
}
|
|
81
104
|
|
|
82
105
|
async function setAuthContext(user, params): Promise<AuthContext> {
|
|
83
|
-
|
|
84
|
-
// TODO Dont allow user to set this - they could set dev
|
|
85
|
-
const questions = [];
|
|
86
|
-
questions.push({
|
|
87
|
-
type: 'list',
|
|
88
|
-
name: 'environment',
|
|
89
|
-
message: 'Which environment would you like to use?',
|
|
90
|
-
choices: ['Dev', 'Prod'],
|
|
91
|
-
default: 'Dev',
|
|
92
|
-
});
|
|
93
|
-
|
|
106
|
+
const config = await getConfig();
|
|
94
107
|
let apiGateway;
|
|
95
|
-
|
|
96
|
-
if
|
|
97
|
-
|
|
108
|
+
console.log(config.environments)
|
|
109
|
+
if(config.environments) {
|
|
110
|
+
const questions = [];
|
|
111
|
+
questions.push({
|
|
112
|
+
type: 'list',
|
|
113
|
+
name: 'environment',
|
|
114
|
+
message: 'Which environment would you like to use?',
|
|
115
|
+
choices: Object.keys(config.environments),
|
|
116
|
+
default: Object.keys(config.environments)[0],
|
|
117
|
+
});
|
|
118
|
+
const answers = await inquirer.prompt(questions);
|
|
119
|
+
apiGateway = config.environments[answers.environment]
|
|
98
120
|
} else {
|
|
99
121
|
apiGateway = 'https://api.vibeiq.com/prod/api';
|
|
100
122
|
}
|
|
@@ -106,8 +128,13 @@ async function setAuthContext(user, params): Promise<AuthContext> {
|
|
|
106
128
|
orgSlug: params.orgSlug,
|
|
107
129
|
};
|
|
108
130
|
// SET SDK CONFIG
|
|
109
|
-
|
|
131
|
+
setSdkConfig(Auth.config);
|
|
110
132
|
|
|
133
|
+
return refreshCurrentUserOrg();
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
async function refreshCurrentUserOrg() {
|
|
137
|
+
console.debug("refreshing current user org")
|
|
111
138
|
const currentUser = await Request.request('/users/current', {
|
|
112
139
|
method: 'GET',
|
|
113
140
|
headers: {
|
|
@@ -122,6 +149,7 @@ async function setAuthContext(user, params): Promise<AuthContext> {
|
|
|
122
149
|
if (org) {
|
|
123
150
|
Auth.config.orgId = org.orgId || org.id;
|
|
124
151
|
}
|
|
125
|
-
|
|
152
|
+
// cache config in the fs
|
|
153
|
+
storeConfig(Object.assign({}, Auth.config))
|
|
126
154
|
return Object.assign({}, Auth.config);
|
|
127
155
|
}
|
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
|
}
|
|
@@ -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
|
+
}
|