@intuned/browser-dev 2.2.3-test-build.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 (206) 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/export.d.js +5 -0
  6. package/dist/ai/export.d.ts +641 -0
  7. package/dist/ai/extractStructuredData.js +320 -0
  8. package/dist/ai/extractStructuredDataUsingAi.js +139 -0
  9. package/dist/ai/extractionHelpers/screenshotHelpers.js +56 -0
  10. package/dist/ai/extractionHelpers/validateSchema.js +148 -0
  11. package/dist/ai/index.d.ts +641 -0
  12. package/dist/ai/index.js +19 -0
  13. package/dist/ai/isPageLoaded.js +77 -0
  14. package/dist/ai/prompt.js +39 -0
  15. package/dist/ai/tests/testCheckAllTypesAreStrings.spec.js +137 -0
  16. package/dist/ai/tests/testExtractFromContent.spec.js +372 -0
  17. package/dist/ai/tests/testExtractStructuredData.spec.js +646 -0
  18. package/dist/ai/tests/testIsPageLoaded.spec.js +277 -0
  19. package/dist/ai/tools/index.js +48 -0
  20. package/dist/ai/types/errors.js +67 -0
  21. package/dist/ai/types/models.js +45 -0
  22. package/dist/ai/types/types.js +48 -0
  23. package/dist/ai/validators.js +167 -0
  24. package/dist/common/Logger/index.js +60 -0
  25. package/dist/common/Logger/types.js +5 -0
  26. package/dist/common/SdkError.js +50 -0
  27. package/dist/common/aiModelsValidations.js +32 -0
  28. package/dist/common/browser_scripts.js +2596 -0
  29. package/dist/common/ensureBrowserScripts.js +18 -0
  30. package/dist/common/extendedTest.js +148 -0
  31. package/dist/common/extractionHelpers.js +19 -0
  32. package/dist/common/formatZodError.js +18 -0
  33. package/dist/common/fuzzySearch/fuzzySearch.test.js +250 -0
  34. package/dist/common/fuzzySearch/levenshtein-search.js +298 -0
  35. package/dist/common/fuzzySearch/utils.js +23 -0
  36. package/dist/common/getModelProvider.js +18 -0
  37. package/dist/common/getSimplifiedHtml.js +122 -0
  38. package/dist/common/hashObject.js +32 -0
  39. package/dist/common/html2markdown/convertElementToMarkdown.js +469 -0
  40. package/dist/common/html2markdown/index.js +19 -0
  41. package/dist/common/jwtTokenManager.js +18 -0
  42. package/dist/common/loadRuntime.js +16 -0
  43. package/dist/common/locatorHelpers.js +41 -0
  44. package/dist/common/matching/collectStrings.js +32 -0
  45. package/dist/common/matching/levenshtein.js +40 -0
  46. package/dist/common/matching/matching.js +317 -0
  47. package/dist/common/matching/types.js +1 -0
  48. package/dist/common/noEmpty.js +9 -0
  49. package/dist/common/saveSnapshotWithExamples.js +60 -0
  50. package/dist/common/tests/testEnsureBrowserScript.spec.js +31 -0
  51. package/dist/common/xpathMapping.js +107 -0
  52. package/dist/helpers/clickUntilExhausted.js +85 -0
  53. package/dist/helpers/downloadFile.js +125 -0
  54. package/dist/helpers/export.d.js +5 -0
  55. package/dist/helpers/export.d.ts +1220 -0
  56. package/dist/helpers/extractMarkdown.js +35 -0
  57. package/dist/helpers/filterEmptyValues.js +54 -0
  58. package/dist/helpers/gotoUrl.js +98 -0
  59. package/dist/helpers/index.d.ts +1220 -0
  60. package/dist/helpers/index.js +128 -0
  61. package/dist/helpers/processDate.js +25 -0
  62. package/dist/helpers/resolveUrl.js +64 -0
  63. package/dist/helpers/sanitizeHtml.js +74 -0
  64. package/dist/helpers/saveFileToS3.js +50 -0
  65. package/dist/helpers/scrollToLoadContent.js +57 -0
  66. package/dist/helpers/tests/extendedTest.js +130 -0
  67. package/dist/helpers/tests/testClickUntilExhausted.spec.js +387 -0
  68. package/dist/helpers/tests/testDownloadFile.spec.js +204 -0
  69. package/dist/helpers/tests/testExtractMarkdown.spec.js +290 -0
  70. package/dist/helpers/tests/testFilterEmptyValues.spec.js +151 -0
  71. package/dist/helpers/tests/testGoToUrl.spec.js +37 -0
  72. package/dist/helpers/tests/testProcessDate.spec.js +13 -0
  73. package/dist/helpers/tests/testResolveUrl.spec.js +341 -0
  74. package/dist/helpers/tests/testSanitizeHtml.spec.js +330 -0
  75. package/dist/helpers/tests/testScrollToLoadContent.spec.js +163 -0
  76. package/dist/helpers/tests/testValidateDataUsingSchema.spec.js +342 -0
  77. package/dist/helpers/tests/testWithDomSettledWait.spec.js +164 -0
  78. package/dist/helpers/tests/testWithNetworkIdleWait.spec.js +114 -0
  79. package/dist/helpers/types/Attachment.js +115 -0
  80. package/dist/helpers/types/CustomTypeRegistry.js +48 -0
  81. package/dist/helpers/types/RunEnvironment.js +18 -0
  82. package/dist/helpers/types/ValidationError.js +17 -0
  83. package/dist/helpers/types/index.js +51 -0
  84. package/dist/helpers/uploadFileToS3.js +154 -0
  85. package/dist/helpers/utils/getS3Client.js +22 -0
  86. package/dist/helpers/utils/index.js +73 -0
  87. package/dist/helpers/utils/isDownload.js +10 -0
  88. package/dist/helpers/utils/isGenerateCodeMode.js +9 -0
  89. package/dist/helpers/utils/isLocator.js +9 -0
  90. package/dist/helpers/utils/jwtTokenManager.js +18 -0
  91. package/dist/helpers/validateDataUsingSchema.js +103 -0
  92. package/dist/helpers/waitForDomSettled.js +90 -0
  93. package/dist/helpers/withNetworkSettledWait.js +91 -0
  94. package/dist/index.d.js +16 -0
  95. package/dist/index.d.ts +10 -0
  96. package/dist/index.js +16 -0
  97. package/dist/intunedServices/ApiGateway/aiApiGateway.js +99 -0
  98. package/dist/intunedServices/ApiGateway/factory.js +13 -0
  99. package/dist/intunedServices/ApiGateway/providers/Anthropic.js +26 -0
  100. package/dist/intunedServices/ApiGateway/providers/Gemini.js +29 -0
  101. package/dist/intunedServices/ApiGateway/providers/OpenAI.js +29 -0
  102. package/dist/intunedServices/ApiGateway/tests/testApiGateway.spec.js +224 -0
  103. package/dist/intunedServices/ApiGateway/types.js +11 -0
  104. package/dist/intunedServices/cache/cache.js +61 -0
  105. package/dist/intunedServices/cache/index.js +12 -0
  106. package/dist/intunedServices/cache/tests/testCache.spec.js +117 -0
  107. package/dist/optimized-extractors/common/buildExamplesPrompt.js +12 -0
  108. package/dist/optimized-extractors/common/buildImagesFromPage.js +55 -0
  109. package/dist/optimized-extractors/common/extractStructuredDataUsingClaude.js +135 -0
  110. package/dist/optimized-extractors/common/extractStructuredDataUsingGoogle.js +37 -0
  111. package/dist/optimized-extractors/common/extractStructuredDataUsingOpenAi.js +132 -0
  112. package/dist/optimized-extractors/common/extractStrucutredDataUsingAiInstance.js +122 -0
  113. package/dist/optimized-extractors/common/findTableHeaders.js +162 -0
  114. package/dist/optimized-extractors/common/index.js +55 -0
  115. package/dist/optimized-extractors/common/isTableHeaderOrFooter.js +84 -0
  116. package/dist/optimized-extractors/common/matching/matching.js +212 -0
  117. package/dist/optimized-extractors/common/matching/matching.test.js +655 -0
  118. package/dist/optimized-extractors/common/matching/types.js +18 -0
  119. package/dist/optimized-extractors/common/matching/utils.js +184 -0
  120. package/dist/optimized-extractors/common/utils.js +58 -0
  121. package/dist/optimized-extractors/export.d.js +5 -0
  122. package/dist/optimized-extractors/export.d.ts +397 -0
  123. package/dist/optimized-extractors/extractArray.js +120 -0
  124. package/dist/optimized-extractors/extractObject.js +104 -0
  125. package/dist/optimized-extractors/index.d.ts +397 -0
  126. package/dist/optimized-extractors/index.js +31 -0
  127. package/dist/optimized-extractors/listExtractionHelpers/__tests__/dynamicListExtractor.spec.js +312 -0
  128. package/dist/optimized-extractors/listExtractionHelpers/__tests__/findSetOfXpathsToCreateAnArrayExtractor.test.js +22 -0
  129. package/dist/optimized-extractors/listExtractionHelpers/__tests__/getContainerElement.test.js +21 -0
  130. package/dist/optimized-extractors/listExtractionHelpers/__tests__/partOfSameArrayXpath.test.js +42 -0
  131. package/dist/optimized-extractors/listExtractionHelpers/__tests__/verifyThatAllXpathsArePartOfSameArray.test.js +9 -0
  132. package/dist/optimized-extractors/listExtractionHelpers/dynamicListExtractor.js +152 -0
  133. package/dist/optimized-extractors/listExtractionHelpers/errors.js +46 -0
  134. package/dist/optimized-extractors/listExtractionHelpers/getListMatches.js +14 -0
  135. package/dist/optimized-extractors/listExtractionHelpers/runAiExtraction.js +240 -0
  136. package/dist/optimized-extractors/listExtractionHelpers/typesAndSchema.js +5 -0
  137. package/dist/optimized-extractors/listExtractionHelpers/utils/extractPropertiesUsingGPTFromArray.js +277 -0
  138. package/dist/optimized-extractors/listExtractionHelpers/utils/extractStructuredListUsingAi.js +44 -0
  139. package/dist/optimized-extractors/listExtractionHelpers/utils/getListContainerXpath.js +94 -0
  140. package/dist/optimized-extractors/listExtractionHelpers/utils/getRelativeContainerXpathSelector.js +20 -0
  141. package/dist/optimized-extractors/listExtractionHelpers/utils/getSimplifiedHtmlPerListItem.js +21 -0
  142. package/dist/optimized-extractors/listExtractionHelpers/utils/tablesUtils.js +48 -0
  143. package/dist/optimized-extractors/listExtractionHelpers/utils/validateOptions.js +52 -0
  144. package/dist/optimized-extractors/models/anthropicModel.js +23 -0
  145. package/dist/optimized-extractors/models/openaiModel.js +23 -0
  146. package/dist/optimized-extractors/objectExtractionHelpers/AIExtractors.js +73 -0
  147. package/dist/optimized-extractors/objectExtractionHelpers/__tests__/checksumUtils.test.js +103 -0
  148. package/dist/optimized-extractors/objectExtractionHelpers/__tests__/testObjectExtractorFromLocator.spec.js +107 -0
  149. package/dist/optimized-extractors/objectExtractionHelpers/__tests__/testObjectExtractorFromPage.spec.js +107 -0
  150. package/dist/optimized-extractors/objectExtractionHelpers/calculateObjectExampleHash.js +28 -0
  151. package/dist/optimized-extractors/objectExtractionHelpers/captureSnapshot.js +26 -0
  152. package/dist/optimized-extractors/objectExtractionHelpers/checksumUtils.js +32 -0
  153. package/dist/optimized-extractors/objectExtractionHelpers/constants.js +7 -0
  154. package/dist/optimized-extractors/objectExtractionHelpers/dynamicObjectExtractor.js +106 -0
  155. package/dist/optimized-extractors/objectExtractionHelpers/errors.js +42 -0
  156. package/dist/optimized-extractors/objectExtractionHelpers/findDomMatches.js +54 -0
  157. package/dist/optimized-extractors/objectExtractionHelpers/getSimplifiedHtml.js +122 -0
  158. package/dist/optimized-extractors/objectExtractionHelpers/typesAndSchemas.js +5 -0
  159. package/dist/optimized-extractors/objectExtractionHelpers/validateDynamicObjectExtractorOptions.js +52 -0
  160. package/dist/optimized-extractors/types/aiModelsValidation.js +45 -0
  161. package/dist/optimized-extractors/types/errors.js +42 -0
  162. package/dist/optimized-extractors/types/jsonSchema.d.js +5 -0
  163. package/dist/optimized-extractors/types/jsonSchema.d.ts +50 -0
  164. package/dist/optimized-extractors/types/types.js +5 -0
  165. package/dist/optimized-extractors/validators.js +152 -0
  166. package/dist/vite-env.d.js +1 -0
  167. package/dist/vite-env.d.ts +9 -0
  168. package/docs.md +14 -0
  169. package/generated-docs/ai/functions/extractStructuredData.mdx +255 -0
  170. package/generated-docs/ai/functions/isPageLoaded.mdx +88 -0
  171. package/generated-docs/ai/interfaces/ArraySchema.mdx +36 -0
  172. package/generated-docs/ai/interfaces/BasicSchema.mdx +14 -0
  173. package/generated-docs/ai/interfaces/BooleanSchema.mdx +28 -0
  174. package/generated-docs/ai/interfaces/ImageBufferContentItem.mdx +16 -0
  175. package/generated-docs/ai/interfaces/ImageUrlContentItem.mdx +16 -0
  176. package/generated-docs/ai/interfaces/NumberSchema.mdx +35 -0
  177. package/generated-docs/ai/interfaces/ObjectSchema.mdx +39 -0
  178. package/generated-docs/ai/interfaces/StringSchema.mdx +35 -0
  179. package/generated-docs/ai/interfaces/TextContentItem.mdx +14 -0
  180. package/generated-docs/ai/type-aliases/ContentItem.mdx +12 -0
  181. package/generated-docs/ai/type-aliases/JsonSchema.mdx +47 -0
  182. package/generated-docs/ai/type-aliases/SUPPORTED_MODELS.mdx +85 -0
  183. package/generated-docs/helpers/functions/downloadFile.mdx +99 -0
  184. package/generated-docs/helpers/functions/extractMarkdown.mdx +56 -0
  185. package/generated-docs/helpers/functions/filterEmptyValues.mdx +51 -0
  186. package/generated-docs/helpers/functions/goToUrl.mdx +124 -0
  187. package/generated-docs/helpers/functions/processDate.mdx +55 -0
  188. package/generated-docs/helpers/functions/resolveUrl.mdx +165 -0
  189. package/generated-docs/helpers/functions/sanitizeHtml.mdx +113 -0
  190. package/generated-docs/helpers/functions/saveFileToS3.mdx +127 -0
  191. package/generated-docs/helpers/functions/scrollToLoadContent.mdx +89 -0
  192. package/generated-docs/helpers/functions/uploadFileToS3.mdx +121 -0
  193. package/generated-docs/helpers/functions/validateDataUsingSchema.mdx +90 -0
  194. package/generated-docs/helpers/functions/waitForDomSettled.mdx +91 -0
  195. package/generated-docs/helpers/functions/withNetworkSettledWait.mdx +76 -0
  196. package/generated-docs/helpers/interfaces/Attachment.mdx +56 -0
  197. package/generated-docs/helpers/interfaces/S3Configs.mdx +52 -0
  198. package/generated-docs/helpers/interfaces/SanitizeHtmlOptions.mdx +22 -0
  199. package/generated-docs/helpers/type-aliases/AttachmentType.mdx +10 -0
  200. package/generated-docs/helpers/type-aliases/FileType.mdx +61 -0
  201. package/generated-docs/helpers/type-aliases/Trigger.mdx +62 -0
  202. package/how-to-run-tests.md +10 -0
  203. package/intuned-runtime-setup.md +13 -0
  204. package/package.json +119 -0
  205. package/tsconfig.eslint.json +5 -0
  206. package/tsconfig.json +26 -0
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.SignedUrlAttachmentSchema = exports.SignedUrlAttachment = exports.AttachmentTypeSchema = exports.AttachmentSchema = exports.Attachment = void 0;
7
+ var _clientS = require("@aws-sdk/client-s3");
8
+ var _s3RequestPresigner = require("@aws-sdk/s3-request-presigner");
9
+ var _utils = require("../utils");
10
+ var _getS3Client = require("../utils/getS3Client");
11
+ var _zod = require("zod");
12
+ const AttachmentTypeSchema = exports.AttachmentTypeSchema = _zod.z.literal("document");
13
+ const AttachmentSchema = exports.AttachmentSchema = _zod.z.object({
14
+ fileName: _zod.z.string(),
15
+ bucket: _zod.z.string(),
16
+ region: _zod.z.string(),
17
+ suggestedFileName: _zod.z.string(),
18
+ endpoint: _zod.z.string().optional(),
19
+ fileType: AttachmentTypeSchema.optional()
20
+ });
21
+ class Attachment {
22
+ constructor(fileName, bucket, region, suggestedFileName, endpoint, fileType) {
23
+ const validatedData = AttachmentSchema.parse({
24
+ fileName,
25
+ bucket,
26
+ region,
27
+ suggestedFileName,
28
+ endpoint,
29
+ fileType
30
+ });
31
+ this.fileName = validatedData.fileName;
32
+ this.bucket = validatedData.bucket;
33
+ this.region = validatedData.region;
34
+ this.suggestedFileName = validatedData.suggestedFileName;
35
+ this.endpoint = validatedData.endpoint;
36
+ this.fileType = validatedData.fileType;
37
+ }
38
+ toJSON() {
39
+ return this.toDict();
40
+ }
41
+ toDict() {
42
+ return {
43
+ fileName: this.fileName,
44
+ bucket: this.bucket,
45
+ region: this.region,
46
+ suggestedFileName: this.suggestedFileName,
47
+ ...(this.endpoint ? {
48
+ endpoint: this.endpoint
49
+ } : {}),
50
+ ...(this.fileType ? {
51
+ fileType: this.fileType
52
+ } : {})
53
+ };
54
+ }
55
+ static fromDict(data) {
56
+ const validatedData = AttachmentSchema.parse(data);
57
+ return new Attachment(validatedData.fileName, validatedData.bucket, validatedData.region, validatedData.suggestedFileName, validatedData.endpoint, validatedData.fileType);
58
+ }
59
+ async getSignedUrl(expiration = 3600 * 24 * 5) {
60
+ if ((0, _utils.isGenerateCodeMode)()) {
61
+ return "https://not.real.com";
62
+ }
63
+ const s3Client = (0, _getS3Client.getS3Client)(this.endpoint, this.region);
64
+ try {
65
+ const response = await (0, _s3RequestPresigner.getSignedUrl)(s3Client, new _clientS.GetObjectCommand({
66
+ Bucket: this.bucket,
67
+ Key: this.fileName
68
+ }), {
69
+ expiresIn: expiration
70
+ });
71
+ return response;
72
+ } catch (error) {
73
+ console.log(error);
74
+ throw new Error("Error generating signed URL");
75
+ }
76
+ }
77
+ getS3Key() {
78
+ return `https://${this.bucket}.s3.${this.region}.amazonaws.com/${this.fileName}`;
79
+ }
80
+ getFilePath() {
81
+ return this.fileName;
82
+ }
83
+ getFileType() {
84
+ return this.fileType || "";
85
+ }
86
+ }
87
+ exports.Attachment = Attachment;
88
+ const SignedUrlAttachmentSchema = exports.SignedUrlAttachmentSchema = AttachmentSchema.extend({
89
+ downloadSignedUrl: _zod.z.string().url()
90
+ });
91
+ class SignedUrlAttachment extends Attachment {
92
+ constructor(fileName, downloadSignedUrl, suggestedFileName) {
93
+ const url = new URL(downloadSignedUrl);
94
+ const bucket = url.hostname.split(".")[0];
95
+ const key = url.pathname.substring(1);
96
+ const validatedUrl = _zod.z.string().url().parse(downloadSignedUrl);
97
+ super(key, bucket, "", suggestedFileName ?? fileName);
98
+ this.downloadSignedUrl = validatedUrl;
99
+ }
100
+ async getSignedUrl() {
101
+ return this.downloadSignedUrl;
102
+ }
103
+ toDict() {
104
+ return {
105
+ ...super.toDict(),
106
+ downloadSignedUrl: this.downloadSignedUrl
107
+ };
108
+ }
109
+ static fromDict(data) {
110
+ const validatedData = SignedUrlAttachmentSchema.parse(data);
111
+ const attachment = new SignedUrlAttachment(validatedData.fileName, validatedData.downloadSignedUrl, validatedData.suggestedFileName);
112
+ return attachment;
113
+ }
114
+ }
115
+ exports.SignedUrlAttachment = SignedUrlAttachment;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.CustomTypeRegistry = exports.AttachmentValidator = void 0;
7
+ class AttachmentValidator {
8
+ validate(data) {
9
+ if (!data || typeof data !== "object") {
10
+ return false;
11
+ }
12
+ const requiredFields = ["fileName", "bucket", "region", "suggestedFileName"];
13
+ return requiredFields.every(field => field in data && typeof data[field] === "string" && data[field].length > 0);
14
+ }
15
+ getName() {
16
+ return "attachment";
17
+ }
18
+ }
19
+ exports.AttachmentValidator = AttachmentValidator;
20
+ class CustomTypeRegistry {
21
+ registry = new Map();
22
+ constructor(registerIntunedTypes = true) {
23
+ if (registerIntunedTypes) {
24
+ this.registerIntunedTypes();
25
+ }
26
+ }
27
+ registerIntunedTypes() {
28
+ this.register(new AttachmentValidator());
29
+ }
30
+ register(validator) {
31
+ const typeName = validator.getName().toLowerCase();
32
+ this.registry.set(typeName, validator);
33
+ }
34
+ get(typeName) {
35
+ return this.registry.get(typeName.toLowerCase());
36
+ }
37
+ isCustomType(typeName) {
38
+ return this.registry.has(typeName.toLowerCase());
39
+ }
40
+ validate(typeName, data) {
41
+ const validator = this.get(typeName);
42
+ return validator ? validator.validate(data) : false;
43
+ }
44
+ getAllTypes() {
45
+ return Array.from(this.registry.keys());
46
+ }
47
+ }
48
+ exports.CustomTypeRegistry = CustomTypeRegistry;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.RunType = exports.RunEnvironment = void 0;
7
+ let RunEnvironment = exports.RunEnvironment = function (RunEnvironment) {
8
+ RunEnvironment["IDE"] = "IDE";
9
+ RunEnvironment["DEPLOYED"] = "DEPLOYED";
10
+ return RunEnvironment;
11
+ }({});
12
+ let RunType = exports.RunType = function (RunType) {
13
+ RunType["SYNC"] = "SYNC";
14
+ RunType["ASYNC"] = "ASYNC";
15
+ RunType["JOB"] = "JOB";
16
+ RunType["QUEUE"] = "QUEUE";
17
+ return RunType;
18
+ }({});
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ValidationError = void 0;
7
+ class ValidationError extends Error {
8
+ constructor(message, data) {
9
+ super(message);
10
+ this.name = "ValidationError";
11
+ this.data = data;
12
+ if (Error.captureStackTrace) {
13
+ Error.captureStackTrace(this, ValidationError);
14
+ }
15
+ }
16
+ }
17
+ exports.ValidationError = ValidationError;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "Attachment", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _Attachment.Attachment;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "AttachmentValidator", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _CustomTypeRegistry.AttachmentValidator;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "CustomTypeRegistry", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _CustomTypeRegistry.CustomTypeRegistry;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "CustomTypeValidator", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _CustomTypeRegistry.CustomTypeValidator;
28
+ }
29
+ });
30
+ Object.defineProperty(exports, "RunEnvironment", {
31
+ enumerable: true,
32
+ get: function () {
33
+ return _RunEnvironment.RunEnvironment;
34
+ }
35
+ });
36
+ Object.defineProperty(exports, "RunType", {
37
+ enumerable: true,
38
+ get: function () {
39
+ return _RunEnvironment.RunType;
40
+ }
41
+ });
42
+ Object.defineProperty(exports, "ValidationError", {
43
+ enumerable: true,
44
+ get: function () {
45
+ return _ValidationError.ValidationError;
46
+ }
47
+ });
48
+ var _ValidationError = require("./ValidationError");
49
+ var _RunEnvironment = require("./RunEnvironment");
50
+ var _Attachment = require("./Attachment");
51
+ var _CustomTypeRegistry = require("./CustomTypeRegistry");
@@ -0,0 +1,154 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.uploadFileToS3 = void 0;
7
+ var _fsExtra = require("fs-extra");
8
+ var _clientS = require("@aws-sdk/client-s3");
9
+ var _Attachment = require("../helpers/types/Attachment");
10
+ var _uuid = require("uuid");
11
+ var _utils = require("./utils");
12
+ var _fs = _interopRequireDefault(require("fs"));
13
+ var _jwtTokenManager = require("../common/jwtTokenManager");
14
+ var _zod = _interopRequireDefault(require("zod"));
15
+ var _nodeFetch = _interopRequireDefault(require("node-fetch"));
16
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
17
+ function sanitizeKey(key) {
18
+ let result = key.replace(/[^a-zA-Z0-9.\-_/]/g, "_");
19
+ result = result.replace(/_{2,}/g, "_");
20
+ return result;
21
+ }
22
+ const stringToJSONSchema = _zod.default.string().transform((str, ctx) => {
23
+ try {
24
+ return JSON.parse(str);
25
+ } catch (e) {
26
+ ctx.addIssue({
27
+ code: "custom",
28
+ message: "Invalid JSON"
29
+ });
30
+ return _zod.default.NEVER;
31
+ }
32
+ });
33
+ const getUploadSignedUrlResponseSchema = stringToJSONSchema.pipe(_zod.default.object({
34
+ id: _zod.default.string().uuid(),
35
+ writeSignedUrl: _zod.default.string().url(),
36
+ readSignedUrl: _zod.default.string().url()
37
+ }));
38
+ const uploadFileToS3 = async input => {
39
+ const {
40
+ file,
41
+ configs,
42
+ fileNameOverride,
43
+ contentType
44
+ } = input;
45
+ const bucketName = (configs === null || configs === void 0 ? void 0 : configs.bucket) ?? process.env.AWS_BUCKET ?? process.env.INTUNED_S3_BUCKET ?? undefined;
46
+ const region = (configs === null || configs === void 0 ? void 0 : configs.region) ?? process.env.AWS_REGION ?? process.env.INTUNED_S3_REGION ?? undefined;
47
+ const endpoint = (configs === null || configs === void 0 ? void 0 : configs.endpoint) ?? process.env.AWS_ENDPOINT_URL ?? process.env.INTUNED_S3_ENDPOINT_URL;
48
+ const accessKeyId = (configs === null || configs === void 0 ? void 0 : configs.accessKeyId) ?? process.env.AWS_ACCESS_KEY_ID ?? process.env.INTUNED_S3_ACCESS_KEY_ID;
49
+ const secretAccessKey = (configs === null || configs === void 0 ? void 0 : configs.secretAccessKey) ?? process.env.AWS_SECRET_ACCESS_KEY ?? process.env.INTUNED_S3_SECRET_ACCESS_KEY;
50
+ const isDownloadedFile = (0, _utils.isDownload)(file);
51
+ if ((0, _utils.isGenerateCodeMode)()) {
52
+ console.log("Uploaded file successfully");
53
+ if (isDownloadedFile) {
54
+ return new _Attachment.Attachment(`${(0, _uuid.v4)()}/${file.suggestedFilename()}`, "testing_bucket", "testing_region", file.suggestedFilename() || "downloaded_file", endpoint, "document");
55
+ }
56
+ }
57
+ let suggestedFileName;
58
+ if (isDownloadedFile) {
59
+ suggestedFileName = file.suggestedFilename();
60
+ }
61
+ const fileName = fileNameOverride ?? suggestedFileName ?? (0, _uuid.v4)();
62
+ const fileBody = await getFileBody(file);
63
+ if (!region || !bucketName) {
64
+ return await uploadToIntuned({
65
+ name: fileName,
66
+ suggestedName: suggestedFileName || fileName,
67
+ body: fileBody
68
+ });
69
+ }
70
+ if (isDownloadedFile && !(0, _utils.isGenerateCodeMode)() && !(await file.path())) {
71
+ throw new Error("File path not found");
72
+ }
73
+ let credentials = undefined;
74
+ if (accessKeyId && secretAccessKey) {
75
+ credentials = {
76
+ accessKeyId,
77
+ secretAccessKey
78
+ };
79
+ }
80
+ const s3Client = new _clientS.S3Client({
81
+ region,
82
+ endpoint,
83
+ credentials
84
+ });
85
+ try {
86
+ const cleanedFileName = sanitizeKey(fileName);
87
+ const key = `${(0, _uuid.v4)()}/${cleanedFileName}`;
88
+ const command = new _clientS.PutObjectCommand({
89
+ Bucket: bucketName,
90
+ Key: key,
91
+ Body: fileBody,
92
+ ContentType: contentType
93
+ });
94
+ const response = await s3Client.send(command);
95
+ if (response.$metadata.httpStatusCode === 200) {
96
+ return new _Attachment.Attachment(key, bucketName, region, suggestedFileName || fileName, endpoint);
97
+ } else {
98
+ throw new Error("Error uploading file");
99
+ }
100
+ } catch (error) {
101
+ if (error instanceof Error && error.message.includes("Credentials")) {
102
+ throw new Error("Credentials not available");
103
+ }
104
+ throw new Error(`Error uploading file: ${error instanceof Error ? error.message : String(error)}`);
105
+ } finally {
106
+ if (isDownloadedFile) {
107
+ var _file$delete;
108
+ await ((_file$delete = file.delete) === null || _file$delete === void 0 ? void 0 : _file$delete.call(file));
109
+ }
110
+ if (typeof file === "string") {
111
+ try {
112
+ _fs.default.unlinkSync(file);
113
+ } catch (e) {}
114
+ }
115
+ }
116
+ };
117
+ exports.uploadFileToS3 = uploadFileToS3;
118
+ async function getFileBody(file) {
119
+ if ((0, _utils.isDownload)(file)) {
120
+ const filePath = await file.path();
121
+ if (!filePath) {
122
+ throw new Error("Downloaded file path not found");
123
+ }
124
+ return (0, _fsExtra.readFile)(filePath);
125
+ } else if (Buffer.isBuffer(file)) {
126
+ return file;
127
+ } else {
128
+ throw new Error("Invalid file type");
129
+ }
130
+ }
131
+ async function uploadToIntuned({
132
+ name,
133
+ suggestedName,
134
+ body
135
+ }) {
136
+ const uploadInfoResponse = await (0, _jwtTokenManager.callBackendFunctionWithToken)("files/uploadSignedUrls");
137
+ if (!uploadInfoResponse.ok) {
138
+ throw new Error(`Failed to get upload signed URL: ${uploadInfoResponse.statusText}`);
139
+ }
140
+ const uploadInfoText = await uploadInfoResponse.text();
141
+ const uploadInfo = getUploadSignedUrlResponseSchema.parse(uploadInfoText);
142
+ const uploadResponse = await (0, _nodeFetch.default)(uploadInfo.writeSignedUrl, {
143
+ method: "PUT",
144
+ body: await getFileBody(body),
145
+ headers: {
146
+ "Content-Type": "application/octet-stream"
147
+ }
148
+ });
149
+ const uploadResponseText = await uploadResponse.text();
150
+ if (!uploadResponse.ok) {
151
+ throw new Error(`Failed to upload file: ${uploadResponse.status} - ${uploadResponseText}`);
152
+ }
153
+ return new _Attachment.SignedUrlAttachment(name, uploadInfo.readSignedUrl, suggestedName);
154
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getS3Client = getS3Client;
7
+ var _clientS = require("@aws-sdk/client-s3");
8
+ function getS3Client(endpoint, region) {
9
+ let s3ClientInstance = null;
10
+ if (!s3ClientInstance) {
11
+ const resolvedRegion = region || process.env.AWS_REGION || process.env.INTUNED_S3_REGION;
12
+ s3ClientInstance = new _clientS.S3Client({
13
+ region: resolvedRegion,
14
+ credentials: {
15
+ accessKeyId: process.env.AWS_ACCESS_KEY_ID || "",
16
+ secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY || ""
17
+ },
18
+ endpoint: endpoint || undefined
19
+ });
20
+ }
21
+ return s3ClientInstance;
22
+ }
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "GatewayFactory", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _factory.GatewayFactory;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "compressStringSpaces", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _extractionHelpers.compressStringSpaces;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "ensureBrowserScripts", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _ensureBrowserScripts.ensureBrowserScripts;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "getS3Client", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _getS3Client.getS3Client;
28
+ }
29
+ });
30
+ Object.defineProperty(exports, "getSimplifiedHtml", {
31
+ enumerable: true,
32
+ get: function () {
33
+ return _getSimplifiedHtml.getSimplifiedHtml;
34
+ }
35
+ });
36
+ Object.defineProperty(exports, "isDownload", {
37
+ enumerable: true,
38
+ get: function () {
39
+ return _isDownload.isDownload;
40
+ }
41
+ });
42
+ Object.defineProperty(exports, "isGenerateCodeMode", {
43
+ enumerable: true,
44
+ get: function () {
45
+ return _isGenerateCodeMode.isGenerateCodeMode;
46
+ }
47
+ });
48
+ Object.defineProperty(exports, "isLocator", {
49
+ enumerable: true,
50
+ get: function () {
51
+ return _isLocator.isLocator;
52
+ }
53
+ });
54
+ Object.defineProperty(exports, "selectLocatorsUsingXpath", {
55
+ enumerable: true,
56
+ get: function () {
57
+ return _extractionHelpers.selectLocatorsUsingXpath;
58
+ }
59
+ });
60
+ Object.defineProperty(exports, "splitContainerIntoListLocators", {
61
+ enumerable: true,
62
+ get: function () {
63
+ return _extractionHelpers.splitContainerIntoListLocators;
64
+ }
65
+ });
66
+ var _isLocator = require("./isLocator");
67
+ var _isGenerateCodeMode = require("./isGenerateCodeMode");
68
+ var _factory = require("../../intunedServices/ApiGateway/factory");
69
+ var _getS3Client = require("./getS3Client");
70
+ var _isDownload = require("./isDownload");
71
+ var _ensureBrowserScripts = require("../../common/ensureBrowserScripts");
72
+ var _extractionHelpers = require("../../common/extractionHelpers");
73
+ var _getSimplifiedHtml = require("../../common/getSimplifiedHtml");
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isDownload = isDownload;
7
+ function isDownload(value) {
8
+ const anyValue = value;
9
+ return anyValue && typeof anyValue.delete === "function" && typeof anyValue.path === "function" && typeof anyValue.suggestedFilename === "function";
10
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isGenerateCodeMode = isGenerateCodeMode;
7
+ function isGenerateCodeMode() {
8
+ return process.env.MODE === "generate_code";
9
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isLocator = isLocator;
7
+ function isLocator(locator) {
8
+ return "count" in locator && typeof locator.count === "function";
9
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "backendFunctionsTokenManager", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _jwtTokenManager.backendFunctionsTokenManager;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "callBackendFunctionWithToken", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _jwtTokenManager.callBackendFunctionWithToken;
16
+ }
17
+ });
18
+ var _jwtTokenManager = require("@intuned/runtime/dist/common/jwtTokenManager");
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.validateDataUsingSchema = void 0;
7
+ var _ajv = _interopRequireDefault(require("ajv"));
8
+ var _types = require("./types");
9
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
+ const ajv = new _ajv.default({
11
+ strict: false,
12
+ removeAdditional: false
13
+ });
14
+ ajv.addKeyword({
15
+ keyword: "x-custom-type",
16
+ schemaType: "string",
17
+ compile: () => () => true
18
+ });
19
+ const customTypeRegistry = new _types.CustomTypeRegistry();
20
+ function preprocessSchema(schema) {
21
+ if (typeof schema !== "object" || schema === null) {
22
+ return schema;
23
+ }
24
+ if (Array.isArray(schema)) {
25
+ return schema.map(item => preprocessSchema(item));
26
+ }
27
+ const processedSchema = {
28
+ ...schema
29
+ };
30
+ if (processedSchema.type && typeof processedSchema.type === "string") {
31
+ if (customTypeRegistry.isCustomType(processedSchema.type)) {
32
+ return {
33
+ type: "object",
34
+ additionalProperties: true,
35
+ "x-custom-type": processedSchema.type
36
+ };
37
+ }
38
+ }
39
+ for (const key in processedSchema) {
40
+ if (key === "properties" && typeof processedSchema[key] === "object") {
41
+ const newProperties = {};
42
+ for (const propKey in processedSchema[key]) {
43
+ newProperties[propKey] = preprocessSchema(processedSchema[key][propKey]);
44
+ }
45
+ processedSchema[key] = newProperties;
46
+ } else if (key === "items") {
47
+ processedSchema[key] = preprocessSchema(processedSchema[key]);
48
+ } else if (typeof processedSchema[key] === "object") {
49
+ processedSchema[key] = preprocessSchema(processedSchema[key]);
50
+ }
51
+ }
52
+ return processedSchema;
53
+ }
54
+ function validateCustomTypes(data, schema, path = "root") {
55
+ const errors = [];
56
+ if (typeof schema !== "object" || schema === null) {
57
+ return errors;
58
+ }
59
+ if (schema["x-custom-type"]) {
60
+ const customType = schema["x-custom-type"];
61
+ if (!customTypeRegistry.validate(customType, data)) {
62
+ errors.push(`${path} does not match custom type '${customType}'`);
63
+ }
64
+ return errors;
65
+ }
66
+ if (schema.type === "object" && schema.properties && typeof data === "object" && data !== null && !Array.isArray(data)) {
67
+ for (const [propKey, propSchema] of Object.entries(schema.properties)) {
68
+ if (Object.prototype.hasOwnProperty.call(data, propKey)) {
69
+ const propPath = path === "root" ? propKey : `${path}.${propKey}`;
70
+ errors.push(...validateCustomTypes(data[propKey], propSchema, propPath));
71
+ }
72
+ }
73
+ }
74
+ if (schema.type === "array" && schema.items && Array.isArray(data)) {
75
+ data.forEach((item, index) => {
76
+ const itemPath = `${path}[${index}]`;
77
+ errors.push(...validateCustomTypes(item, schema.items, itemPath));
78
+ });
79
+ }
80
+ return errors;
81
+ }
82
+ const validateDataUsingSchema = async input => {
83
+ const {
84
+ data,
85
+ schema
86
+ } = input;
87
+ const processedSchema = preprocessSchema(schema);
88
+ const validate = ajv.compile(processedSchema);
89
+ const valid = validate(data);
90
+ const errors = [];
91
+ if (!valid) {
92
+ var _validate$errors;
93
+ const schemaErrors = ((_validate$errors = validate.errors) === null || _validate$errors === void 0 ? void 0 : _validate$errors.map(err => `${err.instancePath || "root"} ${err.message}`).filter(error => !error.includes("x-custom-type"))) || [];
94
+ errors.push(...schemaErrors);
95
+ }
96
+ const customTypeErrors = validateCustomTypes(data, processedSchema);
97
+ errors.push(...customTypeErrors);
98
+ if (errors.length > 0) {
99
+ const errorMessage = errors.join(", ") || "Unknown validation error";
100
+ throw new _types.ValidationError(`Data validation failed: ${errorMessage}`, data);
101
+ }
102
+ };
103
+ exports.validateDataUsingSchema = validateDataUsingSchema;