@intuned/browser-dev 0.1.4-dev.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (212) hide show
  1. package/.babelrc +21 -0
  2. package/.eslintignore +10 -0
  3. package/.eslintrc.js +39 -0
  4. package/BROWSER_SCRIPTS_SETUP.md +84 -0
  5. package/LICENSE +43 -0
  6. package/README.md +160 -0
  7. package/RELEASE.md +60 -0
  8. package/dist/ai/export.d.js +5 -0
  9. package/dist/ai/export.d.ts +641 -0
  10. package/dist/ai/extractStructuredData.js +320 -0
  11. package/dist/ai/extractStructuredDataUsingAi.js +142 -0
  12. package/dist/ai/extractionHelpers/screenshotHelpers.js +56 -0
  13. package/dist/ai/extractionHelpers/validateSchema.js +148 -0
  14. package/dist/ai/index.d.ts +641 -0
  15. package/dist/ai/index.js +19 -0
  16. package/dist/ai/isPageLoaded.js +80 -0
  17. package/dist/ai/prompt.js +39 -0
  18. package/dist/ai/tests/testCheckAllTypesAreStrings.spec.js +137 -0
  19. package/dist/ai/tests/testExtractFromContent.spec.js +372 -0
  20. package/dist/ai/tests/testExtractStructuredData.spec.js +646 -0
  21. package/dist/ai/tests/testIsPageLoaded.spec.js +277 -0
  22. package/dist/ai/tools/index.js +48 -0
  23. package/dist/ai/types/errors.js +67 -0
  24. package/dist/ai/types/models.js +45 -0
  25. package/dist/ai/types/types.js +48 -0
  26. package/dist/ai/validators.js +167 -0
  27. package/dist/common/Logger/index.js +60 -0
  28. package/dist/common/Logger/types.js +5 -0
  29. package/dist/common/SdkError.js +50 -0
  30. package/dist/common/aiModelsValidations.js +32 -0
  31. package/dist/common/ensureBrowserScripts.js +14 -0
  32. package/dist/common/extendedTest.js +157 -0
  33. package/dist/common/extractionHelpers.js +19 -0
  34. package/dist/common/formatZodError.js +18 -0
  35. package/dist/common/fuzzySearch/fuzzySearch.test.js +250 -0
  36. package/dist/common/fuzzySearch/levenshtein-search.js +298 -0
  37. package/dist/common/fuzzySearch/utils.js +23 -0
  38. package/dist/common/getModelProvider.js +18 -0
  39. package/dist/common/getSimplifiedHtml.js +122 -0
  40. package/dist/common/hashObject.js +32 -0
  41. package/dist/common/html2markdown/convertElementToMarkdown.js +469 -0
  42. package/dist/common/html2markdown/index.js +19 -0
  43. package/dist/common/jwtTokenManager.js +57 -0
  44. package/dist/common/loadRuntime.js +16 -0
  45. package/dist/common/locatorHelpers.js +41 -0
  46. package/dist/common/matching/collectStrings.js +32 -0
  47. package/dist/common/matching/levenshtein.js +40 -0
  48. package/dist/common/matching/matching.js +317 -0
  49. package/dist/common/matching/types.js +1 -0
  50. package/dist/common/noEmpty.js +9 -0
  51. package/dist/common/saveSnapshotWithExamples.js +60 -0
  52. package/dist/common/script.js +2602 -0
  53. package/dist/common/tests/testEnsureBrowserScript.spec.js +31 -0
  54. package/dist/common/xpathMapping.js +107 -0
  55. package/dist/helpers/clickUntilExhausted.js +85 -0
  56. package/dist/helpers/downloadFile.js +125 -0
  57. package/dist/helpers/export.d.js +5 -0
  58. package/dist/helpers/export.d.ts +1220 -0
  59. package/dist/helpers/extractMarkdown.js +35 -0
  60. package/dist/helpers/filterEmptyValues.js +54 -0
  61. package/dist/helpers/gotoUrl.js +98 -0
  62. package/dist/helpers/index.d.ts +1220 -0
  63. package/dist/helpers/index.js +122 -0
  64. package/dist/helpers/processDate.js +25 -0
  65. package/dist/helpers/resolveUrl.js +64 -0
  66. package/dist/helpers/sanitizeHtml.js +74 -0
  67. package/dist/helpers/saveFileToS3.js +50 -0
  68. package/dist/helpers/scrollToLoadContent.js +57 -0
  69. package/dist/helpers/tests/testClickUntilExhausted.spec.js +372 -0
  70. package/dist/helpers/tests/testDownloadFile.spec.js +206 -0
  71. package/dist/helpers/tests/testExtractMarkdown.spec.js +290 -0
  72. package/dist/helpers/tests/testFilterEmptyValues.spec.js +151 -0
  73. package/dist/helpers/tests/testGoToUrl.spec.js +37 -0
  74. package/dist/helpers/tests/testProcessDate.spec.js +13 -0
  75. package/dist/helpers/tests/testResolveUrl.spec.js +341 -0
  76. package/dist/helpers/tests/testSanitizeHtml.spec.js +330 -0
  77. package/dist/helpers/tests/testScrollToLoadContent.spec.js +163 -0
  78. package/dist/helpers/tests/testValidateDataUsingSchema.spec.js +342 -0
  79. package/dist/helpers/tests/testWithDomSettledWait.spec.js +164 -0
  80. package/dist/helpers/tests/testWithNetworkIdleWait.spec.js +114 -0
  81. package/dist/helpers/types/Attachment.js +115 -0
  82. package/dist/helpers/types/CustomTypeRegistry.js +48 -0
  83. package/dist/helpers/types/RunEnvironment.js +18 -0
  84. package/dist/helpers/types/ValidationError.js +17 -0
  85. package/dist/helpers/types/index.js +51 -0
  86. package/dist/helpers/uploadFileToS3.js +154 -0
  87. package/dist/helpers/utils/getS3Client.js +22 -0
  88. package/dist/helpers/utils/index.js +73 -0
  89. package/dist/helpers/utils/isDownload.js +10 -0
  90. package/dist/helpers/utils/isGenerateCodeMode.js +9 -0
  91. package/dist/helpers/utils/isLocator.js +9 -0
  92. package/dist/helpers/utils/jwtTokenManager.js +18 -0
  93. package/dist/helpers/validateDataUsingSchema.js +103 -0
  94. package/dist/helpers/waitForDomSettled.js +90 -0
  95. package/dist/helpers/withNetworkSettledWait.js +91 -0
  96. package/dist/index.d.js +16 -0
  97. package/dist/index.d.ts +10 -0
  98. package/dist/index.js +16 -0
  99. package/dist/intunedServices/ApiGateway/aiApiGateway.js +143 -0
  100. package/dist/intunedServices/ApiGateway/factory.js +16 -0
  101. package/dist/intunedServices/ApiGateway/providers/Anthropic.js +26 -0
  102. package/dist/intunedServices/ApiGateway/providers/Gemini.js +29 -0
  103. package/dist/intunedServices/ApiGateway/providers/OpenAI.js +29 -0
  104. package/dist/intunedServices/ApiGateway/tests/testApiGateway.spec.js +355 -0
  105. package/dist/intunedServices/ApiGateway/types.js +11 -0
  106. package/dist/intunedServices/cache/cache.js +61 -0
  107. package/dist/intunedServices/cache/index.js +12 -0
  108. package/dist/intunedServices/cache/tests/testCache.spec.js +117 -0
  109. package/dist/optimized-extractors/common/buildExamplesPrompt.js +12 -0
  110. package/dist/optimized-extractors/common/buildImagesFromPage.js +55 -0
  111. package/dist/optimized-extractors/common/extractStructuredDataUsingClaude.js +135 -0
  112. package/dist/optimized-extractors/common/extractStructuredDataUsingGoogle.js +37 -0
  113. package/dist/optimized-extractors/common/extractStructuredDataUsingOpenAi.js +132 -0
  114. package/dist/optimized-extractors/common/extractStrucutredDataUsingAiInstance.js +122 -0
  115. package/dist/optimized-extractors/common/findTableHeaders.js +162 -0
  116. package/dist/optimized-extractors/common/index.js +55 -0
  117. package/dist/optimized-extractors/common/isTableHeaderOrFooter.js +84 -0
  118. package/dist/optimized-extractors/common/matching/matching.js +212 -0
  119. package/dist/optimized-extractors/common/matching/matching.test.js +655 -0
  120. package/dist/optimized-extractors/common/matching/types.js +18 -0
  121. package/dist/optimized-extractors/common/matching/utils.js +184 -0
  122. package/dist/optimized-extractors/common/utils.js +58 -0
  123. package/dist/optimized-extractors/export.d.js +5 -0
  124. package/dist/optimized-extractors/export.d.ts +397 -0
  125. package/dist/optimized-extractors/extractArray.js +120 -0
  126. package/dist/optimized-extractors/extractObject.js +104 -0
  127. package/dist/optimized-extractors/index.d.ts +397 -0
  128. package/dist/optimized-extractors/index.js +31 -0
  129. package/dist/optimized-extractors/listExtractionHelpers/__tests__/dynamicListExtractor.spec.js +269 -0
  130. package/dist/optimized-extractors/listExtractionHelpers/__tests__/findSetOfXpathsToCreateAnArrayExtractor.test.js +22 -0
  131. package/dist/optimized-extractors/listExtractionHelpers/__tests__/getContainerElement.test.js +21 -0
  132. package/dist/optimized-extractors/listExtractionHelpers/__tests__/partOfSameArrayXpath.test.js +42 -0
  133. package/dist/optimized-extractors/listExtractionHelpers/__tests__/testArrayExtractorFromLocator.spec.js +146 -0
  134. package/dist/optimized-extractors/listExtractionHelpers/__tests__/testArrayExtractorFromPage.spec.js +130 -0
  135. package/dist/optimized-extractors/listExtractionHelpers/__tests__/verifyThatAllXpathsArePartOfSameArray.test.js +9 -0
  136. package/dist/optimized-extractors/listExtractionHelpers/dynamicListExtractor.js +160 -0
  137. package/dist/optimized-extractors/listExtractionHelpers/errors.js +46 -0
  138. package/dist/optimized-extractors/listExtractionHelpers/getListMatches.js +14 -0
  139. package/dist/optimized-extractors/listExtractionHelpers/runAiExtraction.js +243 -0
  140. package/dist/optimized-extractors/listExtractionHelpers/typesAndSchema.js +5 -0
  141. package/dist/optimized-extractors/listExtractionHelpers/utils/extractPropertiesUsingGPTFromArray.js +277 -0
  142. package/dist/optimized-extractors/listExtractionHelpers/utils/extractStructuredListUsingAi.js +44 -0
  143. package/dist/optimized-extractors/listExtractionHelpers/utils/getListContainerXpath.js +94 -0
  144. package/dist/optimized-extractors/listExtractionHelpers/utils/getRelativeContainerXpathSelector.js +20 -0
  145. package/dist/optimized-extractors/listExtractionHelpers/utils/getSimplifiedHtmlPerListItem.js +21 -0
  146. package/dist/optimized-extractors/listExtractionHelpers/utils/tablesUtils.js +48 -0
  147. package/dist/optimized-extractors/listExtractionHelpers/utils/validateOptions.js +52 -0
  148. package/dist/optimized-extractors/models/anthropicModel.js +23 -0
  149. package/dist/optimized-extractors/models/openaiModel.js +23 -0
  150. package/dist/optimized-extractors/objectExtractionHelpers/AIExtractors.js +73 -0
  151. package/dist/optimized-extractors/objectExtractionHelpers/__tests__/checksumUtils.test.js +103 -0
  152. package/dist/optimized-extractors/objectExtractionHelpers/__tests__/testObjectExtractorFromLocator.spec.js +107 -0
  153. package/dist/optimized-extractors/objectExtractionHelpers/__tests__/testObjectExtractorFromPage.spec.js +107 -0
  154. package/dist/optimized-extractors/objectExtractionHelpers/calculateObjectExampleHash.js +28 -0
  155. package/dist/optimized-extractors/objectExtractionHelpers/captureSnapshot.js +26 -0
  156. package/dist/optimized-extractors/objectExtractionHelpers/checksumUtils.js +32 -0
  157. package/dist/optimized-extractors/objectExtractionHelpers/constants.js +7 -0
  158. package/dist/optimized-extractors/objectExtractionHelpers/dynamicObjectExtractor.js +106 -0
  159. package/dist/optimized-extractors/objectExtractionHelpers/errors.js +42 -0
  160. package/dist/optimized-extractors/objectExtractionHelpers/findDomMatches.js +54 -0
  161. package/dist/optimized-extractors/objectExtractionHelpers/getSimplifiedHtml.js +122 -0
  162. package/dist/optimized-extractors/objectExtractionHelpers/typesAndSchemas.js +5 -0
  163. package/dist/optimized-extractors/objectExtractionHelpers/validateDynamicObjectExtractorOptions.js +52 -0
  164. package/dist/optimized-extractors/types/aiModelsValidation.js +45 -0
  165. package/dist/optimized-extractors/types/errors.js +42 -0
  166. package/dist/optimized-extractors/types/jsonSchema.d.js +5 -0
  167. package/dist/optimized-extractors/types/jsonSchema.d.ts +50 -0
  168. package/dist/optimized-extractors/types/types.js +5 -0
  169. package/dist/optimized-extractors/validators.js +152 -0
  170. package/dist/types/intuned-runtime.d.js +1 -0
  171. package/dist/types/intuned-runtime.d.ts +64 -0
  172. package/dist/vite-env.d.js +1 -0
  173. package/dist/vite-env.d.ts +9 -0
  174. package/generated-docs/ai/functions/extractStructuredData.mdx +255 -0
  175. package/generated-docs/ai/functions/isPageLoaded.mdx +88 -0
  176. package/generated-docs/ai/interfaces/ArraySchema.mdx +36 -0
  177. package/generated-docs/ai/interfaces/BasicSchema.mdx +14 -0
  178. package/generated-docs/ai/interfaces/BooleanSchema.mdx +28 -0
  179. package/generated-docs/ai/interfaces/ImageBufferContentItem.mdx +16 -0
  180. package/generated-docs/ai/interfaces/ImageUrlContentItem.mdx +16 -0
  181. package/generated-docs/ai/interfaces/NumberSchema.mdx +35 -0
  182. package/generated-docs/ai/interfaces/ObjectSchema.mdx +39 -0
  183. package/generated-docs/ai/interfaces/StringSchema.mdx +35 -0
  184. package/generated-docs/ai/interfaces/TextContentItem.mdx +14 -0
  185. package/generated-docs/ai/type-aliases/ContentItem.mdx +12 -0
  186. package/generated-docs/ai/type-aliases/JsonSchema.mdx +47 -0
  187. package/generated-docs/ai/type-aliases/SUPPORTED_MODELS.mdx +85 -0
  188. package/generated-docs/helpers/functions/downloadFile.mdx +99 -0
  189. package/generated-docs/helpers/functions/extractMarkdown.mdx +56 -0
  190. package/generated-docs/helpers/functions/filterEmptyValues.mdx +51 -0
  191. package/generated-docs/helpers/functions/goToUrl.mdx +124 -0
  192. package/generated-docs/helpers/functions/processDate.mdx +55 -0
  193. package/generated-docs/helpers/functions/resolveUrl.mdx +165 -0
  194. package/generated-docs/helpers/functions/sanitizeHtml.mdx +113 -0
  195. package/generated-docs/helpers/functions/saveFileToS3.mdx +127 -0
  196. package/generated-docs/helpers/functions/scrollToLoadContent.mdx +89 -0
  197. package/generated-docs/helpers/functions/uploadFileToS3.mdx +121 -0
  198. package/generated-docs/helpers/functions/validateDataUsingSchema.mdx +90 -0
  199. package/generated-docs/helpers/functions/waitForDomSettled.mdx +91 -0
  200. package/generated-docs/helpers/functions/withNetworkSettledWait.mdx +76 -0
  201. package/generated-docs/helpers/interfaces/Attachment.mdx +56 -0
  202. package/generated-docs/helpers/interfaces/S3Configs.mdx +52 -0
  203. package/generated-docs/helpers/interfaces/SanitizeHtmlOptions.mdx +22 -0
  204. package/generated-docs/helpers/type-aliases/AttachmentType.mdx +10 -0
  205. package/generated-docs/helpers/type-aliases/FileType.mdx +61 -0
  206. package/generated-docs/helpers/type-aliases/Trigger.mdx +62 -0
  207. package/how-to-generate-docs.md +61 -0
  208. package/how-to-run-tests.md +42 -0
  209. package/intuned-runtime-setup.md +13 -0
  210. package/package.json +124 -0
  211. package/tsconfig.eslint.json +5 -0
  212. package/tsconfig.json +26 -0
@@ -0,0 +1,76 @@
1
+ ---
2
+ title: withNetworkSettledWait
3
+ description: ""
4
+ ---
5
+
6
+ ```typescript
7
+ export declare function withNetworkSettledWait<T>(callback: (page: Page) => Promise<T>,
8
+ options?: {
9
+ page: Page;
10
+ timeoutInMs?: number;
11
+ maxInflightRequests?: number;
12
+ }): Promise<T>;
13
+ ```
14
+
15
+ Executes a callback function and waits for network requests to settle before returning.
16
+
17
+ This function monitors network activity and waits for all pending requests to complete
18
+ (or reach the specified maximum) before resolving. Useful for ensuring dynamic content
19
+ has fully loaded after performing actions that trigger network requests.
20
+
21
+ ## Examples
22
+
23
+ <CodeGroup>
24
+
25
+ ```typescript Navigation with Network Settlement
26
+ import { withNetworkSettledWait } from "@intuned/browser";
27
+ export default async function handler(params, page, context){
28
+ // Navigate and ensure all resources are loaded
29
+ await withNetworkSettledWait(
30
+ async (page) => {
31
+ await page.goto('https://spa-app.com/dashboard');
32
+ // Return when navigation is complete and network is idle
33
+ },
34
+ {
35
+ page,
36
+ timeoutInMs: 20000,
37
+ maxInflightRequests: 0 // Wait for complete network silence
38
+ }
39
+ );
40
+ }
41
+ ```
42
+
43
+ </CodeGroup>
44
+
45
+ ## Arguments
46
+
47
+ <ParamField path="callback" type="Function" required
48
+ >
49
+ The callback function to execute. Receives the page object as parameter
50
+
51
+ </ParamField>
52
+
53
+ <ParamField path="options" type="Object"
54
+ >
55
+ Configuration options for network monitoring
56
+
57
+ <Expandable title="options">
58
+ <ParamField path="options.page" type="Page">
59
+ The Playwright page object to monitor for network activity
60
+ </ParamField>
61
+
62
+ <ParamField path="options.timeoutInMs" type="number">
63
+ Maximum time to wait in milliseconds before timing out. Defaults to 30000
64
+ </ParamField>
65
+
66
+ <ParamField path="options.maxInflightRequests" type="number">
67
+ Maximum number of pending requests to consider as "settled". Defaults to 0 (waits for all requests to complete)
68
+ </ParamField>
69
+
70
+ </Expandable>
71
+
72
+ </ParamField>
73
+
74
+ ## Returns: `Promise<T>`
75
+
76
+ Promise that resolves to the callback's return value after network settles
@@ -0,0 +1,56 @@
1
+ ---
2
+ title: Attachment
3
+ description: ""
4
+ ---
5
+
6
+ ```typescript
7
+ export interface Attachment {
8
+ fileName: string;
9
+ bucket: string;
10
+ region: string;
11
+ endpoint?: string;
12
+ suggestedFileName: string;
13
+ fileType?: AttachmentType;
14
+ toJSON(): Record<string,
15
+ string>;
16
+ toDict(): Record<string,
17
+ string>;
18
+ getS3Key(): string;
19
+ getFilePath(): string;
20
+ getSignedUrl(expiration?: number): Promise<string>;
21
+ }
22
+ ```
23
+
24
+ Represents an uploaded file stored in AWS S3 with metadata and utility methods.
25
+
26
+ This interface provides a structured way to handle file information for files stored
27
+ in S3, including methods for generating presigned URLs, serialization, and accessing
28
+ file metadata.
29
+
30
+ ## Examples
31
+
32
+ <CodeGroup>
33
+
34
+ ```typescript Attachment Usage
35
+ import { uploadFileToS3 } from "@intuned/browser";
36
+ export default async function handler(params, page, context){
37
+ // Typically returned from uploadFileToS3 or saveFileToS3
38
+
39
+ const uploadedFile: Attachment = await uploadFileToS3({
40
+ file: myFile,
41
+ configs: s3Config
42
+ });
43
+
44
+ // Access file properties
45
+ console.log(uploadedFile.fileName); // "documents/report.pdf"
46
+ console.log(uploadedFile.suggestedFileName); // "Monthly Report.pdf"
47
+
48
+ // Get a presigned URL for download
49
+ const downloadUrl = await uploadedFile.getSignedUrl(3600); // 1 hour
50
+
51
+ // Convert to dictionary for storage or API responses
52
+ const fileDict = uploadedFile.toDict();
53
+ }
54
+ ```
55
+
56
+ </CodeGroup>
@@ -0,0 +1,52 @@
1
+ ---
2
+ title: S3Configs
3
+ description: ""
4
+ ---
5
+
6
+ ```typescript
7
+ export interface S3Configs {
8
+ bucket?: string;
9
+ region?: string;
10
+ accessKeyId?: string;
11
+ secretAccessKey?: string;
12
+ endpoint?: string;
13
+ }
14
+ ```
15
+
16
+ Configuration options for AWS S3 storage operations.
17
+
18
+ This interface defines the authentication and configuration properties
19
+ for connecting to and performing operations with AWS S3 storage. All properties
20
+ are optional and will fall back to environment variables or default configuration.
21
+
22
+ ## Examples
23
+
24
+ <CodeGroup>
25
+
26
+ ```typescript S3 Configuration
27
+ import { uploadFileToS3 } from "@intuned/browser";
28
+ export default async function handler(params, page, context){
29
+ // Basic S3 configuration
30
+ const s3Config: S3Configs = {
31
+ bucket: "my-app-uploads",
32
+ region: "us-east-1",
33
+ accessKeyId: "accessKeyId",
34
+ secretAccessKey: "SecretAccessKeyId"
35
+ };
36
+
37
+ // Use with file upload
38
+ const attachment = await uploadFileToS3({
39
+ file: myFile,
40
+ configs: s3Config
41
+ });
42
+
43
+ // Use with download and upload operations
44
+ const uploadedFile = await saveFileToS3({
45
+ page,
46
+ trigger: downloadUrl,
47
+ configs: s3Config
48
+ });
49
+ }
50
+ ```
51
+
52
+ </CodeGroup>
@@ -0,0 +1,22 @@
1
+ ---
2
+ title: SanitizeHtmlOptions
3
+ description: ""
4
+ ---
5
+
6
+ ```typescript
7
+ export interface SanitizeHtmlOptions {
8
+ html: string;
9
+ removeScripts?: boolean;
10
+ removeStyles?: boolean;
11
+ removeSvgs?: boolean;
12
+ removeComments?: boolean;
13
+ removeLongAttributes?: boolean;
14
+ maxAttributeLength?: number;
15
+ preserveAttributes?: string[];
16
+ removeEmptyTags?: boolean;
17
+ preserveEmptyTags?: string[];
18
+ minifyWhitespace?: boolean;
19
+ }
20
+ ```
21
+
22
+ Configuration options for sanitizing HTML content.
@@ -0,0 +1,10 @@
1
+ ---
2
+ title: AttachmentType
3
+ description: ""
4
+ ---
5
+
6
+ ```typescript
7
+ export type AttachmentType = "document";
8
+ ```
9
+
10
+ Union type representing the supported attachment file types.
@@ -0,0 +1,61 @@
1
+ ---
2
+ title: FileType
3
+ description: ""
4
+ ---
5
+
6
+ ```typescript
7
+ export type FileType = Download | Uint8Array | Buffer | ReadStream;
8
+ ```
9
+
10
+ A union type representing different file formats that can be processed by the SDK.
11
+
12
+ This type alias provides flexibility in how files can be passed to various functions,
13
+ supporting multiple input formats for maximum convenience.
14
+
15
+ ## Examples
16
+
17
+ <CodeGroup>
18
+
19
+ ```typescript Using Download Object
20
+ import { downloadFile, uploadFileToS3 } from "@intuned/browser";
21
+ export default async function handler(params, page, context){
22
+ // From a browser download
23
+ const download = await downloadFile({
24
+ page,
25
+ trigger: "https://example.com/file.pdf"
26
+ });
27
+ const uploaded = await uploadFileToS3({
28
+ file: download,
29
+ configs: s3Config
30
+ });
31
+ }
32
+ ```
33
+
34
+ ```typescript Using Buffer
35
+ import { uploadFileToS3 } from "@intuned/browser";
36
+ export default async function handler(params, page, context){
37
+ // From raw buffer
38
+ const fileBuffer = Buffer.from("PDF content here...", "utf8");
39
+ const uploaded = await uploadFileToS3({
40
+ file: fileBuffer,
41
+ fileNameOverride: "generated.pdf",
42
+ configs: s3Config
43
+ });
44
+ }
45
+ ```
46
+
47
+ ```typescript Using ReadStream
48
+ import { uploadFileToS3 } from "@intuned/browser";
49
+ import { createReadStream } from "fs";
50
+ export default async function handler(params, page, context){
51
+ // From a file stream
52
+ const fileStream = createReadStream("/path/to/document.pdf");
53
+ const uploaded = await uploadFileToS3({
54
+ file: fileStream,
55
+ fileNameOverride: "renamed.pdf",
56
+ configs: s3Config
57
+ });
58
+ }
59
+ ```
60
+
61
+ </CodeGroup>
@@ -0,0 +1,62 @@
1
+ ---
2
+ title: Trigger
3
+ description: ""
4
+ ---
5
+
6
+ ```typescript
7
+ export type Trigger = string | Locator | ((page: Page) => Promise<void>);
8
+ ```
9
+
10
+ <Note>
11
+ All download functions in the helpers module accept Trigger for consistency.
12
+ The trigger method determines how the download operation is initiated.
13
+ </Note>
14
+
15
+ A union type representing different methods to trigger file downloads in web automation.
16
+
17
+ This type alias standardizes how download operations can be initiated, providing
18
+ multiple approaches to suit different automation scenarios.
19
+
20
+ ## Examples
21
+
22
+ <CodeGroup>
23
+
24
+ ```typescript URL String Trigger
25
+ import { downloadFile } from "@intuned/browser";
26
+ export default async function handler(params, page, context){
27
+ // Direct download from URL
28
+ const download = await downloadFile({
29
+ page,
30
+ trigger: "https://example.com/report.pdf"
31
+ });
32
+ }
33
+ ```
34
+
35
+ ```typescript Locator Trigger
36
+ import { downloadFile } from "@intuned/browser";
37
+ export default async function handler(params, page, context){
38
+ // Click a download button/link
39
+ const downloadButton = page.locator("#download-btn");
40
+ const download = await downloadFile({
41
+ page,
42
+ trigger: downloadButton
43
+ });
44
+ }
45
+ ```
46
+
47
+ ```typescript Custom Function Trigger
48
+ import { downloadFile } from "@intuned/browser";
49
+ export default async function handler(params, page, context){
50
+ // Complex download logic
51
+ const download = await downloadFile({
52
+ page,
53
+ trigger: async (page) => {
54
+ await page.click(".menu-trigger");
55
+ await page.waitForSelector(".download-option");
56
+ await page.click(".download-option");
57
+ }
58
+ });
59
+ }
60
+ ```
61
+
62
+ </CodeGroup>
@@ -0,0 +1,61 @@
1
+ ## How to Generate Documentation
2
+
3
+ ### Generating Docs
4
+
5
+ **Generate all docs (recommended):**
6
+
7
+ ```bash
8
+ yarn generate-all-docs
9
+ ```
10
+
11
+ This command processes all `export.d.ts` files from the 3 namespaces and generates their documentation.
12
+
13
+ **Generate docs for a specific file:**
14
+
15
+ ```bash
16
+ yarn generate-docs <input.d.ts> [outputdir]
17
+ ```
18
+
19
+ **Examples:**
20
+
21
+ ```bash
22
+ # Generate docs for helpers (recommended)
23
+ yarn generate-docs ./src/helpers/export.d.ts ./generated-docs/helpers
24
+
25
+ # Generate docs for AI functions
26
+ yarn generate-docs ./src/ai/export.d.ts ./generated-docs/ai
27
+
28
+ # Generate docs for optimized extractors
29
+ yarn generate-docs ./src/optimized-extractors/export.d.ts ./generated-docs/optimized-extractors
30
+
31
+ # Use default output directory (./generated-docs)
32
+ yarn generate-docs ./src/helpers/export.d.ts
33
+ ```
34
+
35
+ **Output Structure:**
36
+
37
+ - Functions will be written to `[outputdir]/functions/`
38
+ - Interfaces will be written to `[outputdir]/interfaces/`
39
+ - Type aliases will be written to `[outputdir]/type-aliases/`
40
+
41
+ ### Available Namespaces
42
+
43
+ The following namespaces have `export.d.ts` files that can be processed:
44
+
45
+ - `./src/helpers/export.d.ts` - Helper functions for web automation
46
+ - `./src/ai/export.d.ts` - AI-powered data extraction functions
47
+ - `./src/optimized-extractors/export.d.ts` - Optimized data extraction functions
48
+
49
+ ### How It Works
50
+
51
+ The script in `./scripts/generate-docs.ts` reads JSDocs from `export.d.ts` files and converts them to Mintlify-compatible markdown format using TypeScript AST parsing.
52
+
53
+ ### Writing JSDocs
54
+
55
+ **Guidelines:**
56
+
57
+ - Follow the conventions found in any `export.d.ts` file
58
+ - Refer to `src/helpers/export.d.ts` for comprehensive examples
59
+ - The markdown converters parse JSDocs into Mintlify-compatible format
60
+ - Include `@example` blocks with TypeScript code snippets
61
+ - Use `@param`, `@returns`, and `@interface` tags for proper documentation
@@ -0,0 +1,42 @@
1
+ ## How to Run Tests
2
+
3
+ ### Creating Test Files
4
+
5
+ Use `src/helpers/tests/extendedTest.ts` which uses Vitest by default. Import all test requirements from it and write your tests.
6
+
7
+ ### Running Tests
8
+
9
+ **Run all tests:**
10
+
11
+ ```bash
12
+ npm test
13
+ ```
14
+
15
+ **Run with UI (live test reports):**
16
+
17
+ ```bash
18
+ npx vitest --ui
19
+ ```
20
+
21
+ **Run tests from a specific file:**
22
+
23
+ ```bash
24
+ npx vitest --ui path/to/test.spec.ts
25
+ ```
26
+
27
+ ### Useful Flags
28
+
29
+ **`-t` flag** - Filter tests by name
30
+
31
+ - Run only tests that match a specific description
32
+ - Also available as `--testNamePattern`
33
+
34
+ ```bash
35
+ npx vitest -t "test description"
36
+ ```
37
+
38
+ **Combine with UI:**
39
+
40
+ ```bash
41
+ npx vitest --ui -t "test description"
42
+ ```
@@ -0,0 +1,13 @@
1
+ ## Setting Up the TypeScript SDK and Runtime
2
+
3
+ First, ensure you have Node.js and Yarn installed on your system, then run `yarn install` to set up the project dependencies.
4
+
5
+ During development, you'll need to create a symlink to use your local version of `@intuned/runtime`.
6
+
7
+ To set up the symlink:
8
+
9
+ 1. Navigate to `webApp/apps/typescript-runtime` and run `yarn build` after `yarn install` to build the runtime
10
+ 2. In the same directory, run `yarn link`
11
+ 3. Navigate to `webApp/apps/typescript-sdk` and run `yarn link "@intuned/runtime"`
12
+
13
+ Note: Whenever you make changes to the runtime code, remember to run `yarn build` in the runtime directory for the changes to reflect in the SDK.
package/package.json ADDED
@@ -0,0 +1,124 @@
1
+ {
2
+ "name": "@intuned/browser-dev",
3
+ "version": "0.1.4-dev.0",
4
+ "description": "runner package for intuned functions",
5
+ "types": "./dist/index.d.ts",
6
+ "typesVersions": {
7
+ "*": {
8
+ "optimized-extractors": [
9
+ "./dist/optimized-extractors/index.d.ts"
10
+ ],
11
+ "ai": [
12
+ "./dist/ai/index.d.ts"
13
+ ]
14
+ }
15
+ },
16
+ "exports": {
17
+ ".": "./dist/index.js",
18
+ "./optimized-extractors": "./dist/optimized-extractors/index.js",
19
+ "./ai": "./dist/ai/index.js",
20
+ "./playwright": "./dist/playwright/index.js",
21
+ "./dist/common/settingsSchema": "./dist/common/settingsSchema.js",
22
+ "./dist/common/getPlaywrightConstructs": "./dist/common/getPlaywrightConstructs.js",
23
+ "./dist/common/contextStorageStateHelpers": "./dist/common/contextStorageStateHelpers.js",
24
+ "./dist/common/types": "./dist/common/types.js",
25
+ "./dist/common/requestMoreInfo": "./dist/common/requestMoreInfo.js",
26
+ "./dist/common/telemetry": "./dist/common/telemetry.js",
27
+ "./dist/common/jwtTokenManager": "./dist/common/jwtTokenManager.js",
28
+ "./dist/common/asyncLocalStorage": "./dist/common/asyncLocalStorage/index.js",
29
+ "./dist/common/cleanEnvironmentVariables": "./dist/common/cleanEnvironmentVariables.js",
30
+ "./dist/commands/common/getFirstLineNumber": "./dist/commands/common/getFirstLineNumber.js",
31
+ "./dist/commands/common/constants": "./dist/commands/common/constants.js",
32
+ "./dist/files/FileUploadAndDownload/utils": "./dist/files/FileUploadAndDownload/utils.js",
33
+ "./dist/ai/index.d.ts": "./dist/ai/index.d.ts"
34
+ },
35
+ "author": "Intuned Team",
36
+ "license": "Elastic-2.0",
37
+ "scripts": {
38
+ "generate-browser-script": "bash scripts/generate-browser-script.sh",
39
+ "prepare": "bash scripts/generate-browser-script.sh || echo 'Skipping browser script generation'",
40
+ "build": "rm -rf dist && yarn generate-browser-script && tsc -p tsconfig.json && yarn copy-dts && babel src --out-dir dist --extensions '.ts' && node scripts/ensure-index-types.js",
41
+ "ensure-types": "node scripts/ensure-index-types.js",
42
+ "test": "vitest run",
43
+ "test:dev": "vitest",
44
+ "test:watch": "vitest",
45
+ "clean-declarations": "find ./types-package -name \"*.d.ts\" -type f -delete",
46
+ "lint": "eslint .",
47
+ "fix": "eslint . --fix",
48
+ "generate-docs": "npx tsx ./scripts/generate-docs.ts",
49
+ "generate-all-docs": "npx tsx ./scripts/generate-docs.ts ./src/helpers/export.d.ts ./generated-docs/helpers && npx tsx ./scripts/generate-docs.ts ./src/ai/export.d.ts ./generated-docs/ai && npx tsx ./scripts/generate-docs.ts ./src/optimized-extractors/export.d.ts ./generated-docs/optimized-extractors",
50
+ "build-browser-scripts": "rollup -c ./src/common/browserScripts/rollup.config.mjs",
51
+ "copy-dts": "copyfiles -u 1 \"src/**/*.d.ts\" dist"
52
+ },
53
+ "dependencies": {
54
+ "@ai-sdk/anthropic": "2.0.1",
55
+ "@ai-sdk/google": "1.0.12",
56
+ "@ai-sdk/openai": "2.0.4",
57
+ "@ai-sdk/provider": "2.0.0",
58
+ "@anthropic-ai/sdk": "0.22.0",
59
+ "@aws-sdk/client-s3": "3.821.0",
60
+ "@aws-sdk/s3-request-presigner": "3.821.0",
61
+ "ai": "5.0.15",
62
+ "ajv": "8.13.0",
63
+ "ajv-formats": "2.1.1",
64
+ "async-mutex": "0.5.0",
65
+ "async-retry": "1.3.3",
66
+ "chalk": "4.1.2",
67
+ "chrono-node": "2.8.3",
68
+ "copyfiles": "2.4.1",
69
+ "date-fns": "4.1.0",
70
+ "dotenv": "^16.3.1",
71
+ "fs-extra": "11.1.1",
72
+ "image-size": "1.1.1",
73
+ "lodash": "4.17.21",
74
+ "neverthrow": "6.1.0",
75
+ "node-html-parser": "7.0.1",
76
+ "openai": "4.77.3",
77
+ "stack-utils": "2.0.6",
78
+ "tslib": "2.6.0",
79
+ "zod": "^3.25.76",
80
+ "zod-to-json-schema": "^3.24.6",
81
+ "zod-validation-error": "3.0.3"
82
+ },
83
+ "devDependencies": {
84
+ "@babel/cli": "^7.23.4",
85
+ "@babel/core": "^7.23.7",
86
+ "@babel/plugin-transform-export-namespace-from": "^7.24.1",
87
+ "@babel/preset-env": "^7.23.7",
88
+ "@babel/preset-typescript": "^7.23.3",
89
+ "@rollup/plugin-commonjs": "^25.0.2",
90
+ "@rollup/plugin-node-resolve": "15.1.0",
91
+ "@rollup/plugin-typescript": "11.1.2",
92
+ "@types/async-retry": "1.4.8",
93
+ "@types/fs-extra": "11.0.1",
94
+ "@types/jest": "^30.0.0",
95
+ "@types/lodash": "4.14.200",
96
+ "@types/node": "^24.1.0",
97
+ "@typescript-eslint/eslint-plugin": "^5.47.1",
98
+ "@typescript-eslint/parser": "^7.5.0",
99
+ "@vitest/ui": "^1.1.3",
100
+ "babel-plugin-macros": "^3.1.0",
101
+ "doctrine": "^3.0.0",
102
+ "eslint": "7.32.0",
103
+ "eslint-plugin-deprecation": "^1.3.3",
104
+ "eslint-plugin-prettier": "^4.2.1",
105
+ "jest": "^30.0.4",
106
+ "msw": "^2.1.2",
107
+ "playwright": "^1.55.0",
108
+ "prettier": "^2.8.8",
109
+ "rollup": "3.26.2",
110
+ "ts-jest": "^29.4.0",
111
+ "typescript": "5.4.4",
112
+ "vite": "^5.4.12",
113
+ "vite-plugin-babel-macros": "^1.0.6",
114
+ "vitest": "^1.1.3"
115
+ },
116
+ "peerDependencies": {
117
+ "@intuned/runtime": "*"
118
+ },
119
+ "peerDependenciesMeta": {
120
+ "@intuned/runtime": {
121
+ "optional": true
122
+ }
123
+ }
124
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "include": ["**/*.ts", "**/*.d.ts"],
4
+ "exclude": ["node_modules"]
5
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es2021",
4
+ "module": "esnext",
5
+ "esModuleInterop": true,
6
+ "moduleResolution": "bundler",
7
+ "resolveJsonModule": true,
8
+ "outDir": "./dist",
9
+ "strict": false,
10
+ "strictNullChecks": true,
11
+ "rootDir": "./src",
12
+ "sourceMap": false,
13
+ "declaration": false,
14
+ "emitDeclarationOnly": false,
15
+ "skipLibCheck": true
16
+ },
17
+ "include": [
18
+ "src/**/*.ts",
19
+ "src/**/*.d.ts",
20
+ "src/assets/**/*",
21
+ "types-package/noEmpty.ts",
22
+ "types-package/**/*.ts",
23
+ "types-package/**/*.d.ts"
24
+ ],
25
+ "exclude": ["node_modules", "**/*.test.ts", "**/__tests__/*"]
26
+ }