automation_model 1.0.49 → 1.0.50

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.
@@ -0,0 +1,61 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+
4
+ function stringifyObject(obj, indentation = 0) {
5
+ let result = "";
6
+ const indent = " ".repeat(indentation);
7
+ if (Array.isArray(obj)) {
8
+ result += "[";
9
+ for (let i = 0; i < obj.length; i++) {
10
+ result += (i > 0 ? ", " : "") + stringifyObject(obj[i], indentation + 2);
11
+ }
12
+ result += "]";
13
+ } else if (typeof obj === "object" && obj !== null) {
14
+ result += "{";
15
+ let first = true;
16
+ for (let key in obj) {
17
+ // eslint-disable-next-line no-prototype-builtins
18
+ if (obj.hasOwnProperty(key)) {
19
+ result +=
20
+ (first ? "\n" : ",\n") +
21
+ indent +
22
+ " " +
23
+ JSON.stringify(key) +
24
+ ": " +
25
+ stringifyObject(obj[key], indentation + 2);
26
+ first = false;
27
+ }
28
+ }
29
+ result += "\n" + indent + "}";
30
+ } else {
31
+ result += JSON.stringify(obj);
32
+ }
33
+ return result;
34
+ }
35
+
36
+ const __dirname = path.resolve();
37
+ const getTableCells = async (page, element, tableSelector, info = {}) => {
38
+ let script = fs.readFileSync(path.join(__dirname, "src", "locator.js"), "utf8");
39
+ let aiConfigPath = path.join(process.cwd(), "ai_config.json");
40
+ if (fs.existsSync(aiConfigPath)) {
41
+ let aiConfig = JSON.parse(fs.readFileSync(aiConfigPath, "utf8"));
42
+ if (aiConfig.changes) {
43
+ script = script.replace("const selectors = null", "const selectors = " + stringifyObject(aiConfig.changes));
44
+ }
45
+ }
46
+ script = script.replace("const tableSelector = null", "const tableSelector = " + stringifyObject(tableSelector));
47
+ await page.evaluate(script);
48
+ try {
49
+ let result = await element.evaluate((_node) => {
50
+ console.log("tableSelector", document.tableSelector);
51
+ return document.processTableQuary(_node, document.tableSelector);
52
+ });
53
+ info.box = result.rect;
54
+ return result.cells;
55
+ } catch (error) {
56
+ console.log("error", error);
57
+ throw error;
58
+ }
59
+ };
60
+
61
+ export { getTableCells };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "automation_model",
3
- "version": "1.0.49",
3
+ "version": "1.0.50",
4
4
  "description": "An automation infrastructure module to be use for generative AI automation projects.",
5
5
  "main": "bin/index.js",
6
6
  "type": "module",
@@ -8,7 +8,7 @@
8
8
  "lib": "lib"
9
9
  },
10
10
  "scripts": {
11
- "pack": "mkdir build && mkdir build/bin && cp ./src/auto_page.js ./build/bin/auto_page.js && cp ./src/environment.js ./build/bin/environment.js && cp ./src/browser_manager.js ./build/bin/browser_manager.js && cp ./src/test_context.js ./build/bin/test_context.js && cp ./src/init_browser.js ./build/bin/init_browser.js && cp ./src/stable_browser.js ./build/bin/stable_browser.js && cp ./src/index.js ./build/bin/index.js && cp ./package.json ./build/package.json",
11
+ "pack": "mkdir build && mkdir build/bin && cp ./src/auto_page.js ./build/bin/auto_page.js && cp ./src/environment.js ./build/bin/environment.js && cp ./src/browser_manager.js ./build/bin/browser_manager.js && cp ./src/test_context.js ./build/bin/test_context.js && cp ./src/init_browser.js ./build/bin/init_browser.js && cp ./src/stable_browser.js ./build/bin/stable_browser.js && cp ./src/index.js ./build/bin/index.js && cp ./package.json ./build/package.json && cp ./src/table_analyze.js ./build/bin/table_analyze.js",
12
12
  "clean": "rm -rf ./build",
13
13
  "build": "npm run clean && npm run pack",
14
14
  "test": "node ./tests/launch_page.js"