1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.validateCampaignSchema = exports.validateBatchData = void 0;
|
4 | const tslib_1 = require("tslib");
|
5 | const ajv_1 = tslib_1.__importDefault(require("ajv"));
|
6 |
|
7 |
|
8 |
|
9 | const validateBatchData = async (batch, campaign) => {
|
10 | const ajv = new ajv_1.default();
|
11 | if (!campaign.info?.input_schema) {
|
12 |
|
13 | return true;
|
14 | }
|
15 | const validate = ajv.compile(campaign.info?.input_schema);
|
16 | const valid = validate(batch.data);
|
17 | if (!valid) {
|
18 | console.error(validate?.errors);
|
19 | throw new Error(`Batch data is invalid: ${validate?.errors}`);
|
20 | }
|
21 | };
|
22 | exports.validateBatchData = validateBatchData;
|
23 | const validateCampaignSchema = (campaign) => {
|
24 | const ajv = new ajv_1.default();
|
25 | if (!campaign.info?.input_schema) {
|
26 |
|
27 | return true;
|
28 | }
|
29 | const valid = ajv.validateSchema(campaign.info?.input_schema);
|
30 | if (valid) {
|
31 | return true;
|
32 | }
|
33 | else {
|
34 | console.error(ajv.errors);
|
35 | throw new Error(`Campaign schema is invalid: ${ajv.errors}`);
|
36 | }
|
37 | };
|
38 | exports.validateCampaignSchema = validateCampaignSchema;
|
39 |
|
\ | No newline at end of file |