@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.
- package/.babelrc +21 -0
- package/.eslintignore +10 -0
- package/.eslintrc.js +39 -0
- package/LICENSE +43 -0
- package/dist/ai/export.d.js +5 -0
- package/dist/ai/export.d.ts +641 -0
- package/dist/ai/extractStructuredData.js +320 -0
- package/dist/ai/extractStructuredDataUsingAi.js +139 -0
- package/dist/ai/extractionHelpers/screenshotHelpers.js +56 -0
- package/dist/ai/extractionHelpers/validateSchema.js +148 -0
- package/dist/ai/index.d.ts +641 -0
- package/dist/ai/index.js +19 -0
- package/dist/ai/isPageLoaded.js +77 -0
- package/dist/ai/prompt.js +39 -0
- package/dist/ai/tests/testCheckAllTypesAreStrings.spec.js +137 -0
- package/dist/ai/tests/testExtractFromContent.spec.js +372 -0
- package/dist/ai/tests/testExtractStructuredData.spec.js +646 -0
- package/dist/ai/tests/testIsPageLoaded.spec.js +277 -0
- package/dist/ai/tools/index.js +48 -0
- package/dist/ai/types/errors.js +67 -0
- package/dist/ai/types/models.js +45 -0
- package/dist/ai/types/types.js +48 -0
- package/dist/ai/validators.js +167 -0
- package/dist/common/Logger/index.js +60 -0
- package/dist/common/Logger/types.js +5 -0
- package/dist/common/SdkError.js +50 -0
- package/dist/common/aiModelsValidations.js +32 -0
- package/dist/common/browser_scripts.js +2596 -0
- package/dist/common/ensureBrowserScripts.js +18 -0
- package/dist/common/extendedTest.js +148 -0
- package/dist/common/extractionHelpers.js +19 -0
- package/dist/common/formatZodError.js +18 -0
- package/dist/common/fuzzySearch/fuzzySearch.test.js +250 -0
- package/dist/common/fuzzySearch/levenshtein-search.js +298 -0
- package/dist/common/fuzzySearch/utils.js +23 -0
- package/dist/common/getModelProvider.js +18 -0
- package/dist/common/getSimplifiedHtml.js +122 -0
- package/dist/common/hashObject.js +32 -0
- package/dist/common/html2markdown/convertElementToMarkdown.js +469 -0
- package/dist/common/html2markdown/index.js +19 -0
- package/dist/common/jwtTokenManager.js +18 -0
- package/dist/common/loadRuntime.js +16 -0
- package/dist/common/locatorHelpers.js +41 -0
- package/dist/common/matching/collectStrings.js +32 -0
- package/dist/common/matching/levenshtein.js +40 -0
- package/dist/common/matching/matching.js +317 -0
- package/dist/common/matching/types.js +1 -0
- package/dist/common/noEmpty.js +9 -0
- package/dist/common/saveSnapshotWithExamples.js +60 -0
- package/dist/common/tests/testEnsureBrowserScript.spec.js +31 -0
- package/dist/common/xpathMapping.js +107 -0
- package/dist/helpers/clickUntilExhausted.js +85 -0
- package/dist/helpers/downloadFile.js +125 -0
- package/dist/helpers/export.d.js +5 -0
- package/dist/helpers/export.d.ts +1220 -0
- package/dist/helpers/extractMarkdown.js +35 -0
- package/dist/helpers/filterEmptyValues.js +54 -0
- package/dist/helpers/gotoUrl.js +98 -0
- package/dist/helpers/index.d.ts +1220 -0
- package/dist/helpers/index.js +128 -0
- package/dist/helpers/processDate.js +25 -0
- package/dist/helpers/resolveUrl.js +64 -0
- package/dist/helpers/sanitizeHtml.js +74 -0
- package/dist/helpers/saveFileToS3.js +50 -0
- package/dist/helpers/scrollToLoadContent.js +57 -0
- package/dist/helpers/tests/extendedTest.js +130 -0
- package/dist/helpers/tests/testClickUntilExhausted.spec.js +387 -0
- package/dist/helpers/tests/testDownloadFile.spec.js +204 -0
- package/dist/helpers/tests/testExtractMarkdown.spec.js +290 -0
- package/dist/helpers/tests/testFilterEmptyValues.spec.js +151 -0
- package/dist/helpers/tests/testGoToUrl.spec.js +37 -0
- package/dist/helpers/tests/testProcessDate.spec.js +13 -0
- package/dist/helpers/tests/testResolveUrl.spec.js +341 -0
- package/dist/helpers/tests/testSanitizeHtml.spec.js +330 -0
- package/dist/helpers/tests/testScrollToLoadContent.spec.js +163 -0
- package/dist/helpers/tests/testValidateDataUsingSchema.spec.js +342 -0
- package/dist/helpers/tests/testWithDomSettledWait.spec.js +164 -0
- package/dist/helpers/tests/testWithNetworkIdleWait.spec.js +114 -0
- package/dist/helpers/types/Attachment.js +115 -0
- package/dist/helpers/types/CustomTypeRegistry.js +48 -0
- package/dist/helpers/types/RunEnvironment.js +18 -0
- package/dist/helpers/types/ValidationError.js +17 -0
- package/dist/helpers/types/index.js +51 -0
- package/dist/helpers/uploadFileToS3.js +154 -0
- package/dist/helpers/utils/getS3Client.js +22 -0
- package/dist/helpers/utils/index.js +73 -0
- package/dist/helpers/utils/isDownload.js +10 -0
- package/dist/helpers/utils/isGenerateCodeMode.js +9 -0
- package/dist/helpers/utils/isLocator.js +9 -0
- package/dist/helpers/utils/jwtTokenManager.js +18 -0
- package/dist/helpers/validateDataUsingSchema.js +103 -0
- package/dist/helpers/waitForDomSettled.js +90 -0
- package/dist/helpers/withNetworkSettledWait.js +91 -0
- package/dist/index.d.js +16 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +16 -0
- package/dist/intunedServices/ApiGateway/aiApiGateway.js +99 -0
- package/dist/intunedServices/ApiGateway/factory.js +13 -0
- package/dist/intunedServices/ApiGateway/providers/Anthropic.js +26 -0
- package/dist/intunedServices/ApiGateway/providers/Gemini.js +29 -0
- package/dist/intunedServices/ApiGateway/providers/OpenAI.js +29 -0
- package/dist/intunedServices/ApiGateway/tests/testApiGateway.spec.js +224 -0
- package/dist/intunedServices/ApiGateway/types.js +11 -0
- package/dist/intunedServices/cache/cache.js +61 -0
- package/dist/intunedServices/cache/index.js +12 -0
- package/dist/intunedServices/cache/tests/testCache.spec.js +117 -0
- package/dist/optimized-extractors/common/buildExamplesPrompt.js +12 -0
- package/dist/optimized-extractors/common/buildImagesFromPage.js +55 -0
- package/dist/optimized-extractors/common/extractStructuredDataUsingClaude.js +135 -0
- package/dist/optimized-extractors/common/extractStructuredDataUsingGoogle.js +37 -0
- package/dist/optimized-extractors/common/extractStructuredDataUsingOpenAi.js +132 -0
- package/dist/optimized-extractors/common/extractStrucutredDataUsingAiInstance.js +122 -0
- package/dist/optimized-extractors/common/findTableHeaders.js +162 -0
- package/dist/optimized-extractors/common/index.js +55 -0
- package/dist/optimized-extractors/common/isTableHeaderOrFooter.js +84 -0
- package/dist/optimized-extractors/common/matching/matching.js +212 -0
- package/dist/optimized-extractors/common/matching/matching.test.js +655 -0
- package/dist/optimized-extractors/common/matching/types.js +18 -0
- package/dist/optimized-extractors/common/matching/utils.js +184 -0
- package/dist/optimized-extractors/common/utils.js +58 -0
- package/dist/optimized-extractors/export.d.js +5 -0
- package/dist/optimized-extractors/export.d.ts +397 -0
- package/dist/optimized-extractors/extractArray.js +120 -0
- package/dist/optimized-extractors/extractObject.js +104 -0
- package/dist/optimized-extractors/index.d.ts +397 -0
- package/dist/optimized-extractors/index.js +31 -0
- package/dist/optimized-extractors/listExtractionHelpers/__tests__/dynamicListExtractor.spec.js +312 -0
- package/dist/optimized-extractors/listExtractionHelpers/__tests__/findSetOfXpathsToCreateAnArrayExtractor.test.js +22 -0
- package/dist/optimized-extractors/listExtractionHelpers/__tests__/getContainerElement.test.js +21 -0
- package/dist/optimized-extractors/listExtractionHelpers/__tests__/partOfSameArrayXpath.test.js +42 -0
- package/dist/optimized-extractors/listExtractionHelpers/__tests__/verifyThatAllXpathsArePartOfSameArray.test.js +9 -0
- package/dist/optimized-extractors/listExtractionHelpers/dynamicListExtractor.js +152 -0
- package/dist/optimized-extractors/listExtractionHelpers/errors.js +46 -0
- package/dist/optimized-extractors/listExtractionHelpers/getListMatches.js +14 -0
- package/dist/optimized-extractors/listExtractionHelpers/runAiExtraction.js +240 -0
- package/dist/optimized-extractors/listExtractionHelpers/typesAndSchema.js +5 -0
- package/dist/optimized-extractors/listExtractionHelpers/utils/extractPropertiesUsingGPTFromArray.js +277 -0
- package/dist/optimized-extractors/listExtractionHelpers/utils/extractStructuredListUsingAi.js +44 -0
- package/dist/optimized-extractors/listExtractionHelpers/utils/getListContainerXpath.js +94 -0
- package/dist/optimized-extractors/listExtractionHelpers/utils/getRelativeContainerXpathSelector.js +20 -0
- package/dist/optimized-extractors/listExtractionHelpers/utils/getSimplifiedHtmlPerListItem.js +21 -0
- package/dist/optimized-extractors/listExtractionHelpers/utils/tablesUtils.js +48 -0
- package/dist/optimized-extractors/listExtractionHelpers/utils/validateOptions.js +52 -0
- package/dist/optimized-extractors/models/anthropicModel.js +23 -0
- package/dist/optimized-extractors/models/openaiModel.js +23 -0
- package/dist/optimized-extractors/objectExtractionHelpers/AIExtractors.js +73 -0
- package/dist/optimized-extractors/objectExtractionHelpers/__tests__/checksumUtils.test.js +103 -0
- package/dist/optimized-extractors/objectExtractionHelpers/__tests__/testObjectExtractorFromLocator.spec.js +107 -0
- package/dist/optimized-extractors/objectExtractionHelpers/__tests__/testObjectExtractorFromPage.spec.js +107 -0
- package/dist/optimized-extractors/objectExtractionHelpers/calculateObjectExampleHash.js +28 -0
- package/dist/optimized-extractors/objectExtractionHelpers/captureSnapshot.js +26 -0
- package/dist/optimized-extractors/objectExtractionHelpers/checksumUtils.js +32 -0
- package/dist/optimized-extractors/objectExtractionHelpers/constants.js +7 -0
- package/dist/optimized-extractors/objectExtractionHelpers/dynamicObjectExtractor.js +106 -0
- package/dist/optimized-extractors/objectExtractionHelpers/errors.js +42 -0
- package/dist/optimized-extractors/objectExtractionHelpers/findDomMatches.js +54 -0
- package/dist/optimized-extractors/objectExtractionHelpers/getSimplifiedHtml.js +122 -0
- package/dist/optimized-extractors/objectExtractionHelpers/typesAndSchemas.js +5 -0
- package/dist/optimized-extractors/objectExtractionHelpers/validateDynamicObjectExtractorOptions.js +52 -0
- package/dist/optimized-extractors/types/aiModelsValidation.js +45 -0
- package/dist/optimized-extractors/types/errors.js +42 -0
- package/dist/optimized-extractors/types/jsonSchema.d.js +5 -0
- package/dist/optimized-extractors/types/jsonSchema.d.ts +50 -0
- package/dist/optimized-extractors/types/types.js +5 -0
- package/dist/optimized-extractors/validators.js +152 -0
- package/dist/vite-env.d.js +1 -0
- package/dist/vite-env.d.ts +9 -0
- package/docs.md +14 -0
- package/generated-docs/ai/functions/extractStructuredData.mdx +255 -0
- package/generated-docs/ai/functions/isPageLoaded.mdx +88 -0
- package/generated-docs/ai/interfaces/ArraySchema.mdx +36 -0
- package/generated-docs/ai/interfaces/BasicSchema.mdx +14 -0
- package/generated-docs/ai/interfaces/BooleanSchema.mdx +28 -0
- package/generated-docs/ai/interfaces/ImageBufferContentItem.mdx +16 -0
- package/generated-docs/ai/interfaces/ImageUrlContentItem.mdx +16 -0
- package/generated-docs/ai/interfaces/NumberSchema.mdx +35 -0
- package/generated-docs/ai/interfaces/ObjectSchema.mdx +39 -0
- package/generated-docs/ai/interfaces/StringSchema.mdx +35 -0
- package/generated-docs/ai/interfaces/TextContentItem.mdx +14 -0
- package/generated-docs/ai/type-aliases/ContentItem.mdx +12 -0
- package/generated-docs/ai/type-aliases/JsonSchema.mdx +47 -0
- package/generated-docs/ai/type-aliases/SUPPORTED_MODELS.mdx +85 -0
- package/generated-docs/helpers/functions/downloadFile.mdx +99 -0
- package/generated-docs/helpers/functions/extractMarkdown.mdx +56 -0
- package/generated-docs/helpers/functions/filterEmptyValues.mdx +51 -0
- package/generated-docs/helpers/functions/goToUrl.mdx +124 -0
- package/generated-docs/helpers/functions/processDate.mdx +55 -0
- package/generated-docs/helpers/functions/resolveUrl.mdx +165 -0
- package/generated-docs/helpers/functions/sanitizeHtml.mdx +113 -0
- package/generated-docs/helpers/functions/saveFileToS3.mdx +127 -0
- package/generated-docs/helpers/functions/scrollToLoadContent.mdx +89 -0
- package/generated-docs/helpers/functions/uploadFileToS3.mdx +121 -0
- package/generated-docs/helpers/functions/validateDataUsingSchema.mdx +90 -0
- package/generated-docs/helpers/functions/waitForDomSettled.mdx +91 -0
- package/generated-docs/helpers/functions/withNetworkSettledWait.mdx +76 -0
- package/generated-docs/helpers/interfaces/Attachment.mdx +56 -0
- package/generated-docs/helpers/interfaces/S3Configs.mdx +52 -0
- package/generated-docs/helpers/interfaces/SanitizeHtmlOptions.mdx +22 -0
- package/generated-docs/helpers/type-aliases/AttachmentType.mdx +10 -0
- package/generated-docs/helpers/type-aliases/FileType.mdx +61 -0
- package/generated-docs/helpers/type-aliases/Trigger.mdx +62 -0
- package/how-to-run-tests.md +10 -0
- package/intuned-runtime-setup.md +13 -0
- package/package.json +119 -0
- package/tsconfig.eslint.json +5 -0
- package/tsconfig.json +26 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "AttachmentValidator", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _types.AttachmentValidator;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "CustomTypeRegistry", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _types.CustomTypeRegistry;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "CustomTypeValidator", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _types.CustomTypeValidator;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "clickButtonAndWait", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _clickUntilExhausted.clickButtonAndWait;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "clickButtonUntilNoChange", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _clickUntilExhausted.clickButtonUntilNoChange;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, "downloadFile", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () {
|
|
39
|
+
return _downloadFile.downloadFile;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
Object.defineProperty(exports, "extractMarkdown", {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
get: function () {
|
|
45
|
+
return _extractMarkdown.extractMarkdown;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
Object.defineProperty(exports, "filterEmptyValues", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
get: function () {
|
|
51
|
+
return _filterEmptyValues.filterEmptyValues;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
Object.defineProperty(exports, "goToUrl", {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function () {
|
|
57
|
+
return _gotoUrl.goToUrl;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
Object.defineProperty(exports, "processDate", {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
get: function () {
|
|
63
|
+
return _processDate.processDate;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
Object.defineProperty(exports, "resolveUrl", {
|
|
67
|
+
enumerable: true,
|
|
68
|
+
get: function () {
|
|
69
|
+
return _resolveUrl.resolveUrl;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
Object.defineProperty(exports, "sanitizeHtml", {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
get: function () {
|
|
75
|
+
return _sanitizeHtml.sanitizeHtml;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
Object.defineProperty(exports, "saveFileToS3", {
|
|
79
|
+
enumerable: true,
|
|
80
|
+
get: function () {
|
|
81
|
+
return _saveFileToS.saveFileToS3;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
Object.defineProperty(exports, "scrollToLoadContent", {
|
|
85
|
+
enumerable: true,
|
|
86
|
+
get: function () {
|
|
87
|
+
return _scrollToLoadContent.scrollToLoadContent;
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
Object.defineProperty(exports, "uploadFileToS3", {
|
|
91
|
+
enumerable: true,
|
|
92
|
+
get: function () {
|
|
93
|
+
return _uploadFileToS.uploadFileToS3;
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
Object.defineProperty(exports, "validateDataUsingSchema", {
|
|
97
|
+
enumerable: true,
|
|
98
|
+
get: function () {
|
|
99
|
+
return _validateDataUsingSchema.validateDataUsingSchema;
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
Object.defineProperty(exports, "waitForDomSettled", {
|
|
103
|
+
enumerable: true,
|
|
104
|
+
get: function () {
|
|
105
|
+
return _waitForDomSettled.waitForDomSettled;
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
Object.defineProperty(exports, "withNetworkSettledWait", {
|
|
109
|
+
enumerable: true,
|
|
110
|
+
get: function () {
|
|
111
|
+
return _withNetworkSettledWait.withNetworkSettledWait;
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
var _gotoUrl = require("./gotoUrl");
|
|
115
|
+
var _uploadFileToS = require("./uploadFileToS3");
|
|
116
|
+
var _withNetworkSettledWait = require("./withNetworkSettledWait");
|
|
117
|
+
var _validateDataUsingSchema = require("./validateDataUsingSchema");
|
|
118
|
+
var _types = require("./types");
|
|
119
|
+
var _downloadFile = require("./downloadFile");
|
|
120
|
+
var _filterEmptyValues = require("./filterEmptyValues");
|
|
121
|
+
var _processDate = require("./processDate");
|
|
122
|
+
var _extractMarkdown = require("./extractMarkdown");
|
|
123
|
+
var _sanitizeHtml = require("./sanitizeHtml");
|
|
124
|
+
var _saveFileToS = require("./saveFileToS3");
|
|
125
|
+
var _resolveUrl = require("./resolveUrl");
|
|
126
|
+
var _waitForDomSettled = require("./waitForDomSettled");
|
|
127
|
+
var _scrollToLoadContent = require("./scrollToLoadContent");
|
|
128
|
+
var _clickUntilExhausted = require("./clickUntilExhausted");
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.processDate = void 0;
|
|
7
|
+
var _dateFns = require("date-fns");
|
|
8
|
+
var chrono = _interopRequireWildcard(require("chrono-node"));
|
|
9
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
10
|
+
const processDate = input => {
|
|
11
|
+
const {
|
|
12
|
+
date
|
|
13
|
+
} = input;
|
|
14
|
+
try {
|
|
15
|
+
const cleaned = date.replace(" - ", " ");
|
|
16
|
+
const results = chrono.parse(cleaned);
|
|
17
|
+
if (results.length > 0) {
|
|
18
|
+
return (0, _dateFns.startOfDay)(results[0].start.date());
|
|
19
|
+
}
|
|
20
|
+
return null;
|
|
21
|
+
} catch (error) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
exports.processDate = processDate;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.resolveUrl = void 0;
|
|
7
|
+
const resolveUrl = async options => {
|
|
8
|
+
if (typeof options.url === "object" && options.url !== null && "evaluate" in options.url) {
|
|
9
|
+
if (options.baseUrl !== undefined || options.page !== undefined) {
|
|
10
|
+
throw new Error("baseUrl and page parameters are not needed when url is Locator");
|
|
11
|
+
}
|
|
12
|
+
const elementName = await options.url.evaluate(element => element.tagName);
|
|
13
|
+
if (elementName !== "A") {
|
|
14
|
+
throw new Error(`Expected an anchor element, got ${elementName}`);
|
|
15
|
+
}
|
|
16
|
+
return await options.url.evaluate(element => element.href);
|
|
17
|
+
} else if (typeof options.url === "string") {
|
|
18
|
+
if (options.baseUrl !== undefined && options.page !== undefined) {
|
|
19
|
+
throw new Error("Cannot provide both 'baseUrl' and 'page' parameters. Please provide only one.");
|
|
20
|
+
}
|
|
21
|
+
if (options.baseUrl === undefined && options.page === undefined) {
|
|
22
|
+
throw new Error("Must provide either 'baseUrl' or 'page' parameter when url is a string.");
|
|
23
|
+
}
|
|
24
|
+
const relativeUrl = options.url;
|
|
25
|
+
let baseUrl;
|
|
26
|
+
if (options.page !== undefined) {
|
|
27
|
+
const parsedUrl = new URL(options.page.url());
|
|
28
|
+
baseUrl = `${parsedUrl.protocol}//${parsedUrl.host}`;
|
|
29
|
+
} else {
|
|
30
|
+
baseUrl = options.baseUrl;
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
new URL(relativeUrl);
|
|
34
|
+
return relativeUrl;
|
|
35
|
+
} catch {}
|
|
36
|
+
const fullUrl = new URL(relativeUrl, baseUrl);
|
|
37
|
+
const {
|
|
38
|
+
protocol,
|
|
39
|
+
hostname,
|
|
40
|
+
port,
|
|
41
|
+
pathname,
|
|
42
|
+
search,
|
|
43
|
+
hash
|
|
44
|
+
} = fullUrl;
|
|
45
|
+
const encodedPath = encodeURI(decodeURI(pathname));
|
|
46
|
+
let encodedQuery = "";
|
|
47
|
+
if (search) {
|
|
48
|
+
const queryString = search.substring(1);
|
|
49
|
+
const params = queryString.split("&").map(param => {
|
|
50
|
+
const [key, value = ""] = param.split("=");
|
|
51
|
+
const encodedKey = encodeURIComponent(decodeURIComponent(key));
|
|
52
|
+
const encodedValue = value ? encodeURIComponent(decodeURIComponent(value)) : "";
|
|
53
|
+
return encodedValue ? `${encodedKey}=${encodedValue}` : encodedKey;
|
|
54
|
+
});
|
|
55
|
+
encodedQuery = params.length > 0 ? `?${params.join("&")}` : "";
|
|
56
|
+
}
|
|
57
|
+
const portStr = port ? `:${port}` : "";
|
|
58
|
+
const encodedFullUrl = `${protocol}//${hostname}${portStr}${encodedPath}${encodedQuery}${hash}`;
|
|
59
|
+
return encodedFullUrl;
|
|
60
|
+
} else {
|
|
61
|
+
throw new TypeError(`url must be string, Locator, got ${typeof options.url}`);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
exports.resolveUrl = resolveUrl;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.sanitizeHtml = void 0;
|
|
7
|
+
var _nodeHtmlParser = require("node-html-parser");
|
|
8
|
+
var _isGenerateCodeMode = require("./utils/isGenerateCodeMode");
|
|
9
|
+
const sanitizeHtml = (options = {
|
|
10
|
+
html: ""
|
|
11
|
+
}) => {
|
|
12
|
+
const {
|
|
13
|
+
html,
|
|
14
|
+
removeScripts = true,
|
|
15
|
+
removeStyles = true,
|
|
16
|
+
removeSvgs = true,
|
|
17
|
+
removeComments = true,
|
|
18
|
+
removeLongAttributes = true,
|
|
19
|
+
maxAttributeLength = 500,
|
|
20
|
+
preserveAttributes = ["class", "src"],
|
|
21
|
+
removeEmptyTags = true,
|
|
22
|
+
preserveEmptyTags = ["img"],
|
|
23
|
+
minifyWhitespace = true
|
|
24
|
+
} = options;
|
|
25
|
+
const root = (0, _nodeHtmlParser.parse)(html, {
|
|
26
|
+
comment: !removeComments
|
|
27
|
+
});
|
|
28
|
+
const elementsToRemove = [];
|
|
29
|
+
if (removeScripts) elementsToRemove.push("script");
|
|
30
|
+
if (removeStyles) elementsToRemove.push("style");
|
|
31
|
+
if (removeSvgs) elementsToRemove.push("svg");
|
|
32
|
+
if (elementsToRemove.length > 0) {
|
|
33
|
+
root.querySelectorAll(elementsToRemove.join(", ")).forEach(el => el.remove());
|
|
34
|
+
}
|
|
35
|
+
if (removeComments) {}
|
|
36
|
+
if (removeLongAttributes) {
|
|
37
|
+
root.querySelectorAll("*").forEach(element => {
|
|
38
|
+
if (element instanceof _nodeHtmlParser.HTMLElement) {
|
|
39
|
+
const attributes = element.attributes;
|
|
40
|
+
Object.keys(attributes).forEach(attr => {
|
|
41
|
+
if (preserveAttributes.includes(attr)) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (attr === "style" || attributes[attr].length > maxAttributeLength) {
|
|
45
|
+
element.removeAttribute(attr);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
if (removeEmptyTags && !(0, _isGenerateCodeMode.isGenerateCodeMode)()) {
|
|
52
|
+
root.querySelectorAll("*").forEach(element => {
|
|
53
|
+
if (element instanceof _nodeHtmlParser.HTMLElement) {
|
|
54
|
+
const tagName = element.tagName.toLowerCase();
|
|
55
|
+
if (preserveEmptyTags.includes(tagName)) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const textContent = element.text.trim();
|
|
59
|
+
const hasChildElements = element.childNodes.length > 0;
|
|
60
|
+
if (textContent.length === 0 && !hasChildElements) {
|
|
61
|
+
element.remove();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
let sanitizedHtml = root.toString();
|
|
67
|
+
if (minifyWhitespace) {
|
|
68
|
+
sanitizedHtml = sanitizedHtml.replace(/>\s*</g, "><");
|
|
69
|
+
sanitizedHtml = sanitizedHtml.replace(/\n\s*\n/g, "\n");
|
|
70
|
+
sanitizedHtml = sanitizedHtml.replace(/\s+/g, " ");
|
|
71
|
+
}
|
|
72
|
+
return sanitizedHtml;
|
|
73
|
+
};
|
|
74
|
+
exports.sanitizeHtml = sanitizeHtml;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.saveFileToS3 = void 0;
|
|
7
|
+
var _downloadFile = require("./downloadFile");
|
|
8
|
+
var _uploadFileToS = require("./uploadFileToS3");
|
|
9
|
+
var _isGenerateCodeMode = require("./utils/isGenerateCodeMode");
|
|
10
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
11
|
+
const loadRuntime = async () => {
|
|
12
|
+
try {
|
|
13
|
+
const runtime = await Promise.resolve().then(() => _interopRequireWildcard(require("@intuned/runtime")));
|
|
14
|
+
return runtime.extendTimeout;
|
|
15
|
+
} catch {
|
|
16
|
+
return () => {
|
|
17
|
+
return;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
const saveFileToS3 = async input => {
|
|
22
|
+
const {
|
|
23
|
+
page,
|
|
24
|
+
trigger,
|
|
25
|
+
timeoutInMs,
|
|
26
|
+
configs,
|
|
27
|
+
fileNameOverride,
|
|
28
|
+
contentType
|
|
29
|
+
} = input;
|
|
30
|
+
if (!page || typeof page.goto !== "function") {
|
|
31
|
+
throw new Error("page must be a playwright Page object");
|
|
32
|
+
}
|
|
33
|
+
const download = await (0, _downloadFile.downloadFile)({
|
|
34
|
+
page,
|
|
35
|
+
trigger,
|
|
36
|
+
timeoutInMs
|
|
37
|
+
});
|
|
38
|
+
if (!(0, _isGenerateCodeMode.isGenerateCodeMode)()) {
|
|
39
|
+
const extendTimeout = await loadRuntime();
|
|
40
|
+
extendTimeout();
|
|
41
|
+
}
|
|
42
|
+
const uploaded = await (0, _uploadFileToS.uploadFileToS3)({
|
|
43
|
+
file: download,
|
|
44
|
+
configs,
|
|
45
|
+
fileNameOverride,
|
|
46
|
+
contentType
|
|
47
|
+
});
|
|
48
|
+
return uploaded;
|
|
49
|
+
};
|
|
50
|
+
exports.saveFileToS3 = saveFileToS3;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.scrollToLoadContent = exports.scrollToBottom = void 0;
|
|
7
|
+
var _locatorHelpers = require("../common/locatorHelpers");
|
|
8
|
+
var _withNetworkSettledWait = require("./withNetworkSettledWait");
|
|
9
|
+
const scrollToBottomInternal = async (page, scrollable) => {
|
|
10
|
+
if ((0, _locatorHelpers.isPage)(scrollable)) {
|
|
11
|
+
const newHeight = await scrollable.evaluate(() => {
|
|
12
|
+
window.scrollTo(0, document.body.scrollHeight);
|
|
13
|
+
return document.body.scrollHeight;
|
|
14
|
+
});
|
|
15
|
+
return newHeight;
|
|
16
|
+
} else {
|
|
17
|
+
const newHeight = await scrollable.evaluate(element => {
|
|
18
|
+
element.scrollTop = element.scrollHeight;
|
|
19
|
+
return element.scrollHeight;
|
|
20
|
+
});
|
|
21
|
+
return newHeight;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const scrollToBottom = async scrollable => {
|
|
25
|
+
const page = (0, _locatorHelpers.isPage)(scrollable) ? scrollable : scrollable.page();
|
|
26
|
+
return await (0, _withNetworkSettledWait.withNetworkSettledWait)(async () => scrollToBottomInternal(page, scrollable), {
|
|
27
|
+
page,
|
|
28
|
+
maxInflightRequests: 0,
|
|
29
|
+
timeoutInMs: 10000
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
exports.scrollToBottom = scrollToBottom;
|
|
33
|
+
const scrollToLoadContent = async input => {
|
|
34
|
+
const {
|
|
35
|
+
onScrollProgress = undefined,
|
|
36
|
+
maxScrolls = 50,
|
|
37
|
+
delayInMs = 100,
|
|
38
|
+
minHeightChange = 100
|
|
39
|
+
} = input || {};
|
|
40
|
+
const scrollable = input.source;
|
|
41
|
+
if (!scrollable) {
|
|
42
|
+
throw new Error("scrollable is required");
|
|
43
|
+
}
|
|
44
|
+
let previousHeight = -1;
|
|
45
|
+
let scrollCount = 0;
|
|
46
|
+
while (scrollCount < maxScrolls) {
|
|
47
|
+
onScrollProgress === null || onScrollProgress === void 0 || onScrollProgress();
|
|
48
|
+
const currentHeight = await scrollToBottom(scrollable);
|
|
49
|
+
if (Math.abs(currentHeight - previousHeight) < minHeightChange) {
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
previousHeight = currentHeight;
|
|
53
|
+
scrollCount++;
|
|
54
|
+
await new Promise(resolve => setTimeout(resolve, delayInMs));
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
exports.scrollToLoadContent = scrollToLoadContent;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "afterAll", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _vitest.afterAll;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "afterEach", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _vitest.afterEach;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "beforeAll", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _vitest.beforeAll;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "beforeEach", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _vitest.beforeEach;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "describe", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _vitest.describe;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
exports.expect = void 0;
|
|
37
|
+
Object.defineProperty(exports, "it", {
|
|
38
|
+
enumerable: true,
|
|
39
|
+
get: function () {
|
|
40
|
+
return _vitest.it;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
exports.test = void 0;
|
|
44
|
+
var dotenv = _interopRequireWildcard(require("dotenv"));
|
|
45
|
+
var _vitest = require("vitest");
|
|
46
|
+
var _runtime = require("@intuned/runtime");
|
|
47
|
+
var _utils = require("../utils");
|
|
48
|
+
var _fsExtra = require("fs-extra");
|
|
49
|
+
var _types = require("../types");
|
|
50
|
+
var _nanoid = require("nanoid");
|
|
51
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
52
|
+
dotenv.config();
|
|
53
|
+
const withPlaywright = (name, testFn, {
|
|
54
|
+
headless,
|
|
55
|
+
trace,
|
|
56
|
+
runId,
|
|
57
|
+
jobId,
|
|
58
|
+
jobRunId,
|
|
59
|
+
queueId
|
|
60
|
+
}) => {
|
|
61
|
+
return async () => {
|
|
62
|
+
return (0, _runtime.runWithContext)({
|
|
63
|
+
runId: runId ?? (0, _nanoid.nanoid)(),
|
|
64
|
+
extendedPayloads: [],
|
|
65
|
+
runEnvironment: _types.RunEnvironment.IDE,
|
|
66
|
+
jobId,
|
|
67
|
+
jobRunId,
|
|
68
|
+
queueId
|
|
69
|
+
}, async () => {
|
|
70
|
+
const downloadsPath = (0, _runtime.getDownloadDirectoryPath)();
|
|
71
|
+
const {
|
|
72
|
+
page,
|
|
73
|
+
context
|
|
74
|
+
} = await (0, _runtime.getProductionPlaywrightConstructs)({
|
|
75
|
+
headless: headless ?? true,
|
|
76
|
+
downloadsPath
|
|
77
|
+
});
|
|
78
|
+
context.setDefaultTimeout(10000);
|
|
79
|
+
try {
|
|
80
|
+
if (trace) {
|
|
81
|
+
await context.tracing.start({
|
|
82
|
+
screenshots: true
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
await testFn({
|
|
86
|
+
context,
|
|
87
|
+
page
|
|
88
|
+
});
|
|
89
|
+
if (trace) {
|
|
90
|
+
await context.tracing.stop({
|
|
91
|
+
path: `./reports/traces/${name}.zip`
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
} finally {
|
|
95
|
+
await page.close();
|
|
96
|
+
await context.close();
|
|
97
|
+
await (0, _fsExtra.remove)(downloadsPath);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
const test = (name, fn, options = {}) => {
|
|
103
|
+
if (process.env.CI) {
|
|
104
|
+
options.headless = true;
|
|
105
|
+
} else {
|
|
106
|
+
options.timeout = 1000000;
|
|
107
|
+
}
|
|
108
|
+
return (0, _vitest.test)(name, withPlaywright(name, fn, options), options);
|
|
109
|
+
};
|
|
110
|
+
exports.test = test;
|
|
111
|
+
_vitest.expect.extend({
|
|
112
|
+
async toHaveText(locator, expectedText) {
|
|
113
|
+
const textContent = await locator.textContent();
|
|
114
|
+
const pass = !!textContent && (0, _utils.compressStringSpaces)(textContent) === expectedText;
|
|
115
|
+
return {
|
|
116
|
+
pass,
|
|
117
|
+
message: () => `Expected locator with selector "${locator}" to have text "${expectedText}", but it has "${textContent}"`
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
test.skip = _vitest.test.skip;
|
|
122
|
+
test.only = (name, fn, options = {}) => {
|
|
123
|
+
if (process.env.CI) {
|
|
124
|
+
options.headless = true;
|
|
125
|
+
} else {
|
|
126
|
+
options.timeout = 1000000;
|
|
127
|
+
}
|
|
128
|
+
return _vitest.test.only(name, withPlaywright(name, fn, options), options);
|
|
129
|
+
};
|
|
130
|
+
const expect = exports.expect = _vitest.expect;
|