import {z} from 'zod' export type UpdateApiV2BillingTicketTimeEntryTimeEntryIdArgs = {timeEntryId: number, body: {startDate?: string | undefined, remote?: boolean | undefined, inHours?: ({agreementId?: number | undefined, agreementProductId?: number | undefined, billingType?: ('BILLABLE' | 'NOT_BILLABLE' | 'NO_CHARGE') | undefined, timeTracked?: number | undefined, agreementOriginType?: ('NONE' | 'SELF' | 'TICKET') | undefined}) | undefined, offHours?: ({agreementId?: number | undefined, agreementProductId?: number | undefined, billingType?: ('BILLABLE' | 'NOT_BILLABLE' | 'NO_CHARGE') | undefined, timeTracked?: number | undefined, agreementOriginType?: ('NONE' | 'SELF' | 'TICKET') | undefined}) | undefined}}; export type UpdateApiV2BillingTicketTimeEntryTimeEntryIdOptions = {baseUrl: string, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const updateApiV2BillingTicketTimeEntryTimeEntryIdResponse = z.object({id: z.number().int().optional(), ticketId: z.number().int().optional(), timeTracked: z.number().int().optional(), startDate: z.number().optional(), remote: z.boolean().optional(), createTime: z.number().optional(), updateTime: z.number().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 }; /** * Updates PSA properties of a ticket time entry * * PUT /v2/billing/ticket-time-entry/{timeEntryId} * * Also accepts auth: sessionKey */ export const updateApiV2BillingTicketTimeEntryTimeEntryId = async (args: UpdateApiV2BillingTicketTimeEntryTimeEntryIdArgs, options: UpdateApiV2BillingTicketTimeEntryTimeEntryIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/billing/ticket-time-entry/${encodeURIComponent(String(args.timeEntryId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(updateApiV2BillingTicketTimeEntryTimeEntryIdResponse, await res.json()) };