@contrail/cli 3.6.0-alpha-8-alpha.2ad94f7 → 3.6.0-alpha-8-alpha.193f9cf

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/README.md CHANGED
@@ -17,7 +17,7 @@ $ npm install -g @contrail/cli
17
17
  $ contrail COMMAND
18
18
  running command...
19
19
  $ contrail (--version)
20
- @contrail/cli/3.6.0-alpha-8-alpha.2ad94f7 linux-x64 node-v24.22.1
20
+ @contrail/cli/3.6.0-alpha-8-alpha.193f9cf linux-x64 node-v24.22.1
21
21
  $ contrail --help [COMMAND]
22
22
  USAGE
23
23
  $ contrail COMMAND
@@ -499,7 +499,7 @@ Set a variable in the configuration
499
499
  ```
500
500
  USAGE
501
501
  $ contrail config set [-l error|warn|info|debug] [-e true|false] [--orgSlug <value>] [--environment
502
- dev|development|prod|production|local] [--apiUserToken <value>] [--config <value>]
502
+ dev|development|prod|production] [--apiUserToken <value>] [--config <value>]
503
503
 
504
504
  FLAGS
505
505
  -e, --alwaysConfirmEnv=<option> [default: true] The Environment variables
@@ -509,7 +509,7 @@ FLAGS
509
509
  --apiUserToken=<value> The API User Token
510
510
  --config=<value> The config name
511
511
  --environment=<option> The Environment
512
- <options: dev|development|prod|production|local>
512
+ <options: dev|development|prod|production>
513
513
  --orgSlug=<value> The org slug
514
514
 
515
515
  DESCRIPTION
@@ -37,14 +37,7 @@ async function authUser() {
37
37
  };
38
38
  (0, sdk_1.setConfig)(sdk_1.Auth.config);
39
39
  try {
40
- // hacky retry policy
41
- return await refreshCurrentUserOrg().catch(async () => {
42
- await (0, common_1.delay)(100);
43
- return await refreshCurrentUserOrg().catch(async () => {
44
- await (0, common_1.delay)(1000);
45
- return await refreshCurrentUserOrg();
46
- });
47
- });
40
+ return await refreshCurrentUserOrg();
48
41
  }
49
42
  catch (e) {
50
43
  if (isNetworkConnectionError(e)) {
@@ -54,9 +47,7 @@ async function authUser() {
54
47
  logger_1.default.info(`Failed to refresh token: ${e}. Requesting auth credentials...`);
55
48
  }
56
49
  }
57
- const authContext = await authenticateWithUsernamePassword(config);
58
- await (0, config_1.storeConfig)(authContext);
59
- return authContext;
50
+ return await authenticateWithUsernamePassword(config);
60
51
  }
61
52
  exports.authUser = authUser;
62
53
  async function getOrgSlug(config) {
@@ -78,22 +69,21 @@ async function authenticateWithApiKey(config, apiKey, orgSlug) {
78
69
  const apiGateway = getApiGateway(config);
79
70
  sdk_1.Auth.config = {
80
71
  apiUserToken: apiKey,
81
- apiRefreshToken: undefined,
72
+ apiRefreshToken: null,
82
73
  apiGateway,
83
74
  orgSlug,
84
75
  };
85
76
  (0, sdk_1.setConfig)(sdk_1.Auth.config);
86
77
  await (0, sdk_1.getCurrentUser)();
87
- await (0, config_1.storeConfig)(sdk_1.Auth.config);
88
- return Object.assign({}, sdk_1.Auth.config);
78
+ return returnAndStoreConfig(sdk_1.Auth.config);
89
79
  }
90
80
  async function authenticateWithUsernamePassword(config) {
91
81
  const apiGateway = getApiGateway(config);
92
82
  const environment = (0, config_1.findEnvironmentName)(apiGateway);
93
- const cognitoConfig = environment ? COGNITO_CONFIGS[environment] : undefined;
94
- if (!environment || !cognitoConfig) {
83
+ if (!environment) {
95
84
  throw new Error(`No Cognito user pool is known for ${apiGateway}. Email and password sign-in works for ${Object.keys(COGNITO_CONFIGS).join(' and ')}; use CONTRAIL_CLI_API_KEY for other environments.`);
96
85
  }
86
+ const cognitoConfig = COGNITO_CONFIGS[environment];
97
87
  const questions = [];
98
88
  if (!process.env.CONTRAIL_CLI_EMAIL) {
99
89
  questions.push({
@@ -172,9 +162,8 @@ async function setAuthContext(user, params) {
172
162
  async function refreshCurrentUserOrg() {
173
163
  logger_1.default.debug('refreshing current user org...');
174
164
  const currentUser = await (0, sdk_1.getCurrentUser)().catch((e) => {
175
- console.error('error getting current user', e.message);
176
165
  if (isExpiredTokenError(e)) {
177
- console.error('access token expired; attempting refresh');
166
+ logger_1.default.debug('access token expired; attempting refresh');
178
167
  return;
179
168
  }
180
169
  throw e;
@@ -194,12 +183,11 @@ async function refreshCurrentUserOrg() {
194
183
  catch (e) {
195
184
  throw Error(`Could not get refresh token: ${e}`);
196
185
  }
197
- await (0, config_1.storeConfig)(sdk_1.Auth.config);
198
186
  }
199
187
  // TODO: To uncomment when telemetry backend is developed.
200
188
  // const current_Version = getVersionFromPackageJson();
201
189
  // await checkTelemetry(current_Version);
202
- return Object.assign({}, sdk_1.Auth.config);
190
+ return returnAndStoreConfig(sdk_1.Auth.config);
203
191
  }
204
192
  function isExpiredTokenError(e) {
205
193
  return e?.message?.includes('token is expired');
@@ -250,6 +238,11 @@ function getVersionFromPackageJson() {
250
238
  return packageJson.version;
251
239
  }
252
240
  exports.getVersionFromPackageJson = getVersionFromPackageJson;
241
+ async function returnAndStoreConfig(config) {
242
+ const configCopy = Object.assign({}, config);
243
+ await (0, config_1.storeConfig)(configCopy);
244
+ return configCopy;
245
+ }
253
246
  function isNetworkConnectionError(e) {
254
247
  const cause = e?.cause;
255
248
  return cause?.code === 'ENOTFOUND' || cause?.code === 'ECONNREFUSED';
@@ -8,9 +8,7 @@ export declare abstract class BaseCommand extends Command {
8
8
  logLevel: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
9
9
  };
10
10
  protected flags: any;
11
- protected args: {
12
- [key: string]: any;
13
- };
11
+ protected args: any;
14
12
  init(): Promise<void>;
15
13
  setLogLevel(logLevel: string, config?: any): void;
16
14
  private confirmEnv;
@@ -17,7 +17,7 @@ class BaseCommand extends core_1.Command {
17
17
  ...baseFlags_1.baseFlags,
18
18
  };
19
19
  flags;
20
- args = {};
20
+ args;
21
21
  async init() {
22
22
  await super.init();
23
23
  if (!this.ctor?.flags)
@@ -15,7 +15,7 @@ class SetConfig extends basecommand_1.BaseCommand {
15
15
  environment: core_1.Flags.string({
16
16
  description: 'The Environment',
17
17
  required: false,
18
- options: ['dev', 'development', 'prod', 'production', 'local'],
18
+ options: ['dev', 'development', 'prod', 'production'],
19
19
  }),
20
20
  apiUserToken: core_1.Flags.string({
21
21
  description: 'The API User Token',
@@ -1,7 +1,6 @@
1
1
  export declare const ENVIRONMENTS: {
2
2
  dev: string;
3
3
  prod: string;
4
- local: string;
5
4
  };
6
5
  export type EnvironmentName = keyof typeof ENVIRONMENTS;
7
6
  export declare function findEnvironmentName(apiGateway: string): EnvironmentName | undefined;
@@ -15,7 +15,6 @@ const defaultConfigFileLocation = (0, node_path_1.join)(configDirectoryLocation,
15
15
  exports.ENVIRONMENTS = {
16
16
  dev: 'https://api.dev.vibeiq.com/dev/api',
17
17
  prod: 'https://api.vibeiq.com/prod/api',
18
- local: 'http://localhost:3000/api',
19
18
  };
20
19
  function findEnvironmentName(apiGateway) {
21
20
  const normalizedGateway = apiGateway?.trim().replace(/\/+$/, '').toLowerCase();
@@ -98,7 +97,7 @@ async function writeConfig(config, configName = null) {
98
97
  const fileContent = await readVibeIQConfig();
99
98
  configFileName = fileContent.configInUse;
100
99
  }
101
- atomicFileWriteSync((0, node_path_1.join)(configDirectoryLocation, `${configFileName}.json`), JSON.stringify(config, null, 2));
100
+ await node_fs_1.promises.writeFile((0, node_path_1.join)(configDirectoryLocation, `${configFileName}.json`), JSON.stringify(config, null, 2));
102
101
  }
103
102
  catch (error) {
104
103
  logger_1.default.error('Could not open config file for writing.');
@@ -106,12 +105,6 @@ async function writeConfig(config, configName = null) {
106
105
  }
107
106
  }
108
107
  exports.writeConfig = writeConfig;
109
- function atomicFileWriteSync(filePath, data) {
110
- const randomId = Math.random().toString(36).substring(2, 15);
111
- const tmpFilepath = `${filePath}.tmp-${randomId}`;
112
- (0, node_fs_1.writeFileSync)(tmpFilepath, data);
113
- (0, node_fs_1.renameSync)(tmpFilepath, filePath);
114
- }
115
108
  async function getConfig() {
116
109
  let fileContent;
117
110
  try {
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "3.6.0-alpha-8-alpha.2ad94f7",
2
+ "version": "3.6.0-alpha-8-alpha.193f9cf",
3
3
  "commands": {
4
4
  "app:create": {
5
5
  "id": "app:create",
@@ -604,8 +604,7 @@
604
604
  "dev",
605
605
  "development",
606
606
  "prod",
607
- "production",
608
- "local"
607
+ "production"
609
608
  ]
610
609
  },
611
610
  "apiUserToken": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/cli",
3
- "version": "3.6.0-alpha-8-alpha.2ad94f7",
3
+ "version": "3.6.0-alpha-8-alpha.193f9cf",
4
4
  "description": "VibeIQ's Contrail Platform CLI.",
5
5
  "bin": {
6
6
  "contrail-cli": "./bin/run",