@intuned/browser-dev 2.2.3-unify-sdks.20

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 (195) hide show
  1. package/.babelrc +21 -0
  2. package/.eslintignore +10 -0
  3. package/.eslintrc.js +39 -0
  4. package/LICENSE +43 -0
  5. package/dist/ai-extractors/AnthropicClient/index.js +23 -0
  6. package/dist/ai-extractors/export.d.js +5 -0
  7. package/dist/ai-extractors/export.d.ts +422 -0
  8. package/dist/ai-extractors/extractStructuredData.js +79 -0
  9. package/dist/ai-extractors/extractionHelpers/extractStructuredDataUsingAi/constants.js +7 -0
  10. package/dist/ai-extractors/extractionHelpers/extractStructuredDataUsingAi/errors.js +42 -0
  11. package/dist/ai-extractors/extractionHelpers/extractStructuredDataUsingAi/extractStructuredDataUsingClaude.js +149 -0
  12. package/dist/ai-extractors/extractionHelpers/extractStructuredDataUsingAi/extractStructuredDataUsingGoogle.js +37 -0
  13. package/dist/ai-extractors/extractionHelpers/extractStructuredDataUsingAi/extractStructuredDataUsingOpenAi.js +144 -0
  14. package/dist/ai-extractors/extractionHelpers/extractStructuredDataUsingAi/extractStrucutredDataUsingAiInstance.js +123 -0
  15. package/dist/ai-extractors/extractionHelpers/extractStructuredDataUsingAi/index.js +55 -0
  16. package/dist/ai-extractors/extractionHelpers/extractStructuredDataUsingAi/isItemTableHeaderOrFooter.js +96 -0
  17. package/dist/ai-extractors/extractionHelpers/extractStructuredDataUsingAi/screenshotHelpers.js +55 -0
  18. package/dist/ai-extractors/extractionHelpers/extractStructuredDataUsingAi/types.js +5 -0
  19. package/dist/ai-extractors/extractionHelpers/extractStructuredDataUsingAi/utils.js +53 -0
  20. package/dist/ai-extractors/extractionHelpers/types.js +5 -0
  21. package/dist/ai-extractors/fileExtractors.js +176 -0
  22. package/dist/ai-extractors/index.js +31 -0
  23. package/dist/ai-extractors/jsonSchema.d.js +5 -0
  24. package/dist/ai-extractors/jsonSchema.d.ts +49 -0
  25. package/dist/ai-extractors/openAiClients/index.js +23 -0
  26. package/dist/ai-extractors/validators.js +239 -0
  27. package/dist/browser/ai/export.d.js +3 -0
  28. package/dist/browser/ai/export.d.ts +587 -0
  29. package/dist/browser/ai/extractMarkdown.js +15 -0
  30. package/dist/browser/ai/extractStructuredData.js +231 -0
  31. package/dist/browser/ai/extractStructuredDataUsingAi.js +140 -0
  32. package/dist/browser/ai/extractionHelpers/screenshotHelpers.js +55 -0
  33. package/dist/browser/ai/extractionHelpers/validateSchema.js +148 -0
  34. package/dist/browser/ai/index.d.ts +587 -0
  35. package/dist/browser/ai/index.js +19 -0
  36. package/dist/browser/ai/isPageLoaded.js +67 -0
  37. package/dist/browser/ai/prompt.js +39 -0
  38. package/dist/browser/ai/tests/testCheckAllTypesAreStrings.spec.js +143 -0
  39. package/dist/browser/ai/tests/testExtractStructuredData.spec.js +622 -0
  40. package/dist/browser/ai/tools/index.js +48 -0
  41. package/dist/browser/ai/types/errors.js +67 -0
  42. package/dist/browser/ai/types/models.js +45 -0
  43. package/dist/browser/ai/types/types.js +48 -0
  44. package/dist/browser/ai/validators.js +136 -0
  45. package/dist/common/Logger/index.js +60 -0
  46. package/dist/common/Logger/types.js +5 -0
  47. package/dist/common/SdkError.js +50 -0
  48. package/dist/common/aiModelsValidations.js +50 -0
  49. package/dist/common/browser_scripts.js +2596 -0
  50. package/dist/common/ensureBrowserScripts.js +17 -0
  51. package/dist/common/environmentVariables.js +16 -0
  52. package/dist/common/eventTracking/getAiTrackingHeaders.js +31 -0
  53. package/dist/common/eventTracking/getFileTrackingHeaders.js +23 -0
  54. package/dist/common/extendedTest.js +148 -0
  55. package/dist/common/extractionHelpers.js +19 -0
  56. package/dist/common/formatZodError.js +18 -0
  57. package/dist/common/fuzzySearch/fuzzySearch.test.js +250 -0
  58. package/dist/common/fuzzySearch/levenshtein-search.js +298 -0
  59. package/dist/common/fuzzySearch/utils.js +23 -0
  60. package/dist/common/getModelProvider.js +18 -0
  61. package/dist/common/getSimplifiedHtml.js +122 -0
  62. package/dist/common/hashObject.js +32 -0
  63. package/dist/common/html2markdown/convertElementToMarkdown.js +469 -0
  64. package/dist/common/html2markdown/index.js +19 -0
  65. package/dist/common/jwtTokenManager.js +18 -0
  66. package/dist/common/loadRuntime.js +16 -0
  67. package/dist/common/locatorHelpers.js +41 -0
  68. package/dist/common/matching/collectStrings.js +32 -0
  69. package/dist/common/matching/levenshtein.js +40 -0
  70. package/dist/common/matching/matching.js +317 -0
  71. package/dist/common/matching/types.js +1 -0
  72. package/dist/common/noEmpty.js +9 -0
  73. package/dist/common/saveSnapshotWithExamples.js +60 -0
  74. package/dist/common/tests/testEnsureBrowserScript.spec.js +31 -0
  75. package/dist/common/xpathMapping.js +107 -0
  76. package/dist/helpers/downloadFile.js +125 -0
  77. package/dist/helpers/export.d.js +1 -0
  78. package/dist/helpers/export.d.ts +1294 -0
  79. package/dist/helpers/extractMarkdown.js +35 -0
  80. package/dist/helpers/filterEmptyValues.js +54 -0
  81. package/dist/helpers/gotoUrl.js +93 -0
  82. package/dist/helpers/index.d.ts +1294 -0
  83. package/dist/helpers/index.js +115 -0
  84. package/dist/helpers/processDate.js +25 -0
  85. package/dist/helpers/resolveUrl.js +63 -0
  86. package/dist/helpers/sanitizeHtml.js +73 -0
  87. package/dist/helpers/saveFileToS3.js +46 -0
  88. package/dist/helpers/scrollToLoadContent.js +50 -0
  89. package/dist/helpers/tests/extendedTest.js +130 -0
  90. package/dist/helpers/tests/testDownloadFile.spec.js +197 -0
  91. package/dist/helpers/tests/testFilterEmptyValues.spec.js +151 -0
  92. package/dist/helpers/tests/testGoToUrl.spec.js +37 -0
  93. package/dist/helpers/tests/testIsPageLoaded.spec.js +285 -0
  94. package/dist/helpers/tests/testProcessDate.spec.js +13 -0
  95. package/dist/helpers/tests/testResolveUrl.spec.js +341 -0
  96. package/dist/helpers/tests/testSanitizeHtml.spec.js +330 -0
  97. package/dist/helpers/tests/testSimplifyHtml.spec.js +251 -0
  98. package/dist/helpers/tests/testValidateDataUsingSchema.spec.js +380 -0
  99. package/dist/helpers/tests/testWaitForDomSettled.spec.js +169 -0
  100. package/dist/helpers/tests/testWaitForNetworkIdle.spec.js +115 -0
  101. package/dist/helpers/types/Attachment.js +81 -0
  102. package/dist/helpers/types/CustomTypeRegistry.js +48 -0
  103. package/dist/helpers/types/RunEnvironment.js +18 -0
  104. package/dist/helpers/types/ValidationError.js +17 -0
  105. package/dist/helpers/types/index.js +51 -0
  106. package/dist/helpers/uploadFileToS3.js +153 -0
  107. package/dist/helpers/utils/getS3Client.js +21 -0
  108. package/dist/helpers/utils/index.js +73 -0
  109. package/dist/helpers/utils/isDownload.js +10 -0
  110. package/dist/helpers/utils/isGenerateCodeMode.js +9 -0
  111. package/dist/helpers/utils/isLocator.js +9 -0
  112. package/dist/helpers/utils/jwtTokenManager.js +18 -0
  113. package/dist/helpers/validateDataUsingSchema.js +119 -0
  114. package/dist/helpers/waitForDomSettled.js +182 -0
  115. package/dist/helpers/waitForNetworkIdle.js +191 -0
  116. package/dist/index.d.js +82 -0
  117. package/dist/index.d.ts +11 -0
  118. package/dist/index.js +84 -0
  119. package/dist/intunedServices/ApiGateway/aiApiGateway.js +87 -0
  120. package/dist/intunedServices/ApiGateway/factory.js +13 -0
  121. package/dist/intunedServices/ApiGateway/providers/Anthropic.js +26 -0
  122. package/dist/intunedServices/ApiGateway/providers/Gemini.js +29 -0
  123. package/dist/intunedServices/ApiGateway/providers/OpenAI.js +29 -0
  124. package/dist/intunedServices/ApiGateway/tests/testApiGateway.spec.js +221 -0
  125. package/dist/intunedServices/ApiGateway/types.js +11 -0
  126. package/dist/intunedServices/cache/cache.js +61 -0
  127. package/dist/intunedServices/cache/index.js +12 -0
  128. package/dist/intunedServices/cache/tests/testCache.spec.js +117 -0
  129. package/dist/optimized-extractors/common/buildExamplesPrompt.js +12 -0
  130. package/dist/optimized-extractors/common/buildImagesFromPage.js +55 -0
  131. package/dist/optimized-extractors/common/extractStructuredDataUsingClaude.js +149 -0
  132. package/dist/optimized-extractors/common/extractStructuredDataUsingGoogle.js +37 -0
  133. package/dist/optimized-extractors/common/extractStructuredDataUsingOpenAi.js +145 -0
  134. package/dist/optimized-extractors/common/extractStrucutredDataUsingAiInstance.js +122 -0
  135. package/dist/optimized-extractors/common/findTableHeaders.js +175 -0
  136. package/dist/optimized-extractors/common/index.js +55 -0
  137. package/dist/optimized-extractors/common/isTableHeaderOrFooter.js +97 -0
  138. package/dist/optimized-extractors/common/matching/matching.js +212 -0
  139. package/dist/optimized-extractors/common/matching/matching.test.js +655 -0
  140. package/dist/optimized-extractors/common/matching/types.js +18 -0
  141. package/dist/optimized-extractors/common/matching/utils.js +184 -0
  142. package/dist/optimized-extractors/common/utils.js +58 -0
  143. package/dist/optimized-extractors/export.d.js +5 -0
  144. package/dist/optimized-extractors/export.d.ts +397 -0
  145. package/dist/optimized-extractors/extractArray.js +120 -0
  146. package/dist/optimized-extractors/extractObject.js +104 -0
  147. package/dist/optimized-extractors/index.d.ts +397 -0
  148. package/dist/optimized-extractors/index.js +31 -0
  149. package/dist/optimized-extractors/listExtractionHelpers/__tests__/dynamicListExtractor.spec.js +312 -0
  150. package/dist/optimized-extractors/listExtractionHelpers/__tests__/findSetOfXpathsToCreateAnArrayExtractor.test.js +22 -0
  151. package/dist/optimized-extractors/listExtractionHelpers/__tests__/getContainerElement.test.js +21 -0
  152. package/dist/optimized-extractors/listExtractionHelpers/__tests__/partOfSameArrayXpath.test.js +42 -0
  153. package/dist/optimized-extractors/listExtractionHelpers/__tests__/verifyThatAllXpathsArePartOfSameArray.test.js +9 -0
  154. package/dist/optimized-extractors/listExtractionHelpers/dynamicListExtractor.js +152 -0
  155. package/dist/optimized-extractors/listExtractionHelpers/errors.js +46 -0
  156. package/dist/optimized-extractors/listExtractionHelpers/getListMatches.js +14 -0
  157. package/dist/optimized-extractors/listExtractionHelpers/runAiExtraction.js +240 -0
  158. package/dist/optimized-extractors/listExtractionHelpers/typesAndSchema.js +5 -0
  159. package/dist/optimized-extractors/listExtractionHelpers/utils/extractPropertiesUsingGPTFromArray.js +277 -0
  160. package/dist/optimized-extractors/listExtractionHelpers/utils/extractStructuredListUsingAi.js +44 -0
  161. package/dist/optimized-extractors/listExtractionHelpers/utils/getListContainerXpath.js +94 -0
  162. package/dist/optimized-extractors/listExtractionHelpers/utils/getRelativeContainerXpathSelector.js +20 -0
  163. package/dist/optimized-extractors/listExtractionHelpers/utils/getSimplifiedHtmlPerListItem.js +21 -0
  164. package/dist/optimized-extractors/listExtractionHelpers/utils/tablesUtils.js +48 -0
  165. package/dist/optimized-extractors/listExtractionHelpers/utils/validateOptions.js +52 -0
  166. package/dist/optimized-extractors/models/anthropicModel.js +23 -0
  167. package/dist/optimized-extractors/models/openaiModel.js +23 -0
  168. package/dist/optimized-extractors/objectExtractionHelpers/AIExtractors.js +73 -0
  169. package/dist/optimized-extractors/objectExtractionHelpers/__tests__/checksumUtils.test.js +103 -0
  170. package/dist/optimized-extractors/objectExtractionHelpers/__tests__/testObjectExtractorFromLocator.spec.js +107 -0
  171. package/dist/optimized-extractors/objectExtractionHelpers/__tests__/testObjectExtractorFromPage.spec.js +107 -0
  172. package/dist/optimized-extractors/objectExtractionHelpers/calculateObjectExampleHash.js +28 -0
  173. package/dist/optimized-extractors/objectExtractionHelpers/captureSnapshot.js +26 -0
  174. package/dist/optimized-extractors/objectExtractionHelpers/checksumUtils.js +32 -0
  175. package/dist/optimized-extractors/objectExtractionHelpers/constants.js +7 -0
  176. package/dist/optimized-extractors/objectExtractionHelpers/dynamicObjectExtractor.js +106 -0
  177. package/dist/optimized-extractors/objectExtractionHelpers/errors.js +42 -0
  178. package/dist/optimized-extractors/objectExtractionHelpers/findDomMatches.js +54 -0
  179. package/dist/optimized-extractors/objectExtractionHelpers/getSimplifiedHtml.js +122 -0
  180. package/dist/optimized-extractors/objectExtractionHelpers/typesAndSchemas.js +5 -0
  181. package/dist/optimized-extractors/objectExtractionHelpers/validateDynamicObjectExtractorOptions.js +52 -0
  182. package/dist/optimized-extractors/types/aiModelsValidation.js +45 -0
  183. package/dist/optimized-extractors/types/errors.js +42 -0
  184. package/dist/optimized-extractors/types/jsonSchema.d.js +5 -0
  185. package/dist/optimized-extractors/types/jsonSchema.d.ts +50 -0
  186. package/dist/optimized-extractors/types/types.js +5 -0
  187. package/dist/optimized-extractors/validators.js +152 -0
  188. package/dist/vite-env.d.js +1 -0
  189. package/dist/vite-env.d.ts +9 -0
  190. package/docs.md +14 -0
  191. package/how-to-run-tests.md +10 -0
  192. package/intuned-runtime-setup.md +13 -0
  193. package/package.json +124 -0
  194. package/tsconfig.eslint.json +5 -0
  195. package/tsconfig.json +26 -0
@@ -0,0 +1,469 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.convertElementToMarkdown = convertElementToMarkdown;
7
+ function convertElementToMarkdown(element) {
8
+ const mdCharsMatcher = /([\\[\]()])/g;
9
+ function escapeMd(text) {
10
+ return text.replace(mdCharsMatcher, "\\$1");
11
+ }
12
+ function listNumberingStart(attrs) {
13
+ var _attrs$getNamedItem;
14
+ const start = (_attrs$getNamedItem = attrs.getNamedItem("start")) === null || _attrs$getNamedItem === void 0 ? void 0 : _attrs$getNamedItem.value;
15
+ if (start) {
16
+ return parseInt(start, 10) - 1;
17
+ } else {
18
+ return 0;
19
+ }
20
+ }
21
+ const slashChars = "\\`*_{}[]()#+-.!";
22
+ const escapedSlashChars = slashChars.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
23
+ const mdBackslashMatcher = new RegExp(`\\\\(?=[${escapedSlashChars}])`, "g");
24
+ const mdDotMatcher = new RegExp(`^(\\s*\\d+)(\\.)(?=\\s)`, "gm");
25
+ const mdPlusMatcher = new RegExp(`^(\\s*)(\\+)(?=\\s)`, "gm");
26
+ const mdDashMatcher = new RegExp(`^(\\s*)(-)(?=\\s|-)`, "gm");
27
+ function escapeMdSection(text) {
28
+ text = text.replace(mdBackslashMatcher, "\\\\");
29
+ text = text.replace(mdDotMatcher, "$1\\$2");
30
+ text = text.replace(mdPlusMatcher, "$1\\$2");
31
+ text = text.replace(mdDashMatcher, "$1\\$2");
32
+ return text;
33
+ }
34
+ function isFirstTbody(element) {
35
+ const previousSibling = element.previousSibling;
36
+ return element.nodeName === "TBODY" && (!previousSibling || previousSibling.nodeName === "THEAD" && /^\s*$/i.test(previousSibling.textContent ?? ""));
37
+ }
38
+ function isHeadingRow(tr) {
39
+ const parentNode = tr.parentNode;
40
+ return parentNode.nodeName === "THEAD" || parentNode.firstChild === tr && (parentNode.nodeName === "TABLE" || isFirstTbody(parentNode)) && Array.from(tr.childNodes).every(function (n) {
41
+ return n.nodeName === "TH";
42
+ });
43
+ }
44
+ class Html2Text {
45
+ p_p = 0;
46
+ pre = false;
47
+ code = false;
48
+ startPre = false;
49
+ blockquote = 0;
50
+ list = [];
51
+ start = true;
52
+ breakToggle = "";
53
+ lastWasNewLine = false;
54
+ a = null;
55
+ outCount = 0;
56
+ abbrList = {};
57
+ outText = "";
58
+ outTextList = [];
59
+ skipInternalLinks = true;
60
+ aStack = [];
61
+ lastWasList = false;
62
+ absoluteUrlMatcher = new RegExp("^[a-zA-Z+]+://");
63
+ emphasis_mark = "_";
64
+ strong_mark = "**";
65
+ break() {
66
+ if (this.p_p === 0) {
67
+ this.p_p = 1;
68
+ }
69
+ }
70
+ softBreak() {
71
+ this.break();
72
+ this.breakToggle = " ";
73
+ }
74
+ processOutput(data, pureData = 0, force = 0) {
75
+ if (this.abbrData !== undefined) {
76
+ this.abbrData += data;
77
+ }
78
+ if (pureData && !this.pre) {
79
+ data = data.replace(/\s+/g, " ");
80
+ if (data && data[0] === " ") {
81
+ this.space = 1;
82
+ data = data.substring(1);
83
+ }
84
+ }
85
+ if (!data && force !== "end") return;
86
+ if (this.startPre) {
87
+ if (!data.startsWith("\n")) {
88
+ data = "\n" + data;
89
+ }
90
+ }
91
+ let newLineIndent = ">".repeat(this.blockquote ?? 0);
92
+ if (!(force === "end" && data && data[0] === ">") && this.blockquote) {
93
+ newLineIndent += " ";
94
+ }
95
+ if (this.pre) {
96
+ if (this.list.length === 0) {
97
+ newLineIndent += " ";
98
+ } else {
99
+ for (let i = 0; i < this.list.length + 1; i++) {
100
+ newLineIndent += " ";
101
+ }
102
+ }
103
+ data = data.replace(/\n/g, `\n${newLineIndent}`);
104
+ }
105
+ if (this.startPre) {
106
+ this.startPre = false;
107
+ if (this.list.length > 0) {
108
+ data = data.trimStart();
109
+ }
110
+ }
111
+ if (this.start) {
112
+ this.space = 0;
113
+ this.p_p = 0;
114
+ this.start = false;
115
+ }
116
+ if (force === "end") {
117
+ this.p_p = 0;
118
+ this.out("\n");
119
+ this.space = 0;
120
+ }
121
+ if (this.p_p) {
122
+ this.out((this.breakToggle + "\n" + newLineIndent).repeat(this.p_p));
123
+ this.space = 0;
124
+ this.breakToggle = "";
125
+ }
126
+ if (this.space) {
127
+ if (!this.lastWasNewLine) {
128
+ this.out(" ");
129
+ }
130
+ this.space = 0;
131
+ }
132
+ if (this.a && force === "end") {
133
+ if (force === "end") {
134
+ this.out("\n");
135
+ }
136
+ const newA = this.a.filter(link => {
137
+ if (this.outCount > link.outcount) {
138
+ this.out(" [" + link.count + "]: " + new URL(link.href, this.baseurl).toString());
139
+ if (link.title) {
140
+ this.out(" (" + link.title + ")");
141
+ }
142
+ this.out("\n");
143
+ return false;
144
+ }
145
+ return true;
146
+ });
147
+ if (this.a.length !== newA.length) {
148
+ this.out("\n");
149
+ }
150
+ this.a = newA;
151
+ }
152
+ if (this.abbrList && force === "end") {
153
+ for (const [abbr, definition] of Object.entries(this.abbrList)) {
154
+ this.out("\n *[" + abbr + "]: " + definition + "\n");
155
+ }
156
+ }
157
+ this.p_p = 0;
158
+ this.out(data);
159
+ this.outCount++;
160
+ }
161
+ out(string) {
162
+ this.outTextList.push(string);
163
+ if (string) {
164
+ this.lastWasNewLine = string.charAt(string.length - 1) === "\n";
165
+ }
166
+ }
167
+ getResult() {
168
+ this.processOutput("", 0, "end");
169
+ this.outText = this.outTextList.join("");
170
+ this.outText = this.outText.replace("&nbsp_place_holder;", " ");
171
+ return this.outText;
172
+ }
173
+ getHeadingLevel(tag) {
174
+ if (tag[0] === "h" && tag.length === 2) {
175
+ try {
176
+ const n = parseInt(tag[1]);
177
+ if (!isNaN(n) && n >= 1 && n <= 9) {
178
+ return n;
179
+ }
180
+ } catch (error) {
181
+ return 0;
182
+ }
183
+ }
184
+ return 0;
185
+ }
186
+ padding() {
187
+ this.p_p = 2;
188
+ }
189
+ handleData(node) {
190
+ if (this.maybeAutomaticLink) {
191
+ const href = this.maybeAutomaticLink;
192
+ if ((href === null || href === void 0 ? void 0 : href.value) === node.nodeValue && this.absoluteUrlMatcher.test(href.value)) {
193
+ this.processOutput(`<${node.nodeValue}>`);
194
+ return;
195
+ } else {
196
+ this.processOutput("[");
197
+ this.maybeAutomaticLink = null;
198
+ }
199
+ }
200
+ if (!this.code && !this.pre && node.nodeValue) {
201
+ const data = escapeMdSection(node.nodeValue);
202
+ this.processOutput(data, 1);
203
+ return;
204
+ }
205
+ this.processOutput(node.textContent || "", 1);
206
+ }
207
+ handleTag(node) {
208
+ const tag = node.nodeName.toLowerCase();
209
+ if (["head", "style", "script"].includes(tag)) {
210
+ return;
211
+ }
212
+ if (this.getHeadingLevel(tag)) {
213
+ this.padding();
214
+ this.processOutput("#".repeat(this.getHeadingLevel(tag)) + " ");
215
+ }
216
+ if (tag == "br") this.processOutput(" \n");
217
+ if (tag == "hr") {
218
+ this.padding();
219
+ this.processOutput("---");
220
+ this.padding();
221
+ }
222
+ if (tag == "blockquote") {
223
+ this.padding();
224
+ this.processOutput("> ", 0, 1);
225
+ }
226
+ }
227
+ handleTagPrefix(node) {
228
+ const nodeName = node.nodeName.toLowerCase();
229
+ let attrs = node.nodeType === node.ELEMENT_NODE ? node.attributes : null;
230
+ if (["table"].includes(nodeName)) {
231
+ this.padding();
232
+ }
233
+ if (nodeName == "td" || nodeName == "th") {
234
+ var _node$parentNode;
235
+ const index = Array.from(((_node$parentNode = node.parentNode) === null || _node$parentNode === void 0 ? void 0 : _node$parentNode.children) ?? []).indexOf(node);
236
+ let prefix = " ";
237
+ if (index === 0) prefix = "| ";
238
+ this.processOutput(prefix);
239
+ }
240
+ if (["div", "p"].includes(nodeName)) {
241
+ this.padding();
242
+ }
243
+ if (nodeName === "blockquote") {
244
+ this.blockquote += 1;
245
+ }
246
+ if (nodeName === "pre") {
247
+ this.pre = true;
248
+ this.startPre = true;
249
+ this.padding();
250
+ }
251
+ if (["code", "tt"].includes(nodeName)) {
252
+ this.processOutput("`");
253
+ }
254
+ if (["em", "i", "u"].includes(nodeName)) {
255
+ this.processOutput(this.emphasis_mark);
256
+ }
257
+ if (["strong", "b"].includes(nodeName)) {
258
+ this.processOutput(this.strong_mark);
259
+ }
260
+ if (["del", "strike", "s"].includes(nodeName)) {
261
+ this.processOutput("<" + nodeName + ">");
262
+ }
263
+ if (nodeName === "abbr") {
264
+ this.abbr_title = null;
265
+ this.abbrData = "";
266
+ const title = attrs && attrs.getNamedItem("title");
267
+ if (attrs && title) {
268
+ this.abbr_title = title.value;
269
+ }
270
+ }
271
+ if (nodeName === "dl") {
272
+ this.padding();
273
+ }
274
+ if (nodeName === "dd") {
275
+ this.processOutput(" ");
276
+ }
277
+ if (nodeName == "a") {
278
+ const href = attrs ? attrs.getNamedItem("href") : null;
279
+ if (href && !(this.skipInternalLinks && href.value.startsWith("#"))) {
280
+ this.aStack.push(attrs);
281
+ this.maybeAutomaticLink = href;
282
+ } else {
283
+ this.aStack.push(null);
284
+ }
285
+ }
286
+ if (nodeName === "img") {
287
+ const src = attrs ? attrs.getNamedItem("src") : null;
288
+ if (src) {
289
+ var _attrs$getNamedItem2, _attrs$getNamedItem3;
290
+ node.setAttribute("href", src.value);
291
+ attrs = node.attributes;
292
+ const alt = (_attrs$getNamedItem2 = attrs.getNamedItem("alt")) === null || _attrs$getNamedItem2 === void 0 ? void 0 : _attrs$getNamedItem2.value;
293
+ this.processOutput("![" + escapeMd(alt ?? "") + "]");
294
+ this.processOutput("(" + escapeMd(((_attrs$getNamedItem3 = attrs.getNamedItem("href")) === null || _attrs$getNamedItem3 === void 0 ? void 0 : _attrs$getNamedItem3.value) ?? "") + ")");
295
+ }
296
+ }
297
+ if (["ul", "ol"].includes(nodeName)) {
298
+ const listStyle = nodeName;
299
+ const numberingStart = listNumberingStart(node.attributes);
300
+ this.list.push({
301
+ name: listStyle,
302
+ num: numberingStart
303
+ });
304
+ this.lastWasList = true;
305
+ } else {
306
+ this.lastWasList = false;
307
+ }
308
+ if (nodeName === "li") {
309
+ let li;
310
+ this.break();
311
+ if (this.list.length > 0) {
312
+ li = this.list[this.list.length - 1];
313
+ } else {
314
+ li = {
315
+ name: "ul",
316
+ num: 0
317
+ };
318
+ }
319
+ const nestCount = this.list.length;
320
+ this.processOutput(" ".repeat(nestCount));
321
+ if (li["name"] == "ul") this.processOutput("*" + " ");else if (li["name"] == "ol") {
322
+ li["num"] += 1;
323
+ this.processOutput(li["num"] + ". ");
324
+ }
325
+ this.start = true;
326
+ }
327
+ }
328
+ handleTagSuffix(node) {
329
+ const nodeName = node.nodeName.toLowerCase();
330
+ if (nodeName === "blockquote") {
331
+ this.blockquote -= 1;
332
+ }
333
+ if (nodeName == "td" || nodeName == "th") {
334
+ this.processOutput(" |");
335
+ }
336
+ if (nodeName == "tr") {
337
+ const cell = (content, node) => {
338
+ const index = Array.from(node.parentNode.childNodes).indexOf(node);
339
+ let prefix = " ";
340
+ if (index === 0) prefix = "| ";
341
+ return prefix + content + " |";
342
+ };
343
+ let borderCells = "";
344
+ const alignMap = {
345
+ left: ":--",
346
+ right: "--:",
347
+ center: ":-:"
348
+ };
349
+ if (isHeadingRow(node)) {
350
+ for (let i = 0; i < node.children.length; i++) {
351
+ let border = "---";
352
+ const align = (node.children[i].getAttribute("align") || "").toLowerCase();
353
+ if (align) border = alignMap[align] || border;
354
+ borderCells += cell(border, node.childNodes[i]);
355
+ }
356
+ }
357
+ this.processOutput(borderCells ? "\n" + borderCells + "\n" : "\n");
358
+ }
359
+ if (nodeName === "pre") {
360
+ this.pre = false;
361
+ this.padding();
362
+ }
363
+ if (["code", "tt"].includes(nodeName)) {
364
+ this.processOutput("`");
365
+ }
366
+ if (["em", "i", "u"].includes(nodeName)) {
367
+ this.processOutput(this.emphasis_mark);
368
+ }
369
+ if (["strong", "b"].includes(nodeName)) {
370
+ this.processOutput(this.strong_mark);
371
+ }
372
+ if (["div", "p"].includes(nodeName)) {
373
+ this.padding();
374
+ }
375
+ if (["del", "strike", "s"].includes(nodeName)) {
376
+ this.processOutput("</" + nodeName + ">");
377
+ }
378
+ if (nodeName === "abbr") {
379
+ if (this.abbr_title && this.abbrData) {
380
+ this.abbrList[this.abbrData] = this.abbr_title;
381
+ this.abbr_title = null;
382
+ }
383
+ this.abbrData = "";
384
+ }
385
+ if (nodeName === "dt") {
386
+ this.break();
387
+ }
388
+ if (nodeName === "dd") {
389
+ this.break();
390
+ }
391
+ if (nodeName === "a") {
392
+ if (this.aStack.length > 0) {
393
+ const a = this.aStack.pop();
394
+ if (this.maybeAutomaticLink) {
395
+ this.maybeAutomaticLink = null;
396
+ } else if (a) {
397
+ var _a$getNamedItem;
398
+ this.processOutput(`](${escapeMd(((_a$getNamedItem = a.getNamedItem("href")) === null || _a$getNamedItem === void 0 ? void 0 : _a$getNamedItem.value) || "")})`);
399
+ }
400
+ }
401
+ }
402
+ if (["ul", "ol"].includes(nodeName)) {
403
+ if (this.list.length > 0) this.list.pop();
404
+ this.lastWasList = true;
405
+ } else {
406
+ this.lastWasList = false;
407
+ }
408
+ if (nodeName === "li") {
409
+ this.break();
410
+ }
411
+ }
412
+ previousIndex(attrs) {
413
+ const href = attrs.getNamedItem("href");
414
+ if (!attrs.getNamedItem("href")) return null;
415
+ let itemIndex = -1;
416
+ for (const a of this.a ?? []) {
417
+ itemIndex += 1;
418
+ let match = false;
419
+ if (a.getNamedItem("href") === href) {
420
+ if (a.getNamedItem("title") || attrs.getNamedItem("title")) {
421
+ if (a.getNamedItem("title") && attrs.getNamedItem("title") && a.getNamedItem("title") === attrs.getNamedItem("title")) {
422
+ match = true;
423
+ }
424
+ } else {
425
+ match = true;
426
+ }
427
+ }
428
+ if (match) return itemIndex;
429
+ }
430
+ return null;
431
+ }
432
+ handle(htmlElement) {
433
+ const filteredNodes = ["style", "script", "noscript"];
434
+ for (const node of filteredNodes) {
435
+ const nodeSelectors = htmlElement.querySelectorAll(node);
436
+ nodeSelectors.forEach(nodeSelector => {
437
+ if (nodeSelector && nodeSelector.parentNode) {
438
+ nodeSelector.parentNode.removeChild(nodeSelector);
439
+ }
440
+ });
441
+ }
442
+ const htmlContent = htmlElement.outerHTML;
443
+ const parser = new DOMParser();
444
+ const doc = parser.parseFromString(htmlContent, "text/html");
445
+ const traverseDOM = node => {
446
+ const tag = node.nodeName.toLowerCase();
447
+ if (node.nodeType === node.TEXT_NODE) {
448
+ const element = node;
449
+ this.handleData(element);
450
+ return;
451
+ }
452
+ if (node.nodeType === node.ELEMENT_NODE) {
453
+ const element = node;
454
+ this.handleTag(element);
455
+ }
456
+ if (!["head", "style", "script"].includes(tag)) {
457
+ this.handleTagPrefix(node);
458
+ node.childNodes.forEach(child => traverseDOM(child));
459
+ this.handleTagSuffix(node);
460
+ }
461
+ };
462
+ traverseDOM(doc.documentElement);
463
+ return this.getResult();
464
+ }
465
+ }
466
+ const converter = new Html2Text();
467
+ const result = converter.handle(element);
468
+ return result;
469
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.convertLocatorToMarkdown = convertLocatorToMarkdown;
7
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
8
+ async function convertLocatorToMarkdown(locator) {
9
+ const markdown = await locator.evaluate(element => {
10
+ return window.__INTUNED__.convertElementToMarkdown(element);
11
+ });
12
+ const prettier = await Promise.resolve().then(() => _interopRequireWildcard(require("prettier/standalone")));
13
+ const parserMarkdown = await Promise.resolve().then(() => _interopRequireWildcard(require("prettier/parser-markdown")));
14
+ const formattedMarkdown = await prettier.format(markdown, {
15
+ parser: "markdown",
16
+ plugins: [parserMarkdown]
17
+ });
18
+ return formattedMarkdown;
19
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "backendFunctionsTokenManager", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _jwtTokenManager.backendFunctionsTokenManager;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "callBackendFunctionWithToken", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _jwtTokenManager.callBackendFunctionWithToken;
16
+ }
17
+ });
18
+ var _jwtTokenManager = require("@intuned/runtime/dist/common/jwtTokenManager");
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.loadRuntime = void 0;
7
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
8
+ const loadRuntime = async () => {
9
+ try {
10
+ const runtime = await Promise.resolve().then(() => _interopRequireWildcard(require("@intuned/runtime")));
11
+ return runtime.getExecutionContext;
12
+ } catch {
13
+ return () => null;
14
+ }
15
+ };
16
+ exports.loadRuntime = loadRuntime;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.findXPathForLocator = findXPathForLocator;
7
+ exports.getLocatorInternalKey = getLocatorInternalKey;
8
+ exports.isLocator = isLocator;
9
+ exports.isPage = isPage;
10
+ function isLocator(searchRegion) {
11
+ return !!(searchRegion !== null && searchRegion !== void 0 && searchRegion.all);
12
+ }
13
+ function isPage(searchRegion) {
14
+ return !!(searchRegion !== null && searchRegion !== void 0 && searchRegion.goto);
15
+ }
16
+ async function findXPathForLocator(locator) {
17
+ const elementsCount = await locator.count();
18
+ if (elementsCount == 0) {
19
+ throw new Error("No elements found for the provided locator");
20
+ }
21
+ if (elementsCount > 1) {
22
+ throw new Error("Multiple elements found for the provided locator, it should match only one element");
23
+ }
24
+ const element = await locator.elementHandle();
25
+ if (!element) {
26
+ throw new Error("No element found for the provided locator");
27
+ }
28
+ function getXPathFromElement(element) {
29
+ if (element.tagName.toLowerCase() === "body" || !element.parentElement) {
30
+ return "html[1]/" + element.tagName.toLowerCase() + "[1]";
31
+ }
32
+ let siblings = Array.from(element.parentElement.children);
33
+ siblings = siblings.filter(sibling => sibling.tagName.toLowerCase() === element.tagName.toLowerCase());
34
+ const index = siblings.indexOf(element) + 1;
35
+ return getXPathFromElement(element.parentElement) + "/" + element.tagName.toLowerCase() + "[" + index + "]";
36
+ }
37
+ return await element.evaluate(getXPathFromElement);
38
+ }
39
+ function getLocatorInternalKey(locator) {
40
+ return locator.toString();
41
+ }
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.collectStrings = collectStrings;
7
+ function collectStrings({
8
+ dataStructure
9
+ }) {
10
+ const strings = [];
11
+ if (dataStructure === null) {
12
+ return strings;
13
+ }
14
+ if (typeof dataStructure === "string") {
15
+ strings.push(dataStructure);
16
+ } else if (typeof dataStructure === "number") {
17
+ strings.push(String(dataStructure));
18
+ } else if (Array.isArray(dataStructure)) {
19
+ for (const item of dataStructure) {
20
+ strings.push(...collectStrings({
21
+ dataStructure: item
22
+ }));
23
+ }
24
+ } else if (typeof dataStructure === "object" && dataStructure !== null) {
25
+ for (const value of Object.values(dataStructure)) {
26
+ strings.push(...collectStrings({
27
+ dataStructure: value
28
+ }));
29
+ }
30
+ }
31
+ return strings;
32
+ }
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.areSimilar = areSimilar;
7
+ exports.levenshteinDistance = levenshteinDistance;
8
+ exports.levenshteinRatio = levenshteinRatio;
9
+ function levenshteinDistance(a, b) {
10
+ if (a.length === 0) return b.length;
11
+ if (b.length === 0) return a.length;
12
+ const matrix = [];
13
+ for (let i = 0; i <= b.length; i++) {
14
+ matrix[i] = [i];
15
+ }
16
+ for (let j = 0; j <= a.length; j++) {
17
+ matrix[0][j] = j;
18
+ }
19
+ for (let i = 1; i <= b.length; i++) {
20
+ for (let j = 1; j <= a.length; j++) {
21
+ if (b.charAt(i - 1) === a.charAt(j - 1)) {
22
+ matrix[i][j] = matrix[i - 1][j - 1];
23
+ } else {
24
+ matrix[i][j] = Math.min(matrix[i - 1][j - 1] + 1, matrix[i][j - 1] + 1, matrix[i - 1][j] + 1);
25
+ }
26
+ }
27
+ }
28
+ return matrix[b.length][a.length];
29
+ }
30
+ function levenshteinRatio(a, b) {
31
+ const distance = levenshteinDistance(a, b);
32
+ const maxLen = a.length + b.length;
33
+ if (maxLen === 0) {
34
+ return 1.0;
35
+ }
36
+ return (maxLen - distance) / maxLen;
37
+ }
38
+ function areSimilar(a, b, threshold = 0.8) {
39
+ return levenshteinRatio(a, b) >= threshold;
40
+ }