import {z} from 'zod' export type SvhelpModelsSlaConditionRule = {type?: string | undefined, field?: string | undefined, op?: string | undefined, value?: string | undefined, values?: Array | undefined, logicOp?: string | undefined}; export type SvhelpModelsSlaStartingPoint = 'SLA_STARTING_POINT_UNSPECIFIED' | 'SLA_STARTING_POINT_FROM_ATTACHMENT' | 'SLA_STARTING_POINT_FROM_CREATION'; export type SvhelpModelsSlaMetric = 'SLA_METRIC_UNSPECIFIED' | 'SLA_METRIC_RESOLUTION' | 'SLA_METRIC_FIRST_RESPONSE'; export type PatchApiV2SlaDefinitionsIdArgs = {id: string, body: {name?: (string | null) | undefined, description?: (string | null) | undefined, targetDurationSeconds?: (number | null) | undefined, useCalendarTime?: (boolean | null) | undefined, scheduleId?: (string | null) | undefined, attachmentCriteria?: Array | undefined, clearAttachmentCriteria?: (boolean | null) | undefined, startingPoint?: SvhelpModelsSlaStartingPoint | undefined, metric?: SvhelpModelsSlaMetric | undefined}}; export type PatchApiV2SlaDefinitionsIdOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const svhelpModelsSlaConditionType = z.enum(["SLA_CONDITION_TYPE_UNSPECIFIED", "SLA_CONDITION_TYPE_PAUSE", "SLA_CONDITION_TYPE_STOP"]); export const svhelpModelsSlaConditionRule = z.object({type: z.string().optional(), field: z.string().optional(), op: z.string().optional(), value: z.string().optional(), values: z.array(z.string()).optional(), logicOp: z.string().optional()}); export const svhelpModelsSlaCondition = z.object({id: z.string().optional(), slaDefinitionId: z.string().optional(), conditionType: svhelpModelsSlaConditionType.optional(), conditionRule: svhelpModelsSlaConditionRule.optional(), resumePolicy: z.string().optional(), priority: z.number().int().optional()}); export const googleProtobufTimestamp = z.string(); export const svhelpModelsSlaActionDefinition = z.object({id: z.string().optional(), slaDefinitionId: z.string().optional(), offsetSeconds: z.number().int().optional(), workflowId: z.string().optional(), createdAt: googleProtobufTimestamp.optional(), updatedAt: googleProtobufTimestamp.optional()}); export const svhelpModelsSlaStartingPoint = z.enum(["SLA_STARTING_POINT_UNSPECIFIED", "SLA_STARTING_POINT_FROM_ATTACHMENT", "SLA_STARTING_POINT_FROM_CREATION"]); export const svhelpModelsSlaMetric = z.enum(["SLA_METRIC_UNSPECIFIED", "SLA_METRIC_RESOLUTION", "SLA_METRIC_FIRST_RESPONSE"]); export const svhelpModelsSlaDefinition = z.object({id: z.string().optional(), teamId: z.string().optional(), name: z.string().optional(), description: z.string().optional(), targetDurationSeconds: z.number().int().optional(), useCalendarTime: z.boolean().optional(), scheduleId: z.string().optional(), conditions: z.array(svhelpModelsSlaCondition).optional(), createdAt: googleProtobufTimestamp.optional(), updatedAt: googleProtobufTimestamp.optional(), attachmentCriteria: z.array(svhelpModelsSlaConditionRule).optional(), actionDefinitions: z.array(svhelpModelsSlaActionDefinition).optional(), startingPoint: svhelpModelsSlaStartingPoint.optional(), metric: svhelpModelsSlaMetric.optional(), archivedAt: googleProtobufTimestamp.optional()}); export const svhelpPublicapiUpdateSlaDefinitionResponse = z.object({data: svhelpModelsSlaDefinition.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 SLA Definition * * PATCH /v2/sla-definitions/{id} */ export const patchApiV2SlaDefinitionsId = async (args: PatchApiV2SlaDefinitionsIdArgs, options?: PatchApiV2SlaDefinitionsIdOptions) => { const {baseUrl = "https://public.api.serval.com", 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(/\/+$/, '')}/v2/sla-definitions/${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(svhelpPublicapiUpdateSlaDefinitionResponse, await res.json()) };