@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,1294 @@
1
+ /* eslint-disable prettier/prettier */
2
+ // prettier-ignore-file
3
+ import type { Locator, Page, ElementHandle } from "playwright-core";
4
+ import type { ReadStream } from "fs";
5
+ import { Download } from "playwright-core";
6
+
7
+ /**
8
+ * Configuration options for sanitizing HTML content.
9
+ */
10
+ export interface SanitizeHtmlOptions {
11
+ /** Remove all <script> elements. Defaults to true. */
12
+ removeScripts?: boolean;
13
+ /** Remove all <style> elements. Defaults to true. */
14
+ removeStyles?: boolean;
15
+ /** Remove all <svg> elements. Defaults to true. */
16
+ removeSvgs?: boolean;
17
+ /** Remove HTML comments. Defaults to true. */
18
+ removeComments?: boolean;
19
+ /** Remove attributes longer than maxAttributeLength. Defaults to true. */
20
+ removeLongAttributes?: boolean;
21
+ /** Maximum length for attributes before removal. Defaults to 500. */
22
+ maxAttributeLength?: number;
23
+ /** List of attribute names to always preserve. Defaults to ["class", "src"]. */
24
+ preserveAttributes?: string[];
25
+ /** Remove empty tags (except preserved ones). Defaults to true. */
26
+ removeEmptyTags?: boolean;
27
+ /** List of tag names to preserve even when empty. Defaults to ["img"]. */
28
+ preserveEmptyTags?: string[];
29
+ /** Remove extra whitespace between tags and empty lines. Defaults to true. */
30
+ minifyWhitespace?: boolean;
31
+ }
32
+
33
+ /**
34
+ * Sanitizes and cleans HTML content by removing unwanted elements, attributes, and whitespace.
35
+ * Provides fine-grained control over each cleaning operation through configurable options.
36
+ *
37
+ * @param {string} htmlString - The HTML content to sanitize
38
+ * @param {SanitizeHtmlOptions} options - Configuration options for sanitization
39
+ * @returns {string} The sanitized HTML string
40
+ *
41
+ * @example
42
+ * ```typescript Basic HTML Sanitization
43
+ * import { sanitizeHtml } from "@intuned/sdk/helpers";
44
+ *
45
+ * const dirtyHtml = `
46
+ * <div>
47
+ * <script>alert('xss')</script>
48
+ * <p style="color: red;">Hello World</p>
49
+ * <span></span>
50
+ * </div>
51
+ * `;
52
+ *
53
+ * const sanitizedHtml = sanitizeHtml(dirtyHtml);
54
+ * // Returns: '<div><p>Hello World</p></div>'
55
+ * ```
56
+ *
57
+ * @example
58
+ * ```typescript Custom Sanitization Options
59
+ * import { sanitizeHtml } from "@intuned/sdk/helpers";
60
+ *
61
+ * const html = `
62
+ * <div data-long-attr="${'x'.repeat(600)}">
63
+ * <style>.test { color: red; }</style>
64
+ * <script>alert('test')</script>
65
+ * <p style="color: blue;">Content</p>
66
+ * <!-- Comment -->
67
+ * </div>
68
+ * `;
69
+ *
70
+ * // Keep styles but remove scripts and comments
71
+ * const result = sanitizeHtml(html, {
72
+ * removeScripts: true,
73
+ * removeStyles: false,
74
+ * removeComments: true,
75
+ * maxAttributeLength: 100,
76
+ * preserveAttributes: ["class", "src", "style"]
77
+ * });
78
+ * ```
79
+ *
80
+ * @example
81
+ * ```typescript Preserve Specific Elements
82
+ * import { sanitizeHtml } from "@intuned/sdk/helpers";
83
+ *
84
+ * const html = `
85
+ * <div>
86
+ * <svg><path d="M10,10"/></svg>
87
+ * <img src="image.jpg" alt="" />
88
+ * <span></span>
89
+ * </div>
90
+ * `;
91
+ *
92
+ * // Keep SVGs and empty spans
93
+ * const result = sanitizeHtml(html, {
94
+ * removeSvgs: false,
95
+ * preserveEmptyTags: ["img", "span"]
96
+ * });
97
+ * ```
98
+ */
99
+
100
+ export declare function sanitizeHtml(
101
+ htmlString: string,
102
+ options?: SanitizeHtmlOptions
103
+ ): string;
104
+
105
+ /**
106
+ * Download a file from a web page using a trigger
107
+ * This function supports three different ways to trigger a download:
108
+ * 1. By URL
109
+ * 2. By clicking on a playwright locator
110
+ * 3. By executing a callback function that takes a page object as an argument and uses it to initiate the download.
111
+ * @param {Page} page - The Playwright Page object.
112
+ * @param {Trigger} trigger - [Trigger](../type-aliases/Trigger) to use for downloading the file.
113
+ * @param {number} [options.timeoutInMs=5000] - Optional. The maximum time in milliseconds to wait for the download to complete. Default = 5000
114
+ * @returns {Promise<Download >} A promise that resolves to a playwright Download object.
115
+ *
116
+ * @example
117
+ * ```typescript URL Download
118
+ * import { downloadFile } from "@intuned/sdk/helpers";
119
+ *
120
+ * const download = await downloadFile(page, "https://sandbox.intuned.dev/pdfs");
121
+ * console.log(await download.path());
122
+ * ```
123
+ *
124
+ * @example
125
+ * ```typescript Locator Download - Link
126
+ * import { downloadFile } from "@intuned/sdk/helpers";
127
+ *
128
+ * const download = await downloadFile(page, page.locator("[href='/download/file.pdf']"));
129
+ * console.log(await download.path());
130
+ * ```
131
+ *
132
+ * @example
133
+ * ```typescript Locator Download - Button
134
+ * import { downloadFile } from "@intuned/sdk/helpers";
135
+ *
136
+ * const download = await downloadFile(page, page.locator("button:has-text('Download')"));
137
+ * console.log(await download.path());
138
+ * ```
139
+ *
140
+ * @example
141
+ * ```typescript Callback Function Download
142
+ * import { downloadFile } from "@intuned/sdk/helpers";
143
+ *
144
+ * const download = await downloadFile(page, (page) => page.locator("button:has-text('Download')").click());
145
+ * console.log(await download.path());
146
+ * ```
147
+ * - If a URL is provided as the trigger, a new page will be created and closed after the download is complete.
148
+ * - If a locator is provided as the trigger, the page will be used to click the element and initiate the download.
149
+ * - If a callback function is provided as the trigger, the function will be called with the page object as an argument and will be responsible for initiating the download.
150
+ */
151
+ export declare function downloadFile(options: {
152
+ page: Page;
153
+ trigger: Trigger;
154
+ timeoutInMs?: number;
155
+ }): Promise<Download>;
156
+
157
+ /**
158
+ * Recursively filters out empty values from nested dictionaries and arrays.
159
+ *
160
+ * Removes:
161
+ * - null/undefined values
162
+ * - Empty strings (after trimming whitespace)
163
+ * - Empty arrays
164
+ * - Empty objects
165
+ * - Arrays/objects that become empty after filtering their contents
166
+ *
167
+ * @param {T} data - The data structure to filter (object, array, or any other type)
168
+ * @returns {T} Filtered data structure with empty values removed
169
+ *
170
+ * @example
171
+ * ```typescript Basic usage
172
+ * filterEmptyValues({ a: "", b: "hello", c: null }) // Returns { b: "hello" }
173
+ * filterEmptyValues([1, "", null, [2, ""]]) // Returns [1, [2]]
174
+ * filterEmptyValues({ users: [{ name: "" }, { name: "John" }] }) // Returns { users: [{ name: "John" }] }
175
+ * ```
176
+ */
177
+ export declare function filterEmptyValues<T>(input: { data: T }): T;
178
+
179
+ /**
180
+ * Navigates to a specified URL on the provided playwright page.
181
+ *
182
+ * @param {Page} page - The Playwright page object to navigate.
183
+ * @param {string} url - The URL to navigate to.
184
+ * @param {number} [options.retries] - Referer header value. If provided, it will take preference over the referer header value set by `page.setExtraHTTPHeaders(headers)`.
185
+ * @param {number} [options.timeoutInMs=30000] - Maximum operation time in milliseconds. This can be configured via various timeout settings on the page or browser context. default 30000.
186
+
187
+ * @param {string} [options.waitUntil=networkidle] - When to consider the operation succeeded. Default = networkidle
188
+ * @param {boolean} [options.throwOnTimeout=False] - Whether to throw if the `page.goto` times out. By default, it ignores the error. default = false.
189
+ * @param {boolean} [options.waitForLoadingStateUsingAi=False] - If true, it will perform an AI Check to determine if the page is fully loaded and idle. default = false.
190
+ * @param {ModelType} [options.model] - [ModelType](../type-aliases/modelType) to use for the AI Check. default claude-3-haiku-20240307
191
+ * @param {string} [options.apiKey] - The API key for the AI service. If not provided, it will use the default API key.
192
+ * @returns {void} - Returns nothing. If the operation fails, it will throw an error unless `throwOnTimeout` is set to false.
193
+ *
194
+ * @example
195
+ * ```typescript without options
196
+ * import { goto } from "@intuned/sdk/helpers";
197
+ *
198
+ * await goto(page, 'https://example.com');
199
+ *
200
+ * ```
201
+ *
202
+ * ```typescript with options
203
+ * import { goto } from "@intuned/sdk/helpers";
204
+ *
205
+ * await goto(page, 'https://example.com', {
206
+ * waitUntil: "load",
207
+ * throwOnTimeout: true,
208
+ * timeoutInMs: 10_000,
209
+ * retries: 3,
210
+ * waitForLoadingStateUsingAi: true,
211
+ * model: "gpt-4",
212
+ * });
213
+ * ```
214
+ */
215
+ export declare function goToUrl(input: {
216
+ page: Page;
217
+ url: string;
218
+ timeoutInMs?: number;
219
+ waitUntil?: "load" | "domcontentloaded" | "networkidle" | "commit";
220
+ retries?: number;
221
+ throwOnTimeout?: boolean;
222
+ waitUntil?: "load" | "domcontentloaded" | "networkidle" | "commit";
223
+ waitForLoadingStateUsingAi?: boolean;
224
+ model?: ModelType;
225
+ apiKey?: string;
226
+ }): Promise<void>;
227
+
228
+ /**
229
+ * Automatically scrolls through infinite scroll content by repeatedly scrolling to the bottom
230
+ * until no new content loads or maximum scroll limit is reached.
231
+ *
232
+ * @param {Object} [options] - Configuration options
233
+ * @param {Page | Locator} [ptions.page] - The Playwright page object
234
+ * @param {Function} [options.onScrollProgress] - Optional callback function to call during each scroll iteration
235
+ * @param {Locator} [options.scrollableContainer] - Specific element to scroll.
236
+ * @param {number} [options.maxScrolls=50] - Maximum number of scroll attempts before stopping, default = 50
237
+ * @param {number} [options.delay=100] - Delay in milliseconds between scroll attempts, default = 100
238
+ * @param {number} [options.minHeightChange=100] - Minimum height change required to continue scrolling, default = 100
239
+ * @returns {Promise<void>} Promise that resolves when scrolling is complete
240
+ *
241
+ * @example
242
+ * ```typescript Basic Infinite Scroll
243
+ * import { scrollToLoadContent } from "@intuned/sdk/helpers";
244
+ *
245
+ * // Scroll through entire page content
246
+ * await scrollToLoadContent(page);
247
+ *
248
+ * // Now all content is loaded and visible
249
+ * const allItems = await page.locator('.item').count();
250
+ * ```
251
+ *
252
+ * @example
253
+ * ```typescript Scroll Specific Container
254
+ * import { scrollToLoadContent } from "@intuned/sdk/helpers";
255
+ *
256
+ * // Scroll through a specific scrollable div
257
+ * const container = page.locator('.scrollable-feed');
258
+ * await scrollToLoadContent(page, undefined, {
259
+ * scrollableContainer: container,
260
+ * maxScrolls: 20
261
+ * });
262
+ * ```
263
+ *
264
+ * @example
265
+ * ```typescript With Progress Tracking
266
+ * import { scrollToLoadContent } from "@intuned/sdk/helpers";
267
+ *
268
+ * let scrollCount = 0;
269
+ * await scrollToLoadContent(
270
+ * page,
271
+ * () => console.log(`Scroll attempt ${++scrollCount}`),
272
+ * {
273
+ * maxScrolls: 100,
274
+ * delay: 0.5
275
+ * }
276
+ * );
277
+ * ```
278
+ */
279
+
280
+ export declare function scrollToLoadContent(options: {
281
+ page: Page | Locator;
282
+ onScrollProgress?: CallableFunction;
283
+ scrollableContainer?: Locator | null;
284
+ maxScrolls?: number;
285
+ delay?: number;
286
+ minHeightChange?: number;
287
+ }): Promise<void>;
288
+
289
+ /**
290
+ * Uses AI vision to determine if a webpage has finished loading by analyzing a screenshot.
291
+ * Detects loading spinners, blank content, or incomplete page states.
292
+ *
293
+ * @param {Page} page - The Playwright page to check
294
+ * @param {Object} [options] - Optional configuration object
295
+ * @param {ModelType} [options.model="gpt-4o-2024-08-06"] - [ModelType](../type-aliases/modelType) to use for the AI Check. default gpt-4o-2024-08-06
296
+ * @param {number} [options.timeoutInMs=10000] - Screenshot timeout in milliseconds
297
+ * @param {string} [options.apiKey] - Optional API key for the AI service
298
+ * @returns {Promise.<{status: LoadingStatus, reason: (string|null|undefined), cost: (number|undefined)}>}
299
+ * - `status`: "True" if page is loaded, "False" if still loading, "Dont know" if uncertain
300
+ * - `reason`: Optional reason for the status (e.g., detected loading spinner)
301
+ * - `cost`: Optional cost of the AI analysis (if applicable)
302
+ * @example
303
+ * ```typescript Check Page Loading
304
+ * import { isPageLoaded } from "@intuned/sdk/helpers";
305
+ *
306
+ * // Wait for page to finish loading
307
+ * await page.goto('https://example.com');
308
+ *
309
+ * const pageLoaded = await isPageLoaded(page);
310
+ * if (pageLoaded['status']) {
311
+ * console.log("Page loaded:", pageLoaded['reason']);
312
+ * // Continue with scraping or interactions
313
+ * } else {
314
+ * console.log("Still loading:", pageLoaded['reason']);
315
+ * // Wait longer or retry
316
+ * }
317
+ * ```
318
+ *
319
+ * @example
320
+ * ```typescript Loading Loop
321
+ * import { isPageLoaded } from "@intuned/sdk/helpers";
322
+ *
323
+ * // Keep checking until page loads
324
+ * let attempts = 0;
325
+ * while (attempts < 10) {
326
+ * const pageLoaded = await isPageLoaded(page, "gpt-4o", 5);
327
+ * if (pageLoaded['status']) break;
328
+ *
329
+ * await page.waitForTimeout(2000);
330
+ * attempts++;
331
+ * }
332
+ * ```
333
+ *
334
+ */
335
+ export declare function isPageLoaded(
336
+ page: Page,
337
+ options?: {
338
+ timeoutInMs?: number;
339
+ model?: ModelType;
340
+ apiKey?: string;
341
+ }
342
+ ): Promise<{
343
+ status: LoadingStatus;
344
+ reason?: string | null;
345
+ cost?: number;
346
+ }>;
347
+
348
+ /**
349
+ * Process various date string formats into Date objects.
350
+ * Returns only the date part (year, month, day).
351
+ * This method can accept a variety of date formats including:
352
+ * - DD/MM/YYYY with optional time (e.g., "22/11/2024 21:19:05", "13/12/2024")
353
+ * - MM/DD/YYYY with optional time and timezone (e.g., "01/17/2025 3:00:00 PM CT", "10/25/2024")
354
+ * - MM/DD/YYYY with time and timezone abbreviations (e.g., "10/23/2024 12:06 PM CST")
355
+ * - MM/DD/YYYY with AM/PM time format (e.g., "11/28/2024 1:59:59 AM", "12/09/2024 9:00 AM")
356
+ * - MM/DD/YYYY with dash separator and time (e.g., "12/19/2024 - 2:00 PM")
357
+ * - M/DD/YYYY and MM/D/YYYY formats (e.g., "8/16/2019", "9/28/2024")
358
+ * - DD MMM YYYY with optional time and timezone (e.g., "5 Dec 2024 8:00 AM PST", "11 Sep 2024")
359
+ * - Full month name formats (e.g., "November 14, 2024", "January 31, 2025, 5:00 pm")
360
+ * - 24-hour time format (e.g., "22/11/2024 19:45:00", "09/01/2025 15:00:00")
361
+ *
362
+ * @param {string} dateString - A string containing a date in various possible formats
363
+ * @returns Date object with only date components if parsing successful, null if parsing fails
364
+ *
365
+ * @example
366
+ * ```typescript Basic Date Processing
367
+ * import { processDate } from "@intuned/sdk/helpers";
368
+ * processDate("22/11/2024 21:19:05") // Returns Date with 2024-11-22 00:00:00
369
+ * processDate("5 Dec 2024 8:00 AM PST") // Returns Date with 2024-12-05 00:00:00
370
+ * ```
371
+ */
372
+ export declare function processDate(input: { date: string }): Date | null;
373
+
374
+ /**
375
+ * Uploads a downloaded file to S3 storage.
376
+ * @param {S3UploadableFile} file - The file to upload, it can be a downloaded file by the downloadFile function or another content, the file is of type [S3UploadableFile](../type-aliases/S3UploadableFile.md)
377
+ * @param {Object} options - The options for uploading the file.
378
+ * @param {S3Configs} [options.s3Configs] - Optional [S3Configs](../interfaces/S3Configs) configuration options.
379
+ * @param {string} [options.fileNameOverride] - Optional. Override for the file name.
380
+ * @param {string} [options.contentType] - Optional. The MIME type of the file, used to specify the type of content being uploaded to S3.
381
+ * @returns {Promise<Attachment>} A promise that resolves to an [Attachment](../interfaces/Attachment) object containing the uploaded file's details.
382
+ *
383
+ *
384
+ * @example
385
+ * ```typescript Download
386
+ * import { downloadFile, uploadFileToS3 } from "@intuned/sdk/helpers";
387
+ *
388
+ * const download = await downloadFile(page, {
389
+ * type: "DownloadByOpeningNewTab",
390
+ * downloadTrigger: (page) => page.locator(".download_button").click(),
391
+ * });
392
+ *
393
+ * const s3Configs: S3Configs = {
394
+ * bucket: 'my-bucket',
395
+ * region: 'us-west-1',
396
+ * accessKeyId: '....',
397
+ * secretAccessKey: '....'
398
+ * };
399
+ *
400
+ * const uploadedFile = await uploadFileToS3(download, { s3Configs });
401
+ * console.log(uploadedFile.urlDescriptor());
402
+ * ```
403
+ */
404
+
405
+ export declare function uploadFileToS3(input: {
406
+ file: S3UploadableFile;
407
+ configs?: S3UploadOptions;
408
+ }): Promise<Attachment>;
409
+
410
+ /**
411
+ * Validates data against a JSON schema using AJV validator.
412
+ * The function automatically cleans the input data before validation by removing empty strings, null values, and undefined properties (recursively for nested objects and arrays), then throws a detailed ValidationError if the cleaned data doesn't match the schema requirements.
413
+ * @param {DataInput} data - [DataInput](../interfaces/DataInput) is the data to validate (will be cleaned before validation)
414
+ * @param {Record<string, any>} schema - JSON schema object defining validation rules
415
+ * @returns {Promise<void>} Promise that resolves if validation passes, throws ValidationError if it fails
416
+ *
417
+ * @example
418
+ * ```typescript Basic User Data Validation
419
+ * import { validateDataUsingSchema } from "@intuned/sdk/helpers";
420
+ *
421
+ * const userData = {
422
+ * name: "John Doe",
423
+ * email: "john@example.com",
424
+ * age: 30
425
+ * };
426
+ *
427
+ * const userSchema = {
428
+ * type: "object",
429
+ * required: ["name", "email", "age"],
430
+ * properties: {
431
+ * name: { type: "string", minLength: 1 },
432
+ * email: { type: "string", format: "email" },
433
+ * age: { type: "number", minimum: 0 }
434
+ * }
435
+ * };
436
+ *
437
+ * await validateDataUsingSchema(userData, userSchema);
438
+ * // Validation passes, no error thrown
439
+ * ```
440
+ *
441
+ * @example
442
+ * ```typescript API Response Validation
443
+ * import { validateDataUsingSchema } from "@intuned/sdk/helpers";
444
+ *
445
+ * const apiResponse = {
446
+ * success: true,
447
+ * data: {
448
+ * items: [
449
+ * { id: 1, title: "Product 1", price: 29.99 },
450
+ * { id: 2, title: "Product 2", price: 49.99 }
451
+ * ],
452
+ * total: 2
453
+ * }
454
+ * };
455
+ *
456
+ * const responseSchema = {
457
+ * type: "object",
458
+ * required: ["success", "data"],
459
+ * properties: {
460
+ * success: { type: "boolean" },
461
+ * data: {
462
+ * type: "object",
463
+ * required: ["items", "total"],
464
+ * properties: {
465
+ * items: {
466
+ * type: "array",
467
+ * items: {
468
+ * type: "object",
469
+ * required: ["id", "title", "price"],
470
+ * properties: {
471
+ * id: { type: "number" },
472
+ * title: { type: "string" },
473
+ * price: { type: "number", minimum: 0 }
474
+ * }
475
+ * }
476
+ * },
477
+ * total: { type: "number", minimum: 0 }
478
+ * }
479
+ * }
480
+ * }
481
+ * };
482
+ *
483
+ * await validateDataUsingSchema(apiResponse, responseSchema);
484
+ * // Validates complex nested API response structure
485
+ * ```
486
+ *
487
+ * @example
488
+ * ```typescript Form Data Validation with Error Handling
489
+ * import { validateDataUsingSchema, ValidationError } from "@intuned/sdk/helpers";
490
+ *
491
+ * const formData = {
492
+ * username: "", // Invalid: empty string
493
+ * password: "123", // Invalid: too short
494
+ * confirmPassword: "456", // Invalid: doesn't match
495
+ * email: "invalid-email" // Invalid: bad format
496
+ * };
497
+ *
498
+ * const formSchema = {
499
+ * type: "object",
500
+ * required: ["username", "password", "email"],
501
+ * properties: {
502
+ * username: { type: "string", minLength: 3 },
503
+ * password: { type: "string", minLength: 8 },
504
+ * email: { type: "string", format: "email" }
505
+ * }
506
+ * };
507
+ *
508
+ * try {
509
+ * await validateDataUsingSchema(formData, formSchema);
510
+ * } catch (error) {
511
+ * if (error instanceof ValidationError) {
512
+ * console.error('Validation failed:', error.message);
513
+ * console.error('Invalid data:', error.data);
514
+ * // Handle validation errors in UI
515
+ * }
516
+ * }
517
+ * ```
518
+ *
519
+ * @example
520
+ * ```typescript Configuration Validation
521
+ * import { validateDataUsingSchema } from "@intuned/sdk/helpers";
522
+ *
523
+ * const config = {
524
+ * database: {
525
+ * host: "localhost",
526
+ * port: 5432,
527
+ * name: "myapp"
528
+ * },
529
+ * features: {
530
+ * enableLogging: true,
531
+ * maxRetries: 3,
532
+ * timeoutInMs: 30000
533
+ * }
534
+ * };
535
+ *
536
+ * const configSchema = {
537
+ * type: "object",
538
+ * required: ["database", "features"],
539
+ * properties: {
540
+ * database: {
541
+ * type: "object",
542
+ * required: ["host", "port", "name"],
543
+ * properties: {
544
+ * host: { type: "string", minLength: 1 },
545
+ * port: { type: "number", minimum: 1, maximum: 65535 },
546
+ * name: { type: "string", pattern: "^[a-zA-Z0-9_]+$" }
547
+ * }
548
+ * },
549
+ * features: {
550
+ * type: "object",
551
+ * properties: {
552
+ * enableLogging: { type: "boolean" },
553
+ * maxRetries: { type: "number", minimum: 0, maximum: 10 },
554
+ * timeoutInMs: { type: "number", minimum: 1000 }
555
+ * }
556
+ * }
557
+ * }
558
+ * };
559
+ *
560
+ * await validateDataUsingSchema(config, configSchema);
561
+ * // Ensures configuration meets requirements before app startup
562
+ * ```
563
+ *
564
+ */
565
+ export declare function validateDataUsingSchema(input: {
566
+ data: DataInput;
567
+ schema: Record<string, any>;
568
+ }): Promise<void>;
569
+
570
+ /**
571
+ * Versatile function that waits for network requests to settle after executing an action.
572
+ * Can be used as a simple decorator, parameterized decorator, or direct async call.
573
+ *
574
+ * @param {Function | Object} funcOrOptions - Either a function to wrap, configuration options for decorator, or full options with page and function
575
+ * @param {number} [funcOrOptions.timeoutInMs=30000] - Maximum time to wait in milliseconds before timing out
576
+ * @param {number} [funcOrOptions.maxInflightRequests=0] - Maximum number of pending requests to consider as "settled"
577
+ * @param {Page} [funcOrOptions.page] - Playwright page object (required for direct async call)
578
+ * @param {Function} [funcOrOptions.func] - Function to execute (required for direct async call)
579
+ * @returns {Function | Promise} Returns wrapped function for decorator usage, or Promise for direct async call
580
+ *
581
+ * @example
582
+ * ```typescript Simple Decorator Usage
583
+ * import { waitForNetworkIdle } from "@intuned/sdk/helpers";
584
+ *
585
+ * // Wrap any async function that takes a Page as first argument
586
+ * const clickAndWait = waitForNetworkIdle(async (page: Page, selector: string) => {
587
+ * await page.locator(selector).click();
588
+ * return 'clicked';
589
+ * });
590
+ *
591
+ * // Use the wrapped function - it will automatically wait for network to settle
592
+ * const result = await clickAndWait(page, '.submit-btn');
593
+ * ```
594
+ *
595
+ * @example
596
+ * ```typescript Parameterized Decorator Usage
597
+ * import { waitForNetworkIdle } from "@intuned/sdk/helpers";
598
+ *
599
+ * // Create a decorator with custom timeout and max inflight requests
600
+ * const scrollByAmount = waitForNetworkIdle({
601
+ * timeoutInMs: 10000,
602
+ * maxInflightRequests: 2
603
+ * })(async (page: Page, amount: number) => {
604
+ * await page.mouse.wheel(0, amount);
605
+ * });
606
+ *
607
+ * // Use the configured wrapper
608
+ * await scrollByAmount(page, 500);
609
+ * ```
610
+ *
611
+ * @example
612
+ * ```typescript Direct Async Call Usage
613
+ * import { waitForNetworkIdle } from "@intuned/sdk/helpers";
614
+ *
615
+ * // Direct execution with all parameters provided
616
+ * const result = await waitForNetworkIdle({
617
+ * page,
618
+ * func: async () => {
619
+ * await page.locator('.submit-btn').click();
620
+ * await page.fill('#input', 'some text');
621
+ * return 'form submitted';
622
+ * },
623
+ * timeoutInMs: 30000,
624
+ * maxInflightRequests: 0
625
+ * });
626
+ *
627
+ * console.log(result); // 'form submitted'
628
+ * ```
629
+ *
630
+ * @example
631
+ * ```typescript Real-world Usage in Tests
632
+ * import { waitForNetworkIdle } from "@intuned/sdk/helpers";
633
+ *
634
+ * // Test with network-heavy interactions
635
+ * const clickElement = waitForNetworkIdle({ timeoutInMs: 10000 })(
636
+ * async (page: Page, selector: string, timeoutInMs = 10) => {
637
+ * await page.locator(selector).first().click({ timeout: timeoutInMs});
638
+ * }
639
+ * );
640
+ *
641
+ * await page.goto("https://example.com/search");
642
+ * await clickElement(page, "[aria-label='Next page']", 10);
643
+ * // Function automatically waits for all network requests to complete
644
+ * ```
645
+ */
646
+ export declare function waitForNetworkIdle(
647
+ funcOrOptions?:
648
+ | ((...args) => Promise<any>)
649
+ | { timeoutInMs?: number; maxInflightRequests?: number }
650
+ | {
651
+ page: Page;
652
+ func: (...args: T) => Promise<any>;
653
+ timeoutInMs?: number;
654
+ maxInflightRequests?: number;
655
+ }
656
+ ): any;
657
+
658
+ /**
659
+ * Wait for the DOM to stop changing before proceeding. Useful for dynamic content
660
+ * that loads progressively or elements that appear/update after initial page load.
661
+ *
662
+ * This function monitors DOM mutations and waits for a specified duration of stability
663
+ * before considering the DOM "settled". It can monitor either the entire page or a
664
+ * specific element within the page.
665
+ *
666
+ * @param options - Configuration object with different properties based on the overload
667
+ * @param {Page} options.page - The Playwright Page to monitor for DOM changes.
668
+ * When provided, monitors the entire document for changes.
669
+ * @param {Locator} options.locator - The Playwright Locator pointing to a specific
670
+ * element to monitor. When provided, only monitors changes within this element.
671
+ * @param {number} [options.settleDuration=500] - Milliseconds the DOM must remain unchanged to be
672
+ * considered settled. Defaults to 0.5.
673
+ * @param {number} [options.timeoutInMs=30000] - Maximum milliseconds to wait before giving up.
674
+ * Defaults to 30000.
675
+ *
676
+ * @returns Promise that resolves to true if DOM settled within timeout, false if timeout error occurred
677
+ *
678
+ * @throws {Error} When invalid parameter combinations are provided (both page and locator,
679
+ * or neither page nor locator)
680
+ *
681
+ * @example
682
+ * ```typescript Wait for Page Content to Stabilize
683
+ * import { waitForDomSettled } from '@intuned/sdk';
684
+ *
685
+ * // Navigate to a dynamic page
686
+ * await page.goto('https://dynamic-site.com');
687
+ *
688
+ * // Wait for entire page content to stabilize
689
+ * const settled = await waitForDomSettled({
690
+ * page: page,
691
+ * settleDuration: 1000
692
+ * });
693
+ *
694
+ * if (settled) {
695
+ * // Safe to scrape or interact with content
696
+ * const items = await page.locator('.item').count();
697
+ * console.log(`Found ${items} stable items`);
698
+ * } else {
699
+ * console.log("DOM never fully settled, proceeding anyway");
700
+ * }
701
+ * ```
702
+ *
703
+ * @example
704
+ * ```typescript Monitor Specific Container
705
+ * import { waitForDomSettled } from '@intuned/sdk';
706
+ *
707
+ * // Wait for a specific feed container to stop updating
708
+ * const newsFeed = page.locator("#news-feed");
709
+ * const settled = await waitForDomSettled({
710
+ * locator: newsFeed,
711
+ * settleDuration: 2000,
712
+ * timeoutInMs: 15000,
713
+ * });
714
+ *
715
+ * if (settled) {
716
+ * // Now the feed is stable, safe to extract articles
717
+ * const articles = await newsFeed.locator('.article').all();
718
+ * console.log(`Feed stabilized with ${articles.length} articles`);
719
+ * }
720
+ * ```
721
+ *
722
+ * @example
723
+ * ```typescript Handle Fast-Changing Content
724
+ * import { waitForDomSettled } from '@intuned/sdk';
725
+ *
726
+ * // For rapidly updating content, use shorter settle duration
727
+ * const liveScores = page.locator("#live-scores");
728
+ * const settled = await waitForDomSettled({
729
+ * locator: liveScores,
730
+ * settleDuration: 200, // Very brief pause in updates
731
+ * timeoutInMs: 10000,
732
+ * });
733
+ *
734
+ * // Capture current state even if constantly updating
735
+ * const currentScores = await liveScores.textContent();
736
+ * ```
737
+ *
738
+ * @example
739
+ * ```typescript Robust Error Handling
740
+ * import { waitForDomSettled } from '@intuned/sdk';
741
+ *
742
+ * try {
743
+ * // Wait for dynamic table to settle
744
+ * const settled = await waitForDomSettled({
745
+ * page: page,
746
+ * settleDuration: 1500,
747
+ * timeoutInMs: 20000,
748
+ * });
749
+ *
750
+ * if (settled) {
751
+ * // Extract data from settled DOM
752
+ * const rows = await page.locator('tbody tr').count();
753
+ * console.log(`Table settled with ${rows} rows`);
754
+ * } else {
755
+ * console.log("DOM never fully settled, proceeding anyway");
756
+ * }
757
+ * } catch (error) {
758
+ * console.log(`DOM monitoring failed: ${error}`);
759
+ * // Fallback to simple wait
760
+ * await page.waitForTimeout(2000);
761
+ * }
762
+ * ```
763
+ */
764
+
765
+ export async function waitForDomSettled(options: {
766
+ page: Page;
767
+ settleDuration?: number;
768
+ timeoutInMs?: number;
769
+ }): Promise<boolean>;
770
+
771
+ export async function waitForDomSettled(options: {
772
+ locator: Locator;
773
+ settleDuration?: number;
774
+ timeoutInMs?: number;
775
+ }): Promise<boolean>;
776
+
777
+ /**
778
+ * Convert HTML content or a Playwright locator to semantic markdown.
779
+ *
780
+ * @param {string | Locator} source - The source of the HTML content, can be a string of HTML or a Playwright Locator.
781
+ * @returns {Promise<string>} A promise that resolves to the markdown representation of the HTML content.
782
+ * @example
783
+ * ```typescript locator source
784
+ * import { extractMarkdown } from "@intuned/sdk/helpers";
785
+ * import { Page, Locator } from "playwright";
786
+ * headerLocator = page.locator('h1')
787
+ * markdown = await extractMarkdown(headerLocator)
788
+ * console.log(markdown); // Outputs the markdown representation of the header
789
+ * ```
790
+ * @example
791
+ * ```typescript string source
792
+ * import { extractMarkdown } from "@intuned/sdk/helpers";
793
+ * import { Page } from "playwright";
794
+ * const htmlString = "<h1>Hello World</h1>";
795
+ * markdown = await extractMarkdown(htmlString);
796
+ * console.log(markdown); // Outputs "# Hello World"
797
+ * ```
798
+ *
799
+ */
800
+ export declare function extractMarkdown(input: {
801
+ source: Page | Locator;
802
+ }): Promise<string>;
803
+
804
+ /**
805
+ * Convert any URL source to an absolute, properly encoded URL.
806
+ *
807
+ * This function provides a unified interface for resolving URLs from different sources:
808
+ * string URLs (relative or absolute), Playwright Locators pointing to anchor elements,
809
+ * or Locator objects representing anchor elements.
810
+ *
811
+ * @param options - Configuration object with different properties based on the overload
812
+ * @param {string | Locator} options.url - The URL source to resolve.
813
+ * - If string: A relative or absolute URL string
814
+ * - If Locator: Must point to an anchor element
815
+ * - If ElementHandle: Must represent an anchor element
816
+ * @param {string} [options.baseUrl] - Base URL string to resolve relative URLs against.
817
+ * Required when url is a string and page is not provided.
818
+ * Cannot be used with Locator url.
819
+ * @param {Page} [options.page] - Playwright Page object to extract base URL from.
820
+ * Required when url is a string and baseUrl is not provided.
821
+ * Cannot be used with Locator url.
822
+ *
823
+ * @returns Promise that resolves to the absolute, properly encoded URL string
824
+ *
825
+ * @throws {Error} When invalid parameter combinations are provided or when
826
+ * Locator doesn't point to an anchor element
827
+ * @throws {TypeError} When url is not of a supported type
828
+ *
829
+ * @example
830
+ * ```typescript Resolve String URLs with baseUrl
831
+ * import { resolveUrl } from '@intuned/sdk';
832
+ *
833
+ * // Using explicit base URL
834
+ * const absoluteUrl = await resolveUrl({
835
+ * url: "/api/users",
836
+ * baseUrl: "https://example.com"
837
+ * });
838
+ * // Returns: "https://example.com/api/users"
839
+ * ```
840
+ *
841
+ * @example
842
+ * ```typescript Resolve String URLs with page
843
+ * import { resolveUrl } from '@intuned/sdk';
844
+ *
845
+ * // Using current page as base
846
+ * await page.goto("https://example.com/dashboard");
847
+ * const absoluteUrl = await resolveUrl({
848
+ * url: "../settings",
849
+ * page: page
850
+ * });
851
+ * // Returns: "https://example.com/settings"
852
+ * ```
853
+ *
854
+ * @example
855
+ * ```typescript Resolve from Anchor Elements with Locator
856
+ * import { resolveUrl } from '@intuned/sdk';
857
+ *
858
+ * // Using Locator pointing to anchor
859
+ * const linkLocator = page.locator('a[href="/products"]');
860
+ * const absoluteUrl = await resolveUrl({ url: linkLocator });
861
+ * // Returns: "https://example.com/products" (automatically resolved by browser)
862
+ * ```
863
+ *
864
+ * @example
865
+ * ```typescript Resolve from Anchor Elements with ElementHandle
866
+ * import { resolveUrl } from '@intuned/sdk';
867
+ *
868
+ * // Using ElementHandle
869
+ * const anchorElement = await page.$('a.nav-link');
870
+ * if (anchorElement) {
871
+ * const absoluteUrl = await resolveUrl({ url: anchorElement });
872
+ * // Returns the fully resolved href attribute
873
+ * }
874
+ * ```
875
+ *
876
+ * @example
877
+ * ```typescript Handle Complex URLs
878
+ * import { resolveUrl } from '@intuned/sdk';
879
+ *
880
+ * // URLs with special characters are properly encoded
881
+ * const encodedUrl = await resolveUrl({
882
+ * url: "/search?q=hello world&category=news",
883
+ * baseUrl: "https://example.com"
884
+ * });
885
+ * // Returns: "https://example.com/search?q=hello%20world&category=news"
886
+ *
887
+ * // Already absolute URLs are returned unchanged
888
+ * const fullUrl = await resolveUrl({
889
+ * url: "https://other-site.com/page",
890
+ * baseUrl: "https://example.com"
891
+ * });
892
+ * // Returns: "https://other-site.com/page"
893
+ * ```
894
+ */
895
+
896
+ export declare function resolveUrl(options: {
897
+ url: string | Locator;
898
+ baseUrl?: string;
899
+ page?: Page;
900
+ }): Promise<string>;
901
+
902
+ /**
903
+ * DataObject is a record of string keys and any values.
904
+ * It can be used to represent a single data object.
905
+ */
906
+ export type DataObject = Record<string, any>;
907
+
908
+ /**
909
+ * DataInput is a [DataObject](./DataObject) or an array of DataObjects.
910
+ * It can be used to represent either a single data object or an array of data objects.
911
+ */
912
+ export type DataInput = DataObject | DataObject[];
913
+
914
+ /**
915
+ * @class Attachment
916
+ * Represents an uploaded file stored in AWS S3 with metadata and utility methods.
917
+ *
918
+ * This interface provides a structured way to handle file information for files stored
919
+ * in S3, including methods for generating signed URLs, serialization, and accessing
920
+ * file metadata.
921
+ *
922
+ * @example
923
+ * ```typescript
924
+ * // Create from data
925
+ * const fileData = {
926
+ * fileName: "documents/report.pdf",
927
+ * bucket: "my-uploads",
928
+ * region: "us-east-1",
929
+ * suggestedFileName: "Monthly Report.pdf"
930
+ * };
931
+ * const uploadedFile: Attachment = createUploadedFile(fileData);
932
+ *
933
+ * // Get a signed URL for download
934
+ * const downloadUrl = await uploadedFile.getSignedUrl(3600); // 1 hour
935
+ *
936
+ * // Convert to dictionary for storage
937
+ * const fileDict = uploadedFile.toDict();
938
+ * ```
939
+ */
940
+ export interface Attachment {
941
+ /** The name/key of the file in the S3 bucket */
942
+ fileName: string;
943
+
944
+ /** The S3 bucket name where the file is stored */
945
+ bucket: string;
946
+
947
+ /** The AWS region where the S3 bucket is located */
948
+ region: string;
949
+
950
+ /** Optional custom S3 endpoint URL. Defaults to undefined for standard AWS S3 */
951
+ endpoint?: string;
952
+
953
+ /** A human-readable filename suggestion for downloads or display */
954
+ suggestedFileName: string;
955
+
956
+ /** The file type of the file */
957
+ fileType?: AttachmentType;
958
+
959
+ /**
960
+ * @method UploadFile.toJSON
961
+ * Returns a JSON-serializable record representation of the file.
962
+ * @returns Complete model data including all fields
963
+ *
964
+ * @example
965
+ * ```typescript
966
+ * file.toJSON()
967
+ * // {
968
+ * // 'fileName': 'docs/report.pdf',
969
+ * // 'bucket': 'uploads',
970
+ * // 'region': 'us-east-1',
971
+ * // 'endpoint': undefined,
972
+ * // 'suggestedFileName': 'Report.pdf'
973
+ * // }
974
+ * ```
975
+ */
976
+ toJSON(): Record<string, string>;
977
+
978
+ /**
979
+ * @method UploadFile.toDict
980
+ * Converts the file metadata to a record, excluding the endpoint field.
981
+ *
982
+ * @returns Record with fileName, bucket, region, and suggestedFileName
983
+ *
984
+ * @example
985
+ * ```typescript
986
+ * file.toDict()
987
+ * // {
988
+ * // 'fileName': 'docs/report.pdf',
989
+ * // 'bucket': 'uploads',
990
+ * // 'region': 'us-east-1',
991
+ * // 'suggestedFileName': 'Report.pdf'
992
+ * // }
993
+ * ```
994
+ */
995
+ toDict(): Record<string, string>;
996
+
997
+ /**
998
+ * @method UploadFile.getS3Key
999
+ * Returns the full S3 URL for the file.
1000
+ *
1001
+ * @returns Complete S3 URL
1002
+ *
1003
+ * @example
1004
+ * ```typescript
1005
+ * file.getS3Key()
1006
+ * // "https://uploads.s3.us-east-1.amazonaws.com/docs/report.pdf"
1007
+ * ```
1008
+ */
1009
+ getS3Key(): string;
1010
+
1011
+ /**
1012
+ * @method UploadFile.getFilePath
1013
+ * Returns the file path/key within the S3 bucket.
1014
+ *
1015
+ * @returns The fileName property (S3 object key)
1016
+ *
1017
+ * @example
1018
+ * ```typescript
1019
+ * file.getFilePath()
1020
+ * // "docs/report.pdf"
1021
+ * ```
1022
+ */
1023
+ getFilePath(): string;
1024
+
1025
+ /**
1026
+ * @method UploadFile.getBucket
1027
+ * Generates a presigned URL for secure, temporary access to the file.
1028
+ *
1029
+ * @param expiration - URL expiration time in seconds. Defaults to 432000 (5 days)
1030
+ * @returns Promise that resolves to presigned URL for downloading the file
1031
+ *
1032
+ * @example
1033
+ * ```typescript
1034
+ * const url = await file.getSignedUrl(3600); // 1 hour expiration
1035
+ * ```
1036
+ */
1037
+ getSignedUrl(expiration?: number): Promise<string>;
1038
+ }
1039
+
1040
+ /**
1041
+ * Types of triggers for downloading a file from a web page.
1042
+ * - `string`: A URL to navigate to for downloading the file.
1043
+ * - `Locator`: A Playwright Locator to click for initiating the download.
1044
+ * - `(page: Page) => Promise<void>`: A callback function that takes a Playwright Page as an argument and performs actions to trigger the download.
1045
+ */
1046
+ export type Trigger = string | Locator | ((page: Page) => Promise<void>);
1047
+
1048
+ /**
1049
+ * @interface S3Configs
1050
+ * Configuration options for AWS S3 storage operations.
1051
+ *
1052
+ * This interface defines the required authentication and configuration properties
1053
+ * for connecting to and performing operations with AWS S3 storage. All properties
1054
+ * are required for proper S3 access.
1055
+ *
1056
+ * @example
1057
+ * ```typescript
1058
+ * // Basic S3 configuration
1059
+ * const s3Config: S3Configs = {
1060
+ * bucket: "my-app-uploads",
1061
+ * region: "us-east-1",
1062
+ * accessKeyId: "AKIAIOSFODNN7EXAMPLE",
1063
+ * secretAccessKey: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
1064
+ * };
1065
+ *
1066
+ * // Use with file upload
1067
+ * const attachment = await uploadFileToS3(file, { s3Configs: s3Config });
1068
+ *
1069
+ * // Use with download operations
1070
+ * const downloadedFile = await downloadFromPageToS3(page, url, { s3Configs: s3Config });
1071
+ * ```
1072
+ */
1073
+ export interface S3Configs {
1074
+ /** The name of the S3 bucket where files will be stored or retrieved */
1075
+ bucket: string;
1076
+
1077
+ /** The AWS region where the S3 bucket is located (e.g., "us-east-1", "eu-west-1") */
1078
+ region: string;
1079
+
1080
+ /** AWS access key ID for authentication and authorization */
1081
+ accessKeyId: string;
1082
+
1083
+ /** AWS secret access key for authentication and authorization */
1084
+ secretAccessKey: string;
1085
+
1086
+ /** Custom S3 endpoint URL for S3-compatible storage services */
1087
+ endpoint?: string;
1088
+ }
1089
+
1090
+ /**
1091
+ * @interface S3UploadOptions
1092
+ * Configuration options for customizing S3 file upload operations.
1093
+ *
1094
+ * This interface provides optional parameters to control various aspects of file uploads
1095
+ * to AWS S3, including file naming, S3 configuration, custom endpoints, and content type
1096
+ * specification. All properties are optional and have sensible defaults.
1097
+ *
1098
+ * @example
1099
+ * ```typescript
1100
+ * // Basic upload with custom filename
1101
+ * const options: S3UploadOptions = {
1102
+ * fileNameOverride: "reports/monthly-report-2024.pdf"
1103
+ * };
1104
+ * const attachment = await uploadFileToS3(file, options);
1105
+ *
1106
+ * // Complete configuration with custom S3 settings
1107
+ * const fullOptions: S3UploadOptions = {
1108
+ * fileNameOverride: "documents/contract.pdf",
1109
+ * s3Configs: {
1110
+ * bucket: "legal-documents",
1111
+ * region: "us-west-2",
1112
+ * accessKeyId: "AKIAIOSFODNN7EXAMPLE",
1113
+ * secretAccessKey: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
1114
+ * endpoint: "https://s3.custom-domain.com",
1115
+ * },
1116
+ * contentType: "application/pdf"
1117
+ * };
1118
+ * const result = await uploadFileToS3(document, fullOptions);
1119
+ * ```
1120
+ */
1121
+ export interface S3UploadOptions {
1122
+ /** Optional custom filename/key for the uploaded file in S3. If not provided, uses original filename */
1123
+ fileNameOverride?: string;
1124
+
1125
+ /** Optional [S3Configs](../interfaces/S3Configs) configuration settings. If not provided, uses default or environment-configured S3 settings */
1126
+ s3Configs?: S3Configs;
1127
+
1128
+ /** Optional MIME type specification for the uploaded file (e.g., "application/pdf", "image/jpeg") */
1129
+ contentType?: string;
1130
+ }
1131
+
1132
+ /**
1133
+ * S3UploadableFile is a union of Download, Uint8Array, Buffer, and ReadStream.
1134
+ */
1135
+ export type S3UploadableFile = Download | Uint8Array | Buffer | ReadStream;
1136
+
1137
+ /**
1138
+ * ModelType is a string representing the model type.
1139
+ * Current supported models are:
1140
+ * - "gpt-4o"
1141
+ * - "gpt-4o-mini"
1142
+ * - "gpt-4o-turbo"
1143
+ * - "gpt-4o-turbo-preview"
1144
+ * - "gpt-4o-turbo-preview-2024-07-18"
1145
+ * - "gpt-4o-turbo-preview-2024-07-18"
1146
+ */
1147
+ export type ModelType = string;
1148
+
1149
+ /**
1150
+ * Downloads a file from a web page and uploads it to S3 storage.
1151
+ * This function supports three different ways to trigger a download:
1152
+ * - By URL
1153
+ * - By clicking on a Playwright locator
1154
+ * - By executing a callback function that takes a Playwright page as an argument and uses it to initiate the download.
1155
+ * @param {Page} page - The Playwright Page object.
1156
+ * @param {Trigger} trigger - [Trigger](../type-aliases/Trigger) to use for downloading the file.
1157
+ * @param {number} [timeoutInMs] - The timeout in milliseconds for the download operation. Default = 5000
1158
+ * @param {S3UploadOptions} uploadOptions - [S3UploadOptions](../interfaces/S3UploadOptions) for uploading the file to S3.
1159
+ * @returns {Promise<Attachment>} A promise that resolves to an [Attachment](../interfaces/Attachment) object containing the uploaded file's details.
1160
+ *
1161
+ * @example
1162
+ * ```typescript URL Download and Upload
1163
+ * import { downloadFromPageToS3 } from "@intuned/sdk/helpers";
1164
+ * import { S3UploadOptions } from "@intuned/sdk/types";
1165
+ *
1166
+ * const uploadOptions: S3UploadOptions = {
1167
+ * s3Configs: {
1168
+ * bucket: 'my-bucket',
1169
+ * region: 'us-west-1',
1170
+ * }
1171
+ * };
1172
+ * const uploadedFile = await downloadFromPageToS3(page, "https://sandbox.intuned.dev/pdfs", uploadOptions);
1173
+ * console.log(uploadedFile.getS3Key());
1174
+ * ```
1175
+ *
1176
+ * @example
1177
+ * ```typescript Locator Download and Upload
1178
+ * import { downloadFromPageToS3 } from "@intuned/sdk/helpers";
1179
+ * import { S3UploadOptions } from "@intuned/sdk/types";
1180
+ * const uploadOptions: S3UploadOptions = {
1181
+ * s3Configs: {
1182
+ * bucket: 'my-bucket',
1183
+ * region: 'us-west-1',
1184
+ * }
1185
+ * };
1186
+ * const uploadedFile = await downloadFromPageToS3(page, page.locator("[href='/download/file.pdf']"), uploadOptions);
1187
+ * console.log(uploadedFile.getS3Key());
1188
+ * ```
1189
+ *
1190
+ * @example
1191
+ * ```typescript Callback Function Download and Upload
1192
+ * import { downloadFromPageToS3 } from "@intuned/sdk/helpers";
1193
+ * import { S3UploadOptions } from "@intuned/sdk/types";
1194
+ * const uploadOptions: S3UploadOptions = {
1195
+ * s3Configs: {
1196
+ * bucket: 'my-bucket',
1197
+ * region: 'us-west-1',
1198
+ * }
1199
+ * };
1200
+ * const uploadedFile = await downloadFromPageToS3(page, async (page) => {
1201
+ * await page.locator("button:has-text('Download')").click();
1202
+ * }, uploadOptions);
1203
+ * console.log(uploadedFile.getS3Key());
1204
+ * ```
1205
+ * @note
1206
+ * - If a URL is provided as the trigger, a new page will be created and closed after the download is complete.
1207
+ * - If a locator is provided as the trigger, the page will be used to click the element and initiate the download.
1208
+ * - If a callback function is provided as the trigger, the function will be called with the page object as an argument and will be responsible for initiating the download.
1209
+ */
1210
+ export declare function downloadFromPageToS3(
1211
+ page: Page,
1212
+ trigger: Trigger,
1213
+ timeoutInMs?: number,
1214
+ uploadOptions: S3UploadOptions
1215
+ ): Promise<Attachment>;
1216
+ /**
1217
+ * Downloads a file from a web page and uploads it to S3 storage.
1218
+ * This function supports three different ways to trigger a download:
1219
+ * - By URL
1220
+ * - By clicking on a Playwright locator
1221
+ * - By executing a callback function that takes a Playwright page as an argument and uses it to initiate the download.
1222
+ * @param {Page} page - The Playwright Page object.
1223
+ * @param {Trigger} trigger - [Trigger](../type-aliases/Trigger) to use for downloading the file.
1224
+ * @param {number} [timeoutInMs = 5000] - The timeout in milliseconds for the download operation. Default = 5000
1225
+ * @param {S3UploadOptions} uploadOptions - [S3UploadOptions](../interfaces/S3UploadOptions) for uploading the file to S3.
1226
+ * @returns {Promise<Attachment>} A promise that resolves to an [Attachment](../interfaces/Attachment) object containing the uploaded file's details.
1227
+ *
1228
+ * @example
1229
+ * ```typescript URL Download and Upload
1230
+ * import { saveFileToS3 } from "@intuned/sdk/helpers";
1231
+ * import { S3UploadOptions } from "@intuned/sdk/types";
1232
+ *
1233
+ * const uploadOptions: S3UploadOptions = {
1234
+ * s3Configs: {
1235
+ * bucket: 'my-bucket',
1236
+ * region: 'us-west-1',
1237
+ * }
1238
+ * };
1239
+ * const uploadedFile = await saveFileToS3(page, "https://sandbox.intuned.dev/pdfs", uploadOptions);
1240
+ * console.log(uploadedFile.getS3Key());
1241
+ * ```
1242
+ *
1243
+ * @example
1244
+ * ```typescript Locator Download and Upload
1245
+ * import { saveFileToS3 } from "@intuned/sdk/helpers";
1246
+ * import { S3UploadOptions } from "@intuned/sdk/types";
1247
+ * const uploadOptions: S3UploadOptions = {
1248
+ * s3Configs: {
1249
+ * bucket: 'my-bucket',
1250
+ * region: 'us-west-1',
1251
+ * }
1252
+ * };
1253
+ * const uploadedFile = await saveFileToS3(page, page.locator("[href='/download/file.pdf']"), uploadOptions);
1254
+ * console.log(uploadedFile.getS3Key());
1255
+ * ```
1256
+ *
1257
+ * @example
1258
+ * ```typescript Callback Function Download and Upload
1259
+ * import { saveFileToS3 } from "@intuned/sdk/helpers";
1260
+ * import { S3UploadOptions } from "@intuned/sdk/types";
1261
+ * const uploadOptions: S3UploadOptions = {
1262
+ * s3Configs: {
1263
+ * bucket: 'my-bucket',
1264
+ * region: 'us-west-1',
1265
+ * }
1266
+ * };
1267
+ * const uploadedFile = await saveFileToS3(page, async (page) => {
1268
+ * await page.locator("button:has-text('Download')").click();
1269
+ * }, uploadOptions);
1270
+ * console.log(uploadedFile.getS3Key());
1271
+ * ```
1272
+ * @note
1273
+ * - If a URL is provided as the trigger, a new page will be created and closed after the download is complete.
1274
+ * - If a locator is provided as the trigger, the page will be used to click the element and initiate the download.
1275
+ * - If a callback function is provided as the trigger, the function will be called with the page object as an argument and will be responsible for initiating the download.
1276
+ */
1277
+ export declare function saveFileToS3(input: {
1278
+ page: Page;
1279
+ trigger: Trigger;
1280
+ timeoutInMs?: number;
1281
+ uploadOptions: S3UploadOptions;
1282
+ }): Promise<Attachment>;
1283
+
1284
+ /**
1285
+ * LoadingStatus is a union of true, false, and "Dont know".
1286
+ */
1287
+ export type LoadingStatus = true | false | "Dont know";
1288
+
1289
+ /**
1290
+ * AttachmentType is a string representing the type of the file.
1291
+ * Current supported types are:
1292
+ * - "document"
1293
+ */
1294
+ export type AttachmentType = "document";