@contrail/cli 1.0.31 → 1.0.32

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 (48) hide show
  1. package/.eslintrc.js +53 -0
  2. package/lib/apps/deploy-app/actions-deployer.js +12 -3
  3. package/lib/apps/deploy-app/app-deployer.js +2 -3
  4. package/lib/apps/deploy-app/app-template-parsers.js +1 -1
  5. package/lib/apps/deploy-app/docker-action-builder.d.ts +10 -0
  6. package/lib/apps/deploy-app/docker-action-builder.js +97 -0
  7. package/lib/apps/deploy-app/interfaces.d.ts +76 -0
  8. package/lib/apps/deploy-app/interfaces.js +4 -0
  9. package/lib/apps/deploy-app/workflow-definition-deployer.js +1 -1
  10. package/lib/apps/deploy-app/workflow-deployer.d.ts +10 -0
  11. package/lib/apps/deploy-app/workflow-deployer.js +87 -0
  12. package/lib/auth/login.js +5 -5
  13. package/lib/cli.js +2 -1
  14. package/lib/colors/color-loader.js +8 -8
  15. package/lib/config/config.js +2 -2
  16. package/lib/interfaces.d.ts +2 -2
  17. package/lib/types/interfaces.js +1 -0
  18. package/lib/types/option-set-merger.js +2 -2
  19. package/lib/types/option-set-parser.js +2 -2
  20. package/lib/types/option-set-uploader.js +2 -2
  21. package/lib/types/parse-types.js +6 -6
  22. package/lib/types/types-extractor.js +4 -4
  23. package/lib/types/types-properties-merger.js +2 -2
  24. package/lib/types/types-uploader.d.ts +1 -1
  25. package/lib/types/types-uploader.js +6 -6
  26. package/package.json +7 -5
  27. package/src/apps/deploy-app/actions-deployer.ts +17 -10
  28. package/src/apps/deploy-app/app-deployer.ts +3 -4
  29. package/src/apps/deploy-app/workflow-definition-deployer.ts +3 -3
  30. package/src/auth/login.ts +124 -124
  31. package/src/cli.ts +115 -115
  32. package/src/colors/color-loader.ts +16 -16
  33. package/src/config/config.ts +9 -11
  34. package/src/config/configCommands.ts +1 -1
  35. package/src/interfaces.ts +9 -10
  36. package/src/types/csv-parser.ts +1 -1
  37. package/src/types/option-set-merger.ts +9 -9
  38. package/src/types/option-set-parser.ts +5 -6
  39. package/src/types/option-set-uploader.ts +2 -2
  40. package/src/types/parse-types.ts +9 -9
  41. package/src/types/types-extractor.ts +5 -5
  42. package/src/types/types-properties-merger.ts +6 -6
  43. package/src/types/types-uploader.ts +31 -31
  44. package/src/workflows/workflow-template-deployer.ts +2 -4
  45. package/src/workflows/workflowCommands.ts +0 -1
  46. package/templates/javascript/actions/example/action.js +37 -37
  47. package/templates/typescript/actions/exampleAction.ts +1 -1
  48. package/templates/typescript/app.yml +1 -1
@@ -12,11 +12,11 @@ export async function ParseTypesFromLocalFiles(args) {
12
12
  if ((args === null || args === void 0 ? void 0 : args.length) < 4) {
13
13
  throw new Error('File names must be included.');
14
14
  }
15
- console.log(`%s Parsing`, chalk.yellow.bold('TYPES AND OPTION SETS'));
15
+ console.log('%s Parsing', chalk.yellow.bold('TYPES AND OPTION SETS'));
16
16
  const fileLocations = args.slice(3);
17
17
  console.log('Using File Location(s): ', fileLocations);
18
18
  await parseTypesFromLocalFiles(fileLocations);
19
- console.log(`%s Parsed`, chalk.yellow.bold('TYPES AND OPTION SETS'));
19
+ console.log('%s Parsed', chalk.yellow.bold('TYPES AND OPTION SETS'));
20
20
  }
21
21
  catch (e) {
22
22
  console.log(`%s Parsing Failed. ${e}`, chalk.red.bold('FAIL'));
@@ -30,11 +30,11 @@ export async function ParseTypesFromFiles(args) {
30
30
  if ((args === null || args === void 0 ? void 0 : args.length) < 4) {
31
31
  throw new Error('File ids must be included.');
32
32
  }
33
- console.log(`%s Parsing`, chalk.yellow.bold('TYPES AND OPTION SETS'));
33
+ console.log('%s Parsing', chalk.yellow.bold('TYPES AND OPTION SETS'));
34
34
  const fileIds = args.slice(3);
35
35
  console.log('Using FileId(s): ', fileIds);
36
36
  await parseTypesFromFiles(fileIds);
37
- console.log(`%s Parsed`, chalk.yellow.bold('TYPES AND OPTION SETS'));
37
+ console.log('%s Parsed', chalk.yellow.bold('TYPES AND OPTION SETS'));
38
38
  }
39
39
  catch (e) {
40
40
  console.log(`%s Parsing Failed. ${e}`, chalk.red.bold('FAIL'));
@@ -48,13 +48,13 @@ export async function ParseTypesFromTemplateFromLocalFiles(args) {
48
48
  if ((args === null || args === void 0 ? void 0 : args.length) < 5) {
49
49
  throw new Error('File names must be included.');
50
50
  }
51
- console.log(`%s Parsing`, chalk.yellow.bold('TYPES AND OPTION SETS'));
51
+ console.log('%s Parsing', chalk.yellow.bold('TYPES AND OPTION SETS'));
52
52
  const templateFileLocation = args[3];
53
53
  const dataFileLocation = args[4];
54
54
  console.log('Using Template File Location: ', templateFileLocation);
55
55
  console.log('Using Data File Location: ', dataFileLocation);
56
56
  await parseTypesFromTemplateFromLocalFiles(templateFileLocation, dataFileLocation);
57
- console.log(`%s Parsed`, chalk.yellow.bold('TYPES AND OPTION SETS'));
57
+ console.log('%s Parsed', chalk.yellow.bold('TYPES AND OPTION SETS'));
58
58
  }
59
59
  catch (e) {
60
60
  console.log(`%s Parsing Failed. ${e}`, chalk.red.bold('FAIL'));
@@ -8,19 +8,19 @@ export async function getTypes(args) {
8
8
  try {
9
9
  const userConfig = await authUser();
10
10
  console.log(`%s Getting all types for orgId: ${userConfig.orgId}`, chalk.blue.bold('START'));
11
- console.log(`%s Retrieving`, chalk.yellow.bold('OPTION SETS'));
11
+ console.log('%s Retrieving', chalk.yellow.bold('OPTION SETS'));
12
12
  const optionSets = await new Entities().get({
13
13
  entityName: 'type-property-option-set',
14
14
  });
15
15
  await getOptionSets(optionSets);
16
- console.log(`%s Retrieved`, chalk.yellow.bold('OPTION SETS'));
17
- console.log(`%s Retrieving`, chalk.yellow.bold('TYPES'));
16
+ console.log('%s Retrieved', chalk.yellow.bold('OPTION SETS'));
17
+ console.log('%s Retrieving', chalk.yellow.bold('TYPES'));
18
18
  const reducedTypes = await getReducedTypes(optionSets);
19
19
  const typesHolder = {
20
20
  types: reducedTypes,
21
21
  };
22
22
  saveData(typesHolder);
23
- console.log(`%s Retrieved`, chalk.yellow.bold('TYPES'));
23
+ console.log('%s Retrieved', chalk.yellow.bold('TYPES'));
24
24
  }
25
25
  catch (e) {
26
26
  console.log(`%s Types Retrieval Failed. ${e}`, chalk.red.bold('FAIL'));
@@ -10,13 +10,13 @@ export async function MergeTypeProperties(args) {
10
10
  if ((args === null || args === void 0 ? void 0 : args.length) < 5) {
11
11
  throw new Error('File name must be included along with a type path.');
12
12
  }
13
- console.log(`%s Importing local file`, chalk.yellow.bold('TYPE PROPERTIES MERGE'));
13
+ console.log('%s Importing local file', chalk.yellow.bold('TYPE PROPERTIES MERGE'));
14
14
  const fileLocation = args[3];
15
15
  console.log('Using File: ', fileLocation);
16
16
  const typePaths = args.slice(4);
17
17
  console.log('Using TypePaths: ', typePaths);
18
18
  await mergeTypeProperties(fileLocation, typePaths);
19
- console.log(`%s Merged`, chalk.yellow.bold('TYPE PROPERTIES MERGE'));
19
+ console.log('%s Merged', chalk.yellow.bold('TYPE PROPERTIES MERGE'));
20
20
  }
21
21
  catch (e) {
22
22
  console.log(`%s Merge Failed. ${e}`, chalk.red.bold('FAIL'));
@@ -1 +1 @@
1
- export declare function uploadTypes(args: any): Promise<void>;
1
+ export declare function uploadTypes(): Promise<void>;
@@ -4,14 +4,14 @@ import fs from 'fs';
4
4
  import { authUser } from '../auth/login';
5
5
  import { getSeparatorByPlatform } from '../common';
6
6
  import * as _ from 'lodash';
7
- const yaml = require('js-yaml');
8
- export async function uploadTypes(args) {
7
+ import yaml from 'js-yaml';
8
+ export async function uploadTypes() {
9
9
  try {
10
10
  const userConfig = await authUser();
11
11
  console.log(`%s Getting all types for orgId: ${userConfig.orgId}`, chalk.blue.bold('START'));
12
- console.log(`%s Uploading`, chalk.yellow.bold('TYPES'));
12
+ console.log('%s Uploading', chalk.yellow.bold('TYPES'));
13
13
  await uploadReducedTypes();
14
- console.log(`%s Uploaded`, chalk.yellow.bold('TYPES'));
14
+ console.log('%s Uploaded', chalk.yellow.bold('TYPES'));
15
15
  }
16
16
  catch (e) {
17
17
  console.log(`%s Types Upload Failed. ${e}`, chalk.red.bold('FAIL'));
@@ -146,7 +146,7 @@ async function uploadReducedTypeProperties(type, currentPropertyTypes, newProper
146
146
  validationFunction: newPropertyType.validationFunction,
147
147
  }),
148
148
  headers: {
149
- 'Accept': 'application/json',
149
+ Accept: 'application/json',
150
150
  'Content-Type': 'application/json',
151
151
  },
152
152
  });
@@ -186,7 +186,7 @@ async function uploadReducedTypeProperties(type, currentPropertyTypes, newProper
186
186
  await Request.request(`/types/${type.id}/type-properties/${currentPropertyType.id}`, {
187
187
  method: 'DELETE',
188
188
  headers: {
189
- 'Accept': 'application/json',
189
+ Accept: 'application/json',
190
190
  'Content-Type': 'application/json',
191
191
  },
192
192
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/cli",
3
- "version": "1.0.31",
3
+ "version": "1.0.32",
4
4
  "description": "VibeIQ's Contrail Platform CLI.",
5
5
  "main": "lib/index.js",
6
6
  "bin": {
@@ -17,7 +17,7 @@
17
17
  "scripts": {
18
18
  "build": "tsc",
19
19
  "format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
20
- "lint": "tslint -p tsconfig.json",
20
+ "lint": "eslint . --fix",
21
21
  "test": "jest --watch"
22
22
  },
23
23
  "author": "",
@@ -32,6 +32,7 @@
32
32
  "chalk": "^4.0.0",
33
33
  "command-line-usage": "^6.1.1",
34
34
  "csvtojson": "^2.0.10",
35
+ "eslint-plugin-unused-imports": "^2.0.0",
35
36
  "esm": "^3.2.25",
36
37
  "execa": "^5.0.0",
37
38
  "inquirer": "^8.2.0",
@@ -45,12 +46,13 @@
45
46
  "@types/jest": "^23.3.14",
46
47
  "@types/lodash": "^4.14.178",
47
48
  "@types/node": "^14.6.4",
49
+ "@typescript-eslint/eslint-plugin": "^5.32.0",
50
+ "@typescript-eslint/parser": "^5.32.0",
51
+ "eslint": "^8.21.0",
48
52
  "jest": "^29.3.1",
49
53
  "prettier": "^1.19.1",
50
54
  "ts-jest": "^29.0.3",
51
- "tslint": "^5.11.0",
52
- "tslint-config-prettier": "^1.18.0",
53
- "typescript": "^3.0.1"
55
+ "typescript": "^4.9.3"
54
56
  },
55
57
  "jest": {
56
58
  "moduleFileExtensions": [
@@ -6,7 +6,6 @@ import { getSeparatorByPlatform } from '../../common';
6
6
 
7
7
  import fs from 'fs';
8
8
 
9
-
10
9
  export async function getActionsForApp(app: App) {
11
10
  return await new Entities().get({
12
11
  entityName: 'event-workflow-action-definition',
@@ -14,16 +13,16 @@ export async function getActionsForApp(app: App) {
14
13
  });
15
14
  }
16
15
 
17
-
18
16
  export function getActionDeclarationIdentifier(actionKey, app: App) {
19
17
  return app.identifier + ':' + actionKey;
20
18
  }
21
19
 
22
- export async function deleteAction(actionId): Promise<any>{
20
+ export async function deleteAction(actionId): Promise<any> {
23
21
  return await new Entities().delete({ entityName: 'event-workflow-action-definition', id: actionId });
24
22
  }
25
23
 
26
24
  export class ActionsDeployer {
25
+
27
26
  async deployActions(appDeclaration: AppDeclaration, app: App) {
28
27
 
29
28
  // FETCH ALL ACTIONS FROM THE API.
@@ -31,16 +30,23 @@ export class ActionsDeployer {
31
30
 
32
31
  // UPSERT / DELETE BASED ON ACTION IDENTIFIER
33
32
  console.log('%s \tDeploying actions.', chalk.yellow.bold('ACTION'));
34
-
33
+ let appActionIdentifiers = [];
35
34
  if (appDeclaration.actions) {
36
- const localActions = Object.keys(appDeclaration.actions);
37
- if (localActions?.length > 0) {
38
- for (const actionKey of localActions) {
35
+ const localActionKeys = Object.keys(appDeclaration.actions);
36
+ appActionIdentifiers = localActionKeys.map(x => getActionDeclarationIdentifier(x, app));
37
+ if (localActionKeys?.length > 0) {
38
+ for (const actionKey of localActionKeys) {
39
39
  await this.deployAction(actionKey, appDeclaration.actions[actionKey], app, existingActions);
40
40
  }
41
41
  }
42
42
  }
43
+ const toDelete = existingActions.filter(x => !appActionIdentifiers.includes(x.identifier));
44
+ for (const action of toDelete) {
45
+ console.log(`%s \tDeleting action: ${action.identifier}`, chalk.yellow.bold('ACTION'));
46
+ await deleteAction(action.id);
47
+ }
43
48
  }
49
+
44
50
  async deployAction(actionKey: string, actionDeclaration: AppActionDeclaration, app: App, existingActions: Array<any>) {
45
51
  console.log(`%s \tDeploying action: ${actionKey}`, chalk.yellow.bold('ACTION'));
46
52
 
@@ -63,8 +69,9 @@ export class ActionsDeployer {
63
69
  identifier: getActionDeclarationIdentifier(actionKey, app),
64
70
  name: actionDeclaration.name,
65
71
  ownerKey: `app:${app.id}`,
66
- public: 'public' in actionDeclaration? actionDeclaration.public: app.public,
72
+ public: 'public' in actionDeclaration ? actionDeclaration.public : app.public,
67
73
  configProperties,
74
+ async: actionDeclaration.async,
68
75
  };
69
76
 
70
77
  const functionString = await this.getFunction(actionDeclaration);
@@ -94,8 +101,9 @@ export class ActionsDeployer {
94
101
 
95
102
  const updates: EventWorkflowActionDefinition = {
96
103
  name: actionDeclaration.name,
97
- public: 'public' in actionDeclaration? actionDeclaration.public: app.public,
104
+ public: 'public' in actionDeclaration ? actionDeclaration.public : app.public,
98
105
  configProperties,
106
+ async: actionDeclaration.async,
99
107
  };
100
108
 
101
109
  const functionString = await this.getFunction(actionDeclaration);
@@ -114,7 +122,6 @@ export class ActionsDeployer {
114
122
  return actionDefinition;
115
123
  }
116
124
 
117
-
118
125
  async getFunction(actionDeclaration: AppActionDeclaration): Promise<string> {
119
126
  if (!actionDeclaration.handler) {
120
127
  return;
@@ -10,10 +10,10 @@ export class AppDeployer {
10
10
  public async deploy(appDeclaration: AppDeclaration) {
11
11
  let app = await this.getExistingApp(appDeclaration);
12
12
  if (!app) {
13
- console.log(`%s Creating new app.`, chalk.yellow.bold('APP'));
13
+ console.log('%s Creating new app.', chalk.yellow.bold('APP'));
14
14
  app = await this.createNewApp(appDeclaration);
15
15
  } else {
16
- console.log(`%s Updating existing app.`, chalk.yellow.bold('APP'));
16
+ console.log('%s Updating existing app.', chalk.yellow.bold('APP'));
17
17
  app = await this.updateExistingApp(appDeclaration, app);
18
18
  }
19
19
  await new ActionsDeployer().deployActions(appDeclaration, app);
@@ -65,7 +65,6 @@ export class AppDeployer {
65
65
  keywords: appDeclaration.keywords,
66
66
  configProperties,
67
67
  triggerKeyDefinitions,
68
- isDockerBased: appDeclaration.isDockerBased,
69
68
  dockerImageRef: appDeclaration.dockerImageRef,
70
69
  };
71
70
  const app = await new Entities().create({ entityName: 'app', object: newApp });
@@ -105,7 +104,7 @@ export class AppDeployer {
105
104
  public async remove(appDeclaration: AppDeclaration) {
106
105
  let app = await this.getExistingApp(appDeclaration);
107
106
  if (app) {
108
- const actions = await getActionsForApp(app)
107
+ const actions = await getActionsForApp(app);
109
108
  for(const action of actions)
110
109
  {
111
110
  console.log(`%s Deleting action: ${action.identifier}`, chalk.yellow.bold('APP'));
@@ -1,7 +1,7 @@
1
1
  import { Entities } from '@contrail/sdk';
2
2
  import chalk from 'chalk';
3
3
  import { App, AppDeclaration, WorkflowDefinition } from '../../interfaces';
4
- import { getActionDeclarationIdentifier, getActionsForApp } from './actions-deployer'
4
+ import { getActionDeclarationIdentifier, getActionsForApp } from './actions-deployer';
5
5
 
6
6
  export class WorkflowDefinitionDeployer {
7
7
  async deployWorkflowDefinitions(appDeclaration: AppDeclaration, app: App) {
@@ -70,7 +70,7 @@ export class WorkflowDefinitionDeployer {
70
70
  }
71
71
 
72
72
  private async populateActionIds(workflowDefinition: WorkflowDefinition, app: App) {
73
- let availableAppActions = await getActionsForApp(app);
73
+ const availableAppActions = await getActionsForApp(app);
74
74
  if (!workflowDefinition.workflowDefinition?.paths) {
75
75
  return;
76
76
  }
@@ -82,7 +82,7 @@ export class WorkflowDefinitionDeployer {
82
82
  const actionKey = actionConfiguration.action;
83
83
  const action = availableAppActions.find(
84
84
  action => action.identifier === getActionDeclarationIdentifier(actionKey, app)
85
- )
85
+ );
86
86
  if (!action) {
87
87
  throw new Error(`Could not find action ${actionKey} declared in workflow definition ${workflowDefinition.name}`);
88
88
  }
package/src/auth/login.ts CHANGED
@@ -5,151 +5,151 @@ import { Auth, AuthContext } from './auth';
5
5
  import { getConfig, storeConfig } from '../config/config';
6
6
 
7
7
  const CONFIGURATION = {
8
- userPoolId: 'us-east-1_x8hXZUsL6',
9
- clientId: process.env.CONTRAIL_COGNITO_CLIENT_ID || '2oubek96sue5rsncovtqhs3scm',
8
+ userPoolId: 'us-east-1_x8hXZUsL6',
9
+ clientId: process.env.CONTRAIL_COGNITO_CLIENT_ID || '2oubek96sue5rsncovtqhs3scm',
10
10
  };
11
11
 
12
12
  export async function authUser(): Promise<AuthContext> {
13
- console.debug("authorizing user")
14
- const config = await getConfig();
15
- if (
16
- config &&
13
+ console.debug('authorizing user');
14
+ const config = await getConfig();
15
+ if (
16
+ config &&
17
17
  config.apiUserToken &&
18
18
  config.apiGateway &&
19
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
- }
35
- const questions = [];
36
- if (!process.env.CONTRAIL_CLI_EMAIL) {
37
- questions.push({
38
- type: 'input',
39
- name: 'email',
40
- validate: (val) => !!val,
41
- message: 'Email',
42
- });
43
- }
44
- if (!process.env.CONTRAIL_CLI_PASSWORD) {
45
- questions.push({
46
- type: 'password',
47
- name: 'password',
48
- validate: (val) => !!val,
49
- message: 'Password',
50
- });
51
- }
52
- if (!process.env.CONTRAIL_CLI_ORGSLUG) {
53
- questions.push({
54
- type: 'input',
55
- name: 'orgSlug',
56
- validate: (val) => !!val,
57
- message: 'Org (slug)',
58
- });
59
- }
60
-
61
- const answers = await inquirer.prompt(questions);
62
- const params = {
63
- email: process.env.CONTRAIL_CLI_EMAIL || answers.email,
64
- password: process.env.CONTRAIL_CLI_PASSWORD || answers.password,
65
- orgSlug: process.env.CONTRAIL_CLI_ORGSLUG || answers.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,
66
26
  };
67
- if (!params.email || !params.password) {
68
- throw new Error('Email and Password required');
27
+ setSdkConfig(Auth.config);
28
+ try {
29
+ return await refreshCurrentUserOrg();
30
+ } catch (e) {
31
+ console.log('Token expired. Requesting auth credentials...');
69
32
  }
70
33
 
71
- const poolData = {
72
- UserPoolId: CONFIGURATION.userPoolId,
73
- ClientId: CONFIGURATION.clientId,
74
- };
34
+ }
35
+ const questions = [];
36
+ if (!process.env.CONTRAIL_CLI_EMAIL) {
37
+ questions.push({
38
+ type: 'input',
39
+ name: 'email',
40
+ validate: (val) => !!val,
41
+ message: 'Email',
42
+ });
43
+ }
44
+ if (!process.env.CONTRAIL_CLI_PASSWORD) {
45
+ questions.push({
46
+ type: 'password',
47
+ name: 'password',
48
+ validate: (val) => !!val,
49
+ message: 'Password',
50
+ });
51
+ }
52
+ if (!process.env.CONTRAIL_CLI_ORGSLUG) {
53
+ questions.push({
54
+ type: 'input',
55
+ name: 'orgSlug',
56
+ validate: (val) => !!val,
57
+ message: 'Org (slug)',
58
+ });
59
+ }
75
60
 
76
- const userPool = new AmazonCognitoIdentity.CognitoUserPool(poolData);
77
- const authData = {
78
- Username: params.email,
79
- Password: params.password,
80
- };
61
+ const answers = await inquirer.prompt(questions);
62
+ const params = {
63
+ email: process.env.CONTRAIL_CLI_EMAIL || answers.email,
64
+ password: process.env.CONTRAIL_CLI_PASSWORD || answers.password,
65
+ orgSlug: process.env.CONTRAIL_CLI_ORGSLUG || answers.orgSlug,
66
+ };
67
+ if (!params.email || !params.password) {
68
+ throw new Error('Email and Password required');
69
+ }
81
70
 
82
- const authDetails = new AmazonCognitoIdentity.AuthenticationDetails(authData);
83
- const userData = {
84
- Username: params.email,
85
- Pool: userPool,
86
- };
71
+ const poolData = {
72
+ UserPoolId: CONFIGURATION.userPoolId,
73
+ ClientId: CONFIGURATION.clientId,
74
+ };
75
+
76
+ const userPool = new AmazonCognitoIdentity.CognitoUserPool(poolData);
77
+ const authData = {
78
+ Username: params.email,
79
+ Password: params.password,
80
+ };
81
+
82
+ const authDetails = new AmazonCognitoIdentity.AuthenticationDetails(authData);
83
+ const userData = {
84
+ Username: params.email,
85
+ Pool: userPool,
86
+ };
87
87
 
88
- const cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData);
88
+ const cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData);
89
89
 
90
- return new Promise((resolve, reject) => {
91
- cognitoUser.authenticateUser(authDetails, {
92
- onSuccess: async (result) => {
93
- const user = result;
94
- const config = await setAuthContext(user, params);
90
+ return new Promise((resolve, reject) => {
91
+ cognitoUser.authenticateUser(authDetails, {
92
+ onSuccess: async (result) => {
93
+ const user = result;
94
+ const config = await setAuthContext(user, params);
95
95
 
96
- resolve(config);
97
- },
98
- onFailure: (err) => {
99
- reject(err);
100
- },
101
- });
96
+ resolve(config);
97
+ },
98
+ onFailure: (err) => {
99
+ reject(err);
100
+ },
102
101
  });
102
+ });
103
103
  }
104
104
 
105
105
  async function setAuthContext(user, params): Promise<AuthContext> {
106
- const config = await getConfig();
107
- let apiGateway;
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]
120
- } else {
121
- apiGateway = 'https://api.vibeiq.com/prod/api';
122
- }
106
+ const config = await getConfig();
107
+ let apiGateway;
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];
120
+ } else {
121
+ apiGateway = 'https://api.vibeiq.com/prod/api';
122
+ }
123
123
 
124
- // Set Auth Config
125
- Auth.config = {
126
- apiUserToken: user.idToken.jwtToken,
127
- apiGateway,
128
- orgSlug: params.orgSlug,
129
- };
130
- // SET SDK CONFIG
131
- setSdkConfig(Auth.config);
124
+ // Set Auth Config
125
+ Auth.config = {
126
+ apiUserToken: user.idToken.jwtToken,
127
+ apiGateway,
128
+ orgSlug: params.orgSlug,
129
+ };
130
+ // SET SDK CONFIG
131
+ setSdkConfig(Auth.config);
132
132
 
133
- return refreshCurrentUserOrg();
133
+ return refreshCurrentUserOrg();
134
134
  }
135
135
 
136
136
  async function refreshCurrentUserOrg() {
137
- console.debug("refreshing current user org")
138
- const currentUser = await Request.request('/users/current', {
139
- method: 'GET',
140
- headers: {
141
- 'Accept': 'application/json',
142
- 'Content-Type': 'application/json',
143
- },
144
- });
145
- if (!currentUser) {
146
- throw Error('Could not get current user');
147
- }
148
- const org = currentUser.orgs.find(o => o.orgSlug === Auth.config.orgSlug);
149
- if (org) {
150
- Auth.config.orgId = org.orgId || org.id;
151
- }
152
- // cache config in the fs
153
- storeConfig(Object.assign({}, Auth.config))
154
- return Object.assign({}, Auth.config);
137
+ console.debug('refreshing current user org');
138
+ const currentUser = await Request.request('/users/current', {
139
+ method: 'GET',
140
+ headers: {
141
+ Accept: 'application/json',
142
+ 'Content-Type': 'application/json',
143
+ },
144
+ });
145
+ if (!currentUser) {
146
+ throw Error('Could not get current user');
147
+ }
148
+ const org = currentUser.orgs.find(o => o.orgSlug === Auth.config.orgSlug);
149
+ if (org) {
150
+ Auth.config.orgId = org.orgId || org.id;
151
+ }
152
+ // cache config in the fs
153
+ storeConfig(Object.assign({}, Auth.config));
154
+ return Object.assign({}, Auth.config);
155
155
  }