qa 0.1.0 → 0.17.0
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 +41 -25
- package/cli.cjs +52 -0
- package/package.json +24 -44
- package/LICENSE +0 -201
- package/assets/logo.png +0 -0
- package/bin/qa.js +0 -5
- package/dist/api/index.d.ts +0 -3
- package/dist/api/index.js +0 -103
- package/dist/auth.d.ts +0 -2
- package/dist/auth.js +0 -28
- package/dist/commands/index.d.ts +0 -3
- package/dist/commands/index.js +0 -5
- package/dist/commands/init.d.ts +0 -19
- package/dist/commands/init.js +0 -48
- package/dist/commands/login.d.ts +0 -20
- package/dist/commands/login.js +0 -67
- package/dist/commands/start.d.ts +0 -19
- package/dist/commands/start.js +0 -34
- package/dist/commands/test.d.ts +0 -54
- package/dist/commands/test.js +0 -51
- package/dist/commands/types.d.ts +0 -6
- package/dist/commands/types.js +0 -1
- package/dist/commands/utils/index.d.ts +0 -16
- package/dist/commands/utils/index.js +0 -59
- package/dist/commands/utils/nodeVersion.d.ts +0 -2
- package/dist/commands/utils/nodeVersion.js +0 -24
- package/dist/commands/utils/prompts.d.ts +0 -19
- package/dist/commands/utils/prompts.js +0 -236
- package/dist/constants.d.ts +0 -6
- package/dist/constants.js +0 -12
- package/dist/ide/index.d.ts +0 -8
- package/dist/ide/index.js +0 -184
- package/dist/ide/utils.d.ts +0 -19
- package/dist/ide/utils.js +0 -102
- package/dist/index.d.ts +0 -10
- package/dist/index.js +0 -24
- package/dist/reporter.d.ts +0 -8
- package/dist/reporter.js +0 -24
- package/dist/ui/index.d.ts +0 -3
- package/dist/ui/index.js +0 -29
package/dist/commands/login.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs/promises';
|
|
2
|
-
import { execSync } from 'node:child_process';
|
|
3
|
-
import { v4 as uuidv4 } from 'uuid';
|
|
4
|
-
import { client } from '@vollq/contracts/client';
|
|
5
|
-
import { CLI_EPILOGUE, PLATFORM_URL, TOKEN_PATH } from '../constants.js';
|
|
6
|
-
const LOGIN_TIMEOUT = 1000 * 60; // 1 minute
|
|
7
|
-
const LOGIN_VERIFY_INTERVAL = 500;
|
|
8
|
-
export const command = 'login [option]';
|
|
9
|
-
export const desc = 'Log in to the vollq.ai platform';
|
|
10
|
-
export const cmdArgs = {
|
|
11
|
-
token: {
|
|
12
|
-
alias: 't',
|
|
13
|
-
desc: 'Provide an access token if you don\'t want to log in via the UI',
|
|
14
|
-
type: 'string',
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
export const builder = (yargs) => {
|
|
18
|
-
return yargs
|
|
19
|
-
.options(cmdArgs)
|
|
20
|
-
.example('qa login', desc)
|
|
21
|
-
.example('qa login --token XXX', 'Log in through access token')
|
|
22
|
-
.epilogue(CLI_EPILOGUE)
|
|
23
|
-
.help();
|
|
24
|
-
};
|
|
25
|
-
export const handler = async (argv) => {
|
|
26
|
-
if (argv?.token) {
|
|
27
|
-
console.log('Logging in via access token', argv.token);
|
|
28
|
-
return argv.token;
|
|
29
|
-
}
|
|
30
|
-
const ticket = uuidv4();
|
|
31
|
-
const loginUrl = `${PLATFORM_URL}/login/${ticket}`;
|
|
32
|
-
console.log([
|
|
33
|
-
'🦄 Logging in via UI 🙌',
|
|
34
|
-
`👉 Visit the following URL to log in: ${loginUrl}`,
|
|
35
|
-
'',
|
|
36
|
-
'...waiting for user to be authenticated...'
|
|
37
|
-
].join('\n'));
|
|
38
|
-
try {
|
|
39
|
-
return login(ticket);
|
|
40
|
-
}
|
|
41
|
-
catch (err) {
|
|
42
|
-
console.log(`🚨 Failed to log-in: ${err.message}`);
|
|
43
|
-
process.exit(1);
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
export async function login(ticket, log = console.log) {
|
|
47
|
-
const loginUrl = `${PLATFORM_URL}/login/${ticket}`;
|
|
48
|
-
execSync(`open ${loginUrl}`);
|
|
49
|
-
const token = await new Promise((resolve, reject) => {
|
|
50
|
-
const timeout = setTimeout(() => reject(new Error('timed out')), LOGIN_TIMEOUT);
|
|
51
|
-
const interval = setInterval(async () => {
|
|
52
|
-
const res = await client.auth.verifyTicket({ params: { ticket } });
|
|
53
|
-
if (res.status !== 200) {
|
|
54
|
-
if (res.status === 500) {
|
|
55
|
-
return reject(new Error('Internal server error'));
|
|
56
|
-
}
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
clearInterval(interval);
|
|
60
|
-
clearTimeout(timeout);
|
|
61
|
-
return resolve(res.body.token);
|
|
62
|
-
}, LOGIN_VERIFY_INTERVAL);
|
|
63
|
-
});
|
|
64
|
-
await fs.writeFile(TOKEN_PATH, `token=${token}\n`);
|
|
65
|
-
log('🎉 Successfully logged in!');
|
|
66
|
-
return token;
|
|
67
|
-
}
|
package/dist/commands/start.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { Argv } from 'yargs';
|
|
2
|
-
export declare const command = "start [option]";
|
|
3
|
-
export declare const desc = "Start the VollQ IDE";
|
|
4
|
-
export declare const cmdArgs: {
|
|
5
|
-
readonly token: {
|
|
6
|
-
readonly alias: "t";
|
|
7
|
-
readonly desc: "Provide an access token to authenticate with the platform";
|
|
8
|
-
readonly type: "string";
|
|
9
|
-
};
|
|
10
|
-
};
|
|
11
|
-
export declare const builder: (yargs: Argv) => Argv<import("yargs").Omit<{}, "token"> & import("yargs").InferredOptionTypes<{
|
|
12
|
-
readonly token: {
|
|
13
|
-
readonly alias: "t";
|
|
14
|
-
readonly desc: "Provide an access token to authenticate with the platform";
|
|
15
|
-
readonly type: "string";
|
|
16
|
-
};
|
|
17
|
-
}>>;
|
|
18
|
-
export declare const handler: (argv: typeof cmdArgs) => Promise<void>;
|
|
19
|
-
//# sourceMappingURL=start.d.ts.map
|
package/dist/commands/start.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { checkNodeVersion } from './utils/nodeVersion.js';
|
|
2
|
-
import { IDE } from '../ide/index.js';
|
|
3
|
-
import { getAccessToken } from '../auth.js';
|
|
4
|
-
import { CLI_EPILOGUE } from '../constants.js';
|
|
5
|
-
let app;
|
|
6
|
-
const onShutdown = async () => {
|
|
7
|
-
await app?.handleShutdown();
|
|
8
|
-
};
|
|
9
|
-
if (process.argv[2] === 'start') {
|
|
10
|
-
process.on('SIGINT', onShutdown);
|
|
11
|
-
process.on('SIGTERM', onShutdown);
|
|
12
|
-
process.on('beforeExit', onShutdown);
|
|
13
|
-
}
|
|
14
|
-
export const command = 'start [option]';
|
|
15
|
-
export const desc = 'Start the VollQ IDE';
|
|
16
|
-
export const cmdArgs = {
|
|
17
|
-
token: {
|
|
18
|
-
alias: 't',
|
|
19
|
-
desc: 'Provide an access token to authenticate with the platform',
|
|
20
|
-
type: 'string',
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
export const builder = (yargs) => {
|
|
24
|
-
checkNodeVersion();
|
|
25
|
-
return yargs
|
|
26
|
-
.options(cmdArgs)
|
|
27
|
-
.example('qa start', desc)
|
|
28
|
-
.epilogue(CLI_EPILOGUE)
|
|
29
|
-
.help();
|
|
30
|
-
};
|
|
31
|
-
export const handler = async (argv) => {
|
|
32
|
-
const token = await getAccessToken(argv.token);
|
|
33
|
-
app = await IDE.start(token);
|
|
34
|
-
};
|
package/dist/commands/test.d.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import type { Argv } from 'yargs';
|
|
2
|
-
import type { TestCommandParameters } from './types.js';
|
|
3
|
-
export declare const command = "test <type> <project> [option]";
|
|
4
|
-
export declare const desc = "Run a test on the vollq.ai platform";
|
|
5
|
-
export declare const cmdArgs: {
|
|
6
|
-
readonly token: {
|
|
7
|
-
readonly alias: "t";
|
|
8
|
-
readonly desc: "Provide an access token to authenticate with the platform";
|
|
9
|
-
readonly type: "string";
|
|
10
|
-
};
|
|
11
|
-
readonly server: {
|
|
12
|
-
readonly desc: "Server URL to use for the API test";
|
|
13
|
-
readonly type: "string";
|
|
14
|
-
};
|
|
15
|
-
readonly reporter: {
|
|
16
|
-
readonly desc: "Specify the reporter to use for the test (currently only \"spec\" is supported)";
|
|
17
|
-
readonly type: "string";
|
|
18
|
-
readonly default: "spec";
|
|
19
|
-
readonly alias: "r";
|
|
20
|
-
};
|
|
21
|
-
readonly filter: {
|
|
22
|
-
readonly desc: "Filter tests by tag or workflow id";
|
|
23
|
-
readonly type: "string";
|
|
24
|
-
readonly alias: "f";
|
|
25
|
-
readonly array: true;
|
|
26
|
-
};
|
|
27
|
-
};
|
|
28
|
-
export declare const builder: (yargs: Argv) => Argv<import("yargs").Omit<{}, "token" | "filter" | "server" | "reporter"> & import("yargs").InferredOptionTypes<{
|
|
29
|
-
readonly token: {
|
|
30
|
-
readonly alias: "t";
|
|
31
|
-
readonly desc: "Provide an access token to authenticate with the platform";
|
|
32
|
-
readonly type: "string";
|
|
33
|
-
};
|
|
34
|
-
readonly server: {
|
|
35
|
-
readonly desc: "Server URL to use for the API test";
|
|
36
|
-
readonly type: "string";
|
|
37
|
-
};
|
|
38
|
-
readonly reporter: {
|
|
39
|
-
readonly desc: "Specify the reporter to use for the test (currently only \"spec\" is supported)";
|
|
40
|
-
readonly type: "string";
|
|
41
|
-
readonly default: "spec";
|
|
42
|
-
readonly alias: "r";
|
|
43
|
-
};
|
|
44
|
-
readonly filter: {
|
|
45
|
-
readonly desc: "Filter tests by tag or workflow id";
|
|
46
|
-
readonly type: "string";
|
|
47
|
-
readonly alias: "f";
|
|
48
|
-
readonly array: true;
|
|
49
|
-
};
|
|
50
|
-
}>>;
|
|
51
|
-
export declare const handler: (argv: typeof cmdArgs & {
|
|
52
|
-
type: "api" | "ui";
|
|
53
|
-
} & TestCommandParameters) => Promise<void>;
|
|
54
|
-
//# sourceMappingURL=test.d.ts.map
|
package/dist/commands/test.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { runAPITest } from '../api/index.js';
|
|
2
|
-
import { runUITest } from '../ui/index.js';
|
|
3
|
-
import { getAccessToken } from '../auth.js';
|
|
4
|
-
import { CLI_EPILOGUE } from '../constants.js';
|
|
5
|
-
export const command = 'test <type> <project> [option]';
|
|
6
|
-
export const desc = 'Run a test on the vollq.ai platform';
|
|
7
|
-
export const cmdArgs = {
|
|
8
|
-
token: {
|
|
9
|
-
alias: 't',
|
|
10
|
-
desc: 'Provide an access token to authenticate with the platform',
|
|
11
|
-
type: 'string',
|
|
12
|
-
},
|
|
13
|
-
server: {
|
|
14
|
-
desc: 'Server URL to use for the API test',
|
|
15
|
-
type: 'string',
|
|
16
|
-
},
|
|
17
|
-
reporter: {
|
|
18
|
-
desc: 'Specify the reporter to use for the test (currently only "spec" is supported)',
|
|
19
|
-
type: 'string',
|
|
20
|
-
default: 'spec',
|
|
21
|
-
alias: 'r',
|
|
22
|
-
},
|
|
23
|
-
filter: {
|
|
24
|
-
desc: 'Filter tests by tag or workflow id',
|
|
25
|
-
type: 'string',
|
|
26
|
-
alias: 'f',
|
|
27
|
-
array: true
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
export const builder = (yargs) => {
|
|
31
|
-
return yargs
|
|
32
|
-
.options(cmdArgs)
|
|
33
|
-
.example('qa test ui login', 'Runs a UI browser test named "login"')
|
|
34
|
-
.example('qa test api myAPI', 'Runs test on API named "myAPI"')
|
|
35
|
-
.example('qa test api myAPI -f loginFlow', 'Runs tests tagged or workflows named with "loginFlow"')
|
|
36
|
-
.epilogue(CLI_EPILOGUE)
|
|
37
|
-
.help();
|
|
38
|
-
};
|
|
39
|
-
export const handler = async (argv) => {
|
|
40
|
-
const token = await getAccessToken(argv.token);
|
|
41
|
-
if (argv.reporter !== 'spec') {
|
|
42
|
-
throw new Error('Currently only the "spec" reporter is supported!');
|
|
43
|
-
}
|
|
44
|
-
if (argv.type === 'ui') {
|
|
45
|
-
return runUITest(token, argv);
|
|
46
|
-
}
|
|
47
|
-
if (argv.type === 'api') {
|
|
48
|
-
return runAPITest(token, argv);
|
|
49
|
-
}
|
|
50
|
-
throw new Error(`Invalid test type "${argv.type}", use "api" or "ui". See \`qa test --help\` for more information.`);
|
|
51
|
-
};
|
package/dist/commands/types.d.ts
DELETED
package/dist/commands/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { SpecificationRequest } from '@vollq/contracts';
|
|
2
|
-
import type { ProjectProps } from './prompts.js';
|
|
3
|
-
type Spinner = {
|
|
4
|
-
stop: () => void;
|
|
5
|
-
};
|
|
6
|
-
export declare function createSpecification(token: string, projectProps: ProjectProps, file: string, spinner: Spinner): Promise<string>;
|
|
7
|
-
export declare function generateTests(token: string, id: string, spinner: Spinner, body: SpecificationRequest['generate']['body']): Promise<void>;
|
|
8
|
-
export declare function fetchProjectNames(token: string): Promise<string[]>;
|
|
9
|
-
export declare function validateAuthToken(token: string): Promise<{
|
|
10
|
-
valid: false;
|
|
11
|
-
} | {
|
|
12
|
-
valid: true;
|
|
13
|
-
email: string;
|
|
14
|
-
}>;
|
|
15
|
-
export {};
|
|
16
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { outro } from '@clack/prompts';
|
|
2
|
-
import { getAuthenticatedClient } from '@vollq/contracts/client';
|
|
3
|
-
export async function createSpecification(token, projectProps, file, spinner) {
|
|
4
|
-
const client = getAuthenticatedClient(token);
|
|
5
|
-
const resSpecCreation = await client.specification.create({
|
|
6
|
-
body: {
|
|
7
|
-
...projectProps,
|
|
8
|
-
file
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
if (resSpecCreation.status !== 201) {
|
|
12
|
-
spinner.stop();
|
|
13
|
-
const error = typeof resSpecCreation.body === 'object' && resSpecCreation.body && 'error' in resSpecCreation.body && resSpecCreation.body.error instanceof Error
|
|
14
|
-
? resSpecCreation.body.error
|
|
15
|
-
: new Error('Unknown error');
|
|
16
|
-
outro(error.message);
|
|
17
|
-
process.exit(0);
|
|
18
|
-
}
|
|
19
|
-
return resSpecCreation.body.data.id;
|
|
20
|
-
}
|
|
21
|
-
export async function generateTests(token, id, spinner, body) {
|
|
22
|
-
const client = getAuthenticatedClient(token);
|
|
23
|
-
const resTests = await client.specification.generate({
|
|
24
|
-
params: { id },
|
|
25
|
-
body
|
|
26
|
-
});
|
|
27
|
-
if (resTests.status !== 200 || (resTests.body && 'error' in resTests.body)) {
|
|
28
|
-
spinner.stop();
|
|
29
|
-
const error = typeof resTests.body === 'object' && resTests.body && 'error' in resTests.body
|
|
30
|
-
? resTests.body.error instanceof Error
|
|
31
|
-
? resTests.body.error
|
|
32
|
-
: new Error(resTests.body.error)
|
|
33
|
-
: new Error('Unknown error');
|
|
34
|
-
outro(error.message);
|
|
35
|
-
process.exit(0);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
export async function fetchProjectNames(token) {
|
|
39
|
-
const client = getAuthenticatedClient(token);
|
|
40
|
-
const projectNames = [];
|
|
41
|
-
try {
|
|
42
|
-
const res = await client.specifications.get();
|
|
43
|
-
if (res.status === 200) {
|
|
44
|
-
projectNames.push(...res.body.data.map((spec) => spec.name));
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
catch {
|
|
48
|
-
// noop
|
|
49
|
-
}
|
|
50
|
-
return projectNames;
|
|
51
|
-
}
|
|
52
|
-
export async function validateAuthToken(token) {
|
|
53
|
-
const client = getAuthenticatedClient(token);
|
|
54
|
-
const res = await client.auth.validatingAccessToken();
|
|
55
|
-
if (res.status !== 200) {
|
|
56
|
-
return { valid: false };
|
|
57
|
-
}
|
|
58
|
-
return res.body;
|
|
59
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import p from 'picocolors';
|
|
2
|
-
export function checkNodeVersion() {
|
|
3
|
-
const currentVersion = process.versions.node;
|
|
4
|
-
const majorVersion = parseInt(currentVersion.split('.')[0]);
|
|
5
|
-
const requiredVersion = 21;
|
|
6
|
-
if (majorVersion < requiredVersion) {
|
|
7
|
-
console.error(p.red(`
|
|
8
|
-
╔════════════════════════════════════════════════════════════╗
|
|
9
|
-
║ Version Check Failed ║
|
|
10
|
-
╚════════════════════════════════════════════════════════════╝
|
|
11
|
-
`));
|
|
12
|
-
console.error(p.yellow(`The "qa" CLI requires Node.js v${requiredVersion} or higher.`));
|
|
13
|
-
console.error(p.yellow('Please upgrade your Node.js installation.'));
|
|
14
|
-
console.error(p.yellow('\nTo upgrade Node.js:'));
|
|
15
|
-
console.error(p.cyan(`
|
|
16
|
-
1. Visit: https://nodejs.org
|
|
17
|
-
2. Or use a version manager like nvm:
|
|
18
|
-
nvm install ${requiredVersion}
|
|
19
|
-
nvm use ${requiredVersion}
|
|
20
|
-
`));
|
|
21
|
-
process.exit(1);
|
|
22
|
-
}
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { type ServerObject, type SpecificationRequest } from '@vollq/contracts';
|
|
2
|
-
import { type OpenAPIV3 } from 'openapi-types';
|
|
3
|
-
export declare function askTestingType(): Promise<string>;
|
|
4
|
-
export declare function askSpecLocation(): Promise<{
|
|
5
|
-
spec: OpenAPIV3.Document<{}>;
|
|
6
|
-
specPath: string;
|
|
7
|
-
}>;
|
|
8
|
-
export interface ProjectProps {
|
|
9
|
-
name: string;
|
|
10
|
-
description: string;
|
|
11
|
-
version: string;
|
|
12
|
-
}
|
|
13
|
-
export declare function askProjectDetails(existingProjectNames: string[], spec: OpenAPIV3.Document): Promise<ProjectProps>;
|
|
14
|
-
type SecurityPayloads = SpecificationRequest['generate']['body']['securityPayloads'];
|
|
15
|
-
export declare function askSecurityParams(spec: OpenAPIV3.Document): Promise<SecurityPayloads>;
|
|
16
|
-
export declare function askServerParams(spec: OpenAPIV3.Document): Promise<ServerObject>;
|
|
17
|
-
export declare function askForUserAuth(): Promise<string>;
|
|
18
|
-
export {};
|
|
19
|
-
//# sourceMappingURL=prompts.d.ts.map
|
|
@@ -1,236 +0,0 @@
|
|
|
1
|
-
import os from 'node:os';
|
|
2
|
-
import fs from 'node:fs';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
import fsp from 'node:fs/promises';
|
|
5
|
-
import { select, text, confirm, outro, isCancel } from '@clack/prompts';
|
|
6
|
-
import { handler as loginFlow } from '../login.js';
|
|
7
|
-
export async function askTestingType() {
|
|
8
|
-
const answerTestingType = await select({
|
|
9
|
-
message: 'What type of testing you would like to do?',
|
|
10
|
-
options: [
|
|
11
|
-
{ value: 'api', label: 'API Testing' },
|
|
12
|
-
{ value: 'ui', label: 'Function UI Testing in a web browser', hint: 'not yet supported' },
|
|
13
|
-
]
|
|
14
|
-
});
|
|
15
|
-
if (isCancel(answerTestingType)) {
|
|
16
|
-
outro('Bye!');
|
|
17
|
-
process.exit(0);
|
|
18
|
-
}
|
|
19
|
-
return answerTestingType;
|
|
20
|
-
}
|
|
21
|
-
export async function askSpecLocation() {
|
|
22
|
-
const specPath = await text({
|
|
23
|
-
message: 'Please provide a file path or URL to your OpenAPI specification or Postman collection!',
|
|
24
|
-
validate: (path) => {
|
|
25
|
-
try {
|
|
26
|
-
if (path.startsWith('https://') || path.startsWith('http://')) {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
fs.accessSync(path);
|
|
30
|
-
}
|
|
31
|
-
catch {
|
|
32
|
-
return 'Path does not exist';
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
if (isCancel(specPath) || typeof specPath !== 'string') {
|
|
37
|
-
outro('Bye!');
|
|
38
|
-
process.exit(0);
|
|
39
|
-
}
|
|
40
|
-
if (specPath.startsWith('https://') || specPath.startsWith('http://')) {
|
|
41
|
-
try {
|
|
42
|
-
const origSpecString = await (await fetch(specPath)).text();
|
|
43
|
-
let filePath = `${os.tmpdir()}/vollq-${specPath.split('/').pop()}`;
|
|
44
|
-
/**
|
|
45
|
-
* make sure it is a json file
|
|
46
|
-
*/
|
|
47
|
-
if (!path.extname(filePath)) {
|
|
48
|
-
filePath += '.json';
|
|
49
|
-
}
|
|
50
|
-
const spec = JSON.parse(origSpecString);
|
|
51
|
-
/**
|
|
52
|
-
* Some OpenAPI specification may leave out the host name in the server URL
|
|
53
|
-
* and expect to take it from the spec origin source. In these cases we need
|
|
54
|
-
* to add it to the server object.
|
|
55
|
-
*/
|
|
56
|
-
if (spec.servers && spec.servers.some((server) => server.url.startsWith('/'))) {
|
|
57
|
-
const source = new URL(specPath);
|
|
58
|
-
spec.servers = spec.servers.map((server) => {
|
|
59
|
-
if (!server.url.startsWith('/')) {
|
|
60
|
-
return server;
|
|
61
|
-
}
|
|
62
|
-
server.url = new URL(server.url, source.origin).href;
|
|
63
|
-
return server;
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
const specString = JSON.stringify(spec);
|
|
67
|
-
await fsp.writeFile(filePath, specString, 'utf8');
|
|
68
|
-
return { spec, specPath: filePath };
|
|
69
|
-
}
|
|
70
|
-
catch (err) {
|
|
71
|
-
const error = err instanceof Error ? err : new Error('Unknown error');
|
|
72
|
-
outro(`Error: ${error.message}`);
|
|
73
|
-
process.exit(0);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
try {
|
|
77
|
-
const specString = fs.readFileSync(specPath, 'utf8');
|
|
78
|
-
const spec = JSON.parse(specString);
|
|
79
|
-
return { spec, specPath };
|
|
80
|
-
}
|
|
81
|
-
catch (err) {
|
|
82
|
-
const error = err instanceof Error ? err : new Error('Unknown error');
|
|
83
|
-
outro(`Error: ${error.message}`);
|
|
84
|
-
process.exit(0);
|
|
85
|
-
}
|
|
86
|
-
throw new Error('I should never reach here');
|
|
87
|
-
}
|
|
88
|
-
const PROJECT_PROPS = {
|
|
89
|
-
name: 'What is the name of your project?',
|
|
90
|
-
description: 'What is the description of your project?',
|
|
91
|
-
version: 'What is the version of your API specification?',
|
|
92
|
-
};
|
|
93
|
-
export async function askProjectDetails(existingProjectNames, spec) {
|
|
94
|
-
const projectProps = {};
|
|
95
|
-
for (const [key, message] of Object.entries(PROJECT_PROPS)) {
|
|
96
|
-
const opts = {
|
|
97
|
-
message,
|
|
98
|
-
initialValue: spec.info[key] || spec.info.title,
|
|
99
|
-
};
|
|
100
|
-
if (key === 'name') {
|
|
101
|
-
opts.validate = (value) => existingProjectNames.includes(value)
|
|
102
|
-
? `Project name "${value}" already exists`
|
|
103
|
-
: undefined;
|
|
104
|
-
}
|
|
105
|
-
const value = await text(opts);
|
|
106
|
-
if (isCancel(value)) {
|
|
107
|
-
outro('Bye!');
|
|
108
|
-
process.exit(0);
|
|
109
|
-
}
|
|
110
|
-
projectProps[key] = value;
|
|
111
|
-
}
|
|
112
|
-
return projectProps;
|
|
113
|
-
}
|
|
114
|
-
export async function askSecurityParams(spec) {
|
|
115
|
-
if (!spec.components ||
|
|
116
|
-
!spec.components.securitySchemes ||
|
|
117
|
-
(Array.isArray(spec.components.securitySchemes) &&
|
|
118
|
-
spec.components.securitySchemes.length === 0)) {
|
|
119
|
-
return {};
|
|
120
|
-
}
|
|
121
|
-
const securitySchemes = new Set(Object.entries(spec.components.securitySchemes).filter(([, schema]) => 'type' in schema));
|
|
122
|
-
const securityObjects = {};
|
|
123
|
-
for (const [name, secScheme] of securitySchemes) {
|
|
124
|
-
const isBasicAuth = secScheme.type === 'http' && secScheme.scheme === 'basic';
|
|
125
|
-
const isJWTAuth = secScheme.type === 'http' && secScheme.scheme === 'bearer' && secScheme.bearerFormat === 'JWT';
|
|
126
|
-
const message = isBasicAuth
|
|
127
|
-
? 'Can you provide a username and password to access the API?'
|
|
128
|
-
: isJWTAuth
|
|
129
|
-
? 'Can you provide an example JWT token to access the API?'
|
|
130
|
-
: secScheme.type === 'apiKey'
|
|
131
|
-
? `Can you provide an example value for the "${secScheme.name}" ${secScheme.in} parameter?`
|
|
132
|
-
: undefined;
|
|
133
|
-
if (!message || 'in' in secScheme && secScheme.in === 'query') {
|
|
134
|
-
continue;
|
|
135
|
-
}
|
|
136
|
-
const value = await text({
|
|
137
|
-
message,
|
|
138
|
-
placeholder: '(leave empty to skip or press "s" to cancel and skip all)',
|
|
139
|
-
});
|
|
140
|
-
if (isCancel(value)) {
|
|
141
|
-
outro('Bye!');
|
|
142
|
-
process.exit(0);
|
|
143
|
-
}
|
|
144
|
-
if (value === 's') {
|
|
145
|
-
break;
|
|
146
|
-
}
|
|
147
|
-
if (!value) {
|
|
148
|
-
continue;
|
|
149
|
-
}
|
|
150
|
-
const scope = secScheme.in.slice(0, 1).toUpperCase() +
|
|
151
|
-
secScheme.in.slice(1);
|
|
152
|
-
securityObjects[name] = {
|
|
153
|
-
name: isBasicAuth || isJWTAuth
|
|
154
|
-
? 'Authorization'
|
|
155
|
-
: secScheme.name,
|
|
156
|
-
value,
|
|
157
|
-
scope
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
return securityObjects;
|
|
161
|
-
}
|
|
162
|
-
async function askCustomServer() {
|
|
163
|
-
const customServerPrompt = await text({
|
|
164
|
-
message: 'What is the server url?',
|
|
165
|
-
placeholder: 'https://api.gigantic-server.com/v1',
|
|
166
|
-
});
|
|
167
|
-
if (isCancel(customServerPrompt)) {
|
|
168
|
-
outro('Bye!');
|
|
169
|
-
process.exit(0);
|
|
170
|
-
}
|
|
171
|
-
return customServerPrompt;
|
|
172
|
-
}
|
|
173
|
-
export async function askServerParams(spec) {
|
|
174
|
-
const CUSTOM_SERVER = 'custom';
|
|
175
|
-
if (!spec.servers || spec.servers.length === 0) {
|
|
176
|
-
const customServer = await askCustomServer();
|
|
177
|
-
return { url: customServer };
|
|
178
|
-
}
|
|
179
|
-
const server = await select({
|
|
180
|
-
message: 'Which server do you want to use?',
|
|
181
|
-
options: [
|
|
182
|
-
...spec.servers.map((server, value) => ({
|
|
183
|
-
label: server.description || server.url,
|
|
184
|
-
value: value.toString(),
|
|
185
|
-
hint: server.description ? server.url : undefined
|
|
186
|
-
})),
|
|
187
|
-
{
|
|
188
|
-
label: 'Custom server url',
|
|
189
|
-
value: CUSTOM_SERVER
|
|
190
|
-
}
|
|
191
|
-
]
|
|
192
|
-
});
|
|
193
|
-
if (isCancel(server)) {
|
|
194
|
-
outro('Bye!');
|
|
195
|
-
process.exit(0);
|
|
196
|
-
}
|
|
197
|
-
const serverVars = {};
|
|
198
|
-
if (typeof server === 'number' && spec.servers[server].variables) {
|
|
199
|
-
for (const [name, val] of Object.entries(spec.servers[server].variables)) {
|
|
200
|
-
const varPrompt = await text({
|
|
201
|
-
message: `What is the value for the "${name}" variable?`,
|
|
202
|
-
initialValue: val.default,
|
|
203
|
-
});
|
|
204
|
-
if (isCancel(varPrompt)) {
|
|
205
|
-
outro('Bye!');
|
|
206
|
-
process.exit(0);
|
|
207
|
-
}
|
|
208
|
-
serverVars[name] = { default: varPrompt };
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
let customServerUrl;
|
|
212
|
-
if (typeof server === 'string' && server === CUSTOM_SERVER) {
|
|
213
|
-
customServerUrl = await askCustomServer();
|
|
214
|
-
}
|
|
215
|
-
const serverObject = {
|
|
216
|
-
url: typeof server === 'number'
|
|
217
|
-
? spec.servers[server].url
|
|
218
|
-
: customServerUrl,
|
|
219
|
-
variables: serverVars
|
|
220
|
-
};
|
|
221
|
-
return serverObject;
|
|
222
|
-
}
|
|
223
|
-
export async function askForUserAuth() {
|
|
224
|
-
const runLoginWorkflow = await confirm({
|
|
225
|
-
message: 'It seems like you are not logged in. Would you like to login now?',
|
|
226
|
-
initialValue: true
|
|
227
|
-
});
|
|
228
|
-
if (isCancel(runLoginWorkflow) || !runLoginWorkflow) {
|
|
229
|
-
outro('Bye!');
|
|
230
|
-
process.exit(0);
|
|
231
|
-
}
|
|
232
|
-
console.log('');
|
|
233
|
-
const token = await loginFlow();
|
|
234
|
-
console.log('');
|
|
235
|
-
return token;
|
|
236
|
-
}
|
package/dist/constants.d.ts
DELETED
package/dist/constants.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { homedir } from 'node:os';
|
|
3
|
-
import { createRequire } from 'node:module';
|
|
4
|
-
const require = createRequire(import.meta.url);
|
|
5
|
-
export const pkg = require('../package.json');
|
|
6
|
-
export const CLI_EPILOGUE = `Documentation: https://docs.vollq.ai/cli
|
|
7
|
-
qa (v${pkg.version})
|
|
8
|
-
© 2025 VollQ, Inc.
|
|
9
|
-
`;
|
|
10
|
-
export const PLATFORM_URL = process.env.VOLLQ_PLATFORM_URL || 'https://vollq.ai' || 'http://localhost:4000';
|
|
11
|
-
export const WORKER_URL = process.env.VOLLQ_WORKER_URL || 'wss://worker.vollq.ai' || 'ws://localhost:8080';
|
|
12
|
-
export const TOKEN_PATH = path.join(homedir(), '/.vollqrc');
|