@contrail/cli 1.0.11 → 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/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/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
|
+
}
|
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
|
+
|
|
@@ -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
|
+
}
|
package/test/app.yml
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
appIdentifier: "@vibe/kamaltest"
|
|
2
|
+
appName: "kamal's test app"
|
|
3
|
+
appDescription: "just a hello world app"
|
|
4
|
+
visibility: private
|
|
5
|
+
publisher: "vibeiq kamal"
|
|
6
|
+
version: 1.0
|
|
7
|
+
|
|
8
|
+
# eventWorkflowTriggerKeyMapping will be used to parse an incoming event into a key that can trigger workflows
|
|
9
|
+
# {} indicates a field on the event. You can use nested fields by separating the levels with a '.'
|
|
10
|
+
# i.e. an event {details: {eventType: 'apparel'}, actionType: 'create'} can be parsed to apparel|create with the following
|
|
11
|
+
eventWorkflowTriggerKeyMapping: "{details.eventType}|{actionType}"
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# Actions can be written in .ts but must be compiled to .js before deployment.
|
|
15
|
+
# Ensure the handler points to a .js file
|
|
16
|
+
actions:
|
|
17
|
+
updateProduct:
|
|
18
|
+
handler: actions/exampleAction.js
|
|
19
|
+
name: "Update Product"
|
|
20
|
+
description: "Updates a product in the destination system."
|
|
21
|
+
actionConfiguration:
|
|
22
|
+
email:
|
|
23
|
+
label: "Email Address"
|
|
24
|
+
propertyType: "string"
|
|
25
|
+
|
|
26
|
+
triggers:
|
|
27
|
+
trigger1:
|
|
28
|
+
key: product|create
|
|
29
|
+
name: "External Product Created"
|
|
30
|
+
external: true
|
|
31
|
+
description: "Triggers on externally created products"
|
|
32
|
+
|
|
33
|
+
# TODO - This is not read
|
|
34
|
+
workflows:
|
|
35
|
+
workflow1:
|
|
36
|
+
name: "Update item on product creation"
|
|
37
|
+
triggerKey: product|create
|
|
38
|
+
paths:
|
|
39
|
+
path1:
|
|
40
|
+
conditional: "{retailPrice} > 10"
|
|
41
|
+
actions:
|
|
42
|
+
updateItem:
|
|
43
|
+
actionId: updateItem
|
|
44
|
+
configuration:
|
|
45
|
+
|
|
46
|
+
|
|
@@ -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
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "test-app",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"lockfileVersion": 1,
|
|
5
|
+
"requires": true,
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"ansi-styles": {
|
|
8
|
+
"version": "4.3.0",
|
|
9
|
+
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
|
|
10
|
+
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
|
|
11
|
+
"requires": {
|
|
12
|
+
"color-convert": "^2.0.1"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"chalk": {
|
|
16
|
+
"version": "4.1.2",
|
|
17
|
+
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
|
|
18
|
+
"integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
|
|
19
|
+
"requires": {
|
|
20
|
+
"ansi-styles": "^4.1.0",
|
|
21
|
+
"supports-color": "^7.1.0"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"color-convert": {
|
|
25
|
+
"version": "2.0.1",
|
|
26
|
+
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
|
|
27
|
+
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
|
|
28
|
+
"requires": {
|
|
29
|
+
"color-name": "~1.1.4"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"color-name": {
|
|
33
|
+
"version": "1.1.4",
|
|
34
|
+
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
|
|
35
|
+
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="
|
|
36
|
+
},
|
|
37
|
+
"has-flag": {
|
|
38
|
+
"version": "4.0.0",
|
|
39
|
+
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
|
|
40
|
+
"integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ=="
|
|
41
|
+
},
|
|
42
|
+
"supports-color": {
|
|
43
|
+
"version": "7.2.0",
|
|
44
|
+
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
|
|
45
|
+
"integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
|
|
46
|
+
"requires": {
|
|
47
|
+
"has-flag": "^4.0.0"
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"typescript": {
|
|
51
|
+
"version": "4.7.4",
|
|
52
|
+
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.7.4.tgz",
|
|
53
|
+
"integrity": "sha512-C0WQT0gezHuw6AdY1M2jxUO83Rjf0HP7Sk1DtXj6j1EwkQNZrHAg2XPWlq62oqEhYvONq5pkC2Y9oPljWToLmQ==",
|
|
54
|
+
"dev": true
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "test-app",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"@contrail/contrail-cli": "bin/init",
|
|
8
|
+
"contrail": "bin/init"
|
|
9
|
+
},
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "tsc",
|
|
15
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [],
|
|
18
|
+
"author": "",
|
|
19
|
+
"license": "ISC",
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"chalk": "^4.0.0"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"typescript": "^4.7.4"
|
|
25
|
+
}
|
|
26
|
+
}
|