import {z} from 'zod' export type ContractTemplateCreateDto = {name?: string | undefined, description?: string | undefined, workDays?: string | undefined, weeklyHours?: number | undefined, dailyHours?: number | undefined, breakMinutesRequired?: number | undefined, breakThresholdMinutes?: number | undefined, salaryType?: string | undefined, vacationDaysAnnual?: number | undefined, sickLeavePaidDays?: number | undefined, employmentModelId?: string | undefined, holidayCollectionId?: string | undefined, countryCode?: string | undefined}; export type CreateApiV1OrganizationsOrgIdContractTemplatesArgs = {orgId: string, body: ContractTemplateCreateDto}; export type CreateApiV1OrganizationsOrgIdContractTemplatesOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const contractTemplateDto = z.object({id: z.string().optional(), organizationId: z.string().optional(), name: z.string().optional(), description: z.string().optional(), i18nKey: z.string().optional(), workDays: z.string().optional(), weeklyHours: z.number().optional(), dailyHours: z.number().optional(), breakMinutesRequired: z.number().int().optional(), breakThresholdMinutes: z.number().int().optional(), salaryType: z.string().optional(), vacationDaysAnnual: z.number().optional(), sickLeavePaidDays: z.number().int().optional(), employmentModelId: z.string().optional(), holidayCollectionId: z.string().optional(), countryCode: z.string().optional(), systemTemplate: z.boolean().optional(), active: z.boolean().optional(), lastUpdate: z.number().int().optional(), created: z.number().int().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 }; /** * Create contract template * * POST /v1/organizations/{orgId}/contract-templates * * Also accepts auth: apiKeyAuth */ export const createApiV1OrganizationsOrgIdContractTemplates = async (args: CreateApiV1OrganizationsOrgIdContractTemplatesArgs, options?: CreateApiV1OrganizationsOrgIdContractTemplatesOptions) => { const {baseUrl = "https://api.timesheet.io", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/organizations/${encodeURIComponent(String(args.orgId))}/contract-templates${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(contractTemplateDto, await res.json()) };