@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.
- package/.babelrc +21 -0
- package/.eslintignore +10 -0
- package/.eslintrc.js +39 -0
- package/BROWSER_SCRIPTS_SETUP.md +84 -0
- package/LICENSE +43 -0
- package/README.md +160 -0
- package/RELEASE.md +60 -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 +142 -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 +80 -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/ensureBrowserScripts.js +14 -0
- package/dist/common/extendedTest.js +157 -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 +57 -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/script.js +2602 -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 +122 -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/testClickUntilExhausted.spec.js +372 -0
- package/dist/helpers/tests/testDownloadFile.spec.js +206 -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 +143 -0
- package/dist/intunedServices/ApiGateway/factory.js +16 -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 +355 -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 +269 -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__/testArrayExtractorFromLocator.spec.js +146 -0
- package/dist/optimized-extractors/listExtractionHelpers/__tests__/testArrayExtractorFromPage.spec.js +130 -0
- package/dist/optimized-extractors/listExtractionHelpers/__tests__/verifyThatAllXpathsArePartOfSameArray.test.js +9 -0
- package/dist/optimized-extractors/listExtractionHelpers/dynamicListExtractor.js +160 -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 +243 -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/types/intuned-runtime.d.js +1 -0
- package/dist/types/intuned-runtime.d.ts +64 -0
- package/dist/vite-env.d.js +1 -0
- package/dist/vite-env.d.ts +9 -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-generate-docs.md +61 -0
- package/how-to-run-tests.md +42 -0
- package/intuned-runtime-setup.md +13 -0
- package/package.json +124 -0
- package/tsconfig.eslint.json +5 -0
- 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,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;
|