@extrahorizon/exh-cli 1.13.0-dev-184-fd0c8a4 → 1.13.0-dev-186-c780c87

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/build/exh.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { OAuth1Client } from '@extrahorizon/javascript-sdk';
2
- export declare function sdkInitOnly(apiHost: string, consumerKey: string, consumerSecret: string): OAuth1Client;
3
2
  export declare function sdkAuth(): Promise<OAuth1Client>;
4
3
  export declare function getSdk(): OAuth1Client;
5
4
  export declare function getNewSdkInstance(): OAuth1Client;
5
+ export declare function writeCredentialsToFile(host: string, consumerKey: string, consumerSecret: string, token: string, tokenSecret: string): void;
package/build/exh.js CHANGED
@@ -1,25 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getNewSdkInstance = exports.getSdk = exports.sdkAuth = exports.sdkInitOnly = void 0;
3
+ exports.writeCredentialsToFile = exports.getNewSdkInstance = exports.getSdk = exports.sdkAuth = void 0;
4
+ const fs = require("fs");
4
5
  const javascript_sdk_1 = require("@extrahorizon/javascript-sdk");
5
- const util_1 = require("./helpers/util");
6
+ const chalk = require("chalk");
7
+ const constants_1 = require("./constants");
6
8
  let sdk = null;
7
- function sdkInitOnly(apiHost, consumerKey, consumerSecret) {
8
- sdk = (0, javascript_sdk_1.createOAuth1Client)({
9
- consumerKey,
10
- consumerSecret,
11
- host: apiHost,
12
- });
13
- return sdk;
14
- }
15
- exports.sdkInitOnly = sdkInitOnly;
16
9
  async function sdkAuth() {
17
- (0, util_1.loadAndAssertCredentials)();
18
- sdk = (0, javascript_sdk_1.createOAuth1Client)({
19
- host: process.env.API_HOST,
20
- consumerKey: process.env.API_OAUTH_CONSUMER_KEY,
21
- consumerSecret: process.env.API_OAUTH_CONSUMER_SECRET,
22
- });
10
+ loadAndAssertCredentials();
11
+ sdk = getNewSdkInstance();
23
12
  try {
24
13
  await sdk.auth.authenticate({
25
14
  token: process.env.API_OAUTH_TOKEN,
@@ -47,3 +36,47 @@ function getNewSdkInstance() {
47
36
  });
48
37
  }
49
38
  exports.getNewSdkInstance = getNewSdkInstance;
39
+ function loadAndAssertCredentials() {
40
+ const credentials = {};
41
+ let errorMessage = '';
42
+ try {
43
+ const credentialsFile = fs.readFileSync(constants_1.EXH_CONFIG_FILE, 'utf-8');
44
+ const credentialFileLines = credentialsFile.split(/\r?\n/);
45
+ for (const credentialFileLine of credentialFileLines) {
46
+ const [key, value] = credentialFileLine.split('=');
47
+ if (key && value) {
48
+ credentials[key.trim()] = value.trim();
49
+ }
50
+ }
51
+ }
52
+ catch (e) {
53
+ errorMessage += 'Couldn\'t open ~/.exh/credentials. ';
54
+ }
55
+ const requiredEnvVariables = ['API_HOST', 'API_OAUTH_CONSUMER_KEY', 'API_OAUTH_CONSUMER_SECRET', 'API_OAUTH_TOKEN', 'API_OAUTH_TOKEN_SECRET'];
56
+ for (const key of requiredEnvVariables) {
57
+ if (credentials[key] && !process.env[key]) {
58
+ process.env[key] = credentials[key];
59
+ }
60
+ }
61
+ const missingEnvironmentVariables = requiredEnvVariables.filter(key => !process.env[key]);
62
+ if (missingEnvironmentVariables.length > 0) {
63
+ errorMessage += `Missing environment variables: ${missingEnvironmentVariables.join(',')}`;
64
+ throw new Error(`Failed to retrieve all credentials. ${errorMessage}`);
65
+ }
66
+ }
67
+ function writeCredentialsToFile(host, consumerKey, consumerSecret, token, tokenSecret) {
68
+ try {
69
+ fs.statSync(constants_1.EXH_CONFIG_FILE_DIR);
70
+ }
71
+ catch (err) {
72
+ fs.mkdirSync(constants_1.EXH_CONFIG_FILE_DIR);
73
+ }
74
+ fs.writeFileSync(constants_1.EXH_CONFIG_FILE, `API_HOST=${host}
75
+ API_OAUTH_CONSUMER_KEY=${consumerKey}
76
+ API_OAUTH_CONSUMER_SECRET=${consumerSecret}
77
+ API_OAUTH_TOKEN=${token}
78
+ API_OAUTH_TOKEN_SECRET=${tokenSecret}
79
+ `);
80
+ console.log(chalk.green('Wrote credentials to', constants_1.EXH_CONFIG_FILE));
81
+ }
82
+ exports.writeCredentialsToFile = writeCredentialsToFile;
@@ -1,7 +1,6 @@
1
1
  import * as yargs from 'yargs';
2
2
  export declare function epilogue(y: yargs.Argv): yargs.Argv;
3
3
  export declare function asyncExec(cmd: string): Promise<string>;
4
- export declare function loadAndAssertCredentials(): void;
5
4
  export declare function getSwaggerDocumentationUrl(subPath: string): string;
6
5
  export declare function ajvValidate<T>(schema: any, data: any): asserts data is T;
7
6
  export declare function getAjvErrorStrings(errors: any[]): string[];
@@ -1,12 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getAjvErrorStrings = exports.ajvValidate = exports.getSwaggerDocumentationUrl = exports.loadAndAssertCredentials = exports.asyncExec = exports.epilogue = void 0;
3
+ exports.getAjvErrorStrings = exports.ajvValidate = exports.getSwaggerDocumentationUrl = exports.asyncExec = exports.epilogue = void 0;
4
4
  const child_process_1 = require("child_process");
5
5
  const fs = require("fs");
6
6
  const path = require("path");
7
7
  const ajv_1 = require("ajv");
8
8
  const chalk = require("chalk");
9
- const constants_1 = require("../constants");
10
9
  const error_1 = require("./error");
11
10
  function epilogue(y) {
12
11
  return y.epilogue('Visit https://docs.extrahorizon.com/extrahorizon-cli/ for more information.').fail((msg, err, argv) => {
@@ -38,35 +37,6 @@ async function asyncExec(cmd) {
38
37
  });
39
38
  }
40
39
  exports.asyncExec = asyncExec;
41
- function loadAndAssertCredentials() {
42
- const credentials = {};
43
- let errorMessage = '';
44
- try {
45
- const credentialsFile = fs.readFileSync(constants_1.EXH_CONFIG_FILE, 'utf-8');
46
- const credentialFileLines = credentialsFile.split(/\r?\n/);
47
- for (const credentialFileLine of credentialFileLines) {
48
- const [key, value] = credentialFileLine.split('=');
49
- if (key && value) {
50
- credentials[key.trim()] = value.trim();
51
- }
52
- }
53
- }
54
- catch (e) {
55
- errorMessage += 'Couldn\'t open ~/.exh/credentials. ';
56
- }
57
- const requiredEnvVariables = ['API_HOST', 'API_OAUTH_CONSUMER_KEY', 'API_OAUTH_CONSUMER_SECRET', 'API_OAUTH_TOKEN', 'API_OAUTH_TOKEN_SECRET'];
58
- for (const key of requiredEnvVariables) {
59
- if (credentials[key] && !process.env[key]) {
60
- process.env[key] = credentials[key];
61
- }
62
- }
63
- const missingEnvironmentVariables = requiredEnvVariables.filter(key => !process.env[key]);
64
- if (missingEnvironmentVariables.length > 0) {
65
- errorMessage += `Missing environment variables: ${missingEnvironmentVariables.join(',')}`;
66
- throw new Error(`Failed to retrieve all credentials. ${errorMessage}`);
67
- }
68
- }
69
- exports.loadAndAssertCredentials = loadAndAssertCredentials;
70
40
  function getSwaggerDocumentationUrl(subPath) {
71
41
  const packageJsonPath = path.join(__dirname, '../../package.json');
72
42
  const packageJsonString = fs.readFileSync(packageJsonPath, 'utf-8');
@@ -1,30 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.whoami = exports.login = void 0;
4
- const fs = require("fs/promises");
5
- const chalk = require("chalk");
6
- const constants_1 = require("../constants");
4
+ const javascript_sdk_1 = require("@extrahorizon/javascript-sdk");
7
5
  const exh_1 = require("../exh");
8
6
  const authRepository = require("../repositories/auth");
9
7
  async function login(host, email, password, consumerKey, consumerSecret) {
10
- const sdk = (0, exh_1.sdkInitOnly)(host, consumerKey, consumerSecret);
8
+ const sdk = (0, javascript_sdk_1.createOAuth1Client)({
9
+ consumerKey,
10
+ consumerSecret,
11
+ host,
12
+ });
11
13
  const response = await sdk.auth.authenticate({
12
14
  email,
13
15
  password,
14
16
  });
15
- try {
16
- await fs.stat(constants_1.EXH_CONFIG_FILE_DIR);
17
- }
18
- catch (err) {
19
- await fs.mkdir(constants_1.EXH_CONFIG_FILE_DIR);
20
- }
21
- await fs.writeFile(constants_1.EXH_CONFIG_FILE, `API_HOST=${host}
22
- API_OAUTH_CONSUMER_KEY=${consumerKey}
23
- API_OAUTH_CONSUMER_SECRET=${consumerSecret}
24
- API_OAUTH_TOKEN=${response.token}
25
- API_OAUTH_TOKEN_SECRET=${response.tokenSecret}
26
- `);
27
- console.log(chalk.green('Wrote credentials to', constants_1.EXH_CONFIG_FILE));
17
+ (0, exh_1.writeCredentialsToFile)(host, consumerKey, consumerSecret, response.token, response.tokenSecret);
28
18
  }
29
19
  exports.login = login;
30
20
  async function whoami() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@extrahorizon/exh-cli",
3
- "version": "1.13.0-dev-184-fd0c8a4",
3
+ "version": "1.13.0-dev-186-c780c87",
4
4
  "main": "build/index.js",
5
5
  "exports": "./build/index.js",
6
6
  "license": "MIT",