import {z} from 'zod' export type AttachmentRef = {'@type'?: string | undefined, '@baseType'?: string | undefined, '@schemaLocation'?: string | undefined, id?: string | undefined, href?: string | undefined, name?: string | undefined, '@referredType'?: string | undefined, description?: string | undefined, url?: string | undefined}; export type Quantity = {amount?: number | undefined, units?: string | undefined}; export type TimePeriod = {endDateTime?: string | undefined, startDateTime?: string | undefined}; export type Attachment = {'@type'?: string | undefined, '@baseType'?: string | undefined, '@schemaLocation'?: string | undefined, id?: string | undefined, href?: string | undefined, attachmentType?: string | undefined, content?: string | undefined, description?: string | undefined, mimeType?: string | undefined, name?: string | undefined, url?: string | undefined, size?: Quantity | undefined, validFor?: TimePeriod | undefined}; export type AttachmentRefOrValue = {'@type'?: string | undefined, '@baseType'?: string | undefined, '@schemaLocation'?: string | undefined, ref?: AttachmentRef | undefined, value?: Attachment | undefined}; export type ChannelRef = {'@type'?: string | undefined, '@baseType'?: string | undefined, '@schemaLocation'?: string | undefined, id?: string | undefined, href?: string | undefined, name?: string | undefined, '@referredType'?: string | undefined}; export type Note = {'@type'?: string | undefined, '@baseType'?: string | undefined, '@schemaLocation'?: string | undefined, id?: string | undefined, author?: string | undefined, date?: string | undefined, text?: string | undefined}; export type RelatedEntity = {'@type'?: string | undefined, '@baseType'?: string | undefined, '@schemaLocation'?: string | undefined, id: string, href?: string | undefined, name?: string | undefined, role: string, '@referredType': string}; export type RelatedParty = {'@type'?: string | undefined, '@baseType'?: string | undefined, '@schemaLocation'?: string | undefined, id: string, href?: string | undefined, name?: string | undefined, role?: string | undefined, '@referredType': string}; export type TroubleTicketStatusType = 'submitted' | 'acknowledged' | 'rejected' | 'pending' | 'held' | 'inProgress' | 'cancelled' | 'closed' | 'resolved'; export type TroubleTicketRelationship = {'@type'?: string | undefined, '@baseType'?: string | undefined, '@schemaLocation'?: string | undefined, id?: string | undefined, href?: string | undefined, name?: string | undefined, relationshipType?: string | undefined}; export type TroubleTicketUpdate = {'@type'?: string | undefined, '@baseType'?: string | undefined, '@schemaLocation'?: string | undefined, description?: string | undefined, expectedResolutionDate?: string | undefined, externalId?: string | undefined, name?: string | undefined, priority?: string | undefined, requestedResolutionDate?: string | undefined, resolutionDate?: string | undefined, severity?: string | undefined, statusChangeReason?: string | undefined, ticketType?: string | undefined, attachment?: Array | undefined, channel?: ChannelRef | undefined, note?: Array | undefined, relatedEntity?: Array | undefined, relatedParty?: Array | undefined, status?: TroubleTicketStatusType | undefined, troubleTicketRelationship?: Array | undefined}; export type PatchApiTroubleTicketIdArgs = {id: string, body: TroubleTicketUpdate}; export type PatchApiTroubleTicketIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const attachmentRef = z.object({"@type": z.string().optional(), "@baseType": z.string().optional(), "@schemaLocation": z.string().optional(), id: z.string().optional(), href: z.string().optional(), name: z.string().optional(), "@referredType": z.string().optional(), description: z.string().optional(), url: z.string().optional()}); export const quantity = z.object({amount: z.number().optional(), units: z.string().optional()}); export const timePeriod = z.object({endDateTime: z.string().optional(), startDateTime: z.string().optional()}); export const attachment = z.object({"@type": z.string().optional(), "@baseType": z.string().optional(), "@schemaLocation": z.string().optional(), id: z.string().optional(), href: z.string().optional(), attachmentType: z.string().optional(), content: z.string().optional(), description: z.string().optional(), mimeType: z.string().optional(), name: z.string().optional(), url: z.string().optional(), size: quantity.optional(), validFor: timePeriod.optional()}); export const attachmentRefOrValue = z.object({"@type": z.string().optional(), "@baseType": z.string().optional(), "@schemaLocation": z.string().optional(), ref: attachmentRef.optional(), value: attachment.optional()}); export const channelRef = z.object({"@type": z.string().optional(), "@baseType": z.string().optional(), "@schemaLocation": z.string().optional(), id: z.string().optional(), href: z.string().optional(), name: z.string().optional(), "@referredType": z.string().optional()}); export const note = z.object({"@type": z.string().optional(), "@baseType": z.string().optional(), "@schemaLocation": z.string().optional(), id: z.string().optional(), author: z.string().optional(), date: z.string().optional(), text: z.string().optional()}); export const relatedEntity = z.object({"@type": z.string().optional(), "@baseType": z.string().optional(), "@schemaLocation": z.string().optional(), id: z.string(), href: z.string().optional(), name: z.string().optional(), role: z.string(), "@referredType": z.string()}); export const relatedParty = z.object({"@type": z.string().optional(), "@baseType": z.string().optional(), "@schemaLocation": z.string().optional(), id: z.string(), href: z.string().optional(), name: z.string().optional(), role: z.string().optional(), "@referredType": z.string()}); export const troubleTicketStatusType = z.enum(["submitted", "acknowledged", "rejected", "pending", "held", "inProgress", "cancelled", "closed", "resolved"]); export const statusChange = z.object({"@type": z.string().optional(), "@baseType": z.string().optional(), "@schemaLocation": z.string().optional(), changeDate: z.string().optional(), changeReason: z.string().optional(), status: z.string().optional()}); export const troubleTicketRelationship = z.object({"@type": z.string().optional(), "@baseType": z.string().optional(), "@schemaLocation": z.string().optional(), id: z.string().optional(), href: z.string().optional(), name: z.string().optional(), relationshipType: z.string().optional()}); export const troubleTicket = z.object({"@type": z.string().optional(), "@baseType": z.string().optional(), "@schemaLocation": z.string().optional(), id: z.string().optional(), href: z.string().optional(), creationDate: z.string().optional(), description: z.string().optional(), expectedResolutionDate: z.string().optional(), externalId: z.string().optional(), lastUpdate: z.string().optional(), name: z.string().optional(), priority: z.string().optional(), requestedResolutionDate: z.string().optional(), resolutionDate: z.string().optional(), severity: z.string().optional(), statusChangeDate: z.string().optional(), statusChangeReason: z.string().optional(), ticketType: z.string().optional(), attachment: z.array(attachmentRefOrValue).optional(), channel: channelRef.optional(), note: z.array(note).optional(), relatedEntity: z.array(relatedEntity).optional(), relatedParty: z.array(relatedParty).optional(), status: troubleTicketStatusType.optional(), statusChange: z.array(statusChange).optional(), troubleTicketRelationship: z.array(troubleTicketRelationship).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 partially a TroubleTicket * * PATCH /troubleTicket/{id} */ export const patchApiTroubleTicketId = async (args: PatchApiTroubleTicketIdArgs, options?: PatchApiTroubleTicketIdOptions) => { const {baseUrl = "https://serverRoot/tmf-api/troubleTicket/v4", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json;charset=utf-8") headers.set('accept', "application/json;charset=utf-8") const url = `${baseUrl.replace(/\/+$/, '')}/troubleTicket/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(troubleTicket, await res.json()) };