qa 0.0.9 → 0.0.11

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.
@@ -1,4 +1,7 @@
1
+ import os from 'node:os';
1
2
  import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ import fsp from 'node:fs/promises';
2
5
  import { TestParameterType } from '@codeless.qa/contracts';
3
6
  import { select, text, confirm, outro, isCancel } from '@clack/prompts';
4
7
  import { handler as loginFlow } from '../login.js';
@@ -18,9 +21,12 @@ export async function askTestingType() {
18
21
  }
19
22
  export async function askSpecLocation() {
20
23
  const specPath = await text({
21
- message: 'Please provide an absolute path to your OpenAPI specification or Postman collection!',
24
+ message: 'Please provide a file path or URL to your OpenAPI specification or Postman collection!',
22
25
  validate: (path) => {
23
26
  try {
27
+ if (path.startsWith('https://') || path.startsWith('http://')) {
28
+ return;
29
+ }
24
30
  fs.accessSync(path);
25
31
  }
26
32
  catch {
@@ -32,6 +38,42 @@ export async function askSpecLocation() {
32
38
  outro('Bye!');
33
39
  process.exit(0);
34
40
  }
41
+ if (specPath.startsWith('https://') || specPath.startsWith('http://')) {
42
+ try {
43
+ const origSpecString = await (await fetch(specPath)).text();
44
+ let filePath = `${os.tmpdir()}/codelessqa-${specPath.split('/').pop()}`;
45
+ /**
46
+ * make sure it is a json file
47
+ */
48
+ if (!path.extname(filePath)) {
49
+ filePath += '.json';
50
+ }
51
+ const spec = JSON.parse(origSpecString);
52
+ /**
53
+ * Some OpenAPI specification may leave out the host name in the server URL
54
+ * and expect to take it from the spec origin source. In these cases we need
55
+ * to add it to the server object.
56
+ */
57
+ if (spec.servers && spec.servers.some((server) => server.url.startsWith('/'))) {
58
+ const source = new URL(specPath);
59
+ spec.servers = spec.servers.map((server) => {
60
+ if (!server.url.startsWith('/')) {
61
+ return server;
62
+ }
63
+ server.url = new URL(server.url, source.origin).href;
64
+ return server;
65
+ });
66
+ }
67
+ const specString = JSON.stringify(spec);
68
+ await fsp.writeFile(filePath, specString, 'utf8');
69
+ return { spec, specPath: filePath, specString };
70
+ }
71
+ catch (err) {
72
+ const error = err instanceof Error ? err : new Error('Unknown error');
73
+ outro(`Error: ${error.message}`);
74
+ process.exit(0);
75
+ }
76
+ }
35
77
  try {
36
78
  const specString = fs.readFileSync(specPath, 'utf8');
37
79
  const spec = JSON.parse(specString);
package/dist/constants.js CHANGED
@@ -7,6 +7,6 @@ export const CLI_EPILOGUE = `Documentation: https://codeless.qa/docs/cli
7
7
  qa (v${pkg.version})
8
8
  © 2024 CodelessQA, Inc.
9
9
  `;
10
- export const PLATFORM_URL = 'https://codeless.qa' || 'http://localhost:4000';
11
- export const WORKER_URL = 'wss://worker.codeless.qa' || 'ws://localhost:8080';
10
+ export const PLATFORM_URL = process.env.CODELESSQA_PLATFORM_URL || 'https://codeless.qa' || 'http://localhost:4000';
11
+ export const WORKER_URL = process.env.CODELESSQA_WORKER_URL || 'wss://worker.codeless.qa' || 'ws://localhost:8080';
12
12
  export const TOKEN_PATH = path.join(homedir(), '/.codeless-qa');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qa",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "author": "Christian Bromann <christian@codeless.qa>",
5
5
  "description": "Codeless QA CLI",
6
6
  "license": "Apache-2.0",
@@ -29,8 +29,8 @@
29
29
  "build": "run-s build:*",
30
30
  "build:ts": "tsc",
31
31
  "build:replace": "run-s build:replace:*",
32
- "build:replace:platform": "replace-in-files --string='process.env.PLATFORM_URL' --replacement=\"''$PLATFORM_URL''\" ./dist/constants.js",
33
- "build:replace:worker": "replace-in-files --string='process.env.WORKER_URL' --replacement=\"''$WORKER_URL''\" ./dist/constants.js",
32
+ "build:replace:platform": "replace-in-files --string='process.env.PLATFORM_URL' --replacement=\"process.env.CODELESSQA_PLATFORM_URL || '$PLATFORM_URL'\" ./dist/constants.js",
33
+ "build:replace:worker": "replace-in-files --string='process.env.WORKER_URL' --replacement=\"process.env.CODELESSQA_WORKER_URL || '$WORKER_URL'\" ./dist/constants.js",
34
34
  "start": "tsc --watch --preserveWatchOutput"
35
35
  }
36
36
  }