doc-detective-common 1.0.3 → 1.2.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 (32) hide show
  1. package/README.md +54 -11
  2. package/icon.png +0 -0
  3. package/index.js +4 -12
  4. package/package.json +14 -3
  5. package/src/schema.js +47 -0
  6. package/{schema/v1/analytics.schema.json → src/schemas/analytics_v1.schema.json} +140 -0
  7. package/src/schemas/checkLink_v1.schema.json +42 -0
  8. package/src/schemas/checkLink_v2.schema.json +54 -0
  9. package/src/schemas/click_v1.schema.json +60 -0
  10. package/src/schemas/find_v1.schema.json +137 -0
  11. package/src/schemas/find_v2.schema.json +78 -0
  12. package/src/schemas/goTo_v1.schema.json +30 -0
  13. package/src/schemas/goTo_v2.schema.json +46 -0
  14. package/src/schemas/httpRequest_v1.schema.json +115 -0
  15. package/src/schemas/httpRequest_v2.schema.json +168 -0
  16. package/src/schemas/matchText_v1.schema.json +32 -0
  17. package/src/schemas/moveMouse_v1.schema.json +60 -0
  18. package/{schema/v1/actions/runShell.schema.json → src/schemas/runShell_v1.schema.json} +13 -4
  19. package/src/schemas/runShell_v2.schema.json +54 -0
  20. package/src/schemas/saveScreenshot_v2.schema.json +41 -0
  21. package/src/schemas/screenshot_v1.schema.json +48 -0
  22. package/src/schemas/scroll_v1.schema.json +50 -0
  23. package/src/schemas/setVariables_v2.schema.json +38 -0
  24. package/src/schemas/startRecording_v1.schema.json +55 -0
  25. package/src/schemas/startRecording_v2.schema.json +47 -0
  26. package/src/schemas/stopRecording_v1.schema.json +20 -0
  27. package/src/schemas/typeKeys_v2.schema.json +50 -0
  28. package/src/schemas/type_v1.schema.json +62 -0
  29. package/src/schemas/wait_v1.schema.json +42 -0
  30. package/src/schemas/wait_v2.schema.json +41 -0
  31. package/src/validate.js +43 -0
  32. package/test/schema.test.js +17 -0
package/README.md CHANGED
@@ -1,38 +1,81 @@
1
1
  # Doc Detective Common
2
2
 
3
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)
4
+ [![NPM Shield](https://img.shields.io/npm/v/doc-detective-common)](https://www.npmjs.com/package/doc-detective-common)
5
5
  [![Discord Shield](https://img.shields.io/badge/chat-on%20discord-purple)](https://discord.gg/mSCCRAhH)
6
6
 
7
7
  Shared resources for Doc Detective projects.
8
8
 
9
9
  ## Install
10
10
 
11
- ```
11
+ ```bash
12
12
  npm i doc-detective-common
13
13
  ```
14
14
 
15
15
  ## Init
16
16
 
17
- ```
17
+ ```javascript
18
18
  const common = require("doc-detective-common");
19
19
  ```
20
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
+
21
55
  ## Objects
22
56
 
23
- ### `common.schema`
57
+ ### `.schemas`
24
58
 
25
59
  JSON schema definitions for various objects used throughout Doc Detective.
26
60
 
27
- Schema files are located in the [`/schema`](https://github.com/doc-detective/doc-detective-common/tree/schema/schema) directory and made available through the `common.schema` object.
61
+ 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.
28
62
 
29
63
  ```json
30
64
  {
31
- "v1": {
32
- "actions": {
33
- "runShell": {Object}
34
- },
35
- "analytics": {Object}
36
- }
65
+ "analytics_v1": {Object},
66
+ "checkLink_v1": {Object},
67
+ "click_v1": {Object},
68
+ "find_v1": {Object},
69
+ "goTo_v1": {Object},
70
+ "httpRequest_v1": {Object},
71
+ "matchText_v1": {Object},
72
+ "moveMouse_v1": {Object},
73
+ "runShell_v1": {Object},
74
+ "screenshot_v1": {Object},
75
+ "scroll_v1": {Object},
76
+ "startRecording_v1": {Object},
77
+ "stopRecording_v1": {Object},
78
+ "type_v1": {Object},
79
+ "wait_v1": {Object}
37
80
  }
38
81
  ```
package/icon.png ADDED
Binary file
package/index.js CHANGED
@@ -1,13 +1,5 @@
1
- const v1_analytics = require("./schema/v1/analytics.schema.json");
2
- const v1_runShell = require("./schema/v1/actions/runShell.schema.json");
1
+ const { schemas } = require("./src/schema");
2
+ const { validate } = require("./src/validate");
3
3
 
4
- const schema = {
5
- v1: {
6
- actions: {
7
- runShell: v1_runShell,
8
- },
9
- analytics: v1_analytics,
10
- },
11
- };
12
-
13
- exports.schema = schema;
4
+ exports.schemas = schemas;
5
+ exports.validate = validate;
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "doc-detective-common",
3
- "version": "1.0.3",
3
+ "version": "1.2.1",
4
4
  "description": "Shared components for Doc Detective projects.",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 0"
7
+ "test": "jest"
8
8
  },
9
9
  "repository": {
10
10
  "type": "git",
@@ -15,5 +15,16 @@
15
15
  "bugs": {
16
16
  "url": "https://github.com/doc-detective/doc-detective-common/issues"
17
17
  },
18
- "homepage": "https://github.com/doc-detective/doc-detective-common#readme"
18
+ "homepage": "https://github.com/doc-detective/doc-detective-common#readme",
19
+ "devDependencies": {
20
+ "jest": "^29.4.1"
21
+ },
22
+ "dependencies": {
23
+ "ajv": "^8.12.0",
24
+ "ajv-errors": "^3.0.0",
25
+ "ajv-formats": "^2.1.1",
26
+ "ajv-keywords": "^5.1.0",
27
+ "app-root-path": "^3.1.0",
28
+ "uuid": "^9.0.0"
29
+ }
19
30
  }
package/src/schema.js ADDED
@@ -0,0 +1,47 @@
1
+ const approot = require("app-root-path");
2
+ const fs = require("fs");
3
+
4
+ //// Init
5
+ const schemas = {};
6
+
7
+ //// Process
8
+ loadSchemas();
9
+ // console.log(schemas.find_v1)
10
+ //// Export
11
+ exports.schemas = schemas;
12
+
13
+ //// Functions
14
+
15
+ // Load schemas from file
16
+ function loadSchemas() {
17
+ // Read files from schema directory
18
+ path = `${__dirname}/schemas`;
19
+ var files = fs.readdirSync(path);
20
+ // Loop through all schema files
21
+ files.forEach(async (file) => {
22
+ // Exit early for files that don't match naming pattern
23
+ if (!file.includes(".schema.json")) return;
24
+ const key = file.replace(".schema.json", "");
25
+ // Load schema from file
26
+ let schema = require(`./schemas/${file}`);
27
+ // Add dynamic ID based on file path
28
+ schema.$id = `file://${__dirname}/schemas/${file}`;
29
+ // Recursively update relative references with app root path
30
+ schema = updateRefPaths(schema);
31
+ // Load into `schema` object
32
+ schemas[key] = schema;
33
+ });
34
+ }
35
+
36
+ // Prepend app-root path to referenced relative paths
37
+ function updateRefPaths(schema) {
38
+ for (let [key, value] of Object.entries(schema)) {
39
+ if (typeof value === "object") {
40
+ updateRefPaths(value);
41
+ }
42
+ if (key === "$ref") {
43
+ schema[key] = `file://${__dirname}/schemas/${value}`;
44
+ }
45
+ }
46
+ return schema;
47
+ }
@@ -441,5 +441,145 @@
441
441
  "required": [
442
442
  "version",
443
443
  "detailLevel"
444
+ ],
445
+ "examples": [
446
+ {
447
+ "version": "0.1.8",
448
+ "userId": "",
449
+ "detailLevel": "action-detailed",
450
+ "tests": {
451
+ "numberTests": 0,
452
+ "passed": 0,
453
+ "failed": 0
454
+ },
455
+ "actions": {
456
+ "numberActions": 0,
457
+ "averageNumberActionsPerTest": 0,
458
+ "maxActionsPerTest": 0,
459
+ "minActionsPerTest": 0,
460
+ "passed": 0,
461
+ "failed": 0
462
+ },
463
+ "actionDetails": {
464
+ "goTo": {
465
+ "numberInstances": 0,
466
+ "passed": 0,
467
+ "failed": 0,
468
+ "uri": 0
469
+ },
470
+ "find": {
471
+ "numberInstances": 0,
472
+ "passed": 0,
473
+ "failed": 0,
474
+ "wait": {
475
+ "numberInstances": 0,
476
+ "duration": 0
477
+ },
478
+ "matchText": {
479
+ "numberInstances": 0,
480
+ "text": 0
481
+ },
482
+ "moveMouse": {
483
+ "numberInstances": 0,
484
+ "alignH": 0,
485
+ "alignV": 0,
486
+ "offsetX": 0,
487
+ "offsetY": 0
488
+ },
489
+ "click": {
490
+ "numberInstances": 0
491
+ },
492
+ "type": {
493
+ "numberInstances": 0,
494
+ "keys": 0,
495
+ "trailingSpecialKey": 0,
496
+ "env": 0
497
+ }
498
+ },
499
+ "matchText": {
500
+ "numberInstances": 0,
501
+ "passed": 0,
502
+ "failed": 0,
503
+ "css": 0,
504
+ "text": 0
505
+ },
506
+ "click": {
507
+ "numberInstances": 0,
508
+ "passed": 0,
509
+ "failed": 0,
510
+ "css": 0
511
+ },
512
+ "type": {
513
+ "numberInstances": 0,
514
+ "passed": 0,
515
+ "failed": 0,
516
+ "css": 0,
517
+ "keys": 0,
518
+ "trailingSpecialKey": 0,
519
+ "env": 0
520
+ },
521
+ "moveMouse": {
522
+ "numberInstances": 0,
523
+ "passed": 0,
524
+ "failed": 0,
525
+ "css": 0,
526
+ "alignH": 0,
527
+ "alignV": 0,
528
+ "offsetX": 0,
529
+ "offsetY": 0
530
+ },
531
+ "scroll": {
532
+ "numberInstances": 0,
533
+ "passed": 0,
534
+ "failed": 0,
535
+ "x": 0,
536
+ "y": 0
537
+ },
538
+ "wait": {
539
+ "numberInstances": 0,
540
+ "passed": 0,
541
+ "failed": 0,
542
+ "duration": 0,
543
+ "css": 0
544
+ },
545
+ "screenshot": {
546
+ "numberInstances": 0,
547
+ "passed": 0,
548
+ "failed": 0,
549
+ "mediaDirectory": 0,
550
+ "filename": 0,
551
+ "matchPrevious": 0,
552
+ "matchThreshold": 0
553
+ },
554
+ "startRecording": {
555
+ "numberInstances": 0,
556
+ "passed": 0,
557
+ "failed": 0,
558
+ "mediaDirectory": 0,
559
+ "filename": 0,
560
+ "gifFps": 0,
561
+ "gifWidth": 0
562
+ },
563
+ "stopRecording": {
564
+ "numberInstances": 0,
565
+ "passed": 0,
566
+ "failed": 0
567
+ },
568
+ "checkLink": {
569
+ "numberInstances": 0,
570
+ "passed": 0,
571
+ "failed": 0,
572
+ "uri": 0,
573
+ "statusCodes": 0
574
+ },
575
+ "runShell": {
576
+ "numberInstances": 0,
577
+ "passed": 0,
578
+ "failed": 0,
579
+ "command": 0,
580
+ "env": 0
581
+ }
582
+ }
583
+ }
444
584
  ]
445
585
  }
@@ -0,0 +1,42 @@
1
+ {
2
+ "title": "checkLink",
3
+ "type": "object",
4
+ "description": "Check if a URI returns an acceptable status code from a GET request.",
5
+ "properties": {
6
+ "action": {
7
+ "type": "string",
8
+ "const": "checkLink"
9
+ },
10
+ "uri": {
11
+ "type": "string",
12
+ "description": "URI to check."
13
+ },
14
+ "statusCodes": {
15
+ "type": "array",
16
+ "items": {
17
+ "type": "integer"
18
+ },
19
+ "default": [
20
+ 200
21
+ ]
22
+ }
23
+ },
24
+ "required": [
25
+ "action",
26
+ "uri"
27
+ ],
28
+ "additionalProperties": false,
29
+ "examples": [
30
+ {
31
+ "action": "checkLink",
32
+ "uri": "https://www.google.com"
33
+ },
34
+ {
35
+ "action": "checkLink",
36
+ "uri": "https://www.google.com",
37
+ "statusCodes": [
38
+ 200
39
+ ]
40
+ }
41
+ ]
42
+ }
@@ -0,0 +1,54 @@
1
+ {
2
+ "title": "checkLink",
3
+ "type": "object",
4
+ "description": "Check if a URL returns an acceptable status code from a GET request.",
5
+ "properties": {
6
+ "id": {
7
+ "type": "string",
8
+ "description": "ID of the step."
9
+ },
10
+ "description": {
11
+ "type": "string",
12
+ "description": "Description of the step."
13
+ },
14
+ "action": {
15
+ "type": "string",
16
+ "const": "checkLink",
17
+ "description": "Action to perform."
18
+ },
19
+ "url": {
20
+ "type": "string",
21
+ "format": "uri",
22
+ "description": "URL to check.",
23
+ "pattern": "^(http://|https://).*",
24
+ "transform": ["trim"]
25
+ },
26
+ "statusCodes": {
27
+ "type": "array",
28
+ "items": {
29
+ "oneOf": [
30
+ {
31
+ "type": "integer"
32
+ }
33
+ ]
34
+ },
35
+ "default": [200]
36
+ }
37
+ },
38
+ "dynamicDefaults": {
39
+ "id": "uuid"
40
+ },
41
+ "required": ["action", "url"],
42
+ "additionalProperties": false,
43
+ "examples": [
44
+ {
45
+ "action": "checkLink",
46
+ "url": "https://www.google.com"
47
+ },
48
+ {
49
+ "action": "checkLink",
50
+ "url": "https://www.google.com",
51
+ "statusCodes": [200]
52
+ }
53
+ ]
54
+ }
@@ -0,0 +1,60 @@
1
+ {
2
+ "title": "click",
3
+ "type": "object",
4
+ "description": "Click an element specified by a CSS sepector.",
5
+ "properties": {
6
+ "action": {
7
+ "type": "string",
8
+ "const": "click"
9
+ },
10
+ "css": {
11
+ "type": "string",
12
+ "description": "CSS selector that uniquely identified the element."
13
+ },
14
+ "alignH": {
15
+ "type": "string",
16
+ "description": "Horizantal alignment of the mouse to the element.",
17
+ "enum": [
18
+ "left",
19
+ "center",
20
+ "right"
21
+ ]
22
+ },
23
+ "alignV": {
24
+ "type": "string",
25
+ "description": "Vertical alignment of the mouse to the element.",
26
+ "enum": [
27
+ "left",
28
+ "center",
29
+ "right"
30
+ ]
31
+ },
32
+ "offsetX": {
33
+ "type": "integer",
34
+ "description": "Number of pixels to offset the mouse along the X axis, relative to the element center. Positive values offset to the right. Negative values offset to the left."
35
+ },
36
+ "offsetY": {
37
+ "type": "integer",
38
+ "description": "Number of pixels to offset the mouse along the Y axis, relative to the element center. Positive values offset to the top. Negative values offset to the bottom."
39
+ }
40
+ },
41
+ "required": [
42
+ "action",
43
+ "css"
44
+ ],
45
+ "additionalProperties": false,
46
+ "examples": [
47
+ {
48
+ "action": "click",
49
+ "css": "#gbqfbb"
50
+ },
51
+ {
52
+ "action": "click",
53
+ "css": "#gbqfbb",
54
+ "alignH": "center",
55
+ "alignV": "center",
56
+ "offsetX": 10,
57
+ "offsetY": 10
58
+ }
59
+ ]
60
+ }
@@ -0,0 +1,137 @@
1
+ {
2
+ "title": "find",
3
+ "type": "object",
4
+ "description": "Check if an element exists with the specified CSS selector.",
5
+ "properties": {
6
+ "action": {
7
+ "type": "string",
8
+ "const": "find"
9
+ },
10
+ "css": {
11
+ "type": "string",
12
+ "description": "CSS selector that uniquely identified the element."
13
+ },
14
+ "wait": {
15
+ "type": "object",
16
+ "description": "Pause before performing the next action.",
17
+ "additionalProperties": false,
18
+ "properties": {
19
+ "duration": {
20
+ "$ref": "wait_v1.schema.json#/properties/duration"
21
+ }
22
+ }
23
+ },
24
+ "matchText": {
25
+ "type": "object",
26
+ "description": "Check if an element displays the expected text.",
27
+ "additionalProperties": false,
28
+ "properties": {
29
+ "text": {
30
+ "$ref": "matchText_v1.schema.json#/properties/text"
31
+ }
32
+ },
33
+ "required": [
34
+ "text"
35
+ ]
36
+ },
37
+ "moveMouse": {
38
+ "type": "object",
39
+ "description": "Move the mouse to an element specified by a CSS sepector. Only runs if a test is being recorded.",
40
+ "additionalProperties": false,
41
+ "properties": {
42
+ "alignH": {
43
+ "$ref": "moveMouse_v1.schema.json#/properties/alignH"
44
+ },
45
+ "alignV": {
46
+ "$ref": "moveMouse_v1.schema.json#/properties/alignV"
47
+ },
48
+ "offsetX": {
49
+ "$ref": "moveMouse_v1.schema.json#/properties/offsetX"
50
+ },
51
+ "offsetY": {
52
+ "$ref": "moveMouse_v1.schema.json#/properties/offsetY"
53
+ }
54
+ }
55
+ },
56
+ "click": {
57
+ "type": "object",
58
+ "description": "Click an element specified by a CSS sepector.",
59
+ "additionalProperties": false,
60
+ "properties": {
61
+ "alignH": {
62
+ "$ref": "click_v1.schema.json#/properties/alignH"
63
+ },
64
+ "alignV": {
65
+ "$ref": "click_v1.schema.json#/properties/alignV"
66
+ },
67
+ "offsetX": {
68
+ "$ref": "click_v1.schema.json#/properties/offsetX"
69
+ },
70
+ "offsetY": {
71
+ "$ref": "click_v1.schema.json#/properties/offsetY"
72
+ }
73
+ }
74
+ },
75
+ "type": {
76
+ "type": "object",
77
+ "description": "Click an element specified by a CSS sepector.",
78
+ "additionalProperties": false,
79
+ "anyOf": [
80
+ {
81
+ "required": [
82
+ "keys"
83
+ ]
84
+ },
85
+ {
86
+ "required": [
87
+ "trailingSpecialKey"
88
+ ]
89
+ }
90
+ ],
91
+ "properties": {
92
+ "keys": {
93
+ "$ref": "type_v1.schema.json#/properties/keys"
94
+ },
95
+ "trailingSpecialKey": {
96
+ "$ref": "type_v1.schema.json#/properties/trailingSpecialKey"
97
+ },
98
+ "env": {
99
+ "$ref": "type_v1.schema.json#/properties/env"
100
+ }
101
+ }
102
+ }
103
+ },
104
+ "required": [
105
+ "action",
106
+ "css"
107
+ ],
108
+ "additionalProperties": false,
109
+ "examples": [
110
+ {
111
+ "action": "find",
112
+ "css": "[title=Search]"
113
+ },
114
+ {
115
+ "action": "find",
116
+ "css": "[title=Search]",
117
+ "wait": {
118
+ "duration": 10000
119
+ },
120
+ "matchText": {
121
+ "text": "Search"
122
+ },
123
+ "moveMouse": {
124
+ "alignH": "center",
125
+ "alignV": "center",
126
+ "offsetX": 0,
127
+ "offsetY": 0
128
+ },
129
+ "click": {},
130
+ "type": {
131
+ "keys": "$SHORTHAIR_CAT_SEARCH",
132
+ "trailingSpecialKey": "Enter",
133
+ "env": "./sample/variables.env"
134
+ }
135
+ }
136
+ ]
137
+ }