import {z} from 'zod' export type EntityReference = {entityId?: string | undefined, entityName?: string | undefined}; export type OnlyId = {id?: string | undefined}; export type CustomAttribute = {attributeDefinitionId?: string | undefined, booleanValue?: boolean | undefined, dateValue?: number | undefined, entityId?: string | undefined, entityReferences?: Array | undefined, numberValue?: unknown | undefined, selectedValueId?: string | undefined, selectedValues?: Array | undefined, stringValue?: string | undefined}; export type Ticket = {id?: string | undefined, version?: string | undefined, assignedPoolingGroupId?: string | undefined, assignedUserId?: string | undefined, billable?: boolean | undefined, billableStatus?: boolean | undefined, ccEmailAddresses?: string | undefined, contactId?: string | undefined, contractId?: string | undefined, createdDate?: number | undefined, customAttributes?: Array | undefined, description?: string | undefined, disableEmailTemplates?: boolean | undefined, email?: string | undefined, entityReferences?: Array | undefined, finishedDate?: number | undefined, firstName?: string | undefined, followUpDate?: number | undefined, invoicingStatus?: ('INVOICED' | 'NOT_INVOICED' | 'PARTLY_INVOICED') | undefined, isTemplate?: boolean | undefined, language?: string | undefined, lastModifiedDate?: number | undefined, lastName?: string | undefined, legacyArticleId?: string | undefined, legacyTimeAndMaterialTicket?: boolean | undefined, mail2TicketId?: string | undefined, mobilePhoneNumber?: string | undefined, note?: string | undefined, partyId?: string | undefined, performanceRecordedStatus?: ('NOT_PERFORMANCE_RECORDABLE' | 'ON_PERFORMANCE_RECORD' | 'PERFORMANCE_RECORDABLE' | 'PERFORMANCE_RECORDED') | undefined, phoneNumber?: string | undefined, publicPageExpirationDate?: number | undefined, publicPageUuid?: string | undefined, resolvedYourIssue?: boolean | undefined, responsibleUserId?: string | undefined, room?: string | undefined, salesOrderId?: string | undefined, solutionDueDate?: number | undefined, subject?: string | undefined, tags?: Array | undefined, ticketCategoryId?: string | undefined, ticketChannelId?: string | undefined, ticketNumber?: string | undefined, ticketPriorityId: string, ticketRating?: ('STARS_1' | 'STARS_2' | 'STARS_3' | 'STARS_4' | 'STARS_5') | undefined, ticketRatingComment?: string | undefined, ticketRatingDate?: number | undefined, ticketServiceLevelAgreementId?: string | undefined, ticketStatusId: string, ticketTypeId?: string | undefined, watchers?: Array | undefined}; export type UpdateApiTicketIdIdArgs = {id: string, dryRun?: boolean | undefined, body: Ticket}; export type UpdateApiTicketIdIdOptions = {baseUrl: string, APIToken?: string | undefined, fetch?: typeof fetch | undefined}; export const entityReference = z.object({entityId: z.string().optional(), entityName: z.string().optional()}); export const onlyId = z.object({id: z.string().optional()}); export const customAttribute = z.object({attributeDefinitionId: z.string().optional(), booleanValue: z.boolean().optional(), dateValue: z.number().int().optional(), entityId: z.string().optional(), entityReferences: z.array(entityReference).optional(), numberValue: z.string().optional(), selectedValueId: z.string().optional(), selectedValues: z.array(onlyId).optional(), stringValue: z.string().optional()}); export const ticket = z.object({id: z.string().optional(), version: z.string().optional(), assignedPoolingGroupId: z.string().optional(), assignedUserId: z.string().optional(), billable: z.boolean().optional(), billableStatus: z.boolean().optional(), ccEmailAddresses: z.string().optional(), contactId: z.string().optional(), contractId: z.string().optional(), createdDate: z.number().int().optional(), customAttributes: z.array(customAttribute).optional(), description: z.string().optional(), disableEmailTemplates: z.boolean().optional(), email: z.string().optional(), entityReferences: z.array(entityReference).optional(), finishedDate: z.number().int().optional(), firstName: z.string().optional(), followUpDate: z.number().int().optional(), invoicingStatus: z.enum(["INVOICED", "NOT_INVOICED", "PARTLY_INVOICED"]).optional(), isTemplate: z.boolean().optional(), language: z.string().optional(), lastModifiedDate: z.number().int().optional(), lastName: z.string().optional(), legacyArticleId: z.string().optional(), legacyTimeAndMaterialTicket: z.boolean().optional(), mail2TicketId: z.string().optional(), mobilePhoneNumber: z.string().optional(), note: z.string().optional(), partyId: z.string().optional(), performanceRecordedStatus: z.enum(["NOT_PERFORMANCE_RECORDABLE", "ON_PERFORMANCE_RECORD", "PERFORMANCE_RECORDABLE", "PERFORMANCE_RECORDED"]).optional(), phoneNumber: z.string().optional(), publicPageExpirationDate: z.number().int().optional(), publicPageUuid: z.string().optional(), resolvedYourIssue: z.boolean().optional(), responsibleUserId: z.string().optional(), room: z.string().optional(), salesOrderId: z.string().optional(), solutionDueDate: z.number().int().optional(), subject: z.string().optional(), tags: z.array(z.string()).optional(), ticketCategoryId: z.string().optional(), ticketChannelId: z.string().optional(), ticketNumber: z.string().optional(), ticketPriorityId: z.string(), ticketRating: z.enum(["STARS_1", "STARS_2", "STARS_3", "STARS_4", "STARS_5"]).optional(), ticketRatingComment: z.string().optional(), ticketRatingDate: z.number().int().optional(), ticketServiceLevelAgreementId: z.string().optional(), ticketStatusId: z.string(), ticketTypeId: z.string().optional(), watchers: z.array(onlyId).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 }; /** * update ticket * * PUT /ticket/id/{id} */ export const updateApiTicketIdId = async (args: UpdateApiTicketIdIdArgs, options: UpdateApiTicketIdIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, APIToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.dryRun != null) query.append("dryRun", String(args.dryRun)) if (APIToken !== undefined) headers.set("AuthenticationToken", APIToken) const url = `${baseUrl.replace(/\/+$/, '')}/ticket/id/${encodeURIComponent(String(args.id))}${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(ticket, await res.json()) };