@quantum-hub/qhubctl 2.2.2-next.1 → 2.2.3-next.1

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 (74) hide show
  1. package/README.md +4 -2
  2. package/dist/commands/compress.d.ts +1 -1
  3. package/dist/commands/compress.js +15 -15
  4. package/dist/commands/datapool-upload.d.ts +1 -1
  5. package/dist/commands/datapool-upload.js +35 -35
  6. package/dist/commands/get-context.d.ts +1 -1
  7. package/dist/commands/get-context.js +5 -5
  8. package/dist/commands/init.d.ts +1 -1
  9. package/dist/commands/init.js +33 -29
  10. package/dist/commands/list-contexts.d.ts +1 -1
  11. package/dist/commands/list-contexts.js +21 -13
  12. package/dist/commands/login.d.ts +1 -1
  13. package/dist/commands/login.js +16 -16
  14. package/dist/commands/logout.d.ts +1 -1
  15. package/dist/commands/logout.js +10 -10
  16. package/dist/commands/openapi.d.ts +1 -1
  17. package/dist/commands/openapi.js +112 -94
  18. package/dist/commands/run.d.ts +3 -3
  19. package/dist/commands/run.js +37 -34
  20. package/dist/commands/serve.d.ts +1 -1
  21. package/dist/commands/serve.js +30 -19
  22. package/dist/commands/services-build-logs.d.ts +2 -2
  23. package/dist/commands/services-build-logs.js +26 -26
  24. package/dist/commands/services-build-status.d.ts +1 -1
  25. package/dist/commands/services-build-status.js +21 -21
  26. package/dist/commands/services-list.d.ts +1 -1
  27. package/dist/commands/services-list.js +20 -17
  28. package/dist/commands/set-context.d.ts +1 -1
  29. package/dist/commands/set-context.js +18 -16
  30. package/dist/commands/up.d.ts +1 -1
  31. package/dist/commands/up.js +50 -48
  32. package/dist/index.d.ts +1 -1
  33. package/dist/index.js +1 -1
  34. package/dist/lib/command.js +2 -2
  35. package/dist/lib/config-dir.js +3 -3
  36. package/dist/lib/debug.js +1 -1
  37. package/dist/lib/entrypoint-resolver.js +15 -15
  38. package/dist/lib/error.js +4 -4
  39. package/dist/lib/fetch.js +3 -1
  40. package/dist/lib/init-user-input.d.ts +1 -1
  41. package/dist/lib/init-user-input.js +28 -26
  42. package/dist/lib/output.d.ts +2 -2
  43. package/dist/lib/output.js +3 -3
  44. package/dist/lib/random-name.js +147 -147
  45. package/dist/lib/random-string.js +2 -2
  46. package/dist/lib/repository.js +5 -5
  47. package/dist/lib/stream-to-blob.d.ts +1 -1
  48. package/dist/lib/stream-to-blob.js +5 -5
  49. package/dist/lib/up/get-description.js +8 -8
  50. package/dist/lib/up/ignore.js +8 -8
  51. package/dist/lib/up/qhubignore-help.js +10 -10
  52. package/dist/lib/up/required-files.js +17 -12
  53. package/dist/lib/up/source.d.ts +2 -2
  54. package/dist/lib/up/source.js +7 -7
  55. package/dist/lib/up/zip.js +8 -8
  56. package/dist/main.js +3 -3
  57. package/dist/model/command.d.ts +2 -2
  58. package/dist/model/command.js +9 -9
  59. package/dist/model/managed-service-config.d.ts +1 -1
  60. package/dist/model/user-config.js +1 -1
  61. package/dist/program.d.ts +1 -1
  62. package/dist/program.js +24 -24
  63. package/dist/service/auth-service.d.ts +3 -3
  64. package/dist/service/auth-service.js +11 -9
  65. package/dist/service/command-service.d.ts +1 -1
  66. package/dist/service/quantum-hub-service.d.ts +3 -3
  67. package/dist/service/quantum-hub-service.js +34 -20
  68. package/dist/service/service-config-service.d.ts +1 -1
  69. package/dist/service/service-config-service.js +8 -8
  70. package/dist/service/user-config-service.d.ts +1 -1
  71. package/dist/service/user-config-service.js +7 -7
  72. package/dist/service/user-service.d.ts +2 -2
  73. package/dist/service/user-service.js +4 -4
  74. package/package.json +9 -3
package/README.md CHANGED
@@ -114,10 +114,12 @@ npm test # run tests + lint
114
114
  npm run test:coverage # run tests with lcov coverage report
115
115
  ```
116
116
 
117
- ### Lint
117
+ ### Lint and format
118
118
 
119
119
  ```bash
120
- npm run lint
120
+ npm run lint # eslint + prettier --check
121
+ npm run lint:code:fix # eslint --fix
122
+ npm run format # prettier --write
121
123
  ```
122
124
 
123
125
  ### Generate docs
@@ -1,2 +1,2 @@
1
- import { Command } from 'commander';
1
+ import { Command } from "commander";
2
2
  export declare const compressCommand: Command;
@@ -1,32 +1,32 @@
1
- import { Command } from 'commander';
2
- import fs from 'fs-extra';
3
- import path from 'node:path';
4
- import { zipProjectFolder } from '../lib/up/zip.js';
5
- import { enforceRequiredFiles } from '../lib/up/required-files.js';
6
- import { QHUBIGNORE_HELP } from '../lib/up/qhubignore-help.js';
7
- import { error, spinner, stdout } from '../lib/output.js';
1
+ import { Command } from "commander";
2
+ import fs from "fs-extra";
3
+ import path from "node:path";
4
+ import { zipProjectFolder } from "../lib/up/zip.js";
5
+ import { enforceRequiredFiles } from "../lib/up/required-files.js";
6
+ import { QHUBIGNORE_HELP } from "../lib/up/qhubignore-help.js";
7
+ import { error, spinner, stdout } from "../lib/output.js";
8
8
  const EXAMPLES = `
9
9
  Examples:
10
10
  $ qhubctl compress`;
11
- export const compressCommand = new Command('compress')
11
+ export const compressCommand = new Command("compress")
12
12
  .description(`Compresses the current project and creates a ZIP file. ${QHUBIGNORE_HELP}`)
13
- .addHelpText('after', EXAMPLES)
13
+ .addHelpText("after", EXAMPLES)
14
14
  .action(async () => {
15
- const spin = spinner('Compressing project');
15
+ const spin = spinner("Compressing project");
16
16
  const targetDirectory = process.cwd();
17
- const targetFilename = 'service.zip';
18
- const targetFilePath = path.join(targetDirectory, '/', targetFilename);
17
+ const targetFilename = "service.zip";
18
+ const targetFilePath = path.join(targetDirectory, "/", targetFilename);
19
19
  try {
20
20
  await enforceRequiredFiles(targetDirectory);
21
21
  }
22
22
  catch (err) {
23
- spin.fail('Compression aborted');
23
+ spin.fail("Compression aborted");
24
24
  error(err.message);
25
25
  }
26
26
  if (fs.existsSync(targetFilePath)) {
27
27
  fs.unlinkSync(targetFilePath);
28
28
  }
29
- await zipProjectFolder('./', targetDirectory, targetFilename);
30
- spin.succeed('Project compressed');
29
+ await zipProjectFolder("./", targetDirectory, targetFilename);
30
+ spin.succeed("Project compressed");
31
31
  stdout(`\nFile created at: ${targetFilePath}`);
32
32
  });
@@ -1,2 +1,2 @@
1
- import { Command } from 'commander';
1
+ import { Command } from "commander";
2
2
  export declare const datapoolUploadCommand: Command;
@@ -1,10 +1,10 @@
1
- import { input, select } from '@inquirer/prompts';
2
- import { Command } from 'commander';
3
- import fs from 'node:fs';
4
- import path from 'node:path';
5
- import { spinner, stdout } from '../lib/output.js';
6
- import { requireAuth } from '../model/command.js';
7
- import { HubPlatformClient, HubPlatformError } from '@quantum-hub/qhub-api/platform';
1
+ import { input, select } from "@inquirer/prompts";
2
+ import { Command } from "commander";
3
+ import fs from "node:fs";
4
+ import path from "node:path";
5
+ import { spinner, stdout } from "../lib/output.js";
6
+ import { requireAuth } from "../model/command.js";
7
+ import { HubPlatformClient, HubPlatformError } from "@quantum-hub/qhub-api/platform";
8
8
  function extractError(err) {
9
9
  const bodyObj = err.body;
10
10
  if (bodyObj.errorMessage)
@@ -33,11 +33,11 @@ function printHttpSpecificError(datapoolId, statusCode, errorMessage) {
33
33
  function handleUploadError(err, datapoolId) {
34
34
  if (err instanceof HubPlatformError) {
35
35
  const statusCode = err.statusCode ?? 500;
36
- let errorMessage = 'Unknown API error occurred';
36
+ let errorMessage = "Unknown API error occurred";
37
37
  if (err.body) {
38
- if (typeof err.body === 'string')
38
+ if (typeof err.body === "string")
39
39
  errorMessage = err.body;
40
- else if (typeof err.body === 'object')
40
+ else if (typeof err.body === "object")
41
41
  errorMessage = extractError(err);
42
42
  else if (err.message)
43
43
  errorMessage = err.message;
@@ -45,7 +45,7 @@ function handleUploadError(err, datapoolId) {
45
45
  else if (err.message) {
46
46
  errorMessage = err.message;
47
47
  }
48
- printHttpSpecificError(datapoolId || 'unknown', statusCode, errorMessage);
48
+ printHttpSpecificError(datapoolId || "unknown", statusCode, errorMessage);
49
49
  }
50
50
  const msg = err instanceof Error ? err.message : String(err);
51
51
  throw new Error(`Unexpected Error: ${msg}`);
@@ -54,26 +54,26 @@ async function promptForDatapoolAction(client) {
54
54
  try {
55
55
  const dataPools = await client.dataPools.getDataPools();
56
56
  if (dataPools.length === 0) {
57
- stdout('No data pools found. Creating a new one...');
58
- return 'create';
57
+ stdout("No data pools found. Creating a new one...");
58
+ return "create";
59
59
  }
60
60
  return await select({
61
- message: 'What would you like to do?',
61
+ message: "What would you like to do?",
62
62
  choices: [
63
- { name: 'Create a new data pool', value: 'create' },
64
- { name: 'Select an existing data pool', value: 'select' },
63
+ { name: "Create a new data pool", value: "create" },
64
+ { name: "Select an existing data pool", value: "select" },
65
65
  ],
66
- default: 'create',
66
+ default: "create",
67
67
  });
68
68
  }
69
69
  catch {
70
- return 'create';
70
+ return "create";
71
71
  }
72
72
  }
73
73
  async function createDatapool(client, suggestedName) {
74
74
  try {
75
75
  const name = await input({
76
- message: 'Enter a name for the new data pool:',
76
+ message: "Enter a name for the new data pool:",
77
77
  default: `Data Pool for ${suggestedName}`,
78
78
  });
79
79
  const datapool = await client.dataPools.createDataPool({ name });
@@ -82,7 +82,7 @@ async function createDatapool(client, suggestedName) {
82
82
  }
83
83
  catch (err) {
84
84
  if (err instanceof HubPlatformError) {
85
- const errorMessage = err.body || err.message || 'Unknown API error occurred';
85
+ const errorMessage = err.body || err.message || "Unknown API error occurred";
86
86
  throw new Error(`Failed to create data pool (HTTP ${err.statusCode}): ${JSON.stringify(errorMessage)}`, { cause: err });
87
87
  }
88
88
  const msg = err instanceof Error ? err.message : String(err);
@@ -93,10 +93,10 @@ async function selectExistingDatapool(client) {
93
93
  try {
94
94
  const dataPools = await client.dataPools.getDataPools();
95
95
  if (dataPools.length === 0) {
96
- stdout('No existing data pools found. Creating a new one...');
97
- return createDatapool(client, 'upload');
96
+ stdout("No existing data pools found. Creating a new one...");
97
+ return createDatapool(client, "upload");
98
98
  }
99
- stdout('\nAvailable data pools:');
99
+ stdout("\nAvailable data pools:");
100
100
  dataPools.forEach((pool, index) => {
101
101
  stdout(`${index + 1}. ${pool.name} (${pool.id})`);
102
102
  });
@@ -110,14 +110,14 @@ async function selectExistingDatapool(client) {
110
110
  return selection;
111
111
  }
112
112
  catch {
113
- throw new Error('Failed to retrieve data pools');
113
+ throw new Error("Failed to retrieve data pools");
114
114
  }
115
115
  }
116
116
  async function ensureDatapoolExists(client, datapoolId, filePaths) {
117
117
  if (!datapoolId) {
118
- stdout('No data pool ID provided. You can create a new data pool or select an existing one.');
118
+ stdout("No data pool ID provided. You can create a new data pool or select an existing one.");
119
119
  const action = await promptForDatapoolAction(client);
120
- return action === 'create'
120
+ return action === "create"
121
121
  ? createDatapool(client, filePaths[0])
122
122
  : selectExistingDatapool(client);
123
123
  }
@@ -129,7 +129,7 @@ async function ensureDatapoolExists(client, datapoolId, filePaths) {
129
129
  if (err instanceof HubPlatformError && err.statusCode === 404) {
130
130
  stdout(`Data pool ${datapoolId} not found. Would you like to create a new data pool instead?`);
131
131
  const action = await promptForDatapoolAction(client);
132
- return action === 'create'
132
+ return action === "create"
133
133
  ? createDatapool(client, filePaths[0])
134
134
  : selectExistingDatapool(client);
135
135
  }
@@ -141,11 +141,11 @@ Examples:
141
141
  $ qhubctl datapool upload --file ./data/dataset.csv
142
142
  $ qhubctl datapool upload --file ./data/dataset.csv --file ./data/metadata.json
143
143
  $ qhubctl datapool upload -f ./data/dataset.csv -f ./data/metadata.json --datapool-id 550e8400-e29b-41d4-a716-446655440000`;
144
- export const datapoolUploadCommand = new Command('upload')
145
- .description('Upload files to a data pool')
146
- .requiredOption('-f, --file <value...>', 'Path to a file to upload (can be specified multiple times)')
147
- .option('-d, --datapool-id <value>', 'ID of the data pool to upload the files to (optional - will prompt to create a new one if not provided)')
148
- .addHelpText('after', EXAMPLES)
144
+ export const datapoolUploadCommand = new Command("upload")
145
+ .description("Upload files to a data pool")
146
+ .requiredOption("-f, --file <value...>", "Path to a file to upload (can be specified multiple times)")
147
+ .option("-d, --datapool-id <value>", "ID of the data pool to upload the files to (optional - will prompt to create a new one if not provided)")
148
+ .addHelpText("after", EXAMPLES)
149
149
  .action(async (opts) => {
150
150
  const userConfig = await requireAuth();
151
151
  const baseUrl = userConfig.endpoint?.basePath
@@ -156,7 +156,7 @@ export const datapoolUploadCommand = new Command('upload')
156
156
  const client = new HubPlatformClient({
157
157
  baseUrl,
158
158
  apiKey,
159
- headers: { 'X-OrganizationId': organizationId },
159
+ headers: { "X-OrganizationId": organizationId },
160
160
  });
161
161
  const filePaths = opts.file;
162
162
  for (const filePath of filePaths) {
@@ -176,12 +176,12 @@ export const datapoolUploadCommand = new Command('upload')
176
176
  try {
177
177
  const fileStream = fs.createReadStream(filePath);
178
178
  const result = await client.dataPools.addDataPoolFile(datapoolId, { file: fileStream });
179
- spin.succeed('\u2713');
179
+ spin.succeed("\u2713");
180
180
  stdout(`Successfully uploaded ${fileName} to data pool ${datapoolId}`);
181
181
  stdout(`File ID: ${result.id}`);
182
182
  }
183
183
  catch (err) {
184
- spin.fail('\u2717');
184
+ spin.fail("\u2717");
185
185
  handleUploadError(err, datapoolId);
186
186
  }
187
187
  }
@@ -1,2 +1,2 @@
1
- import { Command } from 'commander';
1
+ import { Command } from "commander";
2
2
  export declare const getContextCommand: Command;
@@ -1,11 +1,11 @@
1
- import { Command } from 'commander';
2
- import { requireAuth } from '../model/command.js';
1
+ import { Command } from "commander";
2
+ import { requireAuth } from "../model/command.js";
3
3
  const EXAMPLES = `
4
4
  Examples:
5
5
  $ qhubctl get-context`;
6
- export const getContextCommand = new Command('get-context')
7
- .description('Get the current context, i.e., the personal or organization account you are currently working with.')
8
- .addHelpText('after', EXAMPLES)
6
+ export const getContextCommand = new Command("get-context")
7
+ .description("Get the current context, i.e., the personal or organization account you are currently working with.")
8
+ .addHelpText("after", EXAMPLES)
9
9
  .action(async () => {
10
10
  // requireAuth prints "Current context: ..." as a side-effect
11
11
  await requireAuth();
@@ -1,2 +1,2 @@
1
- import { Command } from 'commander';
1
+ import { Command } from "commander";
2
2
  export declare const initCommand: Command;
@@ -1,40 +1,44 @@
1
- import { Command } from 'commander';
2
- import fs from 'fs-extra';
3
- import path from 'node:path';
4
- import { DEFAULT_STARTER, promptUserInput, resolveServiceDirectory } from '../lib/init-user-input.js';
5
- import { randomName } from '../lib/random-name.js';
6
- import { cloneRepository } from '../lib/repository.js';
7
- import { error, stdout } from '../lib/output.js';
8
- import { Runtime } from '../model/managed-service-config.js';
9
- import { writeServiceConfig } from '../service/service-config-service.js';
1
+ import { Command } from "commander";
2
+ import fs from "fs-extra";
3
+ import path from "node:path";
4
+ import { DEFAULT_STARTER, promptUserInput, resolveServiceDirectory, } from "../lib/init-user-input.js";
5
+ import { randomName } from "../lib/random-name.js";
6
+ import { cloneRepository } from "../lib/repository.js";
7
+ import { error, stdout } from "../lib/output.js";
8
+ import { Runtime } from "../model/managed-service-config.js";
9
+ import { writeServiceConfig } from "../service/service-config-service.js";
10
10
  const EXAMPLES = `
11
11
  Examples:
12
12
  $ qhubctl init
13
13
  $ qhubctl init --non-interactive`;
14
- export const initCommand = new Command('init')
15
- .description('Bootstrap project to create a service.')
16
- .option('--name <value>', 'The name of the service')
17
- .option('--non-interactive', 'Run it in non-interactive mode', false)
18
- .addHelpText('after', EXAMPLES)
14
+ export const initCommand = new Command("init")
15
+ .description("Bootstrap project to create a service.")
16
+ .option("--name <value>", "The name of the service")
17
+ .option("--non-interactive", "Run it in non-interactive mode", false)
18
+ .addHelpText("after", EXAMPLES)
19
19
  .action(async (opts) => {
20
20
  const nonInteractive = opts.nonInteractive;
21
21
  let name = opts.name ?? randomName();
22
- const input = nonInteractive ? {
23
- cpu: 1,
24
- descriptionFile: 'README.md',
25
- gpu: undefined,
26
- memory: 1,
27
- name: name,
28
- starter: DEFAULT_STARTER,
29
- } : await promptUserInput(name);
22
+ const input = nonInteractive
23
+ ? {
24
+ cpu: 1,
25
+ descriptionFile: "README.md",
26
+ gpu: undefined,
27
+ memory: 1,
28
+ name: name,
29
+ starter: DEFAULT_STARTER,
30
+ }
31
+ : await promptUserInput(name);
30
32
  name = input.name || name;
31
- const targetDirectory = input.starter ? path.join(process.cwd(), name) : path.join(process.cwd());
33
+ const targetDirectory = input.starter
34
+ ? path.join(process.cwd(), name)
35
+ : path.join(process.cwd());
32
36
  if (input.starter && fs.existsSync(targetDirectory)) {
33
37
  error(`Destination ${targetDirectory} already exists. Please choose another name.`);
34
38
  }
35
39
  const serviceConfig = {
36
40
  name,
37
- descriptionFile: input.descriptionFile ?? 'README.md',
41
+ descriptionFile: input.descriptionFile ?? "README.md",
38
42
  resources: {
39
43
  cpu: input.cpu,
40
44
  memory: input.memory,
@@ -53,12 +57,12 @@ export const initCommand = new Command('init')
53
57
  }
54
58
  const serviceDirectory = resolveServiceDirectory(targetDirectory, input.starter);
55
59
  writeServiceConfig(serviceDirectory, serviceConfig);
56
- stdout('\u{1F389} Initialized project. Happy hacking!');
60
+ stdout("\u{1F389} Initialized project. Happy hacking!");
57
61
  if (input.starter) {
58
- stdout('\n Next steps:');
62
+ stdout("\n Next steps:");
59
63
  stdout(` \u{2022} cd ${name}`);
60
- stdout(' \u{2022} qhubctl up (deploys your code as a service to Kipu Quantum Hub)');
61
- stdout(' \u{2022} qhubctl run (executes your service using the data from the input directory)');
64
+ stdout(" \u{2022} qhubctl up (deploys your code as a service to Kipu Quantum Hub)");
65
+ stdout(" \u{2022} qhubctl run (executes your service using the data from the input directory)");
62
66
  }
63
- stdout('');
67
+ stdout("");
64
68
  });
@@ -1,2 +1,2 @@
1
- import { Command } from 'commander';
1
+ import { Command } from "commander";
2
2
  export declare const listContextsCommand: Command;
@@ -1,26 +1,34 @@
1
- import { Command } from 'commander';
2
- import Table from 'tty-table';
3
- import { spinner, stdout } from '../lib/output.js';
4
- import { requireAuth } from '../model/command.js';
5
- import QuantumHubService from '../service/quantum-hub-service.js';
1
+ import { Command } from "commander";
2
+ import Table from "tty-table";
3
+ import { spinner, stdout } from "../lib/output.js";
4
+ import { requireAuth } from "../model/command.js";
5
+ import QuantumHubService from "../service/quantum-hub-service.js";
6
6
  const EXAMPLES = `
7
7
  Examples:
8
8
  $ qhubctl list-contexts`;
9
- export const listContextsCommand = new Command('list-contexts')
10
- .description('Retrieves the available contexts, i.e., the personal or organizational accounts available to you to work with.')
11
- .addHelpText('after', EXAMPLES)
9
+ export const listContextsCommand = new Command("list-contexts")
10
+ .description("Retrieves the available contexts, i.e., the personal or organizational accounts available to you to work with.")
11
+ .addHelpText("after", EXAMPLES)
12
12
  .action(async () => {
13
13
  const userConfig = await requireAuth();
14
14
  const quantumHubService = new QuantumHubService(userConfig);
15
- const spin = spinner('Loading available contexts');
15
+ const spin = spinner("Loading available contexts");
16
16
  const accounts = await quantumHubService.getAccounts();
17
- spin.succeed('Contexts loaded');
18
- const tableData = accounts
19
- .map(account => ({ displayName: account.displayName ?? '', id: account.id ?? '', isOrganization: account.isOrganization ?? false }));
17
+ spin.succeed("Contexts loaded");
18
+ const tableData = accounts.map((account) => ({
19
+ displayName: account.displayName ?? "",
20
+ id: account.id ?? "",
21
+ isOrganization: account.isOrganization ?? false,
22
+ }));
20
23
  const header = [
21
24
  { value: "displayName", alias: "Name", align: "left" },
22
25
  { value: "id", alias: "ID", align: "left" },
23
- { value: "isOrganization", alias: "Account", width: 14, formatter: (value) => value ? "Organization" : "Personal" },
26
+ {
27
+ value: "isOrganization",
28
+ alias: "Account",
29
+ width: 14,
30
+ formatter: (value) => (value ? "Organization" : "Personal"),
31
+ },
24
32
  ];
25
33
  const t = Table(header, tableData);
26
34
  stdout(t.render());
@@ -1,2 +1,2 @@
1
- import { Command } from 'commander';
1
+ import { Command } from "commander";
2
2
  export declare const loginCommand: Command;
@@ -1,27 +1,27 @@
1
- import { password } from '@inquirer/prompts';
2
- import { Command } from 'commander';
3
- import { spinner } from '../lib/output.js';
4
- import { configDir, getUserConfig, showBasePathRevertNotice, showCustomBasePathWarning } from '../model/command.js';
5
- import { AuthType, defaultBasePath, hasCustomBasePath, resolveEndpoint } from '../model/user-config.js';
6
- import AuthService from '../service/auth-service.js';
7
- import { writeUserConfig } from '../service/user-config-service.js';
1
+ import { password } from "@inquirer/prompts";
2
+ import { Command } from "commander";
3
+ import { spinner } from "../lib/output.js";
4
+ import { configDir, getUserConfig, showBasePathRevertNotice, showCustomBasePathWarning, } from "../model/command.js";
5
+ import { AuthType, defaultBasePath, hasCustomBasePath, resolveEndpoint, } from "../model/user-config.js";
6
+ import AuthService from "../service/auth-service.js";
7
+ import { writeUserConfig } from "../service/user-config-service.js";
8
8
  const EXAMPLES = `
9
9
  Examples:
10
10
  $ qhubctl login -t <personal access token>
11
11
  $ qhubctl login -t <personal access token> --base-path ${defaultBasePath}`;
12
- export const loginCommand = new Command('login')
13
- .description('Login with your credentials')
14
- .option('-t, --token <value>', 'Your personal access token')
15
- .option('--base-path <value>', 'Custom base path for authentication (development)')
16
- .addHelpText('after', EXAMPLES)
12
+ export const loginCommand = new Command("login")
13
+ .description("Login with your credentials")
14
+ .option("-t, --token <value>", "Your personal access token")
15
+ .option("--base-path <value>", "Custom base path for authentication (development)")
16
+ .addHelpText("after", EXAMPLES)
17
17
  .action(async (opts) => {
18
18
  let { token } = opts;
19
19
  const { basePath } = opts;
20
20
  if (!token) {
21
- token = await password({ message: 'Enter or paste your personal access token?', mask: true });
21
+ token = await password({ message: "Enter or paste your personal access token?", mask: true });
22
22
  }
23
23
  if (!token) {
24
- throw new Error('Invalid credentials. Please try again.');
24
+ throw new Error("Invalid credentials. Please try again.");
25
25
  }
26
26
  const userConfig = getUserConfig();
27
27
  const endpoint = resolveEndpoint(userConfig, basePath);
@@ -29,7 +29,7 @@ export const loginCommand = new Command('login')
29
29
  if (basePath) {
30
30
  showCustomBasePathWarning();
31
31
  }
32
- const spin = spinner('Login...');
32
+ const spin = spinner("Login...");
33
33
  const user = await new AuthService({ ...userConfig, endpoint }).authenticate(token);
34
34
  const newUserConfig = {
35
35
  ...userConfig,
@@ -45,7 +45,7 @@ export const loginCommand = new Command('login')
45
45
  endpoint,
46
46
  };
47
47
  writeUserConfig(configDir, newUserConfig);
48
- spin.succeed('Login successful');
48
+ spin.succeed("Login successful");
49
49
  if (revertingToDefault) {
50
50
  showBasePathRevertNotice();
51
51
  }
@@ -1,2 +1,2 @@
1
- import { Command } from 'commander';
1
+ import { Command } from "commander";
2
2
  export declare const logoutCommand: Command;
@@ -1,25 +1,25 @@
1
- import { Command } from 'commander';
2
- import { spinner } from '../lib/output.js';
3
- import { configDir, getUserConfig, showBasePathRevertNotice } from '../model/command.js';
4
- import { hasCustomBasePath } from '../model/user-config.js';
5
- import { writeUserConfig } from '../service/user-config-service.js';
1
+ import { Command } from "commander";
2
+ import { spinner } from "../lib/output.js";
3
+ import { configDir, getUserConfig, showBasePathRevertNotice } from "../model/command.js";
4
+ import { hasCustomBasePath } from "../model/user-config.js";
5
+ import { writeUserConfig } from "../service/user-config-service.js";
6
6
  const EXAMPLES = `
7
7
  Examples:
8
8
  $ qhubctl logout`;
9
- export const logoutCommand = new Command('logout')
10
- .description('Logout')
11
- .addHelpText('after', EXAMPLES)
9
+ export const logoutCommand = new Command("logout")
10
+ .description("Logout")
11
+ .addHelpText("after", EXAMPLES)
12
12
  .action(async () => {
13
13
  const userConfig = getUserConfig();
14
14
  const revertingToDefault = hasCustomBasePath(userConfig);
15
- const spin = spinner('Logout');
15
+ const spin = spinner("Logout");
16
16
  writeUserConfig(configDir, {
17
17
  ...userConfig,
18
18
  auth: undefined,
19
19
  context: undefined,
20
20
  endpoint: undefined,
21
21
  });
22
- spin.succeed('Logout successful');
22
+ spin.succeed("Logout successful");
23
23
  if (revertingToDefault) {
24
24
  showBasePathRevertNotice();
25
25
  }
@@ -1,2 +1,2 @@
1
- import { Command } from 'commander';
1
+ import { Command } from "commander";
2
2
  export declare const openapiCommand: Command;