import {z} from 'zod' export type ObjectStatus = 'Active' | 'Inactive'; export type FunctionType = 'CaseAvailable' | 'CaseBuild' | 'CaseValidate' | 'CaseChange' | 'Case' | 'CaseRelationBuild' | 'CaseRelationValidate' | 'CaseRelation' | 'CollectorStart' | 'CollectorApply' | 'CollectorEnd' | 'Collector' | 'WageTypeValue' | 'WageTypeResult' | 'WageType' | 'PayrunStart' | 'PayrunEmployeeAvailable' | 'PayrunEmployeeStart' | 'PayrunEmployeeEnd' | 'PayrunWageTypeAvailable' | 'PayrunEnd' | 'PayrunBase' | 'Payrun' | 'Payroll' | 'ReportBuild' | 'ReportStart' | 'ReportEnd' | 'Report' | 'All'; export type OverrideType = 'Active' | 'Inactive'; export type Script = {id?: number | undefined, status?: ObjectStatus | undefined, created?: string | undefined, updated?: string | undefined, name: string, functionTypes?: (Array | null) | undefined, value: string, overrideType?: OverrideType | undefined}; export type CreateApiApiTenantsTenantIdRegulationsRegulationIdScriptsArgs = {tenantId: number, regulationId: number, body: Script}; export type CreateApiApiTenantsTenantIdRegulationsRegulationIdScriptsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const objectStatus = z.enum(["Active", "Inactive"]); export const functionType = z.enum(["CaseAvailable", "CaseBuild", "CaseValidate", "CaseChange", "Case", "CaseRelationBuild", "CaseRelationValidate", "CaseRelation", "CollectorStart", "CollectorApply", "CollectorEnd", "Collector", "WageTypeValue", "WageTypeResult", "WageType", "PayrunStart", "PayrunEmployeeAvailable", "PayrunEmployeeStart", "PayrunEmployeeEnd", "PayrunWageTypeAvailable", "PayrunEnd", "PayrunBase", "Payrun", "Payroll", "ReportBuild", "ReportStart", "ReportEnd", "Report", "All"]); export const overrideType = z.enum(["Active", "Inactive"]); export const script = z.object({id: z.number().int().optional(), status: objectStatus.optional(), created: z.string().optional(), updated: z.string().optional(), name: z.string().max(128), functionTypes: z.array(functionType).nullable().optional(), value: z.string().min(1), overrideType: overrideType.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}/scripts */ export const createApiApiTenantsTenantIdRegulationsRegulationIdScripts = async (args: CreateApiApiTenantsTenantIdRegulationsRegulationIdScriptsArgs, options: CreateApiApiTenantsTenantIdRegulationsRegulationIdScriptsOptions) => { 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))}/scripts${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(script, await res.json()) };