import {z} from 'zod' export type GetApiV2TicketsTicketIdCustomFieldValuesArgs = {ticket_id: string}; export type GetApiV2TicketsTicketIdCustomFieldValuesOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const svstoreEntityTypeFieldDataType = z.enum(["DATA_TYPE_UNSPECIFIED", "TEXT", "NUMBER", "BOOL", "TIMESTAMP", "ENUM", "ENTITY_REF", "USER_REF", "UNIQUE", "MULTI_SELECT", "FILE"]); export const googleProtobufValue = z.union([z.number(), z.string(), z.boolean(), z.array(z.unknown()), z.record(z.string(), z.unknown())]).nullable(); export const googleProtobufTimestamp = z.string(); export const svstoreEntityFieldValue = z.object({id: z.string().optional(), entityId: z.string().optional(), fieldId: z.string().optional(), fieldKey: z.string().optional(), fieldName: z.string().optional(), dataType: svstoreEntityTypeFieldDataType.optional(), value: googleProtobufValue.optional(), setByUserId: z.string().nullable().optional(), setByAppInstanceId: z.string().nullable().optional(), createdAt: googleProtobufTimestamp.optional(), deletedAt: googleProtobufTimestamp.optional(), pinned: z.boolean().optional()}); export const svstoreEnumOption = z.object({id: z.string().optional(), value: z.string().optional(), displayName: z.string().optional(), displayOrder: z.number().int().optional()}); export const svstoreEntityTypeField = z.object({id: z.string().optional(), entityTypeId: z.string().optional(), key: z.string().optional(), name: z.string().optional(), dataType: svstoreEntityTypeFieldDataType.optional(), createdAt: googleProtobufTimestamp.optional(), updatedAt: googleProtobufTimestamp.optional(), createdByUserId: z.string().optional(), updatedByUserId: z.string().optional(), enumOptions: z.array(svstoreEnumOption).optional(), isKeyField: z.boolean().optional(), isNameField: z.boolean().optional(), refEntityTypeId: z.string().nullable().optional(), description: z.string().nullable().optional(), sourceEntityTypeId: z.string().nullable().optional(), sectionId: z.string().nullable().optional()}); export const svhelpModelsCustomFieldValue = z.object({fieldValue: svstoreEntityFieldValue.optional(), field: svstoreEntityTypeField.optional()}); export const svstoreEntityFieldSection = z.object({id: z.string().optional(), entityTypeId: z.string().optional(), name: z.string().optional(), sourceEntityTypeId: z.string().nullable().optional(), createdAt: googleProtobufTimestamp.optional(), updatedAt: googleProtobufTimestamp.optional(), createdByUserId: z.string().optional(), updatedByUserId: z.string().optional()}); export const svhelpModelsCustomFieldGroup = z.object({section: svstoreEntityFieldSection.optional(), customFields: z.array(svhelpModelsCustomFieldValue).optional()}); export const svhelpPublicapiGetTicketCustomFieldValuesResponse = z.object({customFields: z.array(svhelpModelsCustomFieldValue).optional(), deprecatedFields: z.array(svhelpModelsCustomFieldValue).optional(), customFieldGroups: z.array(svhelpModelsCustomFieldGroup).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 }; /** * Get Ticket Custom Field Values * * GET /v2/tickets/{ticket_id}/custom-field-values */ export const getApiV2TicketsTicketIdCustomFieldValues = async (args: GetApiV2TicketsTicketIdCustomFieldValuesArgs, options?: GetApiV2TicketsTicketIdCustomFieldValuesOptions) => { const {baseUrl = "https://public.api.serval.com", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/tickets/${encodeURIComponent(String(args.ticket_id))}/custom-field-values${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(svhelpPublicapiGetTicketCustomFieldValuesResponse, await res.json()) };