@open-formulieren/formio-builder
Version:
An opinionated Formio webform builder for Open Forms
112 lines (111 loc) • 3.22 kB
JavaScript
import { z as e } from "zod";
import { buildCommonSchema as c } from "../validation.js";
const f = {
B: Math.pow(1024, 0),
KB: Math.pow(1024, 1),
MB: Math.pow(1024, 2),
GB: Math.pow(1024, 3)
}, n = (a) => {
const s = /^(\d+)\s*(B|KB|MB|GB)?$/i.exec(a);
if (s === null)
return null;
const o = parseInt(s[1], 10), i = (s[2] || "B").toUpperCase();
return o * f[i];
}, l = e.number().int().positive(), g = e.object({
image: e.object({
resize: e.object({
apply: e.boolean().optional(),
width: l.optional(),
height: l.optional()
}).optional()
}).optional()
}), d = (a, s) => {
const {
serverUploadLimit: o
} = s, i = n(o) ?? Number.MAX_SAFE_INTEGER;
return e.string().transform((t, u) => {
const r = n(t);
return r === null ? (u.addIssue({
code: e.ZodIssueCode.custom,
message: a.formatMessage({
id: "QW32Dd",
defaultMessage: [{
type: 0,
value: "Specify a positive, non-zero file size without decimals, e.g. 10MB."
}]
})
}), e.NEVER) : r;
}).refine((t) => t <= i, {
message: a.formatMessage({
id: "5/jkH9",
defaultMessage: [{
type: 0,
value: "Specify a file size less than or equal to the server upload limit."
}]
})
});
}, m = (a) => e.object({
documentType: e.object({
catalogue: e.object({
domain: e.string().optional(),
rsin: e.string().optional()
}),
description: e.string().optional()
}).optional().superRefine((s, o) => {
(!!(s != null && s.description) || !!(s != null && s.catalogue.domain) || !!(s != null && s.catalogue.rsin)) && (s.description || o.addIssue({
code: e.ZodIssueCode.custom,
message: a.formatMessage({
id: "ce0Nz4",
defaultMessage: [{
type: 0,
value: "You must specify a document type description when a catalogue is configured."
}]
}),
path: ["description"]
}), s != null && s.catalogue.domain || o.addIssue({
code: e.ZodIssueCode.custom,
message: a.formatMessage({
id: "xUt2+r",
defaultMessage: [{
type: 0,
value: "You must specify both domain and RSIN."
}]
}),
path: ["catalogue", "domain"]
}), s != null && s.catalogue.rsin ? /^[0-9]{9}$/.test(s.catalogue.rsin) || o.addIssue({
code: e.ZodIssueCode.custom,
message: a.formatMessage({
id: "DE7U4q",
defaultMessage: [{
type: 0,
value: "The RSIN must consist of 9 numbers."
}]
}),
path: ["catalogue", "rsin"]
}) : o.addIssue({
code: e.ZodIssueCode.custom,
message: a.formatMessage({
id: "tzAOAm",
defaultMessage: [{
type: 0,
value: "You must specify both domain and RSIN."
}]
}),
path: ["catalogue", "rsin"]
}));
})
}), p = (a, s) => e.object({
of: g.optional(),
maxNumberOfFiles: e.union([e.null(), e.number().int().positive().optional()]),
fileMaxSize: d(a, s).optional(),
registration: m(a).optional()
}), b = ({
intl: a,
builderContext: s
}) => {
const o = c(a), i = p(a, s);
return o.and(i);
};
export {
b as default
};