UNPKG

1.39 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.validateCampaignSchema = exports.validateBatchData = void 0;
4const tslib_1 = require("tslib");
5const ajv_1 = tslib_1.__importDefault(require("ajv"));
6// export class UtilityService {
7// constructor(private readonly client: Client) {}
8// }
9const validateBatchData = async (batch, campaign) => {
10 const ajv = new ajv_1.default();
11 if (!campaign.info?.input_schema) {
12 // throw new Error('Campaign input schema is not defined')
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};
22exports.validateBatchData = validateBatchData;
23const validateCampaignSchema = (campaign) => {
24 const ajv = new ajv_1.default();
25 if (!campaign.info?.input_schema) {
26 // throw new Error('Campaign input schema is not defined')
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};
38exports.validateCampaignSchema = validateCampaignSchema;
39//# sourceMappingURL=utils.js.map
\No newline at end of file