import {z} from 'zod' export type ObjectStatus = 'Active' | 'Inactive'; export type CollectMode = 'Summary' | 'Minimum' | 'Maximum' | 'Average' | 'Range' | 'Count'; export type OverrideType = 'Active' | 'Inactive'; export type ValueType = 'String' | 'Boolean' | 'Integer' | 'NumericBoolean' | 'Decimal' | 'DateTime' | 'None' | 'Date' | 'Weekday' | 'Month' | 'Year' | 'Money' | 'Percent' | 'WebResource'; export type Collector = {id?: number | undefined, status?: ObjectStatus | undefined, created?: string | undefined, updated?: string | undefined, name: string, nameLocalizations?: ({[key: string]: string | null} | null) | undefined, collectMode?: CollectMode | undefined, negated?: boolean | undefined, overrideType?: OverrideType | undefined, valueType?: ValueType | undefined, culture?: (string | null) | undefined, collectorGroups?: (Array | null) | undefined, threshold?: (number | null) | undefined, minResult?: (number | null) | undefined, maxResult?: (number | null) | undefined, startExpression?: (string | null) | undefined, applyExpression?: (string | null) | undefined, endExpression?: (string | null) | undefined, startActions?: (Array | null) | undefined, applyActions?: (Array | null) | undefined, endActions?: (Array | null) | undefined, attributes?: ({[key: string]: unknown} | null) | undefined, clusters?: (Array | null) | undefined}; export type CreateApiApiTenantsTenantIdRegulationsRegulationIdCollectorsArgs = {tenantId: number, regulationId: number, body: Collector}; export type CreateApiApiTenantsTenantIdRegulationsRegulationIdCollectorsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const objectStatus = z.enum(["Active", "Inactive"]); export const collectMode = z.enum(["Summary", "Minimum", "Maximum", "Average", "Range", "Count"]); export const overrideType = z.enum(["Active", "Inactive"]); export const valueType = z.enum(["String", "Boolean", "Integer", "NumericBoolean", "Decimal", "DateTime", "None", "Date", "Weekday", "Month", "Year", "Money", "Percent", "WebResource"]); export const collector = z.object({id: z.number().int().optional(), status: objectStatus.optional(), created: z.string().optional(), updated: z.string().optional(), name: z.string().max(128), nameLocalizations: z.record(z.string(), z.string().nullable()).nullable().optional(), collectMode: collectMode.optional(), negated: z.boolean().optional(), overrideType: overrideType.optional(), valueType: valueType.optional(), culture: z.string().nullable().optional(), collectorGroups: z.array(z.string()).nullable().optional(), threshold: z.number().nullable().optional(), minResult: z.number().nullable().optional(), maxResult: z.number().nullable().optional(), startExpression: z.string().nullable().optional(), applyExpression: z.string().nullable().optional(), endExpression: z.string().nullable().optional(), startActions: z.array(z.string()).nullable().optional(), applyActions: z.array(z.string()).nullable().optional(), endActions: z.array(z.string()).nullable().optional(), attributes: z.record(z.string(), z.unknown()).nullable().optional(), clusters: z.array(z.string()).nullable().optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * POST /api/tenants/{tenantId}/regulations/{regulationId}/collectors */ export const createApiApiTenantsTenantIdRegulationsRegulationIdCollectors = async (args: CreateApiApiTenantsTenantIdRegulationsRegulationIdCollectorsArgs, options: CreateApiApiTenantsTenantIdRegulationsRegulationIdCollectorsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/api/tenants/${encodeURIComponent(String(args.tenantId))}/regulations/${encodeURIComponent(String(args.regulationId))}/collectors${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(collector, await res.json()) };