doc-detective-common 3.0.0-dev.3 → 3.0.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.
Files changed (35) hide show
  1. package/README.md +0 -85
  2. package/package.json +1 -1
  3. package/src/files.js +8 -6
  4. package/src/resolvePaths.js +17 -17
  5. package/src/schemas/dereferenceSchemas.js +12 -4
  6. package/src/schemas/output_schemas/checkLink_v3.schema.json +2 -2
  7. package/src/schemas/output_schemas/click_v3.schema.json +29 -2
  8. package/src/schemas/output_schemas/config_v3.schema.json +1155 -284
  9. package/src/schemas/output_schemas/context_v3.schema.json +1 -0
  10. package/src/schemas/output_schemas/find_v3.schema.json +384 -10
  11. package/src/schemas/output_schemas/httpRequest_v3.schema.json +27 -2
  12. package/src/schemas/output_schemas/openApi_v3.schema.json +12 -0
  13. package/src/schemas/output_schemas/record_v3.schema.json +3 -4
  14. package/src/schemas/output_schemas/report_v3.schema.json +488 -35
  15. package/src/schemas/output_schemas/runCode_v3.schema.json +2 -2
  16. package/src/schemas/output_schemas/screenshot_v3.schema.json +10 -9
  17. package/src/schemas/output_schemas/spec_v3.schema.json +488 -35
  18. package/src/schemas/output_schemas/step_v3.schema.json +462 -35
  19. package/src/schemas/output_schemas/test_v3.schema.json +475 -35
  20. package/src/schemas/output_schemas/type_v3.schema.json +4 -2
  21. package/src/schemas/output_schemas/wait_v3.schema.json +1 -2
  22. package/src/schemas/schemas.json +6999 -3915
  23. package/src/schemas/src_schemas/checkLink_v3.schema.json +1 -1
  24. package/src/schemas/src_schemas/click_v3.schema.json +9 -2
  25. package/src/schemas/src_schemas/config_v3.schema.json +4 -6
  26. package/src/schemas/src_schemas/context_v3.schema.json +1 -0
  27. package/src/schemas/src_schemas/find_v3.schema.json +15 -3
  28. package/src/schemas/src_schemas/httpRequest_v3.schema.json +2 -1
  29. package/src/schemas/src_schemas/openApi_v3.schema.json +8 -0
  30. package/src/schemas/src_schemas/record_v3.schema.json +2 -3
  31. package/src/schemas/src_schemas/runCode_v3.schema.json +1 -1
  32. package/src/schemas/src_schemas/screenshot_v3.schema.json +7 -10
  33. package/src/schemas/src_schemas/type_v3.schema.json +2 -1
  34. package/src/schemas/src_schemas/wait_v3.schema.json +1 -2
  35. package/src/validate.js +41 -13
package/README.md CHANGED
@@ -1,85 +0,0 @@
1
- # Doc Detective Common
2
-
3
- ![Current version](https://img.shields.io/github/package-json/v/doc-detective/doc-detective-common?color=orange)
4
- [![NPM Shield](https://img.shields.io/npm/v/doc-detective-common)](https://www.npmjs.com/package/doc-detective-common)
5
- [![Discord Shield](https://img.shields.io/badge/chat-on%20discord-purple)](https://discord.gg/mSCCRAhH)
6
-
7
- Shared resources for Doc Detective projects.
8
-
9
- ## Install
10
-
11
- ```bash
12
- npm i doc-detective-common
13
- ```
14
-
15
- ## Init
16
-
17
- ```javascript
18
- const common = require("doc-detective-common");
19
- ```
20
-
21
- ## Methods
22
-
23
- ### `.validate(schemaKey: string, object: object)`
24
-
25
- Validate that `object` matches the specified [schema](#.schemas) definition.
26
-
27
- Returns an object with the following schema:
28
-
29
- ```json
30
- {
31
- "valid": boolean,
32
- "errors": [
33
- {
34
- "instancePath": string,
35
- "schemaPath": string,
36
- "keyword": string,
37
- "params": [{Object}],
38
- "message": string
39
- }
40
- ]
41
- }
42
- ```
43
-
44
- #### Usage
45
-
46
- ```js
47
- const schemaKey = "runShell_v1";
48
- const object = {
49
- action: "runShell",
50
- command: "echo $username",
51
- };
52
- console.log(common.validate(schemaKey, object));
53
- ```
54
-
55
- ### `.readFile(fileURL)`
56
-
57
- Load file contents from a URL or a file path. If a JSON or YAML file, returns an object. If a different file, returns a string.
58
-
59
- ## Objects
60
-
61
- ### `.schemas`
62
-
63
- JSON schema definitions for various objects used throughout Doc Detective.
64
-
65
- Schema objects are located in the [`/schemas`](https://github.com/doc-detective/doc-detective-common/tree/schema/schemas) directory and made available through the `.schemas` object.
66
-
67
- ```json
68
- {
69
- "analytics_v1": {Object},
70
- "checkLink_v1": {Object},
71
- "click_v1": {Object},
72
- "find_v1": {Object},
73
- "goTo_v1": {Object},
74
- "httpRequest_v1": {Object},
75
- "matchText_v1": {Object},
76
- "moveMouse_v1": {Object},
77
- "runShell_v1": {Object},
78
- "screenshot_v1": {Object},
79
- "scroll_v1": {Object},
80
- "startRecording_v1": {Object},
81
- "stopRecording_v1": {Object},
82
- "type_v1": {Object},
83
- "wait_v1": {Object}
84
- }
85
- ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "doc-detective-common",
3
- "version": "3.0.0-dev.3",
3
+ "version": "3.0.0",
4
4
  "description": "Shared components for Doc Detective projects.",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/files.js CHANGED
@@ -4,13 +4,15 @@ const axios = require("axios");
4
4
  const { URL } = require("url");
5
5
 
6
6
  /**
7
- * Reads a file from a given URL or local file path and returns its content.
8
- * Supports JSON and YAML file formats.
7
+ * Reads and parses content from a remote URL or local file path, supporting JSON and YAML formats.
9
8
  *
10
- * @param {string} fileURLOrPath - The URL or local file path of the file to read.
11
- * @returns {Promise<Object|string|null>} - The parsed content of the file if it's JSON or YAML,
12
- * the raw content if it's another format,
13
- * or null if an error occurs.
9
+ * Attempts to parse the file content as JSON first, then YAML. If both parsing attempts fail, returns the raw content as a string. Returns `null` if the file cannot be read.
10
+ *
11
+ * @param {Object} options
12
+ * @param {string} options.fileURLOrPath - The URL or local file path to read.
13
+ * @returns {Promise<Object|string|null>} Parsed object for JSON or YAML files, raw string for other formats, or `null` if reading fails.
14
+ *
15
+ * @throws {Error} If {@link fileURLOrPath} is missing, not a string, or is an empty string.
14
16
  */
15
17
  async function readFile({ fileURLOrPath }) {
16
18
  if (!fileURLOrPath) {
@@ -5,21 +5,19 @@ const { validate } = require("./validate");
5
5
  exports.resolvePaths = resolvePaths;
6
6
 
7
7
  /**
8
- * Resolves relative paths in configuration and specification objects to absolute paths.
8
+ * Recursively resolves all relative path properties in a configuration or specification object to absolute paths.
9
9
  *
10
- * This function traverses an object (either a config or spec) and converts all path properties
11
- * to absolute paths based on the provided configuration and file path. It can handle nested objects
12
- * and special path relationships like path/directory and savePath/saveDirectory.
10
+ * Traverses the provided object, converting all recognized path-related properties to absolute paths using the given configuration and reference file path. Supports nested objects and distinguishes between config and spec objects based on schema validation. Throws an error if the object is not a valid config or spec, or if the object type is missing for nested objects.
13
11
  *
14
12
  * @async
15
- * @param {Object} options - The options object.
16
- * @param {Object} options.config - The configuration object containing settings like relativePathBase.
17
- * @param {Object} options.object - The object whose paths need to be resolved.
18
- * @param {string} options.filePath - The reference file path for resolving relative paths.
19
- * @param {boolean} [options.nested=false] - Flag indicating if this is a recursive call for a nested object.
20
- * @param {string} [options.objectType] - The type of object ('config' or 'spec'). Required for nested objects.
21
- * @returns {Promise<Object>} The object with all paths resolved to absolute paths.
22
- * @throws {Error} Throws an error if the object isn't a valid config or spec, or if objectType is missing for nested objects.
13
+ * @param {Object} options - Options for path resolution.
14
+ * @param {Object} options.config - Configuration object containing settings such as `relativePathBase`.
15
+ * @param {Object} options.object - The config or spec object whose path properties will be resolved.
16
+ * @param {string} options.filePath - Reference file path used for resolving relative paths.
17
+ * @param {boolean} [options.nested=false] - Indicates if this is a recursive call for a nested object.
18
+ * @param {string} [options.objectType] - Specifies the object type ('config' or 'spec'); required for nested objects.
19
+ * @returns {Promise<Object>} The object with all applicable path properties resolved to absolute paths.
20
+ * @throws {Error} If the object is neither a valid config nor spec, or if `objectType` is missing for nested objects.
23
21
  */
24
22
  async function resolvePaths({
25
23
  config,
@@ -66,12 +64,14 @@ async function resolvePaths({
66
64
  ];
67
65
 
68
66
  /**
69
- * Resolves a path based on the provided base type, relative path, and file path.
67
+ * Resolves a relative path to an absolute path using a specified base type and reference file path.
70
68
  *
71
- * @param {string} baseType - The base type of the path ("file" or "cwd").
72
- * @param {string} relativePath - The relative path to resolve.
73
- * @param {string} filePath - The file path to use as a reference.
74
- * @returns {string} - The resolved path.
69
+ * @param {string} baseType - Indicates whether to resolve relative to the reference file's directory ("file") or the current working directory ("cwd").
70
+ * @param {string} relativePath - The path to resolve, which may be relative or absolute.
71
+ * @param {string} filePath - The reference file or directory path used for resolution.
72
+ * @returns {string} The absolute path corresponding to {@link relativePath}.
73
+ *
74
+ * @remark If {@link relativePath} is already absolute, it is returned unchanged. If {@link filePath} does not exist, its extension is used to infer whether it is a file or directory.
75
75
  */
76
76
  function resolve(baseType, relativePath, filePath) {
77
77
  // If path is already absolute, return it
@@ -6,9 +6,12 @@ const fs = require("fs");
6
6
  await dereferenceSchemas();
7
7
  })();
8
8
 
9
- /*
10
- * Walks through all schema in src/src_schema
11
- * For each schema, dereferences it and writes it to src/schema
9
+ /**
10
+ * Processes JSON schema files by updating reference paths, dereferencing all `$ref` pointers, and generating fully resolved schema outputs.
11
+ *
12
+ * For each schema in the input directory, this function updates reference paths, writes intermediate schemas to a build directory, dereferences all references, removes `$id` properties, and writes the final schemas to an output directory. It also creates a consolidated `schemas.json` file containing all dereferenced schemas keyed by filename.
13
+ *
14
+ * @remark The function assumes all schema files listed exist in the input directory and does not handle missing files or invalid JSON beyond throwing synchronous errors.
12
15
  */
13
16
  async function dereferenceSchemas() {
14
17
  const inputDir = path.resolve(`${__dirname}/src_schemas`);
@@ -127,7 +130,12 @@ function updateRefPaths(schema) {
127
130
  return schema;
128
131
  }
129
132
 
130
- // Prepend app-root path to referenced relative paths
133
+ /**
134
+ * Recursively removes all `$id` properties from a JSON schema object.
135
+ *
136
+ * @param {object} schema - The JSON schema object to process.
137
+ * @returns {object} The schema object with all `$id` properties deleted.
138
+ */
131
139
  function deleteDollarIds(schema) {
132
140
  for (let [key, value] of Object.entries(schema)) {
133
141
  if (typeof value === "object") {
@@ -5,7 +5,7 @@
5
5
  {
6
6
  "description": "Check if an HTTP or HTTPS URL returns an acceptable status code from a GET request.",
7
7
  "type": "string",
8
- "pattern": "(^(http://|https://|/).*|\\$[A-Za-z0-9_]+)",
8
+ "pattern": "(^(http://|https://|\\/).*|\\$[A-Za-z0-9_]+$)",
9
9
  "transform": [
10
10
  "trim"
11
11
  ]
@@ -66,7 +66,7 @@
66
66
  "string": {
67
67
  "description": "Check if an HTTP or HTTPS URL returns an acceptable status code from a GET request.",
68
68
  "type": "string",
69
- "pattern": "(^(http://|https://|/).*|\\$[A-Za-z0-9_]+)",
69
+ "pattern": "(^(http://|https://|\\/).*|\\$[A-Za-z0-9_]+$)",
70
70
  "transform": [
71
71
  "trim"
72
72
  ]
@@ -14,6 +14,20 @@
14
14
  },
15
15
  {
16
16
  "type": "object",
17
+ "anyOf": [
18
+ {
19
+ "required": [
20
+ "button",
21
+ "selector"
22
+ ]
23
+ },
24
+ {
25
+ "required": [
26
+ "button",
27
+ "elementText"
28
+ ]
29
+ }
30
+ ],
17
31
  "properties": {
18
32
  "button": {
19
33
  "description": "Kind of click to perform.",
@@ -35,8 +49,7 @@
35
49
  }
36
50
  },
37
51
  {
38
- "type": "boolean",
39
- "nullable": true
52
+ "type": "boolean"
40
53
  }
41
54
  ],
42
55
  "components": {
@@ -52,6 +65,20 @@
52
65
  },
53
66
  "object": {
54
67
  "type": "object",
68
+ "anyOf": [
69
+ {
70
+ "required": [
71
+ "button",
72
+ "selector"
73
+ ]
74
+ },
75
+ {
76
+ "required": [
77
+ "button",
78
+ "elementText"
79
+ ]
80
+ }
81
+ ],
55
82
  "properties": {
56
83
  "button": {
57
84
  "description": "Kind of click to perform.",