@contrail/cli 1.0.2 → 1.0.3

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.
Files changed (53) hide show
  1. package/.vscode/settings.json +5 -5
  2. package/bin/init +3 -3
  3. package/lib/auth/auth.d.ts +9 -9
  4. package/lib/auth/auth.js +2 -2
  5. package/lib/auth/login.d.ts +1 -1
  6. package/lib/auth/login.js +112 -96
  7. package/lib/cli.d.ts +5 -5
  8. package/lib/cli.js +30 -30
  9. package/lib/create-app/create.d.ts +1 -1
  10. package/lib/create-app/create.js +63 -48
  11. package/lib/create-app/setup-template.d.ts +1 -1
  12. package/lib/create-app/setup-template.js +34 -48
  13. package/lib/deploy-app/actions-deployer.d.ts +10 -10
  14. package/lib/deploy-app/actions-deployer.js +86 -75
  15. package/lib/deploy-app/app-deployer.d.ts +8 -10
  16. package/lib/deploy-app/app-deployer.js +79 -84
  17. package/lib/deploy-app/app-template-parsers.d.ts +7 -0
  18. package/lib/deploy-app/app-template-parsers.js +37 -0
  19. package/lib/deploy-app/deploy.d.ts +2 -2
  20. package/lib/deploy-app/deploy.js +56 -30
  21. package/lib/deploy-app/interfaces.d.ts +74 -43
  22. package/lib/deploy-app/interfaces.js +4 -0
  23. package/package.json +63 -63
  24. package/publish.sh +5 -0
  25. package/src/auth/auth.ts +9 -9
  26. package/src/auth/login.ts +124 -107
  27. package/src/cli.ts +32 -33
  28. package/src/create-app/create.ts +73 -58
  29. package/src/create-app/setup-template.ts +37 -56
  30. package/src/deploy-app/actions-deployer.ts +109 -84
  31. package/src/deploy-app/app-deployer.ts +86 -89
  32. package/src/deploy-app/app-template-parsers.ts +43 -0
  33. package/src/deploy-app/deploy.ts +64 -33
  34. package/src/deploy-app/interfaces.ts +78 -43
  35. package/templates/javascript/actions/example/action.js +37 -37
  36. package/templates/javascript/app.yml +54 -42
  37. package/templates/javascript/package.json +23 -23
  38. package/templates/javascript/set_auth.bat +3 -0
  39. package/templates/javascript/set_auth.sh +3 -0
  40. package/templates/typescript/actions/exampleAction.ts +38 -0
  41. package/templates/typescript/app.yml +56 -0
  42. package/templates/typescript/package.json +24 -0
  43. package/templates/typescript/set_auth.bat +3 -0
  44. package/templates/typescript/set_auth.sh +3 -0
  45. package/templates/typescript/tsconfig.json +31 -0
  46. package/tsconfig.json +22 -22
  47. package/tslint.json +57 -57
  48. package/lib/deploy-app/actions.d.ts +0 -5
  49. package/lib/deploy-app/actions.js +0 -17
  50. package/lib/deploy-app/app-declaration.d.ts +0 -20
  51. package/lib/deploy-app/app-declaration.js +0 -0
  52. package/lib/deploy-app/app.d.ts +0 -8
  53. package/lib/deploy-app/app.js +0 -56
@@ -1,43 +1,78 @@
1
- /** Describes the derivative JSON / object represented
2
- * in app.yml file.
3
- */
4
- export interface AppDeclartion {
5
- appIdentifier: string;
6
- appName: string;
7
- appDescription?: string;
8
- visibility: 'private' | 'public';
9
- publisher: string;
10
- version: string;
11
- thumbnail?: string;
12
- keywords?: Array<string>;
13
- actions?: { [key: string]: AppActionDeclaration };
14
- appConfiguration: { [key: string]: AppConfigurationElement };
15
- }
16
-
17
- export interface AppConfigurationElement {
18
- propertyType: string;
19
- options?: any[];
20
- label: string;
21
- }
22
-
23
- export interface AppActionDeclaration {
24
- handler: string;
25
- name: string;
26
- description?: string;
27
- }
28
-
29
- export interface App {
30
- id: string;
31
- identifier: string;
32
- name: string;
33
- private: boolean;
34
- }
35
-
36
- export interface EventWorkflowActionDefinition {
37
- id?: string;
38
- identifier?: string;
39
- name?: string;
40
- executeFunctionString?: string;
41
- ownerKey?: string;
42
- public?: boolean;
43
- }
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?: { [key: string]: AppActionDeclaration };
15
+ appConfiguration: ConfigPropertyElements;
16
+ triggers: { [key: string]: AppTriggerDeclaration };
17
+ }
18
+
19
+ export interface ConfigPropertyElements {
20
+ [key: string]: ConfigPropertyElement;
21
+ }
22
+
23
+ export interface ConfigPropertyElement {
24
+ propertyType: string;
25
+ options?: any[];
26
+ label: string;
27
+ }
28
+
29
+ export interface AppActionDeclaration {
30
+ handler: string;
31
+ name: string;
32
+ description?: string;
33
+ actionConfiguration: ConfigPropertyElements;
34
+ }
35
+
36
+ export interface AppTriggerDeclaration {
37
+ key: string;
38
+ name: string;
39
+ external?: boolean;
40
+ description?: string;
41
+ }
42
+
43
+ export interface App {
44
+ id: string;
45
+ identifier: string;
46
+ name: string;
47
+ public: boolean;
48
+ description?: string;
49
+ publisher: string;
50
+ thumbnail: string; // should be a public link
51
+ eventWorkflowTriggerKeyMapping: string;
52
+ configProperties?: ConfigProperty[];
53
+ triggerKeyDefinitions?: TriggerKeyDefinition[];
54
+ }
55
+
56
+ export class ConfigProperty {
57
+ slug: string;
58
+ propertyType: string;
59
+ options?: any[];
60
+ label: string;
61
+ }
62
+
63
+ export interface EventWorkflowActionDefinition {
64
+ id?: string;
65
+ identifier?: string;
66
+ name?: string;
67
+ executeFunctionString?: string;
68
+ ownerKey?: string;
69
+ public?: boolean;
70
+ configProperties?: ConfigProperty[];
71
+ }
72
+
73
+ export class TriggerKeyDefinition {
74
+ name: string;
75
+ description?: string;
76
+ triggerKey: string;
77
+ external?: boolean;
78
+ }
@@ -1,38 +1,38 @@
1
- async function execute(config, event, Functions) {
2
- const getBodyFromEvent = (config, event) => {
3
- let body = Functions.StringUtil.parseVariables(config.message, event);
4
- console.log('body: ', body);
5
- if (config.sendDetails) {
6
- const data = event;
7
- const properties = {};
8
- let addedProperty = false;
9
- for (const property of config.fieldsToForward) {
10
- const variableLevels = property.split('.');
11
- let replacementValue = data;
12
- for (let i = 0; i < variableLevels.length; i++) {
13
- replacementValue = replacementValue[variableLevels[i]];
14
- }
15
- properties[property] = replacementValue;
16
- addedProperty = true;
17
- }
18
- if (addedProperty) {
19
- body = body + ' Properties: ' + JSON.stringify(properties) + '.';
20
- }
21
- }
22
- return JSON.stringify({ text: body });
23
- };
24
- const body = getBodyFromEvent(config, event);
25
- console.log('Sending message: ', body);
26
- const response = await Functions.fetch(config.url, {
27
- method: 'POST',
28
- body: body,
29
- headers: { 'Content-Type': 'application/json' }
30
- });
31
- if (!response.ok) {
32
- console.log('Webhook event failed to publish');
33
- console.log('Response: ', JSON.stringify(response));
34
- }
35
- else {
36
- console.log('Published!');
37
- }
1
+ async function execute(config, event, Functions) {
2
+ const getBodyFromEvent = (config, event) => {
3
+ let body = Functions.StringUtil.parseVariables(config.message, event);
4
+ console.log('body: ', body);
5
+ if (config.sendDetails) {
6
+ const data = event;
7
+ const properties = {};
8
+ let addedProperty = false;
9
+ for (const property of config.fieldsToForward) {
10
+ const variableLevels = property.split('.');
11
+ let replacementValue = data;
12
+ for (let i = 0; i < variableLevels.length; i++) {
13
+ replacementValue = replacementValue[variableLevels[i]];
14
+ }
15
+ properties[property] = replacementValue;
16
+ addedProperty = true;
17
+ }
18
+ if (addedProperty) {
19
+ body = body + ' Properties: ' + JSON.stringify(properties) + '.';
20
+ }
21
+ }
22
+ return JSON.stringify({ text: body });
23
+ };
24
+ const body = getBodyFromEvent(config, event);
25
+ console.log('Sending message: ', body);
26
+ const response = await Functions.fetch(config.url, {
27
+ method: 'POST',
28
+ body: body,
29
+ headers: { 'Content-Type': 'application/json' }
30
+ });
31
+ if (!response.ok) {
32
+ console.log('Webhook event failed to publish');
33
+ console.log('Response: ', JSON.stringify(response));
34
+ }
35
+ else {
36
+ console.log('Published!');
37
+ }
38
38
  }
@@ -1,42 +1,54 @@
1
- appIdentifier: "@your-co/app-name"
2
- appName: "Your App Name"
3
- appDescription: "Your app description."
4
- visibility: public
5
- publisher: "Your company name"
6
- version: 1.0
7
-
8
- appConfiguration:
9
- apiHost:
10
- label: "API Host"
11
- propertyType: "string"
12
- userName:
13
- label: "User Name"
14
- propertyType: "string"
15
- password:
16
- label: "Password"
17
- propertyType: "string"
18
-
19
- actions:
20
- updateProduct:
21
- handler: actions/example/action.js
22
- name: "Update Product"
23
- description: "Updates a product in the destination system."
24
-
25
- triggers:
26
- trigger1:
27
- key: product|create
28
- name: "Produt Created"
29
-
30
- workflows:
31
- workflow1:
32
- name: "Update item on product creation"
33
- triggerKey: product|create
34
- paths:
35
- path1:
36
- conditional: "{retailPrice} > 10"
37
- actions:
38
- updateItem:
39
- actionId: updateItem
40
- configuration:
41
-
42
-
1
+ appIdentifier: "@your-co/app-name"
2
+ appName: "Your App Name"
3
+ appDescription: "Your app description."
4
+ visibility: public
5
+ publisher: "Your company name"
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
+ appConfiguration:
14
+ apiHost:
15
+ label: "API Host"
16
+ propertyType: "string"
17
+ userName:
18
+ label: "User Name"
19
+ propertyType: "string"
20
+ password:
21
+ label: "Password"
22
+ propertyType: "string"
23
+
24
+ actions:
25
+ updateProduct:
26
+ handler: actions/example/action.js
27
+ name: "Update Product"
28
+ description: "Updates a product in the destination system."
29
+ actionConfiguration:
30
+ email:
31
+ label: "Email Address"
32
+ propertyType: "string"
33
+
34
+ triggers:
35
+ trigger1:
36
+ key: product|create
37
+ name: "External Product Created"
38
+ external: true
39
+ description: "Triggers on externally created products"
40
+
41
+ # TODO - This is not read
42
+ workflows:
43
+ workflow1:
44
+ name: "Update item on product creation"
45
+ triggerKey: product|create
46
+ paths:
47
+ path1:
48
+ conditional: "{retailPrice} > 10"
49
+ actions:
50
+ updateItem:
51
+ actionId: updateItem
52
+ configuration:
53
+
54
+
@@ -1,23 +1,23 @@
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
- "test": "echo \"Error: no test specified\" && exit 1"
15
- },
16
- "keywords": [
17
- ],
18
- "author": "",
19
- "license": "ISC",
20
- "dependencies": {
21
- "chalk": "^4.0.0"
22
- }
23
- }
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
+ "test": "echo \"Error: no test specified\" && exit 1"
15
+ },
16
+ "keywords": [
17
+ ],
18
+ "author": "",
19
+ "license": "ISC",
20
+ "dependencies": {
21
+ "chalk": "^4.0.0"
22
+ }
23
+ }
@@ -0,0 +1,3 @@
1
+ set CONTRAIL_CLI_EMAIL=
2
+ set CONTRAIL_CLI_PASSWORD=
3
+ set CONTRAIL_CLI_ORGSLUG=
@@ -0,0 +1,3 @@
1
+ export CONTRAIL_CLI_EMAIL=
2
+ export CONTRAIL_CLI_PASSWORD=
3
+ export CONTRAIL_CLI_ORGSLUG=
@@ -0,0 +1,38 @@
1
+ async function execute(config, event, Functions) {
2
+ const getBodyFromEvent = (config, event) => {
3
+ let body = Functions.StringUtil.parseVariables(config.message, event);
4
+ console.log('body: ', body);
5
+ if (config.sendDetails) {
6
+ const data = event;
7
+ const properties = {};
8
+ let addedProperty = false;
9
+ for (const property of config.fieldsToForward) {
10
+ const variableLevels = property.split('.');
11
+ let replacementValue = data;
12
+ for (let i = 0; i < variableLevels.length; i++) {
13
+ replacementValue = replacementValue[variableLevels[i]];
14
+ }
15
+ properties[property] = replacementValue;
16
+ addedProperty = true;
17
+ }
18
+ if (addedProperty) {
19
+ body = body + ' Properties: ' + JSON.stringify(properties) + '.';
20
+ }
21
+ }
22
+ return JSON.stringify({ text: body });
23
+ };
24
+ const body = getBodyFromEvent(config, event);
25
+ console.log('Sending message: ', body);
26
+ const response = await Functions.fetch(config.url, {
27
+ method: 'POST',
28
+ body: body,
29
+ headers: { 'Content-Type': 'application/json' }
30
+ });
31
+ if (!response.ok) {
32
+ console.log('Webhook event failed to publish');
33
+ console.log('Response: ', JSON.stringify(response));
34
+ }
35
+ else {
36
+ console.log('Published!');
37
+ }
38
+ }
@@ -0,0 +1,56 @@
1
+ appIdentifier: "@your-co/app-name"
2
+ appName: "Your App Name"
3
+ appDescription: "Your app description."
4
+ visibility: public
5
+ publisher: "Your company name"
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
+ appConfiguration:
14
+ apiHost:
15
+ label: "API Host"
16
+ propertyType: "string"
17
+ userName:
18
+ label: "User Name"
19
+ propertyType: "string"
20
+ password:
21
+ label: "Password"
22
+ propertyType: "string"
23
+
24
+ # Actions can be written in .ts but must be compiled to .js before deployment.
25
+ # Ensure the handler points to a .js file
26
+ actions:
27
+ updateProduct:
28
+ handler: actions/exampleAction.js
29
+ name: "Update Product"
30
+ description: "Updates a product in the destination system."
31
+ actionConfiguration:
32
+ email:
33
+ label: "Email Address"
34
+ propertyType: "string"
35
+
36
+ triggers:
37
+ trigger1:
38
+ key: product|create
39
+ name: "External Product Created"
40
+ external: true
41
+ description: "Triggers on externally created products"
42
+
43
+ # TODO - This is not read
44
+ workflows:
45
+ workflow1:
46
+ name: "Update item on product creation"
47
+ triggerKey: product|create
48
+ paths:
49
+ path1:
50
+ conditional: "{retailPrice} > 10"
51
+ actions:
52
+ updateItem:
53
+ actionId: updateItem
54
+ configuration:
55
+
56
+
@@ -0,0 +1,24 @@
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
+ ],
19
+ "author": "",
20
+ "license": "ISC",
21
+ "dependencies": {
22
+ "chalk": "^4.0.0"
23
+ }
24
+ }
@@ -0,0 +1,3 @@
1
+ set CONTRAIL_CLI_EMAIL=
2
+ set CONTRAIL_CLI_PASSWORD=
3
+ set CONTRAIL_CLI_ORGSLUG=
@@ -0,0 +1,3 @@
1
+ export CONTRAIL_CLI_EMAIL=
2
+ export CONTRAIL_CLI_PASSWORD=
3
+ export CONTRAIL_CLI_ORGSLUG=
@@ -0,0 +1,31 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es2017",
4
+ "module": "commonjs",
5
+ "declaration": true,
6
+ "esModuleInterop": true,
7
+ "outDir": "./actions",
8
+ "strict": false,
9
+ "experimentalDecorators": true,
10
+ "strictPropertyInitialization": false,
11
+ "noImplicitAny": false,
12
+ "emitDecoratorMetadata": true,
13
+ "skipLibCheck": true,
14
+ "moduleResolution": "node",
15
+ "lib": [
16
+ "es5",
17
+ "ES2015",
18
+ "ES2016",
19
+ "ES2017",
20
+ "dom",
21
+ "esnext.asynciterable"
22
+ ],
23
+ },
24
+ "include": [
25
+ "actions"
26
+ ],
27
+ "exclude": [
28
+ "node_modules",
29
+ "**/__tests__/*"
30
+ ]
31
+ }
package/tsconfig.json CHANGED
@@ -1,23 +1,23 @@
1
- {
2
- "compilerOptions": {
3
- "target": "esnext",
4
- "module": "esnext",
5
- "declaration": true,
6
- "esModuleInterop": true,
7
- "outDir": "./lib",
8
- "strict": false,
9
- "experimentalDecorators": true,
10
- "strictPropertyInitialization": false,
11
- "noImplicitAny": false,
12
- "emitDecoratorMetadata": true,
13
- "skipLibCheck": true,
14
- "moduleResolution": "node"
15
- },
16
- "include": [
17
- "src"
18
- ],
19
- "exclude": [
20
- "node_modules",
21
- "**/__tests__/*"
22
- ]
1
+ {
2
+ "compilerOptions": {
3
+ "target": "esnext",
4
+ "module": "esnext",
5
+ "declaration": true,
6
+ "esModuleInterop": true,
7
+ "outDir": "./lib",
8
+ "strict": false,
9
+ "experimentalDecorators": true,
10
+ "strictPropertyInitialization": false,
11
+ "noImplicitAny": false,
12
+ "emitDecoratorMetadata": true,
13
+ "skipLibCheck": true,
14
+ "moduleResolution": "node"
15
+ },
16
+ "include": [
17
+ "src"
18
+ ],
19
+ "exclude": [
20
+ "node_modules",
21
+ "**/__tests__/*"
22
+ ]
23
23
  }