import joi from "joi"; const appSchema = joi.object().keys({ app_id: joi.number().integer().allow("", null), bundle_id: joi.string().allow("", null), sdk_version: joi.string().allow("", null), name: joi.string().allow("", null), cat: joi.array().items(joi.string().allow("", null)), ad_unit_id: joi.string().allow("", null), ad_unit_type: joi.string().allow("", null), app_api_key: joi.number().integer().allow("", null), app_publisher_id: joi.number().integer().allow("", null), publisher_is_network_partner: joi.boolean(), publisher_name: joi.string().allow("", null), seller_id: joi.string().allow("", null), eecpm: joi.number(), }); const siteSchema = joi.object().keys({ name: joi.string().allow("", null), domain: joi.string().domain().allow("", null), // few correct urls are still failing to validate with this check // page: joi.string().uri({ allowQuerySquareBrackets: true }).allow("", null), page: joi.string().allow("", null), }); const userSchema = joi.object().keys({ odid: joi.string().uuid().allow("", null), ogury_cookie_id: joi.string().allow("", null), bidswitch_cookie_id: joi.string().allow("", null), tdd_cookie_id: joi.string().allow("", null), consent: joi.string().allow("", null), consent_ads: joi.string().allow("", null), data_optin: joi.boolean().allow("", null), is_gdpr_applied: joi.boolean().allow("", null), tcf_version: joi.number().integer().allow("", null), }); const contextSchema = joi.object().keys({ day_of_week: joi.number().integer().allow("", null), hour: joi.number().integer().allow("", null), city: joi.string().allow("", null), ssp: joi.string().allow("", null), country: joi.string().allow("", null), }); const deviceSchema = joi.object().keys({ name: joi.string().allow("", null), os_version: joi.string().allow("", null), connectivity: joi.string().allow("", null), isp: joi.string().allow("", null), ifa: joi.string().allow("", null), language: joi.string().allow("", null), ua: joi.string().allow("", null), ip: joi.string().ip({ version: "ipv4" }).required(), os: joi.string().allow("", null), is_omid_compliant: joi.boolean().allow("", null), }); const campaignSchema = joi.object().keys({ id: joi.number().integer(), category_iab: joi.array().items(joi.string().allow("", null)), creatives: joi.array().items(joi.number().integer()), }); const baseRequestSchema = joi .object() .keys({ id: joi.string().uuid().required(), request_id: joi.string().allow("", null), type: joi.string().allow("", null), source_type: joi.string().allow("", null), app: appSchema, site: siteSchema, user: userSchema, context: contextSchema, device: deviceSchema, campaigns: joi.array().items(campaignSchema).min(1).required(), size: joi.number().min(1).positive(), }) .options({ allowUnknown: true }); export const internalRequestSchema = baseRequestSchema; export const headerBiddingRequestSchema = baseRequestSchema.keys({ bidFloor: joi.number().min(0), header_bidding_type: joi.string().allow("", null), tmax: joi.number().allow(null), });