import {z} from 'zod' 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 GetApiApiTenantsTenantIdSystemPropertiesArgs = {tenantId: number, functionType?: FunctionType | undefined, readOnly?: boolean | undefined}; export type GetApiApiTenantsTenantIdSystemPropertiesOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; 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 actionSource = z.enum(["Script", "System"]); export const actionParameterInfo = z.object({name: z.string().min(1), description: z.string().nullable().optional(), valueTypes: z.array(z.string()).nullable().optional(), valueSources: z.array(z.string()).nullable().optional(), valueReferences: z.array(z.string()).nullable().optional()}); export const actionIssueInfo = z.object({name: z.string().min(1), message: z.string().nullable().optional(), parameterCount: z.number().int().optional()}); export const actionInfo = z.object({name: z.string().min(1), functionType: functionType.optional(), namespace: z.string().nullable().optional(), description: z.string().nullable().optional(), categories: z.array(z.string()).nullable().optional(), source: actionSource.optional(), parameters: z.array(actionParameterInfo).nullable().optional(), issues: z.array(actionIssueInfo).nullable().optional()}); export const getApiApiTenantsTenantIdSystemPropertiesResponse = z.array(actionInfo); 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 }; /** * GET /api/tenants/{tenantId}/system/properties */ export const getApiApiTenantsTenantIdSystemProperties = async (args: GetApiApiTenantsTenantIdSystemPropertiesArgs, options: GetApiApiTenantsTenantIdSystemPropertiesOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.functionType != null) query.append("functionType", String(args.functionType)) if (args.readOnly != null) query.append("readOnly", String(args.readOnly)) const url = `${baseUrl.replace(/\/+$/, '')}/api/tenants/${encodeURIComponent(String(args.tenantId))}/system/properties${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiApiTenantsTenantIdSystemPropertiesResponse, await res.json()) };